使用Gazebo导入world环境与机器人

转载自:https://zhuanlan.zhihu.com/p/90489579

使用Gazebo导入world环境与机器人

Zhihao

Zhihao

AI Robotic

1.首先应该通过gazebo建立一个世界模型,然后导出成一个以.world为后缀的文件。

2.使用launch文件启动gazebo加载world模型,或者说是将world模型加入gazebo仿真器中作为环境。

这一步是重点!

first,我们应该告诉gazebo 要加载的world文件放在哪里。并通过arg标签,设置此world文件加载时的参数。

  <!-- 设置launch文件的参数 --> 
  <arg name="world_name" value="$(find mbot_gazebo)/worlds/playground.world"/>
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>

roslaunch Arguments(参数说明)

You can append the following arguments to the launch files to change the behavior of Gazebo:
paused
Start Gazebo in a paused state (default false)
use_sim_time
Tells ROS nodes asking for time to get the Gazebo-published simulation time, published over the ROS topic /clock (default true)
gui
Launch the user interface window of Gazebo (default true)
headless (deprecated) recording (previously called headless)
Enable gazebo state log recording
debug
Start gzserver (Gazebo Server) in debug mode using gdb (default false)
verbose
Run gzserver and gzclient with --verbose, printing errors and warnings to the terminal (default false)

除了上述几个,还有一个最重要的就是world_name参数,此参数用于加载其他的world模型。

第二步,我们应该通过include empty_world.launch文件,加载上述world文件,并将上面所设置的参数传递给empty_world文件中。

  <!-- 运行gazebo仿真环境 -->
    <include file="$(find gazebo_ros)/launch/empty_world.launch">
        <arg name="world_name" value="$(arg world_name)" />
        <arg name="debug" value="$(arg debug)" />
        <arg name="gui" value="$(arg gui)" />
        <arg name="paused" value="$(arg paused)"/>
        <arg name="use_sim_time" value="$(arg use_sim_time)"/>
        <arg name="headless" value="$(arg headless)"/>
    </include>

 

下面就要加载机器人的模型了,官网(http://gazebosim.org/tutorials?tut=ros_roslaunch)中给出来两种方法,本文中使用ROS Service Call Spawn Method,可以参考官网教程,描述如下:

The first method keeps your robot's ROS packages more portable between computers and repository check outs. It allows you to keep your robot's location relative to a ROS package path, but also requires you to make a ROS service call using a small (python) script.
This method uses a small python script called spawn_model to make a service call request to the gazebo_ros ROS node (named simply "gazebo" in the rostopic namespace) to add a custom URDF into Gazebo. The spawn_model script is located within the gazebo_ros package. You can use this script in the following way:
rosrun gazebo_ros spawn_model -file `rospack find MYROBOT_description`/urdf/MYROBOT.urdf -urdf -x 0 -y 0 -z 1 -model MYROBOT
XACRO Example with PR2
If your URDF is not in XML format but rather in XACRO format, you can make a similar modification to your launch file. You can run this PR2 example by installing this package:
ROS Jade:
sudo apt-get install ros-jade-pr2-common
Then adding this to your launch file created previously in this tutorial:
<!-- 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" />

简单来说,就是使用官方提供出的spawn_urdf节点,此节点可以将机器人导入Gazebo中。我们要做的,只是将我们需要的机器人模型传递给这个节点即可。具体做法请看下面几步:

第三步,应该加载机器人模型

 <!-- 加载机器人模型描述参数 -->
    <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find mbot_description)/urdf/xacro/gazebo/mbot_with_camera_gazebo.xacro'" /> 

第四步设置

  <!-- 运行joint_state_publisher节点,发布机器人的关节状态  -->
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" ></node> 

    <!-- 运行robot_state_publisher节点,发布tf  -->
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"  output="screen" >
        <param name="publish_frequency" type="double" value="50.0" />
    </node>

第五步,通过节点将机器人加载到gezebo中。

 <!-- 在gazebo中加载机器人模型-->
 <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
  args="-urdf -model mbot -param robot_description"/> 

此节点的参数有:

Commands:
    -[urdf|gazebo] - specify incoming xml is urdf or gazebo format
    -[file|param] [<file_name>|<param_name>] - source of the model xml
    -model <model_name> - name of the model to be spawned.
    -reference_frame <entity_name> - optinal: name of the model/body where initial pose is defined.
                                     If left empty or specified as "world", gazebo world frame is used.
    -namespace <ros_namespace> - optional: all subsequent ROS interface plugins will be inside of this namespace.
    -x <x in meters> - optional: initial pose, use 0 if left out
    -y <y in meters> - optional: initial pose, use 0 if left out
    -z <z in meters> - optional: initial pose, use 0 if left out
    -R <roll in radians> - optional: initial pose, use 0 if left out
    -P <pitch in radians> - optional: initial pose, use 0 if left out
    -Y <yaw in radians> - optional: initial pose, use 0 if left out

 

发布于 2019-11-06

  • 7
    点赞
  • 64
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值