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

transform (x,y,z) coordinate from kinect to /map frame using tf

asked 2017-04-19 10:55:36 -0500

cluelessnigerian gravatar image

Hi, I'm tracking an object using a kinect and trying to publish the tf transform of that object in a "/map frame. I'm able to return the object's x, y and depth data using OpenCV. However, I'm struggling with the tf stuff. I've written a function which is meant to update the transform

void updatetransform(double x, double y, double z)
     r = -1.5708;
     p = 0;
     y = -3.1415;

   static tf::TransformBroadcaster br;  

  transform.setOrigin(tf::Vector3(x, y, z));
  quaternion.setRPY(r,p,y);  //where r p y are fixed 

  br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "kinect2_ir_optical_frame","drone/base_link"));

  ROS_INFO("Sent Drone Transform at %f %f %f", x, y, z);


and in my launch file

  <node name = "Drone_Detector" pkg="detector" type="detect_drone" output="screen" />
  <node pkg="tf" type="static_transform_publisher" name="baselink" args="0 0 1 -1.5708 0 -1.5708 /map /kinect2_link 50" />

But when I run Rviz, using "/map" as a fixed frame, the drone/base_link tf isn't shown in the screen. I've attached a picture of what it looks like at this link. My x,y and depth values are okay from what the kinect but the transform is wrong. Am I doing something wrong here?

Also here's my tf_tree which looks about right to me. Link here

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-04-19 15:13:02 -0500

rbbg gravatar image

I don't see any obvious problems with the code, and it seems from your rviz screenshot that the base/drone_link is indeed present (I suspect it to be at the end of the yellow line.) Can you expand up the TF -> Frames tree and inspect the x y and z of the base/drone_link transform to confirm that they are what you expect them to be?

Perhaps it's a good idea to first test the updateTransform function with a know x y and z.

edit flag offensive delete link more


I took your advice and took a look at TF -> Frames. The X,Y,Z values in the relative position are about right for drone/base_link. Link Here.However, I'm not quite sure if I understand the output of the remaining values (orientation etc) so I'm not sure how to interpret

cluelessnigerian gravatar image cluelessnigerian  ( 2017-04-20 07:02:23 -0500 )edit

It seems to me that you don't see the transform on the screen simply because it is too large. the Y and Z values of -438 and -323 indicate that the frame will be very far away, and not in the default view. If you zoom out very far it should show up. I'm not sure I understand what the problem is.

rbbg gravatar image rbbg  ( 2017-04-20 13:53:03 -0500 )edit

I think I'm probably not calculating the transform properly. -438 and -323 are actual pixel positions of the object I'm tracking from the kinect. Surely there must be a way to transform them into a frame that actually shows up within the map frame.

cluelessnigerian gravatar image cluelessnigerian  ( 2017-04-20 14:02:27 -0500 )edit

Question Tools

1 follower


Asked: 2017-04-19 10:55:36 -0500

Seen: 1,262 times

Last updated: Apr 19 '17