[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)
{
   logging::initializeLogger("simTimetest");
   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(
           100ms,
           [&]() {
               log_info( "time {}.{} useSimTime: {}", node.now().seconds(), node.now().nanoseconds(), useSimTime );
            });

   rclcpp::spin(node.get_node_base_interface());

   rclcpp::shutdown();
  return 0;
}
edit retag flag offensive close merge delete