0
$\begingroup$

ROS VERSION: Melodic OS VERSION: Ubuntu 18.04 package tf version: 1.12.1

I'm trying to create a node that processes a PolygonStamped object and transform each point of it to a especified frame_id in order to calculate prohibited regions.

I'm publishing for this example the tf from utm to map as a traslation 5,5,0 (x,y,z) and no rotation.

Here is the fragment where I try to set up the transformation process:

        for zone in zones_dict:
            obj = PolygonStamped()
            obj.header.stamp = rospy.get_time()
            obj.header.frame_id = 'utm'
            obj.header.frame_id = zones_dict[zone]['frame_id']

            for point in zones_dict[zone]['points']:
                point_stamped = PointStamped()
                point_stamped.header.frame_id = str(zones_dict[zone]['frame_id'])
                point_stamped.header.stamp = rospy.Time.now()
                point_stamped.point.x = point[0]
                point_stamped.point.y = point[1]
                point_stamped.point.z = point[2]
                print(point_stamped)

                point_transformed = self.tf_listener.transformPoint(str(obj.header.frame_id), point_stamped)
            
                print(point_transformed)
                point_formatted = Point32()
                point_formatted.x = point_transformed.point.x
                point_formatted.y = point_transformed.point.y
                point_formatted.z = point_transformed.point.z

                obj.polygon.points.append(point_formatted)

Variable point_stamped

header: 
  seq: 0
  stamp: 
    secs: 1706527825
    nsecs:  68283081
  frame_id: "map"
point: 
  x: 0.0
  y: 0.0
  z: 0.0

Variable point_transformed

header: 
  seq: 0
  stamp: 
    secs: 1706527825
    nsecs:  68283081
  frame_id: "map"
point: 
  x: 0.0
  y: 0.0
  z: 0.0

Supposed behaviour (point_transformed)

header: 
  seq: 0
  stamp: 
    secs: 1706527825
    nsecs:  68283081
  frame_id: "utm"
point: 
  x: 5.0
  y: 5.0
  z: 0.0

Why the function transformPoint returns me the same point_stamped? Also I'm not aware of the state of tf2 in this version, since I have worked with Noetic, but should I use tf2 even in this outdated distribution of ROS?

$\endgroup$
1
  • $\begingroup$ Forgot to mention that if I try to debug the function just using "utm" instead of obj.header.frame_id on the transformPoint there's a lookUp exception. But the transformation is being published using static_transform_publisher and quite fast. $\endgroup$
    – ÁngeLoGa
    Commented Jan 29 at 11:44

1 Answer 1

0
$\begingroup$

I have managed to solve this issue attaching a waitForTransform function each time brefore using the transformPoint method. Perhaps it is related to tf trying to extrapolate the result.

But, despite that I think this is not the best way to do due to having multiple areas defined by a bunch of points would last longer than needed. If someone has some experience on this, any feedback is appreciated.

$\endgroup$
2
  • $\begingroup$ It seems like you are repeatedly re-creating the self.tf_listener object. Don't do that. The better way is to create just one after the rospy.init_node(), and then reuse it everywhere. I often just assign it to a global variable. $\endgroup$
    – Mike973
    Commented Oct 26 at 18:00
  • $\begingroup$ Hey thanks for the comment Mike, it's been a while since this post hehe. But how did you manage to know that I was recreating the self.tf_listener object? In the code attached, it only shows that I use it to transform a point from a frame to another. I really hope I did as you said since it makes no sense to constantly recreate that variable $\endgroup$
    – ÁngeLoGa
    Commented Oct 27 at 22:46

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.