Gazebo的使用配置
Kinetic 和 Melodic的 xacro 文件语法不同

Gazebo对电脑显卡有一定要求,对Nvida显卡支持较好,对AMD的显卡支持较差,如果是AMD的显卡,复杂的世界模型一般加载不出来

利用spawn_model脚本向gazebo_ros节点(在主题中,空间名为 gazebo)发出服务请求,进而添加 URDF 到 Gazebo 中

1
rosrun gazebo_ros spawn_model -file `rospack find MYROBOT_description`/urdf/MYROBOT.urdf -urdf -x 0 -y 0 -z 1 -model MYROBOT

如果是.xacro, 可以转化为 urdf 文件:

xacro转urdf

如果是kinetic,执行

1
rosrun xacro xacro.py robot1.xacro > robot1_processed.urdf

会得到:
1
2
3
xacro: Traditional processing is deprecated. Switch to --inorder processing!
To check for compatibility of your document, use option --check-order.
For more infos, see http://wiki.ros.org/xacro#Processing_Order xacro.py is deprecated; please use xacro instead

说明xacro.py命令已经过期,使用xacro替换: rosrun xacro xacro robot1.xacro > robot1_processed.urdf


如果是在Melodic,执行rosrun xacro xacro --inorder $(locate robot.urdf.xacro) > robot_inorder.urdf,结果得到

1
xacro: in-order processing became default in ROS Melodic. You can drop the option.

查看关节图

先执行sudo apt install -y liburdfdom-tools

1
2
3
check_urdf pr2.urdf
# 再打开转换的pdf
urdf_to_graphiz pr2.urdf

查看spawn_model的所有参数,可以运行:

1
rosrun gazebo_ros spawn_model -h

在 launch文件中,对于urdf可以这样编写:

1
2
<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-file $(find baxter_description)/urdf/baxter.urdf -urdf -z 1 -model baxter" />

对于xacro,这样编写:

1
2
3
4
5
<!-- Convert an xacro and put on parameter server -->
<param name="robot_description" command="$(find xacro)/xacro.py $(find pr2_description)/robots/pr2.urdf.xacro" />

<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-param robot_description -urdf -model pr2" />

URDF的报错原因:加了等标签,但没加具体内容。

rosrun gazebo_ros spawn_model -file robot.urdf -urdf -model robot

sdf: standard definition of world for Gazebo

1
2
3
4
5
6
7
8
9
10
<launch>
<include file="$(find gazebo_ros)/launch/empty_world.launch" >
</include>

<arg name='robot_urdf' default="$(find xacro)/xacro '$(find vehicle_simulator)/urdf/robot.urdf.xacro'" />
<param name="robot_description" command="$(arg robot_urdf)" />
<node pkg="gazebo_ros" type="spawn_model" name="spawn_robot" args="-urdf -param robot_description -model robot -x 0 -y 0 -z 0.5"/>

<node pkg="teleop_twist_keyboard" type="teleop_twist_keyboard.py" name="teleop" />
</launch>

正常的输出信息.png

Gazebo的gui参数经常是false,这是因为显示界面会显著加大资源占用

world文件可以直接改名称,不影响使用

兼容问题

2022-05-24_51.png
2022-05-24_52.png

加入camera仿真

Gazebo只给出了水平FOV, 竖直FOV会根据图片的宽和高自动计算。 Gazebo有函数double VerticalFOV() const,解释: The vertical FOV is calculated from width, height, hfov。有bool SetHorizontalFOV (double _hfov)函数,但是没有函数bool SetVerticalFOV (double _hfov)

差速模块

出现下面日志,说明差速控制模块正常加载。

1
2
3
4
5
6
[ INFO] [1720590402.172629168, 68.803000000]: Starting plugin DiffDrive(ns = //)
[ INFO] [1720590402.172729086, 68.803000000]: DiffDrive(ns = //): <rosDebugLevel> = na
[ INFO] [1720590402.173268546, 68.803000000]: DiffDrive(ns = //): <tf_prefix> =
[ INFO] [1720590402.173831755, 68.803000000]: DiffDrive(ns = //): Try to subscribe to cmd_vel
[ INFO] [1720590402.175204165, 68.803000000]: DiffDrive(ns = //): Subscribe to cmd_vel
[ INFO] [1720590402.175652313, 68.803000000]: DiffDrive(ns = //): Advertise odom on odom

libgazebo_ros_gps_sensor.so

libgazebo_ros_bumper.so

libgazebo_ros_ray_sensor.so