gazebo_ros_demo笔记

本笔记主要基于代码:https://github.com/ros-simulation/gazebo_ros_demos

1、gazebo_tutorials

这是一个gazebo plugin的简单教程,它的源文件如下:

#include <gazebo/common/Plugin.hh>
#include <ros/ros.h>

namespace gazebo
{
//所继承的plugin类型为WorldPlugin
class WorldPluginTutorial : public WorldPlugin
{
public:
  WorldPluginTutorial() : WorldPlugin()
  {
    // Make sure the ROS node for Gazebo has already been initialized
    if (!ros::isInitialized())
    {
      ROS_FATAL_STREAM("A ROS node for Gazebo has not been initialized, unable to load plugin. "
        << "Load the Gazebo system plugin 'libgazebo_ros_api_plugin.so' in the gazebo_ros package)");
      return;
    }

    ROS_INFO("Hello World!");
  }
//用于加载sdf配置文件
  void Load(physics::WorldPtr _world, sdf::ElementPtr _sdf)
  {
  }

};
//注册插件
GZ_REGISTER_WORLD_PLUGIN(WorldPluginTutorial)
}
  • CMakeLists.txtpackage.xml文件中也需要添加gazebo_ros的相关配置。
    它的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 gazebo_tutorials)/worlds/hello.world"/>
    <!-- more default parameters can be changed here -->
  </include>
</launch>
  • 这里hello.world仍旧使用了empty.world的内容,但是通过添加:
<plugin name="gazebo_tutorials" filename="libgazebo_tutorials.so"/>

将该文件指向gazebo_tutorials插件。

2、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"/>

  <!-- 生成一组控制器 -->
  <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>

  • 控制命令: rostopic pub /rrbot/joint2_position_controller/command std_msgs/Float64 "data: -0.9"

3、rrbot_description

这里会在Rviz中显示一个rrbot,并且可以通过GUI调整关节角。
它的launch文件如下:

<launch>
<!-- 用于自动生成urdf文件,命令一般为:xacro --inorder model.xacro > model.urdf -->
  <param name="robot_description"
    command="$(find xacro)/xacro --inorder '$(find rrbot_description)/urdf/rrbot.xacro'" />

  <!-- 用于发布sensor_msgs/JointState topic  -->
  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
    <param name="use_gui" value="TRUE"/>
  </node>

  <!-- 从上面的topic中计算tf,这两个pkg都可以通过ROS安装 -->
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher"/>

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

</launch>

4、rrbot_gazebo

gazebo中显示rrbot
它的launch文件如下:

<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-->
  <!--include file="$(find rrbot_control)/launch/rrbot_control.launch" /-->

</launch>

这里运行ros_control都没有反应,现在忙其他事去了,以后有缘再更~

发布了57 篇原创文章 · 获赞 4 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_38258767/article/details/103869597