Robotics StackExchange | Archived questions

runtime error from rclcpp::Time

I am getting the error terminate called after throwing an instance of 'std::runtime_error' what(): can't compare times with different time sources when I compare two rclcpp::Time object .

Below is the code

`

  rclcpp::Time last_published_(rclcpp::Time(std::numeric_limits<rcl_time_point_value_t>::min()))

  rclcpp::Time TIME_MIN = rclcpp::Time(std::numeric_limits<rcl_time_point_value_t>::min());

  rclcpp::Time header_stamp = msg->header.stamp;

  if (last_published_ != TIME_MIN  &&
        (((header_stamp - last_published_).nanoseconds()/1000*1000*1000) > 1.5 * (1.0 / expected_rate_)))

   {
    publish_rate_warnings_++;
   }

`

Any help would be appreciated.

Asked by Skyking on 2018-09-11 01:28:36 UTC

Comments

Answers

This is rather strange, but there are a couple of things you could try.

Can you test the code with the if statement only containing last_publisher_ != TIME_MIN just to confirm that is causing the problem. Also you want to change .nanoseconds()/1000*1000*1000 to either .nanoseconds()/1000000000 or .nanoseconds()/(1000*1000*1000)

Are you deliberately creating a rclcpp::Time object as a copy of another Time object in the following line? The difference in the style of construction between TIME_MIN and last_published_ may be causing this problem (even though it probably shouldn't!).

rclcpp::Time last_published_(rclcpp::Time(std::numeric_limits<rcl_time_point_value_t>::min()));

This could be more succinctly written as:

rclcpp::Time last_published_(std::numeric_limits<rcl_time_point_value_t>::min());

If you construct TIME_MIN in the same way as below it may help:

rclcpp::Time TIME_MIN(std::numeric_limits<rcl_time_point_value_t>::min());

Hope this helps.

Asked by PeteBlackerThe3rd on 2018-09-11 02:24:50 UTC

Comments

Time objects can have different clocks, see the optional argument: https://github.com/ros2/rclcpp/blob/b1af28047c26da0fe5723e3ea95ed1143bc224e5/rclcpp/include/rclcpp/time.hpp#L35 and with that clock there may be different time sources, such as simulated time or system time. It's only valid to compare times on the same epoch.

To read more see the design article: http://design.ros2.org/articles/clock_and_time.html

Asked by tfoote on 2018-09-11 02:49:18 UTC

Comments