gazebo

来源:互联网 发布:系统加速软件 编辑:程序博客网 时间:2024/05/16 08:11

http://blog.csdn.net/xuehuafeiwu123/article/details/71108959
http://gazebosim.org/tutorials?tut=ros_urdf&cat=connect_ros
ubuntu14.04 使用gazebo2.x 版本

  • 启动gazebo方法
gazebo

通知启动包含gzserver 和 gzclient
安装gazebo ros pkg

sudo apt-get install ros-indigo-gazebo-ros-pkgs ros-indigo-gazebo-ros-control

安装后gazebo认识

这里写图片描述
知道这些工具在哪,并且加深对ROS文件体系的认识

  • 运行GAZEBO
roscore &rosrun gazebo_ros gazebo

话题列表

rostopic listrobot@ubuntu:/opt/ros/indigo/lib/gazebo_ros$ rostopic list/clock/gazebo/link_states/gazebo/model_states/gazebo/parameter_descriptions/gazebo/parameter_updates/gazebo/set_link_state/gazebo/set_model_state/rosout/rosout_agg

服务列表

robot@ubuntu:/opt/ros/indigo/lib/gazebo_ros$ rosservice list /gazebo/apply_body_wrench/gazebo/apply_joint_effort/gazebo/clear_body_wrenches/gazebo/clear_joint_forces/gazebo/delete_model/gazebo/get_joint_properties/gazebo/get_link_properties/gazebo/get_link_state/gazebo/get_loggers/gazebo/get_model_properties/gazebo/get_model_state/gazebo/get_physics_properties/gazebo/get_world_properties/gazebo/pause_physics/gazebo/reset_simulation/gazebo/reset_world/gazebo/set_joint_properties/gazebo/set_link_properties/gazebo/set_link_state/gazebo/set_logger_level/gazebo/set_model_configuration/gazebo/set_model_state/gazebo/set_parameters/gazebo/set_physics_properties/gazebo/spawn_gazebo_model/gazebo/spawn_sdf_model/gazebo/spawn_urdf_model/gazebo/unpause_physics/rosout/get_loggers/rosout/set_logger_level
  • empty_world.launch
<launch>  <arg name="paused" default="false"/>  <arg name="use_sim_time" default="true"/>  <arg name="extra_gazebo_args" default=""/>  <arg name="gui" default="true"/>  <arg name="headless" default="false"/>  <arg name="debug" default="false"/>  <arg name="physics" default="ode"/>  <arg name="verbose" default="false"/>  <arg name="world_name" default="worlds/empty.world"/>  <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->  <!-- set use_sim_time flag -->  <group if="$(arg use_sim_time)">    <param name="/use_sim_time" value="true" />  </group>  <!-- set command arguments -->  <arg unless="$(arg paused)" name="command_arg1" value=""/>  <arg     if="$(arg paused)" name="command_arg1" value="-u"/>  <arg unless="$(arg headless)" name="command_arg2" value=""/>  <arg     if="$(arg headless)" name="command_arg2" value="-r"/>  <arg unless="$(arg verbose)" name="command_arg3" value=""/>  <arg     if="$(arg verbose)" name="command_arg3" value="--verbose"/>  <arg unless="$(arg debug)" name="script_type" value="gzserver"/>  <arg     if="$(arg debug)" name="script_type" value="debug"/>  <!-- start gazebo server-->  <node name="gazebo" pkg="gazebo_ros" type="$(arg script_type)" respawn="false" output="screen"    args="$(arg command_arg1) $(arg command_arg2) $(arg command_arg3) -e $(arg physics) $(arg extra_gazebo_args) $(arg world_name)" />  <!-- start gazebo client -->  <group if="$(arg gui)">    <node name="gazebo_gui" pkg="gazebo_ros" type="gzclient" respawn="false" output="screen"/>  </group></launch>

前面的arg 设置了一些变量
paused
在暂停状态打开Gazebo (default false)
use_sim_time
节点启动模拟时间,启动主题topic /clock (default true)
gui
启动Gazebo用户接口 (default true)
headless
禁止仿真器调用任何渲染组件。不能在gui:=true (default false)是使用
debug
用gdb (default false)调试模式启动 gzserver (Gazebo Server)

中间的group 中出现了 if unless
if表示仅当属性设置时(为真)才执行。
unless表示当属性没有设置时(为假)才执行。
所有标签都可以用if和unless,包括根据求值的得到结果的标签。1为真,0为假,其他返回值错误。
· if=value (optional)
· if是计算值是否为真,包括标签和它的内容。
unless=value (optional)
· Unless 是计算值是否为真,包括标签和它的内容
这里”world_name” 中worlds/empty_world 在哪儿?
文中的GAZEBO_RESOURCE_PATH变量指的是?(printenv打印不出来!如果你知道欢迎留言)
http://blog.chinaunix.net/uid-29742351-id-4961536.html

robot@ubuntu:/opt/ros/indigo/share/gazebo_ros/launch$ sudo find / -name empty_world.world [sudo] password for robot: /usr/share/gazebo-2.2/worlds/empty_world.world
  • gazebo launch 文件更换世界环境

参考给的例子range_world.launch

<?xml version="1.0"?><launch>  <!-- these are the arguments you can pass this launch file, for example paused:=true -->  <arg name="paused" default="false"/>  <arg name="use_sim_time" default="true"/>  <arg name="extra_gazebo_args" default=""/>  <arg name="gui" default="true"/>  <arg name="debug" default="false"/>  <arg name="physics" default="ode"/>  <arg name="verbose" default="true"/>  <arg name="world" default="gazebo_ros_range"/>   <!-- set use_sim_time flag -->  <group if="$(arg use_sim_time)">    <param name="/use_sim_time" value="true" />  </group>  <include file="$(find gazebo_ros)/launch/empty_world.launch">    <arg name="world_name" value="$(find gazebo_plugins)/test/test_worlds/$(arg world).world"/>    <arg name="gui" value="$(arg gui)"/>    <arg name="debug" value="$(arg debug)"/>  </include></launch>

将empty_world.launch文件 包含进来,并将“world_name”变量修改成其他world环境。
参考launch 例子:mud_world.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="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>
  • 创建你的gazebo package

    文件夹目录如下:

../catkin_ws/src    /MYROBOT_description        package.xml        CMakeLists.txt        /urdf            MYROBOT.urdf        /meshes            mesh1.dae            mesh2.dae            ...        /materials        /cad    /MYROBOT_gazebo        /launch            MYROBOT.launch        /worlds            MYROBOT.world        /models            world_object1.dae            world_object2.stl            world_object3.urdf        /materials        /plugins

对应cmakelists.txt

cmake_minimum_required(VERSION 2.8.3)project(YOURROBOT_gazebo_plugins)find_package(catkin REQUIRED COMPONENTS  gazebo_ros)# Depend on system install of Gazebofind_package(gazebo REQUIRED)include_directories(include ${catkin_INCLUDE_DIRS} ${GAZEBO_INCLUDE_DIRS} ${SDFormat_INCLUDE_DIRS})# Build whatever you need hereadd_library(...) # TODOcatkin_package(    DEPENDS      gazebo_ros    CATKIN_DEPENDS    INCLUDE_DIRS    LIBRARIES)

package.xml

<build_depend>gazebo_ros</build_depend><run_depend>gazebo_ros</run_depend>
  • 创建MYROBOT.world 文件
<?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://gas_station</uri>      <name>gas_station</name>      <pose>-2.0 7.0 0 0 0 0</pose>    </include>  </world></sdf>

sdf 指代model database.
SQL Server Compact Edition Database Files
https://bitbucket.org/osrf/gazebo_models/downloads/

ros 初始化gazebo 下载模型路径为~/gazebo/model
ros 默认world文件位置为/usr/share/gazebo-2.2

建立新模型:http://m.blog.csdn.net/wilylcyu/article/details/51754495
MYbot.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 MYROBOT_gazebo)/worlds/MYROBOT.world"/>    <!-- more default parameters can be changed here -->  </include></launch>
  • 向gazebo中加载urdf 模型
    1)调用 spawn 服务
rosrun gazebo_ros spawn_model -file `rospack find neo_robot_descriptions`/mp_400/mp_400.urdf -urdf -x 0 -y 0 -z 1 -model mp_400

这里加是加进去了,但是环境中看不到????
如果是xacro 文件,转化:

rosrun xacro xacro.py `rospack find pr2_description`/robots/pr2.urdf.xacro -o /tmp/pr2.urdfcheck_urdf pr2.urdfurdf_to_graphiz pr2.urdfrosrun tf view_frames

查看spawn_model 所有参数

rosrun gazebo_ros spawn_model -h

launch 文件中写法:

<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-file $(find baxter_description)/urdf/baxter.urdf -urdf -z 1 -model baxter" />

launch 例子

<!-- 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" />
原创粉丝点击