Ask Your Question

AttributeError: 'Point' object has no attribute 'point'

asked 2017-11-06 22:16:48 -0500

Ravi Joshi gravatar image

I am transforming a point from source frame to target frame using tf2. Below is the code snippet:

import tf2_ros
import tf2_geometry_msgs

transform = tf_buffer.lookup_transform(target_frame, source_frame, rospy.Time(0), rospy.Duration(1.0))
pose_transformed = tf2_geometry_msgs.do_transform_point(point_wrt_kinect, transform)
print pose_transformed

It throws following error:

  pose_transformed = tf2_geometry_msgs.do_transform_point(point_wrt_kinect, transform)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/tf2_geometry_msgs/", line 59, in do_transform_point
    p = transform_to_kdl(transform) * PyKDL.Vector(point.point.x, point.point.y, point.point.z)
AttributeError: 'Point' object has no attribute 'point'

The point is defined as follows:

from geometry_msgs.msg import Point
point_wrt_kinect = Point()
point_wrt_kinect.x = -0.41
point_wrt_kinect.y = -0.13
point_wrt_kinect.z =  0.77

However, since I am getting the above error. So I redefined the point as follows

from geometry_msgs.msg import Point
class MyPoint():
    def __init__(self):
        self.point = Point()

And then initialize the point as below:

point_wrt_kinect = MyPoint()
point_wrt_kinect.point = Point(-0.41, -0.13, 0.77)

It works! However is a there better way to do it?

edit retag flag offensive close merge delete



BTW: That's a really well formulated question. It contains all the info and also your current solution. (and pose_transformed should be point_stamped)

NEngelhard gravatar image NEngelhard  ( 2017-11-07 00:41:26 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-11-07 00:38:28 -0500

NEngelhard gravatar image

updated 2017-11-07 01:02:38 -0500

I think the author had a PointStamped in mind when implementing the function. So you could could do something like

ps = geometry_msgs.msg.PointStamped(point=point_wrt_kinect)
pose_transformed = tf2_geometry_msgs.do_transform_point(ps, transform)

The code for the function is here: [ )

The function only uses the point-member of the passed point-variable so it for example does not check if the frame-id of a passed PointStamped-variable would fit to the frames of the transformation (the frame is here used to set the resulting frame of the returned PoseStamped).

So in the end, do_transform_point looks like it's processing objects with Headers but ignores them and only works on the raw points and transformation.

edit flag offensive delete link more


Suggestion: give it a stamp and frame_id as well. Methods that take a PointStamped will probably assume that they can use the header.stamp and header.frame_id fields to lookup TF frames.

gvdhoorn gravatar image gvdhoorn  ( 2017-11-07 00:45:50 -0500 )edit

I expanded the answer a bit, the function ignores the frame of the Point. I think the function should print at least a warning if point_st.header.frame_id != transform.child_frame_id (if the point_st has a frame_id)

NEngelhard gravatar image NEngelhard  ( 2017-11-07 00:57:16 -0500 )edit

My comment was meant more for the 'general case' where one invokes methods that take *Stamped versions of objects.

I can see why this particular method wouldn't look at stamp, as you're already passing in the transform. But checking for the frame_id would perhaps be nice, as you write.

gvdhoorn gravatar image gvdhoorn  ( 2017-11-07 01:21:36 -0500 )edit

Thank you very much.

Ravi Joshi gravatar image Ravi Joshi  ( 2017-11-07 03:27:32 -0500 )edit
NEngelhard gravatar image NEngelhard  ( 2017-11-07 03:27:51 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-11-06 22:16:48 -0500

Seen: 1,386 times

Last updated: Nov 07 '17