我正在构建一个与Planner节点(ROS2 Action_server)交互的状态机节点(ROS2 Action_client)。在计划者节点的执行回调中,我需要发布一个主题(从同一节点)。动作运行时是否可以发布主题?
class PlanningProblemServer(Node):
def __init__(self): super().__init__('planning_problem_server')
self._action_server = ActionServer(self, PlanAid, 'planning_problem_sm',
execute_callback=self.execute_callback,
goal_callback=self.goal_callback,
cancel_callback=self.cancel_callback)
self._publisher = self.create_publisher(Bool, 'Planning_problem_data')
def goal_callback(self, goal_request): #Some code
def cancel_callback(self, goal_handle): #Some code
def execute_callback(self, goal_handle):
feedback_msg.feedback = "loading planning problem...!"
goal_handle.publish_feedback(feedback_msg)
msg = String()
msg.data = "abc"
self._publisher.publish(msg)
goal_handle.set_succeeded()
return result
def main(args=None):
rclpy.init(args=args)
minimal_action_server = PlanningProblemServer()
rclpy.spin(minimal_action_server)
minimal_action_server.destroy()
rclpy.shutdown()
if __name__ == '__main__': main()
使用上面的代码,我得到以下错误,
Traceback (most recent call last):
File "/home/developer/ros2_ws/ros2/src/planning_problem/planning_prob_pkg/planning_prob_node.py", line 102, in <module>
if __name__ == '__main__': main()
File "/home/developer/ros2_ws/ros2/src/planning_problem/planning_prob_pkg/planning_prob_node.py", line 96, in main
rclpy.spin(minimal_action_server)
File "/opt/ros/crystal/lib/python3.6/site-packages/rclpy/__init__.py", line 119, in spin
executor.spin_once()
File "/opt/ros/crystal/lib/python3.6/site-packages/rclpy/executors.py", line 572, in spin_once
raise handler.exception()
File "/opt/ros/crystal/lib/python3.6/site-packages/rclpy/task.py", line 206, in __call__
self._handler.send(None)
File "/opt/ros/crystal/lib/python3.6/site-packages/rclpy/action/server.py", line 323, in _execute_goal
execute_result = await await_or_execute(execute_callback, goal_handle)
File "/opt/ros/crystal/lib/python3.6/site-packages/rclpy/executors.py", line 92, in await_or_execute
return callback(*args)
File "/home/developer/ros2_ws/ros2/src/planning_problem/planning_prob_pkg/planning_prob_node.py", line 59, in execute_callback
self._publisher.publish(msg)
File "/opt/ros/crystal/lib/python3.6/site-packages/rclpy/publisher.py", line 28, in publish
_rclpy.rclpy_publish(self.publisher_handle, msg)
ValueError: PyCapsule_GetPointer called with invalid PyCapsule object
答案 0 :(得分:0)
我对ros python界面不是很好
但是乍看之下,您是将发布者创建为bool类型吗 而您将其作为字符串发送?