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

Time system when using tf2 lookupTransform

asked 2023-07-02 20:19:15 -0500

hck007 gravatar image

Given I have a topic /tf in rosbag, I want to run the rosbag and use lookupTransform to get transform between different frames. The most usual way to get latest transform is lookupTransform("target_frame", "source_frame", rospy.Time(0)). What time system does the function lookupTransform use, does this function use the wall clock time of the computer calling the function lookupTransform, or does it use the timestamp in rosbag. Also, is there any difference when using lookupTransform("target_frame", "source_frame", rospy.Time(0)) and lookupTransform("target_frame", "source_frame", rospy.Time())

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-07-02 22:19:09 -0500

Guess Giant gravatar image

As mintar puts it:

The value of ros::time::now() depends on whether the parameter use_sim_time is set.

  1. If use_sim_time == false, ros::time::now() gives you system time (seconds since 1970-01-01 0:00, so something like > 1471868323.123456).
  2. If use_sim_time == true, and you play a rosbag, ros::time::now() gives you the time when the rosbag was recorded (probably also something like 1471868323.123456).
  3. If use_sim_time == true, and you run a simulator like Gazebo, ros::time::now() gives you the time from when the simulation was started, starting with zero (so probably something like 63.123456 if the simulator has been running for 63.123456 seconds).

So in your case if you want the nodes to use the time from where the rosbag was recorded, you have to append --clock to rosbag play so that it publishes simulated time in /clock, and well as set the param use_time_time before any other node starts in a fresh roscore instance.

There might not be a difference in rospy.TIme(0) and rospy.Time() because the default arguments are 0 anyway, see API.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2023-07-02 20:19:15 -0500

Seen: 179 times

Last updated: Jul 02 '23