ros2--gazebo--launch
如何在launch中启动gazebo,配置gazebo的参数?
配置过程
1,加载gz_sim的launch文件
pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim')
gazebo = IncludeLaunchDescription(
PythonLaunchDescriptionSource(
os.path.join(pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py')),
launch_arguments={'gz_args': '-r ' + world_file}.items(),
)
IncludeLaunchDescription和PythonLaunchDescriptionSource;
gz sim启动参数配置
gz sim的参数可以通过以下指令查看:
gz sim --help
-r
-r Run simulation on start.
启动后立即运行仿真(不暂停)。
世界文件
链接
2,启动ros_gz_sim的create
3,启动ros_gz_bridge
4,启动robot_state_publisher
#4,启动robot_state_publish
robot_state_publisher_node=Node(
package="robot_state_publisher",
executable="robot_state_publisher",
parameters=[{"robot_description":robot_description_config.toxml(),
"use_sim_time": True}],
output="screen"
)
'use_sim_time': True的作用:
核心功能
-
启用仿真时间:
当设置为True
时,节点会从 ROS 2 的/clock
Topic 获取时间(通常由 Gazebo 等仿真器发布),而非使用系统物理时间。 -
同步仿真环境:
确保所有节点在仿真环境中使用统一的时间基准,避免因系统时钟导致的时序问题。