[ROS2] Using sim time parameter, nodes time is always zero

asked 2019-08-25 14:16:50 -0500

madmax gravatar image

I am trying to get the current simulation time, but I always receive zeros..
As soon as I set use_sim_time back to false, I receive current system time.

Sim time should be working, shouldn't it?
I am on Dashing release.

Here is the code:

int main(int argc, char ** argv)
   rclcpp::init(argc, argv);

   rclcpp::Node node("timeTest");

   rclcpp::Parameter simTime( "use_sim_time", rclcpp::ParameterValue( true ) );
   node.set_parameter( simTime );
   auto useSimTime = node.get_parameter( "use_sim_time" ).as_bool();

   auto periodic_timer = node.create_wall_timer(
           [&]() {
               log_info( "time {}.{} useSimTime: {}", node.now().seconds(), node.now().nanoseconds(), useSimTime );


  return 0;
edit retag flag offensive close merge delete