教程 | 阿克曼结构移动机器人的gazebo仿真(二)
第二章、配置xacro文件
0.前言
上一节已经将urdf导出来了,这一节需要配置一下xacro文件。先看一下导出的功能包在gazebo以及rviz中显示的效果。
将功能包放进工作空间进行编译,source一下环境,先看gazebo:
roslaunch tianracer_description gazebo.launch
可以看到模型已经加载到gazebo中的empty_world中了,此时模型还是白板,稍后可对颜色进行配置。
再看rviz,先修改tianracer_description/launch中的 arg name="gui" default="False"改为arg name="gui" default="True"
roslaunch tianracer_description display.launch
此时左侧会出现joint_state_publisher的可视化窗口,拖动上边的动态条即可控制小车的每个关节。
1.添加传动装置
新建tianracer_description.xacro文件,将urdf文件中的代码复制过来,并对其进行修改。
<?xml version="1.0" encoding="utf-8"?>
<robot name="tianracer" xmlns:xacro="http://ros.org/wiki/xacro"><link name="base_link">
</link>
<link name="chassis"><inertial><originxyz="0.0623235722457065 0.0014584636628485 0.0350371599032402"rpy="0 0 0" /><massvalue="5" /><inertia ixx="0.010609" ixy="0" ixz="0"iyy="0.050409" iyz="0"izz="0.05865" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><mesh filename="package://tianracer_description/meshes/base_link.STL" /></geometry><materialname=""><colorrgba="0.792156862745098 0.819607843137255 0.933333333333333 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/base_link.STL" /></geometry></collision></link><joint name="base_link_joint" type="fixed"><origin xyz="0 0 0" rpy="0 0 0" /> <parent link="base_link"/><child link="chassis" /></joint> <linkname="left_steering_hinge"><inertial><originxyz="0.00160901052986848 0.00421500740928921 0.000999991873067492"rpy="0 0 0" /><massvalue="0.34" /><inertiaixx="4E-06"ixy="0"ixz="0"iyy="4E-06"iyz="0"izz="4E-06" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/left_steering_hinge.STL" /></geometry><materialname=""><colorrgba="1 1 1 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/left_steering_hinge.STL" /></geometry></collision></link><jointname="left_steering_hinge_joint"type="revolute"><originxyz="0.1237 0.070647 0.0235"rpy="0 0 0" /><parentlink="base_link" /><childlink="left_steering_hinge" /><axisxyz="0 0 1" /><limitlower="-0.6"upper="0.6"effort="10"velocity="1000" /></joint><linkname="left_front_wheel"><inertial><originxyz="-1.16652756898539E-10 0.000722301233977055 -0.000982991824011559"rpy="0 0 0" /><massvalue="0.7" /><inertia ixx="0.00026046" ixy="0" ixz="0"iyy="0.00026046" iyz="0"izz="0.00041226" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/left_front_wheel.STL" /></geometry><materialname=""><colorrgba="0.792156862745098 0.819607843137255 0.933333333333333 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/left_front_wheel.STL" /></geometry></collision></link><jointname="left_front_wheel_joint"type="continuous"><originxyz="0 0.015649 0"rpy="0 0 0" /><parentlink="left_steering_hinge" /><childlink="left_front_wheel" /><axisxyz="0 1 0" /></joint><linkname="right_steering_hinge"><inertial><originxyz="0.00160901052986852 -0.00421500740928916 0.00100000812693248"rpy="0 0 0" /><massvalue="0.34" /><inertiaixx="4E-06"ixy="0"ixz="0"iyy="4E-06"iyz="0"izz="4E-06" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/right_steering_hinge.STL" /></geometry><materialname=""><colorrgba="1 1 1 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/right_steering_hinge.STL" /></geometry></collision></link>
<jointname="right_steering_hinge_joint"type="revolute"><originxyz="0.12626 -0.065953 0.0235"rpy="0 0 0" /><parentlink="base_link" /><childlink="right_steering_hinge" /><axisxyz="0 0 1" /><limitlower="-0.6"upper="0.6"effort="10"velocity="1000" /></joint>
<linkname="right_front_wheel"><inertial><originxyz="1.16652479342783E-10 -0.000722301233976874 -0.000982991824011684"rpy="0 0 0" /><massvalue="0.7" /><inertia ixx="0.00026046" ixy="0" ixz="0"iyy="0.00026046" iyz="0"izz="0.00041226" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/right_front_wheel.STL" /></geometry><materialname=""><colorrgba="0.792156862745098 0.819607843137255 0.933333333333333 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/right_front_wheel.STL" /></geometry></collision></link><jointname="right_front_wheel_joint"type="continuous"><originxyz="0 -0.015649 0"rpy="0 0 0" /><parentlink="right_steering_hinge" /><childlink="right_front_wheel" /><axisxyz="0 1 0" /></joint><linkname="left_rear_wheel"><inertial><originxyz="-6.22009417952651E-06 0.000722301233977513 1.58299866985546E-05"rpy="0 0 0" /><massvalue="0.7" /><inertia ixx="0.00026046" ixy="0" ixz="0"iyy="0.00026046" iyz="0"izz="0.00041226" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/left_rear_wheel.STL" /></geometry><materialname=""><colorrgba="0.792156862745098 0.819607843137255 0.933333333333333 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/left_rear_wheel.STL" /></geometry></collision></link><jointname="left_rear_wheel_joint"type="continuous"><originxyz="-0.12626 0.081602 0.0225"rpy="0 0 0" /><parentlink="base_link" /><childlink="left_rear_wheel" /><axisxyz="0 1 0" /></joint><linkname="right_rear_wheel"><inertial><originxyz="5.49312575473526E-06 -0.000722301233977277 1.60966959317256E-05"rpy="0 0 0" /><massvalue="0.7" /><inertia ixx="0.00026046" ixy="0" ixz="0"iyy="0.00026046" iyz="0"izz="0.00041226" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><mesh filename="package://tianracer_description/meshes/right_rear_wheel.STL" /></geometry><materialname=""><colorrgba="0.792156862745098 0.819607843137255 0.933333333333333 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/right_rear_wheel.STL" /></geometry></collision></link><jointname="right_rear_wheel_joint"type="continuous"><originxyz="-0.1237 -0.086296 0.0225"rpy="0 0 0" /><parentlink="base_link" /><childlink="right_rear_wheel" /><axisxyz="0 1 0" /></joint><linkname="lidar"><inertial><originxyz="-0.0120919804823413 0.0023160815953297 -0.0191850779635995"rpy="0 0 0" /><massvalue="0.0792224121739075" /><inertiaixx="2.10579541640659E-05"ixy="-1.189626176555E-07"ixz="4.23690141563745E-07"iyy="2.51190032657276E-05"iyz="-7.86831091483644E-09"izz="4.38241306407012E-05" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/lidar.STL" /></geometry><materialname=""><colorrgba="0.792156862745098 0.819607843137255 0.933333333333333 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/lidar.STL" /></geometry></collision></link><jointname="lidar_joint"type="fixed"><originxyz="0.093603 -8.284E-05 0.12377"rpy="0 0 0" /><parentlink="base_link" /><childlink="lidar" /><axisxyz="0 0 0" /></joint><linkname="camera"><inertial><originxyz="-0.00831465204525364 0.000297862545499916 -0.000809694900417546"rpy="0 0 0" /><massvalue="0.0203878842392581" /><inertiaixx="4.0787812214101E-06"ixy="-1.28709200468823E-08"ixz="-1.65865223773842E-08"iyy="3.17565570823081E-06"iyz="-1.52713816393124E-08"izz="2.98536150732633E-06" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/camera.STL" /></geometry><materialname=""><colorrgba="0.43921568627451 0.43921568627451 0.43921568627451 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/camera.STL" /></geometry></collision></link><jointname="camera_joint"type="fixed"><originxyz="0.14851 0.0022137 0.0975"rpy="0 0 0" /><parentlink="base_link" /><childlink="camera" /><axisxyz="0 0 0" /></joint><linkname="real_sense"><inertial><originxyz="-0.00975078931607951 0.00306064913353049 -7.04374991291334E-05"rpy="0 0 0" /><massvalue="0.103311749598955" /><inertiaixx="7.35323632954531E-05"ixy="3.0437488683846E-06"ixz="2.08538534427428E-08"iyy="7.40427481540393E-06"iyz="-1.93018760531168E-08"izz="7.2832884533889E-05" /></inertial><visual><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/real_sense.STL" /></geometry><materialname=""><colorrgba="0.666666666666667 0.698039215686274 0.768627450980392 1" /></material></visual><collision><originxyz="0 0 0"rpy="0 0 0" /><geometry><meshfilename="package://tianracer_description/meshes/real_sense.STL" /></geometry></collision></link><jointname="real_sense_joint"type="fixed"><originxyz="0.19864 0.0038046 0.052021"rpy="0 0 0" /><parentlink="base_link" /><childlink="real_sense" /><axisxyz="0 0 0" /></joint>
上边主要修改的内容是第一句修改为xacro声明:
<?xml version="1.0" encoding="utf-8"?>
<robot name="tianracer" xmlns:xacro="http://ros.org/wiki/xacro">
以及一些惯性参数的修改。
本次项目做的是基于twist消息的阿克曼转向移动机器人,为实现该机器人的运动学,我们给两个后轮以及连接两个前轮的steer添加传动装置。为使用ROS控制驱动机器人,需要在模型中加入transmission元素,将传动装置与joint绑定。
<transmission name="right_steering_hinge_joint_trans"><type>transmission_interface/SimpleTransmission</type><joint name="right_steering_hinge_joint" ><hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface></joint><actuator name="right_steering_hinge_joint_motor"><hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction><motorTorqueConstant>100</motorTorqueConstant></actuator></transmission> <transmission name="left_steering_hinge_joint_trans"><type>transmission_interface/SimpleTransmission</type><joint name="left_steering_hinge_joint" ><hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface></joint><actuator name="left_steering_hinge_joint_motor"><hardwareInterface>hardware_interface/EffortJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction><motorTorqueConstant>100</motorTorqueConstant></actuator></transmission><transmission name="right_rear_wheel_joint_trans"><type>transmission_interface/SimpleTransmission</type><joint name="right_rear_wheel_joint" ><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface></joint><actuator name="right_rear_wheel_joint_motor"><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction></actuator></transmission> <transmission name="left_rear_wheel_joint_trans"><type>transmission_interface/SimpleTransmission</type><joint name="left_rear_wheel_joint" ><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface></joint><actuator name="left_rear_wheel_joint_motor"><hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface><mechanicalReduction>1</mechanicalReduction></actuator></transmission>
2.添加插件
在与tianracer_description.xacro路径相同路径下新建tianracer.gazebo文件
添加gazebo插件
由于车轮实际上会接触地面,因此会与地面发生物理相互作用,将各个link添加部件材料的附加信息,并且定义各个link的颜色信息。参考
[gazebo官网] http://gazebosim.org/tutorials/?tut=ros_urdf
<gazebo reference="chassis"><mu1 value="0.0"/><mu2 value="0.0"/><kp value="10000000.0" /><kd value="1.0" /><material>Gazebo/Red</material>
</gazebo>
<gazebo reference="left_steering_hinge"><mu1 value="2.0"/><mu2 value="2.0"/><kp value="10000000.0" /><kd value="1.0" /><fdir1 value="1 0 0"/><material>Gazebo/Grey</material>
</gazebo>
<gazebo reference="left_rear_wheel"><mu1 value="2.0"/><mu2 value="2.0"/><kp value="10000000.0" /><kd value="1.0" /><fdir1 value="1 0 0"/><material>Gazebo/Black</material>
</gazebo>
<gazebo reference="right_steering_hinge"><mu1 value="2.0"/><mu2 value="2.0"/><kp value="10000000.0" /><kd value="1.0" /><fdir1 value="1 0 0"/><material>Gazebo/Grey</material>
</gazebo>
<gazebo reference="right_rear_wheel"><mu1 value="2.0"/><mu2 value="2.0"/><kp value="10000000.0" /><kd value="1.0" /><fdir1 value="1 0 0"/><material>Gazebo/Black</material>
</gazebo>
<gazebo reference="left_front_wheel"><mu1 value="2.0"/><mu2 value="2.0"/><kp value="10000000.0" /><kd value="1.0" /><fdir1 value="0 0 1"/><material>Gazebo/Black</material>
</gazebo>
<gazebo reference="right_front_wheel"><mu1 value="2.0"/><mu2 value="2.0"/><kp value="10000000.0" /><kd value="1.0" /><fdir1 value="0 0 1"/><material>Gazebo/Black</material>
</gazebo>
添加ros_control插件
由于gazebo并没阿克曼车型的插件,要链接gazebo与ros,我们先添加ros_control插件,它读取所有transmission标记,以及joint_state_publisher插件
<gazebo><plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so"><robotNamespace>/tianracer</robotNamespace><robotParam>robot_description</robotParam><robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType><legacyModeNS>true</legacyModeNS></plugin>
</gazebo><gazebo><plugin name="joint_state_publisher" filename="libgazebo_ros_joint_state_publisher.so"><jointName>left_rear_wheel_joint, right_rear_wheel_joint, left_steering_hinge_joint, right_steering_hinge_joint, right_front_wheel_joint,left_ front_wheel_joint</jointName><updateRate>50.0</updateRate><robotNamespace>/tianracer</robotNamespace><alwaysOn>true</alwaysOn></plugin></gazebo>
添加二维激光雷达插件
<!-- hokuyo -->
<xacro:unless value="$(optenv DISABLE_GAZEBO_LASER false)"><gazebo reference="lidar"><material>Gazebo/Grey</material><sensor type="ray" name="hokuyo_sensor"><pose>0 0 0.0124 0 0 0</pose><visualize>false</visualize><update_rate>40</update_rate><ray><scan><horizontal><samples>1081</samples><resolution>1</resolution><min_angle>-2.3561944902</min_angle><max_angle>2.3561944902</max_angle></horizontal></scan><range><min>0.1</min><max>10.0</max><resolution>0.01</resolution></range><noise><mean>0.0</mean><stddev>0.01</stddev></noise></ray><plugin name="gazebo_ros_hokuyo_controller" filename="libgazebo_ros_laser.so"><topicName>/scan</topicName><frameName>lidar</frameName></plugin></sensor></gazebo>
</xacro:unless>
注意雷达的名字需要与link名对应上。
添加单目摄像头以及深度摄像头插件
<!-- camera --><gazebo reference="camera"><material>Gazebo/Grey</material><sensor type="camera" name="camera1"><update_rate>30.0</update_rate><camera name="head"><horizontal_fov>1.3962634</horizontal_fov><image><width>800</width><height>800</height><format>R8G8B8</format></image><clip><near>0.02</near><far>300</far></clip><noise><type>gaussian</type><!-- Noise is sampled independently per pixel on each frame.That pixel's noise value is added to each of its colorchannels, which at that point lie in the range [0,1]. --><mean>0.0</mean><stddev>0.007</stddev></noise></camera><plugin name="camera_controller" filename="libgazebo_ros_camera.so"><alwaysOn>true</alwaysOn><updateRate>0.0</updateRate><cameraName>rrbot/camera1</cameraName><imageTopicName>image_raw</imageTopicName><cameraInfoTopicName>camera_info</cameraInfoTopicName><frameName>camera</frameName><hackBaseline>0.07</hackBaseline><distortionK1>0.0</distortionK1><distortionK2>0.0</distortionK2><distortionK3>0.0</distortionK3><distortionT1>0.0</distortionT1><distortionT2>0.0</distortionT2></plugin></sensor></gazebo><gazebo reference="real_sense"><sensor type="depth" name="real_sense"><always_on>true</always_on><update_rate>20.0</update_rate><camera><horizontal_fov>${60.0*3.14/180.0}</horizontal_fov><image><format>R8G8B8</format><width>640</width><height>480</height></image><clip><near>0.05</near><far>8.0</far></clip></camera><plugin name="kinect_real_sense_controller" filename="libgazebo_ros_openni_kinect.so"><cameraName>real_sense</cameraName><alwaysOn>true</alwaysOn><updateRate>10</updateRate><imageTopicName>rgb/image_raw</imageTopicName><depthImageTopicName>depth/image_raw</depthImageTopicName><pointCloudTopicName>depth/points</pointCloudTopicName><cameraInfoTopicName>rgb/camera_info</cameraInfoTopicName><depthImageCameraInfoTopicName>depth/camera_info</depthImageCameraInfoTopicName><frameName>real_sense</frameName><baseline>0.1</baseline><distortion_k1>0.0</distortion_k1><distortion_k2>0.0</distortion_k2><distortion_k3>0.0</distortion_k3><distortion_t1>0.0</distortion_t1><distortion_t2>0.0</distortion_t2><pointCloudCutoff>0.4</pointCloudCutoff></plugin></sensor></gazebo>
这里深度摄像头的插件用kinect的插件代替。
最后将tianracer.gazebo添加到tianracer_description.xacro文件里边:
<xacro:include filename="$(find tianracer_description)/urdf/tianracer.gazebo" />
小结
至此,我们已经配置好小车的各个link的颜色以及传感器的插件,但我们仍无法让小车运动起来,因为我们还未配置小车的controllers。下一节通过配置controllers让小车动起来。
参考资料
1.古月老师的<<ROS机器人开发实践>>
2.从零开始自动驾驶:https://www.bilibili.com/video/BV1ZJ41187tS?spm_id_from=333.999.0.0
教程 | 阿克曼结构移动机器人的gazebo仿真(二)相关推荐
- 教程 | 阿克曼结构移动机器人的gazebo仿真(一)
第一章.从SOLIDWORKS中导出URDF 二轮差速小车已经完结.接下去要进入阿克曼结构移动机器人的仿真.阿克曼小车的结构也就是我们看到最多的应用最广的车型,也称为car-like robot.在这 ...
- 教程 | 阿克曼结构移动机器人的gazebo仿真(五)
第四章.用xacro优化URDF并配置gazebo仿真插件 1►前言 上节用简易模型写了一个小车的URDF代码,这一节将用xacro对其进行优化,这里我并不打算用宏对参数进行封装,因为我个人觉得这样看 ...
- 教程 | 阿克曼结构移动机器人的gazebo仿真(九)
第九章.模型替换以及TEB调参技巧 1.前言 上节内容让小车在gazebo仿真环境中实现导航,本节内容重点介绍一下gazebo仿真中的模型替换方法以及TEB调参的技巧. 2.模型替换 阿克曼小车项目从 ...
- 阿克曼结构移动机器人的gazebo仿真(八)
阿克曼结构移动机器人的gazebo仿真(八) 第八章.实现小车自主导航 0.前言 上一节通过配置小车的里程计,用gmapping算法建了房间的二维栅格地图:这一节通过配置AMCL定位以及move_ba ...
- 阿克曼结构移动机器人的gazebo仿真(九)
阿克曼结构移动机器人的gazebo仿真(九) 第九章.模型替换以及TEB调参技巧 0.前言 上节内容让小车在gazebo仿真环境中实现导航,本节内容重点介绍一下gazebo仿真中的模型替换方法以及TE ...
- 阿克曼小车urdf模型搭建与gazebo仿真
阿克曼小车urdf模型搭建与gazebo仿真 参考: 一.urdf模型 1.urdf 模型搭建 1.1 link标签 1.2 joint相关 1.3 偏移关系讲解 2. xacro描述机器人 3. r ...
- Visp_ros学习笔记(二):在Gazebo环境下实现Pionner3dx移动机器人视觉伺服仿真
开发环境:Unbuntu 18.04 LTS + ROS Melodic + ViSP 3.3.1 本文主要介绍了如何实现Pionner3dx移动机器人视觉伺服仿真,仿真环境是ROS+Gazebo ...
- 【从零开始的ROS四轴机械臂控制】(二) - ROS与Gazebo连接,Gazebo仿真及urdf文件修改
[从零开始的ROS四轴机械臂控制(二)] 四.urdf文件及gazebo仿真 1.simple_arm示例 (1)config文件夹 (2)launch文件夹 (3)meshes文件夹 (4)urdf ...
- 如何生成gazebo仿真环境的二维地图真值
在移动机器人仿真中,二维地图真值可以用来评价slam建图结果,也可以直接给路径规划算法提供输入. 利用gazebo进行仿真时,有很多方法都可以获取静态仿真环境的二维地图真值,本文将对以下链接: hyf ...
最新文章
- OCQ亮相中国移动办公峰会 荣获2017中国移动办公创新品牌
- AI正从“感知智能”走向“认知智能”
- 数据结构与算法之二叉树的先序遍历,中序遍历,后序遍历
- 数据库:SQL 语法速成手册,建议新手收藏!
- 如何解决360浏览器卡死的问题
- SonarLint插件的安装与使用
- ios 录音生成.aac录音文件
- ios崩溃日志分析,无dSYM文件
- 苹果手机密码设置在哪里_oppo怎么设置SIM密码-oppo手机SIM卡密码设置详细教程
- 如何开发Alexa Intent skill
- cadence SPB17.4 - 更换已有原理图的标题栏
- python制作雕刻软件_Mac动画制作软件——blender for Mac
- 使用软碟通做启动盘给电脑装系统时如何分区
- 计算机组成原理ACC MQ,计算机组成原理讲案第一章.ppt
- Python中“xx+=xx”与“xx=xx+xx”的区别
- RK3399 Android7.1如何查看屏幕分辨率
- 11 个最佳免费安全网站
- mysql 匹配多个字符_在MySQL语句中,可以匹配0个到多个字符的通配符是____。
- STK之Commu模块之三仿真卫星通信链路参数计算
- 如何用多台机器产生agent到A上。