12.27-ros-gazebo基础
Posted lizhensheng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了12.27-ros-gazebo基础相关的知识,希望对你有一定的参考价值。
gazebo与ROS的连接
前言
- 仿真平台搭建的参考
参考
connect to ROS
Using roslaunch to start Gazebo, world files and URDF models
学习记录
与ROS的集成
- gazebo7是独立的软件,与ROS的连接是通过gazebo_ros_pkgs包来完成的,这些包完成了很多工作,包括依赖关系,catkin支持,URDF和SDF文件的兼容,对ros_control的支持。
- 这些接口主要包括:
gazebo_ros
gazebo_msgs
gazebo_plugins
gazebo_tests
gazebo_worlds
gazebo_tools
gazebo_ros_api_plugin
gazebo_ros_paths_plugin
从旧版本升级
- 查看网页吧,这里不赘述
- 一个较大的变化是gazebo变成的gazebo_ros
Launch Files
CMakeLists.txt
package.xml
安装gazebo_ros_pkgs
sudo apt-get install ros-kinetic-gazebo-ros-pkgs ros-kinetic-gazebo-ros-control
- 测试安装
roscore &
rosrun gazebo_ros gazebo
启动一个环境
<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="worlds/mud.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->
<arg name="paused" value="false"/>
<arg name="use_sim_time" value="true"/>
<arg name="gui" value="true"/>
<arg name="headless" value="false"/>
<arg name="debug" value="false"/>
</include>
</launch>
- 环境文件是一个sdf描述文件
<sdf version="1.4">
<world name="default">
<include>
<uri>model://sun</uri>
</include>
<include>
<uri>model://ground_plane</uri>
</include>
<include>
<uri>model://double_pendulum_with_base</uri>
<name>pendulum_thick_mud</name>
<pose>-2.0 0 0 0 0 0</pose>
</include>
...
</world>
</sdf>
创建项目
connect to ROS
Using roslaunch to start Gazebo, world files and URDF models
gazebo_ros
gazebo_msgs
gazebo_plugins
gazebo_tests
gazebo_worlds
gazebo_tools
gazebo_ros_api_plugin
gazebo_ros_paths_plugin
sudo apt-get install ros-kinetic-gazebo-ros-pkgs ros-kinetic-gazebo-ros-control
roscore &
rosrun gazebo_ros gazebo
<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="worlds/mud.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->
<arg name="paused" value="false"/>
<arg name="use_sim_time" value="true"/>
<arg name="gui" value="true"/>
<arg name="headless" value="false"/>
<arg name="debug" value="false"/>
</include>
</launch>
<sdf version="1.4">
<world name="default">
<include>
<uri>model://sun</uri>
</include>
<include>
<uri>model://ground_plane</uri>
</include>
<include>
<uri>model://double_pendulum_with_base</uri>
<name>pendulum_thick_mud</name>
<pose>-2.0 0 0 0 0 0</pose>
</include>
...
</world>
</sdf>
实际操作
roslaunch来渲染你的URDF格式的机器人模型
- 调用ROS service
rosrun gazebo_ros spawn_model -file `rospack find MYROBOT_description`/urdf/MYROBOT.urdf -urdf -x 0 -y 0 -z 1 -model MYROBOT
rosrun gazebo_ros spawn_model -file `rospack find baxter_description`/urdf/baxter.urdf -urdf -z 1 -model baxter
- 使用roslaunch
<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-file $(find baxter_description)/urdf/baxter.urdf -urdf -z 1 -model baxter" />
- XACRO 例子
<!-- Convert an xacro and put on parameter server -->
<param name="robot_description" command="$(find xacro)/xacro.py $(find pr2_description)/robots/pr2.urdf.xacro" />
<!-- Spawn a robot into Gazebo -->
<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-param robot_description -urdf -model pr2" />
使用机器人模型库中的模型
需要实际操作
在package.xml中声明model paths
<export>
<gazebo_ros gazebo_model_path="$prefix/models"/>
<gazebo_ros gazebo_media_path="$prefix/models"/>
</export>
使用插件
- 插件可以根据需要添加到sdf文件中,可以添加到
等元素下。如果需要添加定义到URDF文件下,你需要先用 元素包裹 元素。
将插件插入到元素下
<gazebo>
<plugin name="differential_drive_controller" filename="libdiffdrive_plugin.so">
... plugin parameters ...
</plugin>
</gazebo>
- 如果是URDF文件下,有一个特性支持自动转化为SDF下的
元素下
<model name="your_robot_model">
<plugin name="differential_drive_controller" filename="libdiffdrive_plugin.so">
... plugin parameters ...
</plugin>
</model>
将插件插入到元素下(同理)
<gazebo reference="your_link_name">
<plugin name="your_link_laser_controller" filename="libgazebo_ros_laser.so">
... plugin parameters ...
</plugin>
</gazebo>
如果 reference没有值,则默认为
整个机器人
以上是关于12.27-ros-gazebo基础的主要内容,如果未能解决你的问题,请参考以下文章