gazebo与ros_control学习 (1)

首先说的通俗一点就是跑一遍官网例子
本文将使用ros_control和gazebo插件gazebo_ros_control实现模拟控制器,并驱动机器人joint运动。

1 gazebo和ros_control数据流

ros_control的安装

sudo apt-get install ros-kinetic-ros-control ros-kinetic-ros-controllers

首先学习一些关于ros_control的基础知识
这里写图片描述
官方代码链接:
https://github.com/ros-simulation/gazebo_ros_demos

2 ros_control 基础

下面就结合具体的官方代码来分析下,是如何让仿真中的模型动起来的。首先~/catkin_ws/src/gazebo_ros_demos/rrbot_description/urdf/rrbot.xacro文件定义了两个运动关节的transmission,它的type是:transmission_interface/SimpleTransmission,它的hardwareInterface是:EffortJointInterface
派生到我的代码片


    <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> 

接着在 ~/catkin_ws/src/gazebo_ros_demos/rrbot_description/urdf/rrbot.gazebo 里有一些传感器的。plugin:libgazebo_ros_control.so,libgazebo_ros_gpu_laser.so,libgazebo_ros_camera.sohokuyo激光雷达的如下,也就是说即使没有传感器,也可以仿真得到传感器的数据。

 <gazebo reference="hokuyo_link">  
       <sensor type="gpu_ray" name="head_hokuyo_sensor">  
         <pose>0 0 0 0 0 0</pose>  
         <visualize>false</visualize>  
         <update_rate>40</update_rate>  
         <ray>  
           <scan>  
             <horizontal>  
               <samples>720</samples>  
               <resolution>1</resolution>  
               <min_angle>-1.570796</min_angle>  
               <max_angle>1.570796</max_angle>  
             </horizontal>  
           </scan>  
           <range>  
             <min>0.10</min>  
             <max>30.0</max>  
             <resolution>0.01</resolution>  
           </range>  
           <noise>  
             <type>gaussian</type>  
             <!-- Noise parameters based on published spec for Hokuyo laser  
                  achieving "+-30mm" accuracy at range < 10m.  A mean of 0.0m and  
                  stddev of 0.01m will put 99.7% of samples within 0.03m of the true  
                  reading. -->  
             <mean>0.0</mean>  
             <stddev>0.01</stddev>  
           </noise>  
         </ray>  
         <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_gpu_laser.so">  
           <topicName>/rrbot/laser/scan</topicName>  
           <frameName>hokuyo_link</frameName>  
         </plugin>  
       </sensor>  
     </gazebo>  
关于ros_control的plugin也在这个文件中,如下 
    <gazebo>  
      <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">  
        <robotNamespace>/rrbot</robotNamespace>  
        <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>  
      </plugin>  
    </gazebo>  

再者,依照官网的解释ros_control会去读取~/catkin_ws/src/gazebo_ros_demos/rrbot_description/urdf/rrbot.xacro中的transmisson条目,每个运动关节都需要一个transmission。那么这些运动关节是以什么方式运动,或者pid参数是如何设定呢?因此就需要一个配置文件来配置这些。这里名叫~/catkin_ws/src/gazebo_ros_demos/rrbot_control/config/rrbot_control.yaml文件。Hardwareinterface的作用就在这个配置文件中体现了,注意Joint1和Joint2的type

   rrbot:  
      # Publish all joint states -----------------------------------  
      joint_state_controller:  
        type: joint_state_controller/JointStateController  
        publish_rate: 50    

      # Position Controllers ---------------------------------------  
      joint1_position_controller:  
        type: effort_controllers/JointPositionController  
        joint: joint1  
        pid: {p: 100.0, i: 0.01, d: 10.0}  
      joint2_position_controller:  
        type: effort_controllers/JointPositionController  
        joint: joint2  
        pid: {p: 100.0, i: 0.01, d: 10.0}  

具体的关于启动的文件,都写在launch文件中了,具体来说就是rrbot_world.launch和rrbot_control.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.py '$(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"/>  

    </launch>  

以下的这个lanuch文件是用来启动controller_manager和发布joint states

    <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>  




  • 0
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

穿着帆布鞋也能走猫步

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

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

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

打赏作者

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

抵扣说明:

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

余额充值