gazebo中添加激光雷达,echo不到数据

用的是turtlebot的包(turtlebot_descriptionturtlebot_simulator),想要在它的基础上做一些修改搭建一个仿真环境。原本的turtlebot是搭载的一个深度摄像头作为距离传感器,我想换成激光雷达,所以修改了URDF文件,导入到gazebo后可以看到模型没问题。

这个时候也能看到仿真时间,也可以用键盘控制它运动,但是只要我一尝试echo 激光雷达的数据(其他topic的数据也一样),仿真就会终止。

zhouxr@zhouxr-ThinkPad-T470p:~$ rostopic echo /rplidar/scan 
WARNING: no messages received and simulated time is active.
Is /clock being published?

运行gazebo的终端提示如图所示的错误信息:

这是参考的教程
[https://blog.csdn.net/zyh821351004/article/details/48846179]
[https://blog.csdn.net/qq_36355662/article/details/61616513]

1赞

WARNING: no messages received and simulated time is active.
Is /clock being published?
这个意思是没有激光数据被发布出来。应该你没pub激光雷达数据。看下你的launch文件和.urdf文件

1赞

这是顶层的launch文件

<launch>
  <arg name="gui"        default="true"/>
  <arg name="world_file" default="$(env TURTLEBOT_GAZEBO_WORLD_FILE)"/>

  <arg name="base"       value="$(optenv TURTLEBOT_BASE kobuki)"/> <!-- create, roomba -->
  <arg name="battery"    value="$(optenv TURTLEBOT_BATTERY /proc/acpi/battery/BAT0)"/>  <!-- /proc/acpi/battery/BAT0 -->
  <arg name="stacks"     value="$(optenv TURTLEBOT_STACKS hexagons)"/>  <!-- circles, hexagons -->
  <arg name="3d_sensor"  value="$(optenv TURTLEBOT_3D_SENSOR kinect)"/>  <!-- rplidar, kinect, asus_xtion_pro -->

  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="use_sim_time" value="true"/>
    <arg name="debug" value="false"/>
    <arg name="gui" value="$(arg gui)" />
    <arg name="world_name" value="$(arg world_file)"/>
  </include>

  <include file="$(find turtlebot_gazebo)/launch/includes/$(arg base).launch.xml">
    <arg name="base" value="$(arg base)"/>
    <arg name="stacks" value="$(arg stacks)"/>
    <arg name="3d_sensor" value="$(arg 3d_sensor)"/>
  </include>

  <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher">
    <param name="publish_frequency" type="double" value="30.0" />
  </node>

  <!-- Fake laser -->
  <node pkg="nodelet" type="nodelet" name="laserscan_nodelet_manager" args="manager"/>

</launch>

这是顶层的URDF文件:

<?xml version="1.0"?>
<!--
    - Base      : kobuki
    - Stacks    : hexagons
    - 3d Sensor : rplidar
-->    
<robot name="turtlebot" xmlns:xacro="http://ros.org/wiki/xacro">

  <xacro:include filename="$(find turtlebot_description)/urdf/turtlebot_common_library.urdf.xacro" />
  <xacro:include filename="$(find kobuki_description)/urdf/kobuki.urdf.xacro" />
  <xacro:include filename="$(find turtlebot_description)/urdf/stacks/hexagons2.urdf.xacro"/>
  <xacro:include filename="$(find turtlebot_description)/urdf/sensors/rplidar.urdf.xacro"/>
  
  <kobuki/>
  <stack_hexagons parent="base_link"/>
  <sensor_rplidar  parent="base_link"/>
</robot>

这是雷达的URDF文件(rplidar.urdf.xacro):

<?xml version="1.0"?>
<!-- script_version=1.1 -->
<robot name="sensor_rplidar" xmlns:xacro="http://ros.org/wiki/xacro">
  <xacro:include filename="$(find turtlebot_description)/urdf/turtlebot_gazebo.urdf.xacro"/>
  <xacro:include filename="$(find turtlebot_description)/urdf/turtlebot_properties.urdf.xacro"/>

  <!-- RPLidar 2D LIDAR -->
  <xacro:macro name="sensor_rplidar" params="parent">
    <joint name="laser" type="fixed">
      <!--top of 30mm-->
      <origin xyz="-0.01364 0.0 0.1840" rpy="0 0.0 0.0" />
      <parent link="${parent}" />
      <child link="base_laser_link" />
    </joint>


    <link name="base_laser_link">
      <visual>
        <origin xyz="0 0 0.02" rpy="0 0 0"/>
        <geometry>
          <!--cylinder length="0.04049" radius="0.0377"/-->
            <mesh filename="package://turtlebot_description/meshes/sensors/hokuyo.dae"/>
        </geometry>
        <!-- material name="Red" / -->
      </visual>
      
      <inertial>
        <mass value="1e-5" />
        <origin xyz="0 0 0" />
        <inertia ixx="1e-6" ixy="0.0" ixz="0.0"
          iyy="1e-6" iyz="0.0"
          izz="1e-6" />
      </inertial>
    </link>

    <!-- Set up laser gazebo details -->
    <rplidar_laser />
  </xacro:macro>
</robot>

这是属性配置的文件:

<?xml version="1.0"?>
<robot name="turtlebot_gazebo" xmlns:xacro="http://ros.org/wiki/xacro">
  <!-- RPLidar LIDAR for simulation -->
  <xacro:macro name="rplidar_laser">
    <gazebo reference="base_laser_link">
      <sensor type="ray" name="laser">
        <pose>0 0 0 0 0 0</pose>
        <visualize>false</visualize>
        <update_rate>5.5</update_rate>
        <ray>
          <scan>
            <horizontal>
              <samples>360</samples>
              <resolution>1</resolution>
              <min_angle>-3.1415926</min_angle>
              <max_angle>3.1415926</max_angle>
            </horizontal>
          </scan>
          <range>
            <min>0.10</min>
            <max>6.0</max>
            <resolution>0.01</resolution>
          </range>
          <noise>
            <type>Gaussian</type>
            <mean>0.0</mean>
            <stddev>0.01</stddev>
          </noise>
        </ray>
        <plugin name="rplidar_node" filename="libgazebo_ros_laser.so">
          <topicName>/rplidar/scan</topicName>
          <frameName>base_laser_link</frameName>
        </plugin>
      </sensor>
    </gazebo>
  </xacro:macro>

</robot>

看着没什么问题。。把rqt_graph图贴出来看下

这是echo之前的

这是echo之后,仿真终止后的

楼主 问题解决了么?我最近也遇到了相同的问题,希望学习一下你的经验!万分感谢