ROS笔记之Gazebo机器人仿真(六)——机器人模型插件添加

10 篇文章 41 订阅

1.引言

  这章里我们将结束如何给机器人模型添加插件。

2.传感器插件

2.1激光雷达插件

(1)在urdf文件夹下的smartcar.urdf中添加:

<gazebo reference="sensor_link">
    <sensor type="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>

          <mean>0.0</mean>
          <stddev>0.01</stddev>
        </noise>
      </ray>
      <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_laser.so">
        <topicName>/laser/scan</topicName>
        <frameName>base_link</frameName>
      </plugin>
    </sensor>
  </gazebo>

  这里对常需要修改的部分代码进行说明:

<gazebo reference="sensor_link">

  表示激光雷达的元件名称为"sensor_link"

<topicName>/laser/scan</topicName>

  表示激光雷达数据的topic名称为“/laser/scan”

 <frameName>base_link</frameName>

  表示基架为“base_link”

(2)在两个终端分别输入指令:

roslaunch  smartcar gazebo.launch
roslaunch  smartcar display.launch

(3)在Rviz界面中添加显示激光雷达
在这里插入图片描述
(4)可以看到添加的激光雷达插件产生的“/laser/scan”的Topic
在这里插入图片描述

2.2 RGB-D相机插件

  我们可以将“sensor_link”定义为激光雷达也可以添加相应的插件将其定义为 RGB-D相机。
(1)在urdf文件夹下的smartcar.urdf中添加:

<gazebo reference="sensor_link">
    <sensor type="depth" name="camera1">
        <always_on>1</always_on>
        <visualize>true</visualize>             
        <camera>
            <horizontal_fov>1.047</horizontal_fov>  
            <image>
                <width>640</width>
                <height>480</height>
                <format>R8G8B8</format>
            </image>
            <depth_camera>

            </depth_camera>
            <clip>
                <near>0.1</near>
                <far>100</far>
            </clip>
        </camera>
             <plugin name="camera_controller" filename="libgazebo_ros_openni_kinect.so">
             <alwaysOn>true</alwaysOn>
                <updateRate>5</updateRate>
                <cameraName>kinect2</cameraName>
                <frameName>base_link</frameName>                   
            <imageTopicName>qhd/image_color_rect</imageTopicName>
            <depthImageTopicName>qhd/image_depth_rect</depthImageTopicName>
            <pointCloudTopicName>depth/points</pointCloudTopicName>
            <cameraInfoTopicName>qhd/camera_info</cameraInfoTopicName>              
            <depthImageCameraInfoTopicName>depth/camera_info</depthImageCameraInfoTopicName>            
            <pointCloudCutoff>0.4</pointCloudCutoff>                
                <hackBaseline>0.07</hackBaseline>
                <distortionK1>0.0</distortionK1>
                <distortionK2>0.0</distortionK2>
                <distortionK3>0.0</distortionK3>
                <distortionT1>0.0</distortionT1>
                <distortionT2>0.0</distortionT2>
            <CxPrime>0.0</CxPrime>
            <Cx>0.0</Cx>
            <Cy>0.0</Cy>
            <focalLength>0.0</focalLength>
            <hackBaseline>0</hackBaseline>
            </plugin>
    </sensor>
  </gazebo>

(2)在两个终端分别输入指令:

roslaunch  smartcar gazebo.launch
roslaunch  smartcar display.launch

(3)在Rviz界面添加相应Topic就能看到深度图像和彩色图像
在这里插入图片描述
在这里插入图片描述

3.运动控制插件

  为了能让机器人运动起来,我们还需要添加滑动转向驱动:

<gazebo>
  <plugin name="skid_steer_drive_controller" filename="libgazebo_ros_skid_steer_drive.so">

    <alwaysOn>true</alwaysOn>

    <updateRate>5</updateRate>

   <leftFrontJoint>wheel1_joint</leftFrontJoint>

    <rightFrontJoint>wheel3_joint</rightFrontJoint>

   <leftRearJoint>wheel2_joint</leftRearJoint>

    <rightRearJoint>wheel4_joint</rightRearJoint> 


    <wheelSeparation>0.060</wheelSeparation> 

    <wheelDiameter>0.040</wheelDiameter>

    <torque>20</torque>

    <commandTopic>cmd_vel</commandTopic>

    <odometryTopic>odom</odometryTopic>

    <odometryFrame>odom</odometryFrame>

    <robotBaseFrame>base_link</robotBaseFrame>

    <broadcastTF>1</broadcastTF>

  </plugin>
</gazebo>

  想要添加更多Gazebo插件,可以看这里

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

不放弃的蜗牛

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

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

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

打赏作者

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

抵扣说明:

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

余额充值