Is it possible to get a robot static TF from params server?

asked 2020-07-16 05:37:24 -0500

schizzz8 gravatar image

updated 2020-07-16 05:38:43 -0500

Hi all,

I'm working on a robot equipped with an RGB-D camera.

The pose of the sensor is specified in an urdf file and I can see it has been properly set by running

~$ rosrun tf tf_echo base_link camera_link
At time 0.000
- Translation: [-0.104, 0.018, 0.980]
- Rotation: in Quaternion [0.000, 0.362, 0.000, 0.932]
            in RPY (radian) [0.000, 0.742, 0.000]
            in RPY (degree) [0.000, 42.500, 0.000]

My goal is to retrieve this transformation inside the node I'm implementing. Being a static tf, I can get it by calling a tf::Transformer::lookupTransform inside the constructor of my node:

bool got_tf = false;
while (!got_tf)
{
  try
  {
    listener_.lookupTransform(base_link_frame_id_, robot_camera_frame_id_,
                              ros::Time(0), camera_pose_);
  }
  catch (tf::TransformException ex)
  {
    ROS_ERROR("%s", ex.what());
    ros::Duration(1.0).sleep();
    continue;
  }
  got_tf = true;
}

However, I have some doubts regarding the efficiency of this method:

  1. I need to instantiate a tf::TransformListener
  2. It's possible that I have to wait some seconds

Therefore, my question is: is there another way (offered by roscpp) to get this transformation? Perhaps, it gets stored on the params server through the urdf?

Thanks

edit retag flag offensive close merge delete

Comments

2

To see whats on your param server you can use rosparam dump dump.yaml It saves the server data into the yaml file (the urdf should be in there).

Dragonslayer gravatar image Dragonslayer  ( 2020-07-16 10:00:03 -0500 )edit
2

To add more deep to @Dragonslayer comment, you can always use a yaml file with the following params:

my_tf:
  translation_x: 0.0
  translation_y: 0.0
  translation_z: 0.0
  rotation_x: 0.0
  rotation_y: 0.0
  rotation_z: 0.0
  rotation_w: 1.0

You can recover those set of params with:

std::map<std::string, double> map_tf;
nh.getParam("my_tf", map_tf);
Weasfas gravatar image Weasfas  ( 2020-07-17 03:10:26 -0500 )edit