ROS总结(三)在仿真模型添加激光雷达

官方教程

完整代码:


<robot name="laser" xmlns:xacro="http://ros.org/wiki/xacro">
  
  <xacro:property name="hokuyo_size" value="0.05" />
  <xacro:property name="base_height" value="0.02" />
  <xacro:property name="base_radius" value="0.25" />

  <xacro:macro name="laser" params="parent"> 
    <link name="base_laser">
      <collision>
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <geometry>
          <box size="${hokuyo_size} ${hokuyo_size} ${hokuyo_size}"/>
        geometry>
      collision>
      <visual>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <geometry>
          
          
          <mesh filename="package://mybot_description/mesh/hokuyo.dae"/>
        geometry>
        
      visual>
    link>
    <joint name="hokuyo_joint" type="fixed">
      <origin xyz="${base_radius - hokuyo_size/2} 0 ${base_height+hokuyo_size/2}" rpy="0 0 0" />
      <parent link="${parent}"/>
      <child link="base_laser" />
    joint>

    <gazebo reference="base_laser">
      <material>Gazebo/Bluematerial>
      <turnGravityOff>falseturnGravityOff>
      <sensor type="gpu_ray" name="head_hokuyo_sensor">
        <pose>${hokuyo_size/2} 0 0 0 0 0pose>
        <visualize>falsevisualize>
        <update_rate>50update_rate>
        <ray>
          <scan>
            <horizontal>
              <samples>720samples>
              <resolution>1resolution>
              <min_angle>-2.3550796min_angle>
              <max_angle>2.3550796max_angle>
            horizontal>
          scan>
          <range>
            <min>0.10min>
            <max>10.0max>
            <resolution>0.001resolution>
          range>
        ray>
        <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_gpu_laser.so">
          <topicName>/scantopicName>
          <frameName>base_laserframeName>
        plugin>
      sensor>
    gazebo>
  xacro:macro>
robot>

分析:

激光的尺寸属性和base_link的参数

  <xacro:property name="hokuyo_size" value="0.05" />
  <xacro:property name="base_height" value="0.02" />
  <xacro:property name="base_radius" value="0.25" />

宏:名称为laser,参数parent(关节的parent属性)

<xacro:macro name="laser" params="parent">

包含三个部分:link、joint、gazebo:

link包含了显示和碰撞属性,显示用了mesh

    <link name="base_laser">
      <collision>
        <origin xyz="0 0 0" rpy="0 0 0"/>
        <geometry>
          <box size="${hokuyo_size} ${hokuyo_size} ${hokuyo_size}"/>
        geometry>
      collision>
      <visual>
        <origin xyz="0 0 0" rpy="0 0 0" />
        <geometry>
          
          
          <mesh filename="package://mybot_description/mesh/hokuyo.dae"/>
        geometry>
        
      visual>
    link>

gazebo:
reference表示该gazebo属性是base_laser这个link的
material是在gazebo中显示的材质
sensor标签声明传感器属性:type类型为gpu_ray(可以探测没有碰撞属性的物体,如actor)

  • visualize:是否显示传感器数据
  • update_rate:更新频率
  • ray:激光数据的参数配置
  • plugin:配合sensor类型gpu_ray使用libgazebo_ros_gpu_laser.so;如果是ray类型则用libgazebo_ros_laser.so
    <gazebo reference="base_laser">
      <material>Gazebo/Bluematerial>
      <turnGravityOff>falseturnGravityOff>
      <sensor type="gpu_ray" name="head_hokuyo_sensor">
        <pose>${hokuyo_size/2} 0 0 0 0 0pose>
        <visualize>falsevisualize>
        <update_rate>50update_rate>
        <ray>
          <scan>
            <horizontal>
              <samples>720samples>
              <resolution>1resolution>
              <min_angle>-2.3550796min_angle>
              <max_angle>2.3550796max_angle>
            horizontal>
          scan>
          <range>
            <min>0.10min>
            <max>10.0max>
            <resolution>0.001resolution>
          range>
        ray>
        <plugin name="gazebo_ros_head_hokuyo_controller" filename="libgazebo_ros_gpu_laser.so">
          <topicName>/scantopicName>
          <frameName>base_laserframeName>
        plugin>
      sensor>
    gazebo>

效果:
ROS总结(三)在仿真模型添加激光雷达_第1张图片
ROS总结(三)在仿真模型添加激光雷达_第2张图片

你可能感兴趣的:(ROS)