gazebo官网例程

首先官网下载代码https://github.com/ros-simulation/gazebo_ros_demos
1 创建编译工作空间
cd ~/catkin_ws/src/
git clone https://github.com/ros-simulation/gazebo_ros_demos.git
cd ..
catkin_make
2 在Rviz运行
cd ~/catkin_ws/src/gazebo_ros_demos/rrbot_description
roslaunch rrbot_description rrbot_rviz.launch
这里写图片描述
3 在gazebo运行
cd ~/catkin_ws/src/gazebo_ros_demos/rrbot_gazebo
roslaunch rrbot_gazebo rrbot_world.launch
这里写图片描述
4 客制化URDF文件
继续使用gazebo中RRBot的URDF,并在其基础上做客制化修改。
4.1 Add transmission elements to a URDF
为了在机器人RRBot中使用ros_control, 我们需要在URDF中增加一些相应的elements(如 element), 这种element被用来连接机器人的actuators和 joints, 详细定义请看 spec 。

对于gazebo_ros_control插件来说,transmission中重要的信息tag如下:


    <joint name=""> - name必须于URDF中其它地方的joint对应
    <type> - transmission类型,目前仅仅实现了"transmission_interface/SimpleTransmission",当然你可以自己根据需求添加
    <hardwareInterface> - 放置在<actuator><joint> tags之内,用来告知gazebo_ros_control插件哪些硬件接口要加载进来(position, velocity or effort interfaces),目前仅effort接口被实现, 根据需要可自行添加其它接口

其它剩下的names and elements目前被忽略处理。
4.2 Add the gazebo_ros_control plugin
除了transmission tags, Gazebo插件也需要添加到URDF文件,该插件作用是解析transmission tags,加载hardware interfaces和controller manager。 缺省的情况下插件gazebo_ros_control很简单,然而基于其插件架构特定,用户可以随便扩展定制自己需要的硬件接口。下面缺省的插件XML定义应该加入到你的URDF文件,

<gazebo>
  <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
    <robotNamespace>/rrbot</robotNamespace>
  </plugin>
</gazebo>

gazebo_ros_control tag有下面几个可选属性:

    <robotNamespace>: 插件实例的ROS命名空间, 在URDF/SDF文件缺省是机器人名字
    <controlPeriod>: controller更新周期update (in seconds), 缺省是Gazebo的period
    <robotParam>: 参数服务器robot_description (URDF)的位置,缺省是'/robot_description'
    <robotSimType>: robot sim interface插件名字  (详细见下面), 缺省是 'DefaultRobotHWSim'

缺省的gazebo_ros_control的行为:
在缺省情况下,没有 tag, gazebo_ros_control会尝试获取它需要的所有接口以实现与基于ros_control的controller通信。
在缺省情况下,它的行为提供如下ros_control接口:

    hardware_interface::JointStateInterface
    hardware_interface::EffortJointInterface
    hardware_interface::VelocityJointInterface - not fully implemented

高级gazebo_ros_control的行为(定制gazebo_ros_control插件):

gazebo_ros_control插件也提供了基于pluginlib的接口,这样方便客制化Gazebo和ros_control之间的硬件接口,以仿真更加复杂的机构(如非线性弹簧,连接等等)。

客制化的新插件必须继承gazebo_ros_control::RobotHWSim, 它是仿真的hardware_interface::RobotHW。 RobotHWSim提供的API可以实现对Gazebo模拟器中joint的读和写。
RobotHWSim的扩展类在URDF model中指定,当机器人model被加载时候也被一起加载。 如下面的XML将加载缺省插件 (行为同没有使用 tag情况):

<gazebo>
  <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
    <robotNamespace>/MYROBOT</robotNamespace>
    <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
  </plugin>
</gazebo>

4.3 RRBot例子
我们添加 块为每个joint。注意:必须包含在和 tags之间。 打开你的rrbot.xacro文件,在文件底部你可以看到:

 <transmission name="tran1">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint1">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor1">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>

  <transmission name="tran2">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint2">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor2">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>
  </transmission>

此外,在文件rrbot.gazebo你会看到插件gazebo_ros_control, 该插件会读取 tags中内容:


<gazebo>
  <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
    <robotNamespace>/rrbot</robotNamespace>
  </plugin>
</gazebo>

4.4 ros_control package
代码解释:
1)在launch文件夹创建rrbot_control/launch/rrbot_control.launch文件,并使用下面内容:

<launch>

  <!-- Load joint controller configurations from YAML file to parameter server -->
  <rosparam file="$(find rrbot_control)/config/rrbot_control.yaml" command="load"/>

  <!-- load the controllers -->
  <node name="controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
    output="screen" ns="/rrbot" args="joint_state_controller
                      joint1_position_controller
                      joint2_position_controller"/>

  <!-- convert joint states to TF transforms for rviz, etc -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
    respawn="false" output="screen">
    <remap from="/joint_states" to="/rrbot/joint_states" />
  </node>

</launch>

a.上面第一行”rosparam”, 加载yaml文件中controller的配置到参数服务器 。
b.controller_spawner node调用python脚本启动2个位置controller, 该脚本创建service call到controller manager,告诉controller manager需要启动哪些controller。
该脚本也加载第三个controller,该controller用来发布所有关节的状态, 并且广播主题/joint_states。 spawner只是roslaunch使用的辅助脚本。
c. 最后一行启动一个robot_state_publisher node, 用来监听来自joint_state_controller的消息/joint_states, 然后发布转换到/tf主题。这样在Rviz中你可以看到仿真的robot并做一些其它任务。

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

穿着帆布鞋也能走猫步

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值