ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Moveit set_to_pose tuple attribute x issue

asked 2019-03-09 16:40:29 -0500

sisko gravatar image

updated 2019-03-10 11:31:18 -0500

I need help with my attempts to create a pose from my transform listener object. The tf listener is successfully delivering data but my problems begin when I try creating a pose object from the tf data, using the code below:

def __init__(self):
  self.tf_buffer = tf2_ros.Buffer()
  self.tf_listener = tf2_ros.TransformListener(self.tf_buffer)

  rospy.sleep(5)

  try:
    if self.tf_buffer.can_transform('wrist_3_link', 'base_footprint', rospy.Time()) :

      self.transform_stamped = self.tf_buffer.lookup_transform('wrist_3_link', 'base_footprint', rospy.Time())

      pose = Pose()
      pose.position = self.transform_stamped.transform.translation
      pose.orientation = euler_from_quaternion((
        self.transform_stamped.transform.rotation.x, 
        self.transform_stamped.transform.rotation.y, 
        self.transform_stamped.transform.rotation.z, 
        self.transform_stamped.transform.rotation.w
      ))

      self.move_to_pose(pose)

  except (tf2_ros.LookupException, tf2_ros.ConnectivityException, tf2_ros.ExtrapolationException) as e:
    rospy.logerr(e)


  def move_to_pose(self, pose):
    rospy.loginfo(pose)
    self.manipulator.set_pose_target(pose)
    plan = self.manipulator.plan()
    self.manipulator.execute(plan)

Which yields the following error:

[INFO] [1552167988.940291, 5.015000]: 
position:    
x: 0.816988026247   
y: -0.109039832758   
z: -0.00443080091744
 orientation: [3.141573333853047, -0.00452701380180146, 3.140211345214987] 

Traceback (most recent call last):   File "/home/sisko/moveit_ws/src/ur5bot_moveit_config/nodes/moveit_goal.py", line 359, in <module>
        TrackBot()   File "/home/sisko/moveit_ws/src/ur5bot_moveit_config/nodes/moveit_goal.py", line 81, in __init__
        self.transform()   File "/home/sisko/moveit_ws/src/ur5bot_moveit_config/nodes/moveit_goal.py", line 115, in transform
        self.move_to_pose(pose)   File "/home/sisko/moveit_ws/src/ur5bot_moveit_config/nodes/moveit_goal.py", line 290, in move_to_pose
        self.manipulator.set_pose_target(pose) File "/opt/ros/kinetic/lib/python2.7/dist-packages/moveit_commander/move_group.py", line 274, in set_pose_target
        ok = self._g.set_pose_target(conversions.pose_to_list(pose), end_effector_link)   File "/opt/ros/kinetic/lib/python2.7/dist-packages/moveit_commander/conversions.py", line 54, in pose_to_list
        pose.append(pose_msg.orientation.x) AttributeError: 'tuple' object has no attribute 'x'

I been working at finding a solution for hours. I would appreciate the help of a fresh pair of eyes.

UPDATE: Just including an example of the data from the transform listener.

************************* Transform Data: 
[INFO] [1552233229.396174, 6.727000]: header: 
  seq: 0
  stamp: 
    secs: 6
    nsecs: 701000000
  frame_id: "wrist_3_link"
child_frame_id: "base_footprint"
transform: 
  translation: 
    x: 0.816964133008
    y: -0.109003488461
    z: -0.00442450622864
  rotation: 
    x: -0.00110212544585
    y: -0.999997191233
    z: -1.36438458498e-05
    w: 0.00209825162089
****************************************
edit retag flag offensive close merge delete

Comments

 pose = Pose()

Is pose a geometry_msgs/Pose? If so, the orientation field is already a Quaternion, so I'm unsure as to why you are using euler_from_quaternion(..).

Note: a geometry_msgs/Pose is almost identical to a geometry_msgs/Transform.

gvdhoorn gravatar image gvdhoorn  ( 2019-03-10 01:23:24 -0500 )edit

And minor comment: I don't believe calling methods on an object instance inside its own constructor is recommended/safe (ie: calling move_to_pose(..) from __init__(..)).

gvdhoorn gravatar image gvdhoorn  ( 2019-03-10 01:24:43 -0500 )edit

Hi @gvdhoom. Thanks for your answer. Regarding if the rotation data is already a quaternion or not, I am not sure. If a quaternion is an object, the raw rotation data does not seem to be an object.

I included a rospy.loginfo example output of my tf data in my question so you can see what I'm working with.

sisko gravatar image sisko  ( 2019-03-10 11:38:13 -0500 )edit

Thank you @gvdhoom. I understand your point - finally :-)

sisko gravatar image sisko  ( 2019-03-10 13:16:44 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-03-10 11:40:13 -0500

This problem is being caused because you're using euler_from_quaternion. This function converts a quaternion object into a list containing three Euler angles as described here. As @gvdhoorn pointed out the pose object stores the orientation as a quaternion not Euler angles, so you're altering the data structure which is the cause of the error you posted.

You can simply copy the translation and rotation from the transform object into the pose object, no conversion is necessary. This should solve the problem you're having here.

edit flag offensive delete link more

Comments

Hmmm!!!

I feel like such a DOH-nut!

sisko gravatar image sisko  ( 2019-03-10 13:14:59 -0500 )edit

It happens to us all at times!

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-03-10 18:53:45 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-09 16:40:29 -0500

Seen: 515 times

Last updated: Mar 10 '19