0
$\begingroup$

I'm trying to create a client to send a goal to the move_group server via Python.

Here is my code snippet:

client = actionlib.SimpleActionClient('move_group', moveit_msgs.msg.MoveGroupAction)

client.wait_for_server()
    
MoveGroupGoal = moveit_msgs.msg.MoveGroupGoal()

start_state_ = moveit_msgs.msg.RobotState()
start_state_.joint_state = [0, 1.2, 0, 0.2, 0, -0.8, 0]
MoveGroupGoal.request.start_state = start_state_

posestamped = geometry_msgs.msg.PoseStamped()
posestamped.header.frame_id = "base_link"
posestamped.pose.orientation.w = 0.025
posestamped.pose.orientation.x = 0.0
posestamped.pose.orientation.y = 1.0
posestamped.pose.orientation.z = 0.0
posestamped.pose.position.x = 0.3
posestamped.pose.position.y = 0.0
posestamped.pose.position.z = 0.8

tolerance_position = 0.1
tolerance_orientation = 0.1

constraint_goal = moveit.core.kinematic_constraints.constructGoalConstraints(
    "tool0", posestamped, tolerance_position, tolerance_orientation)

MoveGroupGoal.request.goal_constraints = constraint_goal

client.send_goal(MoveGroupGoal)

client.wait_for_result()

return client.get_result()

Before running the above code, the demo.launch in the MoveIt package has been launched.

However, when the program executed to line client.send_goal(MoveGroupGoal), I met the following error

  File "/opt/ros/noetic/lib/python3/dist-packages/actionlib/simple_action_client.py", line 92, in send_goal
    self.gh = self.action_client.send_goal(goal, self._handle_transition, self._handle_feedback)
  File "/opt/ros/noetic/lib/python3/dist-packages/actionlib/action_client.py", line 561, in send_goal
    return self.manager.init_goal(goal, transition_cb, feedback_cb)
  File "/opt/ros/noetic/lib/python3/dist-packages/actionlib/action_client.py", line 466, in init_goal
    self.send_goal_fn(action_goal)
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 882, in publish
    self.impl.publish(data)
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 1066, in publish
    serialize_message(b, self.seq, message)
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/msg.py", line 152, in serialize_message
    msg.serialize(b)
  File "/home/xzc/mambaforge/envs/robostackenv/lib/python3.9/site-packages/moveit_msgs/msg/_MoveGroupActionGoal.py", line 917, in serialize
    buff.write(_get_struct_6d3I().pack(_x.goal.request.workspace_parameters.min_corner.x, _x.goal.request.workspace_parameters.min_corner.y, _x.goal.request.workspace_parameters.min_corner.z, _x.goal.request.workspace_parameters.max_corner.x, _x.goal.request.workspace_parameters.max_corner.y, _x.goal.request.workspace_parameters.max_corner.z, _x.goal.request.start_state.joint_state.header.seq, _x.goal.request.start_state.joint_state.header.stamp.secs, _x.goal.request.start_state.joint_state.header.stamp.nsecs))
AttributeError: 'list' object has no attribute 'header'

Did I miss the definitions of some messages?

Thanks in advance!

$\endgroup$

1 Answer 1

0
$\begingroup$

joint_state should be a sensor_msgs/JointState msg not a list. If you search for "header" in the error msg you can see that it is trying to serialize the header in the joint state msg which doesn't exist because you passed a list. _x.goal.request.start_state.joint_state.header.stamp.secs

$\endgroup$
1
  • $\begingroup$ Thanks for the kind reminder that start_state_.joint_state.position can be assigned. $\endgroup$
    – KKKmelody
    Commented Sep 1, 2023 at 1:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.