当前位置:   article > 正文

ROS之旅(三) Ubuntu18.04 ROS环境下利用cartographer以及move_base功能包实现差速小车在仿真环境中路径规划_ros创建gazebo功能包

ros创建gazebo功能包

一、创建工作空间

1.创建工作空间catkin_mbot

mkdir -p ~/catkin_mbot/src
cd ~/catkin_mbot/src

2.初始化工作空间

catkin_init_workspace 

3.编译工作空间

  1. cd ~/catkin_mbot
  2. catkin_make

二、在src下新建mymbot_description功能包

1.创建功能包

  1. cd ~/catkin_mbot/src
  2. catkin_create_pkg mymbot_description xacro

在该功能包下创建三个.xacro文件,分别为:lidar_gazebo.xacro   用于存放激光雷达相关数据、mbot_base_gazebo.xacro  用于存放小车的相关数据、mbot_with_laser_gazebo.xacro  将激光雷达与小车合为一体。

2.lidar_gazebo.xacro

  1. <?xml version="1.0"?>
  2. <robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="laser">
  3. <xacro:macro name="rplidar" params="prefix:=laser">
  4. <!-- Create laser reference frame -->
  5. <link name="${prefix}_link">
  6. <inertial>
  7. <mass value="0.1" />
  8. <origin xyz="0 0 0" />
  9. <inertia ixx="0.01" ixy="0.0" ixz="0.0"
  10. iyy="0.01" iyz="0.0"
  11. izz="0.01" />
  12. </inertial>
  13. <visual>
  14. <origin xyz=" 0 0 0 " rpy="0 0 0" />
  15. <geometry>
  16. <cylinder length="0.05" radius="0.05"/>
  17. </geometry>
  18. <material name="black"/>
  19. </visual>
  20. <collision>
  21. <origin xyz="0.0 0.0 0.0" rpy="0 0 0" />
  22. <geometry>
  23. <cylinder length="0.06" radius="0.05"/>
  24. </geometry>
  25. </collision>
  26. </link>
  27. <gazebo reference="${prefix}_link">
  28. <material>Gazebo/Black</material>
  29. </gazebo>
  30. <gazebo reference="${prefix}_link">
  31. <sensor type="ray" name="rplidar">
  32. <pose>0 0 0 0 0 0</pose>
  33. <visualize>false</visualize>
  34. <update_rate>5.5</update_rate>
  35. <ray>
  36. <scan>
  37. <horizontal>
  38. <samples>360</samples>
  39. <resolution>1</resolution>
  40. <min_angle>-3</min_angle>
  41. <max_angle>3</max_angle>
  42. </horizontal>
  43. </scan>
  44. <range>
  45. <min>0.10</min>
  46. <max>6.0</max>
  47. <resolution>0.01</resolution>
  48. </range>
  49. <noise>
  50. <type>gaussian</type>
  51. <mean>0.0</mean>
  52. <stddev>0.01</stddev>
  53. </noise>
  54. </ray>
  55. <plugin name="gazebo_rplidar" filename="libgazebo_ros_laser.so">
  56. <topicName>/scan</topicName>
  57. <frameName>laser_link</frameName>
  58. </plugin>
  59. </sensor>
  60. </gazebo>
  61. </xacro:macro>
  62. </robot>

3.mbot_base_gazebo.xacro

  1. <?xml version="1.0"?>
  2. <robot name="mbot" xmlns:xacro="http://www.ros.org/wiki/xacro">
  3. <!-- PROPERTY LIST -->
  4. <xacro:property name="M_PI" value="3.1415926"/>
  5. <xacro:property name="base_mass" value="20" />
  6. <xacro:property name="base_radius" value="0.20"/>
  7. <xacro:property name="base_length" value="0.16"/>
  8. <xacro:property name="wheel_mass" value="2" />
  9. <xacro:property name="wheel_radius" value="0.06"/>
  10. <xacro:property name="wheel_length" value="0.025"/>
  11. <xacro:property name="wheel_joint_y" value="0.19"/>
  12. <xacro:property name="wheel_joint_z" value="0.05"/>
  13. <xacro:property name="caster_mass" value="0.5" />
  14. <xacro:property name="caster_radius" value="0.015"/> <!-- wheel_radius - ( base_length/2 - wheel_joint_z) -->
  15. <xacro:property name="caster_joint_x" value="0.18"/>
  16. <!-- Defining the colors used in this robot -->
  17. <material name="yellow">
  18. <color rgba="1 0.4 0 1"/>
  19. </material>
  20. <material name="black">
  21. <color rgba="0 0 0 0.95"/>
  22. </material>
  23. <material name="gray">
  24. <color rgba="0.75 0.75 0.75 1"/>
  25. </material>
  26. <!-- Macro for inertia matrix -->
  27. <xacro:macro name="sphere_inertial_matrix" params="m r">
  28. <inertial>
  29. <mass value="${m}" />
  30. <inertia ixx="${2*m*r*r/5}" ixy="0" ixz="0"
  31. iyy="${2*m*r*r/5}" iyz="0"
  32. izz="${2*m*r*r/5}" />
  33. </inertial>
  34. </xacro:macro>
  35. <xacro:macro name="cylinder_inertial_matrix" params="m r h">
  36. <inertial>
  37. <mass value="${m}" />
  38. <inertia ixx="${m*(3*r*r+h*h)/12}" ixy = "0" ixz = "0"
  39. iyy="${m*(3*r*r+h*h)/12}" iyz = "0"
  40. izz="${m*r*r/2}" />
  41. </inertial>
  42. </xacro:macro>
  43. <!-- Macro for robot wheel -->
  44. <xacro:macro name="wheel" params="prefix reflect">
  45. <joint name="${prefix}_wheel_joint" type="continuous">
  46. <origin xyz="0 ${reflect*wheel_joint_y} ${-wheel_joint_z}" rpy="0 0 0"/>
  47. <parent link="base_link"/>
  48. <child link="${prefix}_wheel_link"/>
  49. <axis xyz="0 1 0"/>
  50. </joint>
  51. <link name="${prefix}_wheel_link">
  52. <visual>
  53. <origin xyz="0 0 0" rpy="${M_PI/2} 0 0" />
  54. <geometry>
  55. <cylinder radius="${wheel_radius}" length = "${wheel_length}"/>
  56. </geometry>
  57. <material name="gray" />
  58. </visual>
  59. <collision>
  60. <origin xyz="0 0 0" rpy="${M_PI/2} 0 0" />
  61. <geometry>
  62. <cylinder radius="${wheel_radius}" length = "${wheel_length}"/>
  63. </geometry>
  64. </collision>
  65. <cylinder_inertial_matrix m="${wheel_mass}" r="${wheel_radius}" h="${wheel_length}" />
  66. </link>
  67. <gazebo reference="${prefix}_wheel_link">
  68. <material>Gazebo/Gray</material>
  69. </gazebo>
  70. <!-- Transmission is important to link the joints and the controller -->
  71. <transmission name="${prefix}_wheel_joint_trans">
  72. <type>transmission_interface/SimpleTransmission</type>
  73. <joint name="${prefix}_wheel_joint" >
  74. <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
  75. </joint>
  76. <actuator name="${prefix}_wheel_joint_motor">
  77. <hardwareInterface>hardware_interface/VelocityJointInterface</hardwareInterface>
  78. <mechanicalReduction>1</mechanicalReduction>
  79. </actuator>
  80. </transmission>
  81. </xacro:macro>
  82. <!-- Macro for robot caster -->
  83. <xacro:macro name="caster" params="prefix reflect">
  84. <joint name="${prefix}_caster_joint" type="continuous">
  85. <origin xyz="${reflect*caster_joint_x} 0 ${-(base_length/2 + caster_radius)}" rpy="0 0 0"/>
  86. <parent link="base_link"/>
  87. <child link="${prefix}_caster_link"/>
  88. <axis xyz="0 1 0"/>
  89. </joint>
  90. <link name="${prefix}_caster_link">
  91. <visual>
  92. <origin xyz="0 0 0" rpy="0 0 0"/>
  93. <geometry>
  94. <sphere radius="${caster_radius}" />
  95. </geometry>
  96. <material name="black" />
  97. </visual>
  98. <collision>
  99. <origin xyz="0 0 0" rpy="0 0 0"/>
  100. <geometry>
  101. <sphere radius="${caster_radius}" />
  102. </geometry>
  103. </collision>
  104. <sphere_inertial_matrix m="${caster_mass}" r="${caster_radius}" />
  105. </link>
  106. <gazebo reference="${prefix}_caster_link">
  107. <material>Gazebo/Black</material>
  108. </gazebo>
  109. </xacro:macro>
  110. <xacro:macro name="mbot_base_gazebo">
  111. <link name="base_footprint">
  112. <visual>
  113. <origin xyz="0 0 0" rpy="0 0 0" />
  114. <geometry>
  115. <box size="0.001 0.001 0.001" />
  116. </geometry>
  117. </visual>
  118. </link>
  119. <gazebo reference="base_footprint">
  120. <turnGravityOff>false</turnGravityOff>
  121. </gazebo>
  122. <joint name="base_footprint_joint" type="fixed">
  123. <origin xyz="0 0 ${base_length/2 + caster_radius*2}" rpy="0 0 0" />
  124. <parent link="base_footprint"/>
  125. <child link="base_link" />
  126. </joint>
  127. <link name="base_link">
  128. <visual>
  129. <origin xyz=" 0 0 0" rpy="0 0 0" />
  130. <geometry>
  131. <cylinder length="${base_length}" radius="${base_radius}"/>
  132. </geometry>
  133. <material name="yellow" />
  134. </visual>
  135. <collision>
  136. <origin xyz=" 0 0 0" rpy="0 0 0" />
  137. <geometry>
  138. <cylinder length="${base_length}" radius="${base_radius}"/>
  139. </geometry>
  140. </collision>
  141. <cylinder_inertial_matrix m="${base_mass}" r="${base_radius}" h="${base_length}" />
  142. </link>
  143. <gazebo reference="base_link">
  144. <material>Gazebo/Blue</material>
  145. </gazebo>
  146. <wheel prefix="left" reflect="1"/>
  147. <wheel prefix="right" reflect="-1"/>
  148. <caster prefix="front" reflect="-1"/>
  149. <caster prefix="back" reflect="1"/>
  150. <!-- controller -->
  151. <gazebo>
  152. <plugin name="differential_drive_controller"
  153. filename="libgazebo_ros_diff_drive.so">
  154. <rosDebugLevel>Debug</rosDebugLevel>
  155. <publishWheelTF>true</publishWheelTF>
  156. <robotNamespace>/</robotNamespace>
  157. <publishTf>1</publishTf>
  158. <publishWheelJointState>true</publishWheelJointState>
  159. <alwaysOn>true</alwaysOn>
  160. <updateRate>100.0</updateRate>
  161. <legacyMode>true</legacyMode>
  162. <leftJoint>left_wheel_joint</leftJoint>
  163. <rightJoint>right_wheel_joint</rightJoint>
  164. <wheelSeparation>${wheel_joint_y*2}</wheelSeparation>
  165. <wheelDiameter>${2*wheel_radius}</wheelDiameter>
  166. <broadcastTF>1</broadcastTF>
  167. <wheelTorque>30</wheelTorque>
  168. <wheelAcceleration>1.8</wheelAcceleration>
  169. <commandTopic>cmd_vel</commandTopic>
  170. <odometryFrame>odom</odometryFrame>
  171. <odometryTopic>odom</odometryTopic>
  172. <robotBaseFrame>base_footprint</robotBaseFrame>
  173. </plugin>
  174. </gazebo>
  175. </xacro:macro>
  176. </robot>

4.mbot_with_laser_gazebo.xacro

  1. <?xml version="1.0"?>
  2. <robot name="arm" xmlns:xacro="http://www.ros.org/wiki/xacro">
  3. <xacro:include filename="$(find mymbot_description)/mbot_base_gazebo.xacro" />
  4. <xacro:include filename="$(find mymbot_description)/lidar_gazebo.xacro" />
  5. <xacro:property name="lidar_offset_x" value="0" />
  6. <xacro:property name="lidar_offset_y" value="0" />
  7. <xacro:property name="lidar_offset_z" value="0.105" />
  8. <!-- lidar -->
  9. <joint name="lidar_joint" type="fixed">
  10. <origin xyz="${lidar_offset_x} ${lidar_offset_y} ${lidar_offset_z}" rpy="0 0 0" />
  11. <parent link="base_link"/>
  12. <child link="laser_link"/>
  13. </joint>
  14. <xacro:rplidar prefix="laser"/>
  15. <mbot_base_gazebo/>
  16. </robot>

三、在src下建立mymbot_gazebo功能包

1.创建功能包

  1. cd ~/catkin_mbot/src
  2. catkin_create_pkg mymbot_gazebo gazebo_plugins gazebo_ros gazebo_ros_control

在该功能包下创建launch、worlds两个文件夹

2.launch文件夹下创建view_mbot_with_laser_gazebo.launch文件

  1. <launch>
  2. <!-- 设置launch文件的参数 -->
  3. <arg name="world_name" value="$(find mymbot_gazebo)/worlds/easy.world"/>
  4. <arg name="paused" default="false"/>
  5. <arg name="use_sim_time" default="true"/>
  6. <arg name="gui" default="true"/>
  7. <arg name="headless" default="false"/>
  8. <arg name="debug" default="false"/>
  9. <!-- 运行gazebo仿真环境 -->
  10. <include file="$(find gazebo_ros)/launch/empty_world.launch">
  11. <arg name="world_name" value="$(arg world_name)" />
  12. <arg name="debug" value="$(arg debug)" />
  13. <arg name="gui" value="$(arg gui)" />
  14. <arg name="paused" value="$(arg paused)"/>
  15. <arg name="use_sim_time" value="$(arg use_sim_time)"/>
  16. <arg name="headless" value="$(arg headless)"/>
  17. </include>
  18. <!-- 加载机器人模型描述参数 -->
  19. <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mymbot_description)/mbot_with_laser_gazebo.xacro'" />
  20. <!-- 运行joint_state_publisher节点,发布机器人的关节状态 -->
  21. <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node>
  22. <!-- 运行robot_state_publisher节点,发布tf -->
  23. <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" output="screen" >
  24. <param name="publish_frequency" type="double" value="50.0" />
  25. </node>
  26. <!-- 在gazebo中加载机器人模型-->
  27. <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
  28. args="-urdf -model mbot -param robot_description"/>
  29. </launch>

3.在worlds文件夹下创建easy.world文件

  1. <sdf version='1.6'>
  2. <world name='default'>
  3. <light name='sun' type='directional'>
  4. <cast_shadows>1</cast_shadows>
  5. <pose frame=''>0 0 10 0 -0 0</pose>
  6. <diffuse>0.8 0.8 0.8 1</diffuse>
  7. <specular>0.2 0.2 0.2 1</specular>
  8. <attenuation>
  9. <range>1000</range>
  10. <constant>0.9</constant>
  11. <linear>0.01</linear>
  12. <quadratic>0.001</quadratic>
  13. </attenuation>
  14. <direction>-0.5 0.1 -0.9</direction>
  15. </light>
  16. <model name='ground_plane'>
  17. <static>1</static>
  18. <link name='link'>
  19. <collision name='collision'>
  20. <geometry>
  21. <plane>
  22. <normal>0 0 1</normal>
  23. <size>100 100</size>
  24. </plane>
  25. </geometry>
  26. <surface>
  27. <friction>
  28. <ode>
  29. <mu>100</mu>
  30. <mu2>50</mu2>
  31. </ode>
  32. <torsional>
  33. <ode/>
  34. </torsional>
  35. </friction>
  36. <contact>
  37. <ode/>
  38. </contact>
  39. <bounce/>
  40. </surface>
  41. <max_contacts>10</max_contacts>
  42. </collision>
  43. <visual name='visual'>
  44. <cast_shadows>0</cast_shadows>
  45. <geometry>
  46. <plane>
  47. <normal>0 0 1</normal>
  48. <size>100 100</size>
  49. </plane>
  50. </geometry>
  51. <material>
  52. <script>
  53. <uri>file://media/materials/scripts/gazebo.material</uri>
  54. <name>Gazebo/Grey</name>
  55. </script>
  56. </material>
  57. </visual>
  58. <self_collide>0</self_collide>
  59. <enable_wind>0</enable_wind>
  60. <kinematic>0</kinematic>
  61. </link>
  62. </model>
  63. <gravity>0 0 -9.8</gravity>
  64. <magnetic_field>6e-06 2.3e-05 -4.2e-05</magnetic_field>
  65. <atmosphere type='adiabatic'/>
  66. <physics name='default_physics' default='0' type='ode'>
  67. <max_step_size>0.001</max_step_size>
  68. <real_time_factor>1</real_time_factor>
  69. <real_time_update_rate>1000</real_time_update_rate>
  70. </physics>
  71. <scene>
  72. <ambient>0.4 0.4 0.4 1</ambient>
  73. <background>0.7 0.7 0.7 1</background>
  74. <shadows>1</shadows>
  75. </scene>
  76. <audio>
  77. <device>default</device>
  78. </audio>
  79. <wind/>
  80. <spherical_coordinates>
  81. <surface_model>EARTH_WGS84</surface_model>
  82. <latitude_deg>0</latitude_deg>
  83. <longitude_deg>0</longitude_deg>
  84. <elevation>0</elevation>
  85. <heading_deg>0</heading_deg>
  86. </spherical_coordinates>
  87. <model name='Untitled'>
  88. <pose frame=''>1.485 0.01 0 0 -0 0</pose>
  89. <link name='Wall_0'>
  90. <collision name='Wall_0_Collision'>
  91. <geometry>
  92. <box>
  93. <size>7 0.15 2.5</size>
  94. </box>
  95. </geometry>
  96. <pose frame=''>0 0 1.25 0 -0 0</pose>
  97. <max_contacts>10</max_contacts>
  98. <surface>
  99. <contact>
  100. <ode/>
  101. </contact>
  102. <bounce/>
  103. <friction>
  104. <torsional>
  105. <ode/>
  106. </torsional>
  107. <ode/>
  108. </friction>
  109. </surface>
  110. </collision>
  111. <visual name='Wall_0_Visual'>
  112. <pose frame=''>0 0 1.25 0 -0 0</pose>
  113. <geometry>
  114. <box>
  115. <size>7 0.15 2.5</size>
  116. </box>
  117. </geometry>
  118. <material>
  119. <script>
  120. <uri>file://media/materials/scripts/gazebo.material</uri>
  121. <name>Gazebo/Grey</name>
  122. </script>
  123. <ambient>1 1 1 1</ambient>
  124. </material>
  125. <meta>
  126. <layer>0</layer>
  127. </meta>
  128. </visual>
  129. <pose frame=''>0 -3.1 0 0 -0 0</pose>
  130. <self_collide>0</self_collide>
  131. <enable_wind>0</enable_wind>
  132. <kinematic>0</kinematic>
  133. </link>
  134. <link name='Wall_1'>
  135. <collision name='Wall_1_Collision'>
  136. <geometry>
  137. <box>
  138. <size>4 0.15 2.5</size>
  139. </box>
  140. </geometry>
  141. <pose frame=''>0 0 1.25 0 -0 0</pose>
  142. <max_contacts>10</max_contacts>
  143. <surface>
  144. <contact>
  145. <ode/>
  146. </contact>
  147. <bounce/>
  148. <friction>
  149. <torsional>
  150. <ode/>
  151. </torsional>
  152. <ode/>
  153. </friction>
  154. </surface>
  155. </collision>
  156. <visual name='Wall_1_Visual'>
  157. <pose frame=''>0 0 1.25 0 -0 0</pose>
  158. <geometry>
  159. <box>
  160. <size>4 0.15 2.5</size>
  161. </box>
  162. </geometry>
  163. <material>
  164. <script>
  165. <uri>file://media/materials/scripts/gazebo.material</uri>
  166. <name>Gazebo/Grey</name>
  167. </script>
  168. <ambient>1 1 1 1</ambient>
  169. </material>
  170. <meta>
  171. <layer>0</layer>
  172. </meta>
  173. </visual>
  174. <pose frame=''>3.425 -1.175 0 0 -0 1.5708</pose>
  175. <self_collide>0</self_collide>
  176. <enable_wind>0</enable_wind>
  177. <kinematic>0</kinematic>
  178. </link>
  179. <link name='Wall_2'>
  180. <collision name='Wall_2_Collision'>
  181. <geometry>
  182. <box>
  183. <size>2.5 0.15 2.5</size>
  184. </box>
  185. </geometry>
  186. <pose frame=''>0 0 1.25 0 -0 0</pose>
  187. <max_contacts>10</max_contacts>
  188. <surface>
  189. <contact>
  190. <ode/>
  191. </contact>
  192. <bounce/>
  193. <friction>
  194. <torsional>
  195. <ode/>
  196. </torsional>
  197. <ode/>
  198. </friction>
  199. </surface>
  200. </collision>
  201. <visual name='Wall_2_Visual'>
  202. <pose frame=''>0 0 1.25 0 -0 0</pose>
  203. <geometry>
  204. <box>
  205. <size>2.5 0.15 2.5</size>
  206. </box>
  207. </geometry>
  208. <material>
  209. <script>
  210. <uri>file://media/materials/scripts/gazebo.material</uri>
  211. <name>Gazebo/Grey</name>
  212. </script>
  213. <ambient>1 1 1 1</ambient>
  214. </material>
  215. <meta>
  216. <layer>0</layer>
  217. </meta>
  218. </visual>
  219. <pose frame=''>3.425 1.925 0 0 -0 1.5708</pose>
  220. <self_collide>0</self_collide>
  221. <enable_wind>0</enable_wind>
  222. <kinematic>0</kinematic>
  223. </link>
  224. <link name='Wall_3'>
  225. <collision name='Wall_3_Collision'>
  226. <geometry>
  227. <box>
  228. <size>7 0.15 2.5</size>
  229. </box>
  230. </geometry>
  231. <pose frame=''>0 0 1.25 0 -0 0</pose>
  232. <max_contacts>10</max_contacts>
  233. <surface>
  234. <contact>
  235. <ode/>
  236. </contact>
  237. <bounce/>
  238. <friction>
  239. <torsional>
  240. <ode/>
  241. </torsional>
  242. <ode/>
  243. </friction>
  244. </surface>
  245. </collision>
  246. <visual name='Wall_3_Visual'>
  247. <pose frame=''>0 0 1.25 0 -0 0</pose>
  248. <geometry>
  249. <box>
  250. <size>7 0.15 2.5</size>
  251. </box>
  252. </geometry>
  253. <material>
  254. <script>
  255. <uri>file://media/materials/scripts/gazebo.material</uri>
  256. <name>Gazebo/Grey</name>
  257. </script>
  258. <ambient>1 1 1 1</ambient>
  259. </material>
  260. <meta>
  261. <layer>0</layer>
  262. </meta>
  263. </visual>
  264. <pose frame=''>0 3.1 0 0 -0 3.14159</pose>
  265. <self_collide>0</self_collide>
  266. <enable_wind>0</enable_wind>
  267. <kinematic>0</kinematic>
  268. </link>
  269. <link name='Wall_4'>
  270. <collision name='Wall_4_Collision'>
  271. <geometry>
  272. <box>
  273. <size>6.35 0.15 2.5</size>
  274. </box>
  275. </geometry>
  276. <pose frame=''>0 0 1.25 0 -0 0</pose>
  277. <max_contacts>10</max_contacts>
  278. <surface>
  279. <contact>
  280. <ode/>
  281. </contact>
  282. <bounce/>
  283. <friction>
  284. <torsional>
  285. <ode/>
  286. </torsional>
  287. <ode/>
  288. </friction>
  289. </surface>
  290. </collision>
  291. <visual name='Wall_4_Visual'>
  292. <pose frame=''>0 0 1.25 0 -0 0</pose>
  293. <geometry>
  294. <box>
  295. <size>6.35 0.15 2.5</size>
  296. </box>
  297. </geometry>
  298. <material>
  299. <script>
  300. <uri>file://media/materials/scripts/gazebo.material</uri>
  301. <name>Gazebo/Grey</name>
  302. </script>
  303. <ambient>1 1 1 1</ambient>
  304. </material>
  305. <meta>
  306. <layer>0</layer>
  307. </meta>
  308. </visual>
  309. <pose frame=''>-3.425 0 0 0 -0 -1.5708</pose>
  310. <self_collide>0</self_collide>
  311. <enable_wind>0</enable_wind>
  312. <kinematic>0</kinematic>
  313. </link>
  314. <static>1</static>
  315. </model>
  316. <model name='control_console'>
  317. <static>1</static>
  318. <link name='link'>
  319. <visual name='visual'>
  320. <geometry>
  321. <mesh>
  322. <uri>model://control_console/meshes/console.dae</uri>
  323. </mesh>
  324. </geometry>
  325. </visual>
  326. <visual name='backvisual'>
  327. <pose frame=''>0 0.29388 1.30113 0 -0 0</pose>
  328. <geometry>
  329. <box>
  330. <size>1.78 0.05 2.60225</size>
  331. </box>
  332. </geometry>
  333. </visual>
  334. <collision name='back_collision'>
  335. <pose frame=''>0 0.29388 1.30113 0 -0 0</pose>
  336. <geometry>
  337. <box>
  338. <size>1.78 0.05 2.60225</size>
  339. </box>
  340. </geometry>
  341. <max_contacts>10</max_contacts>
  342. <surface>
  343. <contact>
  344. <ode/>
  345. </contact>
  346. <bounce/>
  347. <friction>
  348. <torsional>
  349. <ode/>
  350. </torsional>
  351. <ode/>
  352. </friction>
  353. </surface>
  354. </collision>
  355. <collision name='base_collision'>
  356. <pose frame=''>0 -0.14669 0.4128 0 -0 0</pose>
  357. <geometry>
  358. <box>
  359. <size>1.78872 0.97373 0.8256</size>
  360. </box>
  361. </geometry>
  362. <max_contacts>10</max_contacts>
  363. <surface>
  364. <contact>
  365. <ode/>
  366. </contact>
  367. <bounce/>
  368. <friction>
  369. <torsional>
  370. <ode/>
  371. </torsional>
  372. <ode/>
  373. </friction>
  374. </surface>
  375. </collision>
  376. <collision name='mid_collision'>
  377. <pose frame=''>0 0.04268 1.48248 0 -0 0</pose>
  378. <geometry>
  379. <box>
  380. <size>1.70162 0.51806 1.5</size>
  381. </box>
  382. </geometry>
  383. <max_contacts>10</max_contacts>
  384. <surface>
  385. <contact>
  386. <ode/>
  387. </contact>
  388. <bounce/>
  389. <friction>
  390. <torsional>
  391. <ode/>
  392. </torsional>
  393. <ode/>
  394. </friction>
  395. </surface>
  396. </collision>
  397. <collision name='top_collision'>
  398. <pose frame=''>0 -0.15709 2.31203 0 -0 0</pose>
  399. <geometry>
  400. <box>
  401. <size>1.78872 0.95292 0.62632</size>
  402. </box>
  403. </geometry>
  404. <max_contacts>10</max_contacts>
  405. <surface>
  406. <contact>
  407. <ode/>
  408. </contact>
  409. <bounce/>
  410. <friction>
  411. <torsional>
  412. <ode/>
  413. </torsional>
  414. <ode/>
  415. </friction>
  416. </surface>
  417. </collision>
  418. <collision name='panel_collision'>
  419. <pose frame=''>0 -0.36311 0.90329 0.428775 -0 0</pose>
  420. <geometry>
  421. <box>
  422. <size>1.33522 0.550273 0.1</size>
  423. </box>
  424. </geometry>
  425. <max_contacts>10</max_contacts>
  426. <surface>
  427. <contact>
  428. <ode/>
  429. </contact>
  430. <bounce/>
  431. <friction>
  432. <torsional>
  433. <ode/>
  434. </torsional>
  435. <ode/>
  436. </friction>
  437. </surface>
  438. </collision>
  439. <collision name='left_lower_shoulder_collision'>
  440. <pose frame=''>-0.7435 -0.19848 0.87 0.520485 -0 0</pose>
  441. <geometry>
  442. <box>
  443. <size>0.30172 0.7 0.5</size>
  444. </box>
  445. </geometry>
  446. <max_contacts>10</max_contacts>
  447. <surface>
  448. <contact>
  449. <ode/>
  450. </contact>
  451. <bounce/>
  452. <friction>
  453. <torsional>
  454. <ode/>
  455. </torsional>
  456. <ode/>
  457. </friction>
  458. </surface>
  459. </collision>
  460. <collision name='right_lower_shoulder_collision'>
  461. <pose frame=''>0.7435 -0.19848 0.87 0.520485 -0 0</pose>
  462. <geometry>
  463. <box>
  464. <size>0.30172 0.7 0.5</size>
  465. </box>
  466. </geometry>
  467. <max_contacts>10</max_contacts>
  468. <surface>
  469. <contact>
  470. <ode/>
  471. </contact>
  472. <bounce/>
  473. <friction>
  474. <torsional>
  475. <ode/>
  476. </torsional>
  477. <ode/>
  478. </friction>
  479. </surface>
  480. </collision>
  481. <collision name='left_upper_shoulder_collision'>
  482. <pose frame=''>-0.7435 -0.19152 1.99244 -0.620645 0 0</pose>
  483. <geometry>
  484. <box>
  485. <size>0.30172 0.7 0.5</size>
  486. </box>
  487. </geometry>
  488. <max_contacts>10</max_contacts>
  489. <surface>
  490. <contact>
  491. <ode/>
  492. </contact>
  493. <bounce/>
  494. <friction>
  495. <torsional>
  496. <ode/>
  497. </torsional>
  498. <ode/>
  499. </friction>
  500. </surface>
  501. </collision>
  502. <collision name='right_upper_shoulder_collision'>
  503. <pose frame=''>0.7435 -0.19152 1.99244 -0.620645 0 0</pose>
  504. <geometry>
  505. <box>
  506. <size>0.30172 0.7 0.5</size>
  507. </box>
  508. </geometry>
  509. <max_contacts>10</max_contacts>
  510. <surface>
  511. <contact>
  512. <ode/>
  513. </contact>
  514. <bounce/>
  515. <friction>
  516. <torsional>
  517. <ode/>
  518. </torsional>
  519. <ode/>
  520. </friction>
  521. </surface>
  522. </collision>
  523. <self_collide>0</self_collide>
  524. <enable_wind>0</enable_wind>
  525. <kinematic>0</kinematic>
  526. </link>
  527. <pose frame=''>1.12417 2.74992 0 0 -0 0</pose>
  528. </model>
  529. <model name='number5'>
  530. <pose frame=''>4.48715 -0.132796 0.4 0 -0 0</pose>
  531. <static>1</static>
  532. <link name='link'>
  533. <visual name='visual'>
  534. <geometry>
  535. <mesh>
  536. <uri>model://number1/meshes/number.dae</uri>
  537. </mesh>
  538. </geometry>
  539. <material>
  540. <script>
  541. <uri>model://number5/materials/scripts</uri>
  542. <uri>model://number5/materials/textures</uri>
  543. <name>Number/Five</name>
  544. </script>
  545. </material>
  546. </visual>
  547. <self_collide>0</self_collide>
  548. <enable_wind>0</enable_wind>
  549. <kinematic>0</kinematic>
  550. </link>
  551. </model>
  552. <state world_name='default'>
  553. <sim_time>151 774000000</sim_time>
  554. <real_time>154 256918546</real_time>
  555. <wall_time>1649152266 204573612</wall_time>
  556. <iterations>151774</iterations>
  557. <model name='Untitled'>
  558. <pose frame=''>1.485 0.01 0 0 -0 0</pose>
  559. <scale>1 1 1</scale>
  560. <link name='Wall_0'>
  561. <pose frame=''>1.485 -3.09 0 0 -0 0</pose>
  562. <velocity>0 0 0 0 -0 0</velocity>
  563. <acceleration>0 0 0 0 -0 0</acceleration>
  564. <wrench>0 0 0 0 -0 0</wrench>
  565. </link>
  566. <link name='Wall_1'>
  567. <pose frame=''>4.91 -1.165 0 0 -0 1.5708</pose>
  568. <velocity>0 0 0 0 -0 0</velocity>
  569. <acceleration>0 0 0 0 -0 0</acceleration>
  570. <wrench>0 0 0 0 -0 0</wrench>
  571. </link>
  572. <link name='Wall_2'>
  573. <pose frame=''>4.91 1.935 0 0 -0 1.5708</pose>
  574. <velocity>0 0 0 0 -0 0</velocity>
  575. <acceleration>0 0 0 0 -0 0</acceleration>
  576. <wrench>0 0 0 0 -0 0</wrench>
  577. </link>
  578. <link name='Wall_3'>
  579. <pose frame=''>1.485 3.11 0 0 -0 3.14159</pose>
  580. <velocity>0 0 0 0 -0 0</velocity>
  581. <acceleration>0 0 0 0 -0 0</acceleration>
  582. <wrench>0 0 0 0 -0 0</wrench>
  583. </link>
  584. <link name='Wall_4'>
  585. <pose frame=''>-1.94 0.01 0 0 0 -1.5708</pose>
  586. <velocity>0 0 0 0 -0 0</velocity>
  587. <acceleration>0 0 0 0 -0 0</acceleration>
  588. <wrench>0 0 0 0 -0 0</wrench>
  589. </link>
  590. </model>
  591. <model name='control_console'>
  592. <pose frame=''>1.12417 2.74992 0 0 -0 0</pose>
  593. <scale>1 1 1</scale>
  594. <link name='link'>
  595. <pose frame=''>1.12417 2.74992 0 0 -0 0</pose>
  596. <velocity>0 0 0 0 -0 0</velocity>
  597. <acceleration>0 0 0 0 -0 0</acceleration>
  598. <wrench>0 0 0 0 -0 0</wrench>
  599. </link>
  600. </model>
  601. <model name='ground_plane'>
  602. <pose frame=''>0 0 0 0 -0 0</pose>
  603. <scale>1 1 1</scale>
  604. <link name='link'>
  605. <pose frame=''>0 0 0 0 -0 0</pose>
  606. <velocity>0 0 0 0 -0 0</velocity>
  607. <acceleration>0 0 0 0 -0 0</acceleration>
  608. <wrench>0 0 0 0 -0 0</wrench>
  609. </link>
  610. </model>
  611. <model name='number5'>
  612. <pose frame=''>4.48715 -0.132796 0.4 0 -0 0</pose>
  613. <scale>1 1 1</scale>
  614. <link name='link'>
  615. <pose frame=''>4.48715 -0.132796 0.4 0 -0 0</pose>
  616. <velocity>0 0 0 0 -0 0</velocity>
  617. <acceleration>0 0 0 0 -0 0</acceleration>
  618. <wrench>0 0 0 0 -0 0</wrench>
  619. </link>
  620. </model>
  621. <light name='sun'>
  622. <pose frame=''>0 0 10 0 -0 0</pose>
  623. </light>
  624. </state>
  625. <gui fullscreen='0'>
  626. <camera name='user_camera'>
  627. <pose frame=''>4.11801 -5.09183 19.1974 -0 1.33564 1.5642</pose>
  628. <view_controller>orbit</view_controller>
  629. <projection_type>perspective</projection_type>
  630. </camera>
  631. </gui>
  632. </world>
  633. </sdf>

以上两个文件夹可以实现在gazebo中创建一个仿真环境,并启动仿真小车

4.编译

  1. cd ~/catkin_mbot
  2. catkin_make

5.测试

  1. source ~/catkin_mbot/devel/setup.bash
  2. roslaunch mymbot_gazebo view_mbot_with_laser_gazebo.launch

6. 创建新的地图

  1. source ~/catkin_mbot/devel/setup.bash
  2. roslaunch mymbot_gazebo view_mbot_with_laser_gazebo.launch

打开gazebo仿真后在insert一栏可以添加新的物体,其中诸多模型文件会以资源形式上传

删除所有的墙体,以及物体后如图

 点击Edit中的Building Editor

创建墙体

 保存后退出

 点击FIle中的 Save World As,以world_1.world为名保存到map文件夹中

 修改view_mbot_with_laser_gazebo.launch文件中的内容

 将easy.world修改为world_1.world

测试:

运行gazebo仿真

  1. source ~/catkin_mbot/devel/setup.bash
  2. roslaunch mymbot_gazebo view_mbot_with_laser_gazebo.launch

 

 测试成功后将launch中的world改为easy.world

四、引入键盘控制功能,在src下建立mbot_teleop功能包

1.新建功能包

  1. cd ~/catkin_mbot/src
  2. catkin_create_pkg mbot_teleop geometry_msgs rospy

在该功能包下创建launch、scripts两个文件夹

2.launch中新建mbot_teleop.launch文件

  1. <launch>
  2. <node name="mbot_teleop" pkg="mbot_teleop" type="mbot_teleop.py" output="screen">
  3. <param name="scale_linear" value="0.1" type="double"/>
  4. <param name="scale_angular" value="0.4" type="double"/>
  5. </node>
  6. </launch>

3.scripts中新建mbot_teleop.py文件

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import rospy
  4. from geometry_msgs.msg import Twist
  5. import sys, select, termios, tty
  6. msg = """
  7. Control mbot!
  8. ---------------------------
  9. Moving around:
  10. u i o
  11. j k l
  12. m , .
  13. q/z : increase/decrease max speeds by 10%
  14. w/x : increase/decrease only linear speed by 10%
  15. e/c : increase/decrease only angular speed by 10%
  16. space key, k : force stop
  17. anything else : stop smoothly
  18. CTRL-C to quit
  19. """
  20. moveBindings = {
  21. 'i':(1,0),
  22. 'o':(1,-1),
  23. 'j':(0,1),
  24. 'l':(0,-1),
  25. 'u':(1,1),
  26. ',':(-1,0),
  27. '.':(-1,1),
  28. 'm':(-1,-1),
  29. }
  30. speedBindings={
  31. 'q':(1.1,1.1),
  32. 'z':(.9,.9),
  33. 'w':(1.1,1),
  34. 'x':(.9,1),
  35. 'e':(1,1.1),
  36. 'c':(1,.9),
  37. }
  38. def getKey():
  39. tty.setraw(sys.stdin.fileno())
  40. rlist, _, _ = select.select([sys.stdin], [], [], 0.1)
  41. if rlist:
  42. key = sys.stdin.read(1)
  43. else:
  44. key = ''
  45. termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)
  46. return key
  47. speed = .2
  48. turn = 1
  49. def vels(speed,turn):
  50. return "currently:\tspeed %s\tturn %s " % (speed,turn)
  51. if __name__=="__main__":
  52. settings = termios.tcgetattr(sys.stdin)
  53. rospy.init_node('mbot_teleop')
  54. pub = rospy.Publisher('/cmd_vel', Twist, queue_size=5)
  55. x = 0
  56. th = 0
  57. status = 0
  58. count = 0
  59. acc = 0.1
  60. target_speed = 0
  61. target_turn = 0
  62. control_speed = 0
  63. control_turn = 0
  64. try:
  65. print msg
  66. print vels(speed,turn)
  67. while(1):
  68. key = getKey()
  69. # 运动控制方向键(1:正方向,-1负方向)
  70. if key in moveBindings.keys():
  71. x = moveBindings[key][0]
  72. th = moveBindings[key][1]
  73. count = 0
  74. # 速度修改键
  75. elif key in speedBindings.keys():
  76. speed = speed * speedBindings[key][0] # 线速度增加0.1
  77. turn = turn * speedBindings[key][1] # 角速度增加0.1
  78. count = 0
  79. print vels(speed,turn)
  80. if (status == 14):
  81. print msg
  82. status = (status + 1) % 15
  83. # 停止键
  84. elif key == ' ' or key == 'k' :
  85. x = 0
  86. th = 0
  87. control_speed = 0
  88. control_turn = 0
  89. else:
  90. count = count + 1
  91. if count > 4:
  92. x = 0
  93. th = 0
  94. if (key == '\x03'):
  95. break
  96. # 目标速度=速度值*方向值
  97. target_speed = speed * x
  98. target_turn = turn * th
  99. # 速度限位,防止速度增减过快
  100. if target_speed > control_speed:
  101. control_speed = min( target_speed, control_speed + 0.02 )
  102. elif target_speed < control_speed:
  103. control_speed = max( target_speed, control_speed - 0.02 )
  104. else:
  105. control_speed = target_speed
  106. if target_turn > control_turn:
  107. control_turn = min( target_turn, control_turn + 0.1 )
  108. elif target_turn < control_turn:
  109. control_turn = max( target_turn, control_turn - 0.1 )
  110. else:
  111. control_turn = target_turn
  112. # 创建并发布twist消息
  113. twist = Twist()
  114. twist.linear.x = control_speed;
  115. twist.linear.y = 0;
  116. twist.linear.z = 0
  117. twist.angular.x = 0;
  118. twist.angular.y = 0;
  119. twist.angular.z = control_turn
  120. pub.publish(twist)
  121. except:
  122. print e
  123. finally:
  124. twist = Twist()
  125. twist.linear.x = 0; twist.linear.y = 0; twist.linear.z = 0
  126. twist.angular.x = 0; twist.angular.y = 0; twist.angular.z = 0
  127. pub.publish(twist)
  128. termios.tcsetattr(sys.stdin, termios.TCSADRAIN, settings)

删掉该功能包下的src文件夹即可

4.编译

  1. cd ~/catkin_mbot
  2. catkin_make

五、配置导航功能包

1.创建功能包

sudo apt-get install ros-melodic-navigation

2.在src下创建mbot_navigation功能包

  1. cd ~/catkin_mbot/src
  2. catkin_create_pkg mbot_navigation geometry_msgs move_base_msgs

在该功能包下创建config、launch、maps、rviz四个文件夹

config文件夹下创建mbot文件夹,在mbot中创建base_local_planner_params.yaml、costmap_common_params.yaml、global_costmap_params.yaml、local_costmap_params.yaml

3.base_local_planner_params.yaml

  1. controller_frequency: 3.0
  2. recovery_behavior_enabled: false
  3. clearing_rotation_allowed: false
  4. TrajectoryPlannerROS:
  5. max_vel_x: 0.5
  6. min_vel_x: 0.1
  7. max_vel_y: 0.0 # zero for a differential drive robot
  8. min_vel_y: 0.0
  9. max_vel_theta: 1.0
  10. min_vel_theta: -1.0
  11. min_in_place_vel_theta: 0.5
  12. escape_vel: -0.1
  13. acc_lim_x: 1.5
  14. acc_lim_y: 0.0 # zero for a differential drive robot
  15. acc_lim_theta: 1.2
  16. holonomic_robot: false
  17. yaw_goal_tolerance: 0.1 # about 6 degrees
  18. xy_goal_tolerance: 0.1 # 10 cm
  19. latch_xy_goal_tolerance: false
  20. pdist_scale: 0.9
  21. gdist_scale: 0.6
  22. meter_scoring: true
  23. heading_lookahead: 0.325
  24. heading_scoring: false
  25. heading_scoring_timestep: 0.8
  26. occdist_scale: 0.1
  27. oscillation_reset_dist: 0.05
  28. publish_cost_grid_pc: false
  29. prune_plan: true
  30. sim_time: 1.0
  31. sim_granularity: 0.025
  32. angular_sim_granularity: 0.025
  33. vx_samples: 8
  34. vy_samples: 0 # zero for a differential drive robot
  35. vtheta_samples: 20
  36. dwa: true
  37. simple_attractor: false

4.costmap_common_params.yaml

  1. obstacle_range: 2.5
  2. raytrace_range: 3.0
  3. footprint: [[0.175, 0.175], [0.175, -0.175], [-0.175, -0.175], [-0.175, 0.175]]
  4. footprint_inflation: 0.01
  5. robot_radius: 0.175
  6. inflation_radius: 0.15
  7. max_obstacle_height: 0.6
  8. min_obstacle_height: 0.0
  9. observation_sources: scan
  10. scan: {data_type: LaserScan, topic: /scan, marking: true, clearing: true, expected_update_rate: 0}

5.global_costmap_params.yaml

  1. global_costmap:
  2. global_frame: map
  3. robot_base_frame: base_footprint
  4. update_frequency: 1.0
  5. publish_frequency: 1.0
  6. static_map: true
  7. rolling_window: false
  8. resolution: 0.01
  9. transform_tolerance: 1.0
  10. map_type: costmap

6.local_costmap_params.yaml

  1. local_costmap:
  2. global_frame: odom
  3. robot_base_frame: base_footprint
  4. update_frequency: 3.0
  5. publish_frequency: 1.0
  6. static_map: true
  7. rolling_window: false
  8. width: 6.0
  9. height: 6.0
  10. resolution: 0.01
  11. transform_tolerance: 1.0

launch文件夹下存放以下三个文件:

7.amcl.launch

  1. <launch>
  2. <arg name="use_map_topic" default="false"/>
  3. <arg name="scan_topic" default="scan"/>
  4. <node pkg="amcl" type="amcl" name="amcl" clear_params="true">
  5. <param name="use_map_topic" value="$(arg use_map_topic)"/>
  6. <!-- Publish scans from best pose at a max of 10 Hz -->
  7. <param name="odom_model_type" value="diff"/>
  8. <param name="odom_alpha5" value="0.1"/>
  9. <param name="gui_publish_rate" value="10.0"/>
  10. <param name="laser_max_beams" value="60"/>
  11. <param name="laser_max_range" value="12.0"/>
  12. <param name="min_particles" value="500"/>
  13. <param name="max_particles" value="2000"/>
  14. <param name="kld_err" value="0.05"/>
  15. <param name="kld_z" value="0.99"/>
  16. <param name="odom_alpha1" value="0.2"/>
  17. <param name="odom_alpha2" value="0.2"/>
  18. <!-- translation std dev, m -->
  19. <param name="odom_alpha3" value="0.2"/>
  20. <param name="odom_alpha4" value="0.2"/>
  21. <param name="laser_z_hit" value="0.5"/>
  22. <param name="laser_z_short" value="0.05"/>
  23. <param name="laser_z_max" value="0.05"/>
  24. <param name="laser_z_rand" value="0.5"/>
  25. <param name="laser_sigma_hit" value="0.2"/>
  26. <param name="laser_lambda_short" value="0.1"/>
  27. <param name="laser_model_type" value="likelihood_field"/>
  28. <!-- <param name="laser_model_type" value="beam"/> -->
  29. <param name="laser_likelihood_max_dist" value="2.0"/>
  30. <param name="update_min_d" value="0.25"/>
  31. <param name="update_min_a" value="0.2"/>
  32. <param name="odom_frame_id" value="odom"/>
  33. <param name="resample_interval" value="1"/>
  34. <!-- Increase tolerance because the computer can get quite busy -->
  35. <param name="transform_tolerance" value="1.0"/>
  36. <param name="recovery_alpha_slow" value="0.0"/>
  37. <param name="recovery_alpha_fast" value="0.0"/>
  38. <remap from="scan" to="$(arg scan_topic)"/>
  39. </node>
  40. </launch>

8.move_base.launch

  1. <launch>
  2. <node pkg="move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true">
  3. <rosparam file="$(find mbot_navigation)/config/mbot/costmap_common_params.yaml" command="load" ns="global_costmap" />
  4. <rosparam file="$(find mbot_navigation)/config/mbot/costmap_common_params.yaml" command="load" ns="local_costmap" />
  5. <rosparam file="$(find mbot_navigation)/config/mbot/local_costmap_params.yaml" command="load" />
  6. <rosparam file="$(find mbot_navigation)/config/mbot/global_costmap_params.yaml" command="load" />
  7. <rosparam file="$(find mbot_navigation)/config/mbot/base_local_planner_params.yaml" command="load" />
  8. </node>
  9. </launch>

9.nav_cloister_demo.launch

  1. <launch>
  2. <!-- 设置地图的配置文件 -->
  3. <arg name="map" default="map.yaml" />
  4. <!-- 运行地图服务器,并且加载设置的地图-->
  5. <node name="map_server" pkg="map_server" type="map_server" args="$(find mbot_navigation)/maps/$(arg map)"/>
  6. <!-- 运行move_base节点 -->
  7. <include file="$(find mbot_navigation)/launch/move_base.launch"/>
  8. <!-- 启动AMCL节点 -->
  9. <include file="$(find mbot_navigation)/launch/amcl.launch" />
  10. <!-- 对于虚拟定位,需要设置一个/odom与/map之间的静态坐标变换 -->
  11. <node pkg="tf" type="static_transform_publisher" name="map_odom_broadcaster" args="0 0 0 0 0 0 /map /odom 100" />
  12. <!-- 运行rviz -->
  13. <node pkg="rviz" type="rviz" name="rviz" args="-d $(find mbot_navigation)/rviz/nav.rviz"/>
  14. </launch>

10.map

map文件夹中的内容参考我发布的《在激光雷达仿真环境下使用古月居提供的cartographer算法SLAM,最终导出 .pgm 与 .yaml 地图文件全过程》注意修改.yaml文件中的地图路径!!!

我的是:image: /home/rws/catkin_mbot/src/mbot_navigation/maps/map.pgm

11.rviz文件夹中创建nav.rviz文件

  1. Panels:
  2. - Class: rviz/Displays
  3. Help Height: 78
  4. Name: Displays
  5. Property Tree Widget:
  6. Expanded:
  7. - /Global Options1
  8. - /RobotModel1/Links1/base_footprint1
  9. - /Pose Array1
  10. Splitter Ratio: 0.652661026
  11. Tree Height: 691
  12. - Class: rviz/Selection
  13. Name: Selection
  14. - Class: rviz/Tool Properties
  15. Expanded:
  16. - /2D Pose Estimate1
  17. - /2D Nav Goal1
  18. Name: Tool Properties
  19. Splitter Ratio: 0.428570986
  20. - Class: rviz/Views
  21. Expanded:
  22. - /Current View1
  23. Name: Views
  24. Splitter Ratio: 0.5
  25. - Class: rviz/Time
  26. Experimental: false
  27. Name: Time
  28. SyncMode: 0
  29. SyncSource: LaserScan
  30. Visualization Manager:
  31. Class: ""
  32. Displays:
  33. - Alpha: 0.5
  34. Cell Size: 0.5
  35. Class: rviz/Grid
  36. Color: 0; 0; 0
  37. Enabled: true
  38. Line Style:
  39. Line Width: 0.0299999993
  40. Value: Lines
  41. Name: Grid
  42. Normal Cell Count: 0
  43. Offset:
  44. X: 0
  45. Y: 0
  46. Z: 0
  47. Plane: XY
  48. Plane Cell Count: 80
  49. Reference Frame: odom
  50. Value: true
  51. - Angle Tolerance: 0.100000001
  52. Class: rviz/Odometry
  53. Covariance:
  54. Orientation:
  55. Alpha: 0.5
  56. Color: 255; 255; 127
  57. Color Style: Unique
  58. Frame: Local
  59. Offset: 1
  60. Scale: 1
  61. Value: true
  62. Position:
  63. Alpha: 0.300000012
  64. Color: 204; 51; 204
  65. Scale: 1
  66. Value: true
  67. Value: true
  68. Enabled: false
  69. Keep: 100
  70. Name: Odometry
  71. Position Tolerance: 0.100000001
  72. Shape:
  73. Alpha: 1
  74. Axes Length: 1
  75. Axes Radius: 0.100000001
  76. Color: 255; 25; 0
  77. Head Length: 0.300000012
  78. Head Radius: 0.100000001
  79. Shaft Length: 1
  80. Shaft Radius: 0.0500000007
  81. Value: Arrow
  82. Topic: /odom
  83. Unreliable: false
  84. Value: false
  85. - Angle Tolerance: 0.100000001
  86. Class: rviz/Odometry
  87. Covariance:
  88. Orientation:
  89. Alpha: 0.5
  90. Color: 255; 255; 127
  91. Color Style: Unique
  92. Frame: Local
  93. Offset: 1
  94. Scale: 1
  95. Value: true
  96. Position:
  97. Alpha: 0.300000012
  98. Color: 204; 51; 204
  99. Scale: 1
  100. Value: true
  101. Value: true
  102. Enabled: false
  103. Keep: 100
  104. Name: Odometry EKF
  105. Position Tolerance: 0.100000001
  106. Shape:
  107. Alpha: 1
  108. Axes Length: 1
  109. Axes Radius: 0.100000001
  110. Color: 255; 25; 0
  111. Head Length: 0.300000012
  112. Head Radius: 0.100000001
  113. Shaft Length: 1
  114. Shaft Radius: 0.0500000007
  115. Value: Arrow
  116. Topic: /odom
  117. Unreliable: false
  118. Value: false
  119. - Alpha: 1
  120. Class: rviz/RobotModel
  121. Collision Enabled: false
  122. Enabled: true
  123. Links:
  124. All Links Enabled: true
  125. Expand Joint Details: false
  126. Expand Link Details: false
  127. Expand Tree: false
  128. Link Tree Style: Links in Alphabetic Order
  129. back_caster_link:
  130. Alpha: 1
  131. Show Axes: false
  132. Show Trail: false
  133. Value: true
  134. base_footprint:
  135. Alpha: 1
  136. Show Axes: false
  137. Show Trail: false
  138. Value: true
  139. base_link:
  140. Alpha: 1
  141. Show Axes: false
  142. Show Trail: false
  143. Value: true
  144. front_caster_link:
  145. Alpha: 1
  146. Show Axes: false
  147. Show Trail: false
  148. Value: true
  149. laser_link:
  150. Alpha: 1
  151. Show Axes: false
  152. Show Trail: false
  153. Value: true
  154. left_wheel_link:
  155. Alpha: 1
  156. Show Axes: false
  157. Show Trail: false
  158. Value: true
  159. right_wheel_link:
  160. Alpha: 1
  161. Show Axes: false
  162. Show Trail: false
  163. Value: true
  164. Name: RobotModel
  165. Robot Description: robot_description
  166. TF Prefix: ""
  167. Update Interval: 0
  168. Value: true
  169. Visual Enabled: true
  170. - Alpha: 0.699999988
  171. Class: rviz/Map
  172. Color Scheme: map
  173. Draw Behind: true
  174. Enabled: true
  175. Name: Map
  176. Topic: /map
  177. Unreliable: false
  178. Use Timestamp: false
  179. Value: true
  180. - Alpha: 1
  181. Buffer Length: 1
  182. Class: rviz/Path
  183. Color: 255; 0; 0
  184. Enabled: true
  185. Head Diameter: 0.300000012
  186. Head Length: 0.200000003
  187. Length: 0.300000012
  188. Line Style: Lines
  189. Line Width: 0.0299999993
  190. Name: Local Plan
  191. Offset:
  192. X: 0
  193. Y: 0
  194. Z: 0
  195. Pose Color: 255; 85; 255
  196. Pose Style: None
  197. Radius: 0.0299999993
  198. Shaft Diameter: 0.100000001
  199. Shaft Length: 0.100000001
  200. Topic: /move_base/TrajectoryPlannerROS/local_plan
  201. Unreliable: false
  202. Value: true
  203. - Alpha: 1
  204. Buffer Length: 1
  205. Class: rviz/Path
  206. Color: 0; 213; 0
  207. Enabled: true
  208. Head Diameter: 0.300000012
  209. Head Length: 0.200000003
  210. Length: 0.300000012
  211. Line Style: Lines
  212. Line Width: 0.0299999993
  213. Name: Global Plan
  214. Offset:
  215. X: 0
  216. Y: 0
  217. Z: 0
  218. Pose Color: 255; 85; 255
  219. Pose Style: None
  220. Radius: 0.0299999993
  221. Shaft Diameter: 0.100000001
  222. Shaft Length: 0.100000001
  223. Topic: /move_base/TrajectoryPlannerROS/global_plan
  224. Unreliable: false
  225. Value: true
  226. - Alpha: 1
  227. Arrow Length: 0.300000012
  228. Axes Length: 0.300000012
  229. Axes Radius: 0.00999999978
  230. Class: rviz/PoseArray
  231. Color: 170; 255; 127
  232. Enabled: true
  233. Head Length: 0.0700000003
  234. Head Radius: 0.0299999993
  235. Name: Pose Array
  236. Shaft Length: 0.230000004
  237. Shaft Radius: 0.00999999978
  238. Shape: Arrow (Flat)
  239. Topic: /particlecloud
  240. Unreliable: false
  241. Value: true
  242. - Alpha: 1
  243. Autocompute Intensity Bounds: true
  244. Autocompute Value Bounds:
  245. Max Value: 0.30399999
  246. Min Value: 0.30399999
  247. Value: true
  248. Axis: Z
  249. Channel Name: intensity
  250. Class: rviz/LaserScan
  251. Color: 255; 0; 0
  252. Color Transformer: FlatColor
  253. Decay Time: 0
  254. Enabled: true
  255. Invert Rainbow: false
  256. Max Color: 255; 255; 255
  257. Max Intensity: 4096
  258. Min Color: 0; 0; 0
  259. Min Intensity: 0
  260. Name: LaserScan
  261. Position Transformer: XYZ
  262. Queue Size: 10
  263. Selectable: true
  264. Size (Pixels): 3
  265. Size (m): 0.00999999978
  266. Style: Points
  267. Topic: /scan
  268. Unreliable: false
  269. Use Fixed Frame: true
  270. Use rainbow: true
  271. Value: true
  272. - Alpha: 1
  273. Axes Length: 1
  274. Axes Radius: 0.100000001
  275. Class: rviz/Pose
  276. Color: 0; 255; 0
  277. Enabled: true
  278. Head Length: 0.100000001
  279. Head Radius: 0.150000006
  280. Name: Goal Pose
  281. Shaft Length: 0.5
  282. Shaft Radius: 0.0299999993
  283. Shape: Arrow
  284. Topic: /move_base_simple/goal
  285. Unreliable: false
  286. Value: true
  287. - Alpha: 0.699999988
  288. Class: rviz/Map
  289. Color Scheme: costmap
  290. Draw Behind: false
  291. Enabled: true
  292. Name: Inflated Obstacles
  293. Topic: /move_base/local_costmap/costmap
  294. Unreliable: false
  295. Use Timestamp: false
  296. Value: true
  297. - Class: rviz/Marker
  298. Enabled: true
  299. Marker Topic: /waypoint_markers
  300. Name: Marker
  301. Namespaces:
  302. {}
  303. Queue Size: 100
  304. Value: true
  305. Enabled: true
  306. Global Options:
  307. Background Color: 0; 0; 0
  308. Default Light: true
  309. Fixed Frame: map
  310. Frame Rate: 30
  311. Name: root
  312. Tools:
  313. - Class: rviz/MoveCamera
  314. - Class: rviz/Interact
  315. Hide Inactive Objects: true
  316. - Class: rviz/Select
  317. - Class: rviz/SetInitialPose
  318. Topic: /initialpose
  319. - Class: rviz/SetGoal
  320. Topic: /move_base_simple/goal
  321. Value: true
  322. Views:
  323. Current:
  324. Angle: -6.3000164
  325. Class: rviz/TopDownOrtho
  326. Enable Stereo Rendering:
  327. Stereo Eye Separation: 0.0599999987
  328. Stereo Focal Distance: 1
  329. Swap Stereo Eyes: false
  330. Value: false
  331. Invert Z Axis: false
  332. Name: Current View
  333. Near Clip Distance: 0.00999999978
  334. Scale: 52.4497948
  335. Target Frame: <Fixed Frame>
  336. Value: TopDownOrtho (rviz)
  337. X: 0.412709981
  338. Y: -2.02176332
  339. Saved: ~
  340. Window Geometry:
  341. Displays:
  342. collapsed: false
  343. Height: 904
  344. Hide Left Dock: false
  345. Hide Right Dock: false
  346. QMainWindow State: 000000ff00000000fd00000004000000000000016a00000342fc0200000005fb0000001200530065006c0065006300740069006f006e00000001e10000009b0000006100fffffffb0000001e0054006f006f006c002000500072006f007000650072007400690065007302000001ed000001df00000198000000a3fb000000120056006900650077007300200054006f006f02000001df000002110000018500000122fb000000200054006f006f006c002000500072006f0070006500720074006900650073003203000002880000011d000002210000017afb000000100044006900730070006c006100790073010000002800000342000000d700ffffff000000010000010f00000270fc0200000003fb0000001e0054006f006f006c002000500072006f00700065007200740069006500730100000041000000780000000000000000fb0000000a00560069006500770073000000002800000270000000ad00fffffffb0000001200530065006c0065006300740069006f006e010000025a000000b200000000000000000000000200000490000000a9fc0100000001fb0000000a00560069006500770073030000004e00000080000002e10000019700000003000004a00000003efc0100000002fb0000000800540069006d00650000000000000004a00000030000fffffffb0000000800540069006d00650100000000000004500000000000000000000004280000034200000004000000040000000800000008fc0000000100000002000000010000000a0054006f006f006c00730100000000ffffffff0000000000000000
  347. Selection:
  348. collapsed: false
  349. Time:
  350. collapsed: false
  351. Tool Properties:
  352. collapsed: false
  353. Views:
  354. collapsed: false
  355. Width: 1432
  356. X: 2298
  357. Y: 239

12.编译

  1. cd ~/catkin_mbot
  2. catkin_make

六、 gazebo仿真中用到的模型以及本文整个工作空间以上传到如下链接

对应《ROS环境下利用cartographer以及move_base功能包实现差速小车在仿真环境中路径规划》-Linux文档类资源-CSDN下载对应《ROS环境下利用cartographer以及move_base功能包实现差速小车在仿真环境中路更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/qq_40789719/85161158




七、最终测试

  1. source ~/catkin_mbot/devel/setup.bash
  2. roslaunch mymbot_gazebo view_mbot_with_laser_gazebo.launch
  1. source ~/catkin_mbot/devel/setup.bash
  2. roslaunch mbot_navigation nav_cloister_demo.launch

差速小车路径规划仿真

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/339221
推荐阅读
相关标签
  

闽ICP备14008679号