通过学习大神的博客: ros中利用gazebo进行gmapping仿真:kobuki+kinect -> kobuki+rplidar
http://blog.csdn.net/zyh821351004/article/details/48846179
继续改进,才有了下面的实现。好,废话不多说,以下内容出现错误的地方还望大家指出,共同进步,谢谢!
注意下述中的红色提醒!!!
1、首先看 roslaunch turtlebot_gazebo turtlebot_world.launch命令中turtlebot_world.launch的文件。
<launch>
<arg name="world_file" default="$(env TURTLEBOT_GAZEBO_WORLD_FILE)"/>
<arg name="base" value="$(optenv TURTLEBOT_BASE kobuki)"/> <!-- create, roomba -->
<arg name="battery" value="$(optenv TURTLEBOT_BATTERY /proc/acpi/battery/BAT0)"/> <!-- /proc/acpi/battery/BAT0 -->
<arg name="gui" default="true"/>
<arg name="stacks" value="$(optenv TURTLEBOT_STACKS hexagons)"/><!-- circles, hexagons -->
<arg name="3d_sensor" value="$(optenv TURTLEBOT_3D_SENSOR KinectHokuyo)"/> <!-- kinect, asus_xtion_pro -->
<include file="$(find gazebo_ros)/launch/empty_world.launch">
<arg name="use_sim_time" value="true"/>
<arg name="debug" value="false"/>
<arg name="gui" value="$(arg gui)" />
<arg name="world_name" value="$(arg world_file)"/>
</include>
<include file="$(find turtlebot_gazebo)/launch/includes/$(arg base).launch.xml">
<arg name="base" value="$(arg base)"/>
<arg name="stacks" value="$(arg stacks)"/>
<arg name="3d_sensor" value="$(arg 3d_sensor)"/>
</include>
2、由上述蓝色处看kobuki.launch.xml 文件,其中有下面这一句。<argname="urdf_file" default="$(find xacro)/xacro.py'$(find turtlebot_description)/robots/$(argbase)_$(arg stacks)_$(arg3d_sensor).urdf.xacro'"/>
所以,在/turtlebot/turtlebot_description/robots 路径下,建立相应的urdf文件:kobuki_hexagons_KinectHokuyo.urdf.xacro
<?xml version="1.0"?>
<!--
- Base : kobuki
- Stacks : hexagons
- 3d Sensor : kinect+hokuyo
-->
<robot name="turtlebot" xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:include filename="$(find turtlebot_description)/urdf/turtlebot_library.urdf.xacro" />
<xacro:include filename="$(find kobuki_description)/urdf/kobuki.urdf.xacro" />
<xacro:include filename="$(find turtlebot_description)/urdf/stacks/hexagons.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/kinect.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/hokuyo.urdf.xacro"/>
<kobuki/>
<stack_hexagons parent="base_link"/>
<sensor_kinect parent="base_link"/>
<sensor_hokuyo parent="base_link"/>
</robot>
3、进入文件turtlebot_description/urdf/turtlebot_library.urdf.xacro添加hoyuko的urdf文件:<xacro:includefilename="$(findturtlebot_description)/urdf/sensors/hoyuko.urdf.xacro"/>
<?xml version="1.0"?>
<!--
The complete turtlebot library of xacros for easy reference
-->
<robot xmlns:xacro="http://ros.org/wiki/xacro">
<!-- General -->
<xacro:include filename="$(find turtlebot_description)/urdf/common_properties.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/turtlebot_properties.urdf.xacro"/>
<!-- Bases -->
<xacro:include filename="$(find create_description)/urdf/create.urdf.xacro"/>
<xacro:include filename="$(find kobuki_description)/urdf/kobuki.urdf.xacro" />
<!-- Stacks -->
<xacro:include filename="$(find turtlebot_description)/urdf/stacks/circles.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/stacks/hexagons.urdf.xacro"/>
<!-- 3D Sensors -->
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/kinect.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/asus_xtion_pro.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/asus_xtion_pro_offset.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/astra.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/r200.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/sensors/hokuyo.urdf.xacro"/>
</robot>
<?xml version="1.0"?>
<!-- script_version=1.1 -->
<robot name="sensor_hokuyo" xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:include filename="$(find turtlebot_description)/urdf/turtlebot_gazebo.urdf.xacro"/>
<xacro:include filename="$(find turtlebot_description)/urdf/turtlebot_properties.urdf.xacro"/>
<!-- RPLidar 2D LIDAR -->
<xacro:macro name="sensor_hokuyo" params="parent">
<joint name="laser" type="fixed">
<origin xyz="0.10 0 0.425" rpy="0 0.0 0.0" />
<parent link="base_link" />
<child link="base_laser_link" />
</joint>
<link name="base_laser_link">
<visual>
<geometry>
<box size="0.05 0.05 0.05" />
</geometry>
<material name="Black" />
</visual>
<inertial>
<mass value="0.000001" />
<origin xyz="0 0 0" />
<inertia ixx="0.0001" ixy="0.0" ixz="0.0"
iyy="0.0001" iyz="0.0"
izz="0.0001" />
</inertial>
</link>
<!-- Set up laser gazebo details -->
<turtlebot_sim_2dsensor/>
</xacro:macro>
</robot>
5、在turtlebot_description/urdf/turtlebot_gazebo.urdf.xacro文件下添加配置laser在gazebo下的属性值插件配置
<?xml version="1.0"?>
<robot name="turtlebot_gazebo" xmlns:xacro="http://ros.org/wiki/xacro">
<!-- Microsoft Kinect / ASUS Xtion PRO Live for simulation -->
<xacro:macro name="turtlebot_sim_3dsensor">
<gazebo reference="camera_link">
<sensor type="depth" name="camera">
<always_on>true</always_on>
<update_rate>20.0</update_rate>
<camera>
<horizontal_fov>${60.0*M_PI/180.0}</horizontal_fov>
<image>
<format>B8G8R8</format>
<width>640</width>
<height>480</height>
</image>
<clip>
<near>0.05</near>
<far>8.0</far>
</clip>
</camera>
<plugin name="kinect_camera_controller" filename="libgazebo_ros_openni_kinect.so">
<cameraName>camera</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>camera_depth_optical_frame</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>
</xacro:macro>
<xacro:macro name="turtlebot_sim_2dsensor">
<gazebo reference="hokuyo_link">
<sensor type="ray" name="head_hokuyo_sensor">
<pose>0 0 0 0 0 0</pose>
<visualize>false</visualize>
<update_rate>40</update_rate>
<ray>
<scan>
<horizontal>
<samples>720</samples>
<resolution>1</resolution>
<min_angle>-1.570796</min_angle>
<max_angle>1.570796</max_angle>
</horizontal>
</scan>
<range>
<min>0.10</min>
<max>30.0</max>
<resolution>0.01</resolution>
</range>
<noise>
<type>gaussian</type>
<!-- Noise parameters based on published spec for Hokuyo laser
achieving "+-30mm" accuracy at range < 10m. A mean of 0.0m and
stddev of 0.01m will put 99.7% of samples within 0.03m of the true
reading. -->
<mean>0.0</mean>
<stddev>0.01</stddev>
</noise>
</ray>
<plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so">
<topicName>/rrbot/laser/scan</topicName>
<frameName>hokuyo_link</frameName>
</plugin>
</sensor>
</gazebo>
</xacro:macro>
</robot>
6、环境变量加入
打开命令窗口输入:$ gedit ~/.bashrc,添加下述命令到文件尾:
export TURTLEBOT_STACKS=heagons
export TURTLEBOT_3D_SENSOR=KinectHokuyo
7、运行
$ roslaunch turtlebot_gazebo turtlebot_world.launch
上述内容还需完善,请看下一篇:
ROS中给turtlebot加两个传感器:kinect+hokuyo,进行gazebo仿真 (二)