解读gazebo_ros_control gazebo_ros

  • Post author:
  • Post category:其他

本篇的目的是想解读gazebo_ros_control 以及 gazebo_ros.

因为gazebo本身是独立于ros的,通过教程Intermediate: Control plugin 以及教程  Category: Write a plugin 发现自己单纯的写c++ plugin就能控制model,获取sensor信息. 那么ros官方开发的那一套 gazebo_ros_control, gazebo_ros等等,肯定也是用同一种思路开发的, 只不过利用了ros自身的一些其他package, 例如ros_control 和 ros_controllers 进行了集成, 使使用起来更加方便, 毕竟很多robot的基本元素都是形同的, 没必要为每个robot或model开发一个新的plugin. 所以通过插件的形式,配合以yaml文件, 可以快速对一个新的robot模型定制一个专属的plugin.

gazebo_ros_control

这个其实就ros版本的 Model plugins 

gazebo_ros

这个其实就是ros版本的 System Plugin

gazebo_tutorials

这个是在gazebo_ros_demos里的, 是一个 World plugins的例子.

至于gazebo还有的  SensorPlugin, ros中没有与之对于的实现, 可能有gazebo_ros_control 和 gazebo_ros 就够了吧.

joint_state_publisher

读取robot_description中所有非固定的joints, 然后发布这些joints的状态. 通常与robot_state_publisher 联合使用, robot_state_publisher把joint_state_publisher发布来的jointstate转换成tf变换发布出去.

This package publishes sensor_msgs/JointState messages for a robot. The package reads the robot_description parameter from the parameter server, finds all of the non-fixed joints and publishes a JointState message with all those joints defined.

This package can be used in conjunction with the robot_state_publisher node to also publish transforms for all joint states.

robot_state_publisher

 “This package allows you to publish the state of a robot to tf2. Once the state gets published, it is available to all components in the system that also use tf2. The package takes the joint angles of the robot as input and publishes the 3D poses of the robot links, using a kinematic tree model of the robot. “

通过下面的例子可以测试joint_state_publisher和robot_state_publisher. joint_state_publisher有两个版本,joint_state_publisher_gui版本可以控制每个活动关节.

<launch>
  <param name="robot_description"
    command="$(find xacro)/xacro --inorder '$(find rrbot_description)/urdf/rrbot.xacro'" />

  <!-- send fake joint values -->
  <node name="joint_state_publisher" pkg="joint_state_publisher_gui" type="joint_state_publisher_gui">
  <!-- <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher"> -->
    <param name="use_gui" value="TRUE"/>
  </node>

  <!-- Combine joint values -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"/>

  <!-- Show in Rviz   -->
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(find rrbot_description)/launch/rrbot.rviz"/>

</launch>

joint_state_controller

这个是ros_controllers的一部分. 其作用是”Controller to publish joint state”, 也就是和joint_state_publisher是一样的, 发布sensor_msgs::JointState. 

所以在一些luanch中看到, 没有使用joint_state_publisher, 而是joint_state_controller, 使用方式是直接在yaml配置文件中加入这个插件即可.

例子如下:

<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="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>

  <!-- 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 rrbot_gazebo)/worlds/rrbot.world"/>
    <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>

  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description"
    command="$(find xacro)/xacro --inorder '$(find rrbot_description)/urdf/rrbot.xacro'" />

  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
        args="-urdf -model rrbot -param robot_description"/>

  <!-- ros_control rrbot launch file -->
  <!-- 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>

  <node name="rviz" pkg="rviz" type="rviz" args="-d $(find rrbot_description)/launch/rrbot.rviz"/>

</launch>

 上述launch通过controller_manager生成了3个插件,joint_state_controller负责发布jointstate, joint1_position_controller和joint2_position_controller 负责对两个joint进行位置控制.

如果把后两个控制器去掉, 那打开后, rrbot的两个臂直接就掉下去了, 因为倒立摆是一个不稳定的系统.


版权声明:本文为lianghu3124原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。