Actual combat: The ros robot is running unstable. Maybe use_sim_time is not set correctly.

Working on the computer environment, ubuntu 20.04 ros2 version foxy

The ros robot has been developed for a long time, but there is a parameter that beginners can easily overlook: use_sim_time. If the setting is incorrect, the program will have inexplicable problems when running.

use_sim_time: Straightforward translation: use_sim_time 

The time in the ros system is divided into simulation time and system time. The simulation time is generally published by the /gazebo node. You can check the node information ros2 node info /gazebo to find that it is publishing the /clock topic. Other nodes must receive this topic consistent with the simulation time. If it works normally, if it is a physical robot, then the system time collected at this time is the current time of our computer system.

ros2 node info /gazebo
/gazebo
  Subscribers:
    /clock: rosgraph_msgs/msg/Clock
    /parameter_events: rcl_interfaces/msg/ParameterEvent
  Publishers:
    /clock: rosgraph_msgs/msg/Clock
    /parameter_events: rcl_interfaces/msg/ParameterEvent

Use_sim_time is used for this time parameter. There are only two options for the parameter, true (use simulation time) false (no simulation time)

1 Let’s talk about true (using simulation time) first. If you are running gazebo simulation, this parameter must be set to true.

use_sim_time = LaunchConfiguration('use_sim_time', default='true') #launch file declares time variable

Each node in the same launch file must set this parameter. Some nodes can work normally without setting this parameter because the program has default settings. Generally, each node must be added:

parameters=[{'use_sim_time': use_sim_time}], #Use the value of the time variable

2 When it says false (simulation time is not used), run the physical robot.

This variable can be set to a default value in the launch file, or added when running the launch file. For example, when running a mapping program, add it at the end:

ros2 launch jtbot_cartographer cartographer.launch.py use_sim_time:=true

Some launch files do not set this parameter, or the program does not run normally. How do we check whether this parameter is set correctly? The method is to view the parameter list:

ros2 param list

 
We need to check whether the use_sim_time setting of each node is correct.

 Each node needs to be set to true when running the simulation, and false when running the physical robot. If it is wrong, you need to find a way to set this parameter in the launch file. After setting it, check whether the setting is correct through the above method.

This parameter can also be set during operation, follow this command: ros2 param set /scan use_sim_time false

The discovery process of this problem: I was using simulation to run the cartographer_node mapping program, and found that the rviz2 was floating very much, as if the odom was floating around, and the robot looked abnormal. Finally, I found that the time was not set correctly.

 Via command:

ros2 param set /cartographer_node use_sim_time true
Set parameter successful

 When the display was normal, I realized that this parameter is so important.

Guess you like

Origin blog.csdn.net/m0_73694897/article/details/132263789