Gazebo物理仿真环境搭建——ros_control
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
前言
ros_control是ROS为开发者提供的控制中间件
包含一系列接口
提示:以下是本篇文章正文内容,下面案例可供参考
一、ros_control总体框架
将控制和硬件分开,用一些接口实现功能
ros_control的控制器
一般有力控制器、状态控制器、位置控制器、速度控制器
二、仿真步骤
1.配置机器人模型
1.为link添加惯性参数和碰撞属性
给所有link添加惯性参数和碰撞属性
<collision>
<origin xyz=" 0 0 0" rpy="0 0 0" />
<geometry>
<cylinder length="${base_length}" radius="${base_radius}"/>
</geometry>
</collision>
<cylinder_inertial_matrix m="${base_mass}" r="${base_radius}" h="${base_length}" />
为碰撞属性
cylinder_inertial_matrix 为惯性矩阵
惯性矩阵一般用宏定义,如下面的代码所示:(规则刚体的计算公式)
<xacro:macro name="cylinder_inertial_matrix" params="m r h">
<inertial>
<mass value="${m}" />
<inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0"
iyy="${m*(3*r*r+h*h)/12}" iyz = "0"
izz="${m*r*r/2}" />
</inertial>
</xacro:macro>
2.为link添加gazebo标签
如:由于rviz的颜色标签在gazebo中识别不出来,所以需要对每个link添加一个gazebo标签添加颜色
material:颜色
turnGravityoff:关闭重力
3.为joint添加传动装置
如下所示:
<!-- Transmission is important to link the joints and the controller -->
<transmission name="${prefix}_wheel_joint_trans">
<type>transmission_interface/SimpleTransmission</type>
<joint name="${prefix}_wheel_joint" >
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
</joint>
<actuator name="${prefix}_wheel_joint_motor">
<hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
<mechanicalReduction>1</mechanicalReduction>
</actuator>
</transmission>
为关节joint添加传动装置(如电机)
4.添加gazebo控制器插件
就是添加一个虚拟控制板插件,代码如下所示:
<!-- controller -->
<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>left_wheel_joint</leftJoint>
<rightJoint>right_wheel_joint</rightJoint>
<wheelSeparation>${wheel_joint_y*2}</wheelSeparation>
<wheelDiameter>${2*wheel_radius}</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>
robotNamespace:机器人工作空间,一般用/代替,如果使用具体名称,则订阅的速度等控制话题前加上/名称/
leftJoint 、rightJoint:左轮名称和右轮名称,要与文件中设置joint名称的一致
wheelSeparation:轮子间距
wheelDiameter:轮子尺寸
commandTopic:控制器订阅的话题
odometryFrame:里程计的坐标系发布的话题
odometryTopic:里程计信息发布的话题
robotBaseFrame:控制器控制的坐标系
2.创建仿真环境
3.开始仿真
编译时出现两个问题,解决方法如下:
问题一:缺少ros_control
问题二:升级gazebo后缺少依赖库
创建仿真环境大致步骤:
a、启动gazebo
b、加载机器人模型
c、运行一些节点
d、在gazebo中加载机器人模型