GAZEBO学习笔记(2)

前段时间看看这看看那的,没什么结果,也没什么成就感,还是给自己个目标,从简单的任务开始。

用ROS启动一个world,启动Gazebo且在里面建一个Bus,然后用ROS的servers控制它开始/停止转圈。

0. 创建工作空间

做这一步其实是使用ROS创建工作空间以及自己的Gazebo ROS package,方便以后管理。

顺便复习一下:

新建一个工作空间文件夹,创建src文件夹(或者在原有文件夹中进行)

mkdir -p ./connect_ROS/src
cd connect_ROS
catkin_make
cd src
catkin_create_pkg bus_robot_description

参考:Gazebo的网站

使用ROS的命令catkin_create_pkg创建,/bus_robot_description和/bus_robot_gazebo,前者存放robot相关的文件,后者存放world文件和launch文件,路径类似:

../connect_ROS/src
    /bus_robot_description
        package.xml
        CMakeLists.txt
        /urdf
            MYROBOT.urdf
        /meshes
            mesh1.dae
            mesh2.dae
            ...
        /materials
        /cad
    /bus_robot_gazebo 
     package.xml
     CMakeLists.txt
/launch bus_robot.launch /worlds bus_robot.world /models world_object1.dae world_object2.stl world_object3.urdf /materials /plugins

 想让ROS找到launch文件,还是要用catkin_create_pkg创建bus_robot_gazebo,在官方网站里,上面的路径bus_robot_gazebo中没有package.xml和CMakeLists.txt文件,不知道是什么原因?留个坑

1. 用roslaunch启动一个带有Bus model的Gazebo world

1.1 创建bus_robot.world文件

以empty.world文件为基础,在里面添加一个Bus model:

<?xml version="1.0" ?>
<sdf version="1.4">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <include>
      <uri>model://sun</uri>
    </include>
    <include>
      <uri>model://bus</uri>
      <name>bus</name>
      <pose>-2.0 7.0 0 0 0 0</pose>
    </include>
  </world>
</sdf>

先来测试一下world文件能不能用:

gazebo bus_robot.world

将会启动Gazebo里面带辆车

1.2 创建launch文件

创建launch文件夹并添加launch文件:

<launch>
  <!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="$(find bus_robot_gazebo)/worlds/bus_robot.world"/>
    <!-- more default parameters can be changed here -->
  </include>
</launch>
  • 在connect_ROS下使用catkin_make编译之后,用source加载./devel/setup.bash文件,但也还是不能找到bus_robot_gazebo这个包,在网上查了一下,用以下命令可以让ROS识别新目录:
rospack profile

然后就可以运行launch文件了:

roslaunch bus_robot_gazebo bus_robot.launch

可以得到和使用world文件一样的效果,这时候就可以从rostopic里看到gazebo创建的topics了。

 

posted @ 2020-04-14 11:07  临界稳定  阅读(478)  评论(0)    收藏  举报