ros2 / rviz

ROS 3D Robot Visualizer
BSD 3-Clause Clear License
302 stars 213 forks source link

Plugin use_sim_time has no effect #797

Open crabiner opened 2 years ago

crabiner commented 2 years ago

on ros2 galactic I have set "use_sim_time" to true on my custom panel for rviz but the clock is still machine clock and not simulated time I have tried setting the flag on runtime as well, and in callback loop I always see machine clock

see snippet below


ControlPanel::ControlPanel(QWidget* parent) : Panel(parent) 
{
    // Setup ROS2 functionality
    node_ = rclcpp::Node::make_shared("control_panel");
    node_->set_parameter(rclcpp::Parameter("use_sim_time", true));

    auto now = node_->get_clock()->now();
    RCLCPP_INFO(node_->get_logger(), std::to_string(now.nanoseconds()).c_str());

}

`[rviz2-1] [INFO] [1636397904.147354086] [control_panel]: 1636397904147343391`
dmorris0 commented 2 years ago

I have the same problem. I tried setting use_sim_time with the command line: ros2 param set /rviz use_sim_time true but rviz still does not use the time in the rosbag being played

ufrhaidar commented 1 year ago

you're setting the parameter after creating the node, so you'll have to spin a couple of times before the node reads the clock topic properly. Preferably add the parameters to rclcpp::NodeOptions and start the node with those options.