URDF、Gazebo 与 Rviz 综合应用
URDF、Rviz、Gazebo三者的关系,URDF 用于创建机器人模型,Rviz 显示机器人感知到的信息,Gazebo 用于仿真,模拟外界环境,以及机器人的一些传感器。
主要内容:
1.在 Gazebo 中模拟机器人的传感器
2.在 Rviz 中显示这些传感器感知到的数据。具体包括如下内容:
(1)运动控制以及里程计信息显示
(2)摄像头信息仿真以及显示
(3)Kinect 信息仿真以及显示
1.机器人运动控制以及里程计信息显示
arbotix 只能让模型在 rviz 中运动起来,对 gazebo 不生效,因此需要使用 ros_control 进行控制实现。
1.1首先贴一段概念性的介绍:
ros_control:是一组软件包,它包含了控制器接口,控制器管理器,传输和硬件接口。ros_control 是一套机器人控制的中间件,是一套规范,不同的机器人平台只要按照这套规范实现,那么就可以保证 与ROS 程序兼容,通过这套规范,实现了一种可插拔的架构设计,大大提高了程序设计的效率与灵活性。
gazebo 已经实现了 ros_control 的相关接口,如果需要在 gazebo 中控制机器人运动,直接调用相关接口即可
1.2运动控制实现
流程介绍:
1.已经创建完的机器人模型,编写一个单独的 xacro 文件,为机器人模型添加传动装置以及控制
2.将此文件集成进 xacro 文件
3.启动 Gazebo 并发布 /cmd_vel 消息控制机器人运动
1.2.1添加传动装置
框架搭建
(1)在 urdf02_gazebo 中新建一个文件夹 gazebo,后面和 gazebo 仿真相关的 xacro 都放在此目录下。
(2)新建文件 move.xacro ,将其集成到 urdf 目录下的 car.urdf.xacro 中。
(3)复用 demo03_env.launch 文件作为启动文件
复制如下内容到 move.xacro中:
主要分为两部分内容:
1.传动实现:用于连接控制器与关节,让小车动起来就是让轮子能够转起来,轮子转起来就是让关节动起来。在 gazebo 中通过 xacro 宏实现关节转动。
2.控制器部分,加注释的地方需要我们重点关注。
move.xacro
<robot name="my_car_move" xmlns:xacro="http://wiki.ros.org/xacro">
<!-- 传动实现:用于连接控制器与关节 -->
<xacro:macro name="joint_trans" params="joint_name">
<!-- Transmission is important to link the joints and the controller -->
<transmission name="${joint_name}_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="${joint_name}">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
</joint>
<actuator name="${joint_name}_motor">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>
</xacro:macro>
<!-- 每一个驱动轮都需要配置传动装置 -->
<xacro:joint_trans joint_name="base_l_wheel_joint" />
<xacro:joint_trans joint_name="base_r_wheel_joint" />
<!-- 控制器 -->
<gazebo>
<plugin name="differential_drive_controller" filename="libgazebo_ros_diff_drive.so">
<rosDebugLevel>Debug</rosDebugLevel>
<publishWheelTF>true</publishWheelTF>
<robotNamespace>/</robotNamespace>
<publishTf>1</publishTf>
<publishWheelJointState>true</publishWheelJointState>
<alwaysOn>true</alwaysOn>
<updateRate>100.0</updateRate>
<legacyMode>true</legacyMode>
<leftJoint>base_l_wheel_joint</leftJoint> <!-- 左轮 -->
<rightJoint>base_r_wheel_joint</rightJoint> <!-- 右轮 -->
<wheelSeparation>${base_radius * 2}</wheelSeparation> <!-- 车轮间距 -->
<wheelDiameter>${wheel_radius * 2}</wheelDiameter> <!-- 车轮直径 -->
<broadcastTF>1</broadcastTF>
<wheelTorque>30</wheelTorque>
<wheelAcceleration>1.8</wheelAcceleration>
<commandTopic>cmd_vel</commandTopic> <!-- 运动控制话题 -->
<odometryFrame>odom</odometryFrame>
<odometryTopic>odom</odometryTopic> <!-- 里程计话题 -->
<robotBaseFrame>base_footprint</robotBaseFrame> <!-- 根坐标系 -->
</plugin>
</gazebo>
</robot>
运行 demo03_env.launch 加载机器人模型及仿真环境,此时机器人可通过 cmd_vel 进行控制,运行键盘节点:
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
可实现键盘对小车的控制。