Slamtec / rplidar_ros

BSD 2-Clause "Simplified" License
497 stars 532 forks source link

Wrong rotation direction: reverse_data bug #55

Open caselitz opened 3 years ago

caselitz commented 3 years ago

If reverse_data = true (see here), the driver reverses the order of individual point measurements in a scan.

The result is that the output scan does not follow the ROS laser scan massage definition, which says:

                         # in frame frame_id, angles are measured around 
                         # the positive Z axis (counterclockwise, if Z is up)
                         # with zero angle being forward along the x axis

What happens is that a consumer of this wrong scan massage thinks that the individual point measurements were recorded in the opposite temporal order - which causes problems if you try to correct for motion distortion (eg, Cartographer does this).

Conclusion: reversing the data should never happen in the driver, this is a bug.

Until this bug is fixed in the driver, you can use this rplidar_inverted.launch file as workaround:

<launch>
  <arg name="serial_port" default="/dev/ttyUSB0"/>
  <arg name="serial_baudrate" default="115200"/><!--A1/A2 115200, A3 256000-->
  <arg name="frame_id" default="laser"/>
  <arg name="angle_compensate" default="true"/>
  <arg name="scan_mode" default=""/>

  <arg name="frame_id_inverted" value="$(arg frame_id)_inverted"/>
  <node pkg="tf2_ros" type="static_transform_publisher" name="laser_inverted_broadcaster" args="0 0 0 1 0 0 0 $(arg frame_id) $(arg frame_id_inverted)"/>

  <node name="rplidar_node" pkg="rplidar_ros" type="rplidarNode" output="log">
    <param name="serial_port"         type="string" value="$(arg serial_port)"/>
    <param name="serial_baudrate"     type="int"    value="$(arg serial_baudrate)"/>
    <param name="frame_id"            type="string" value="$(arg frame_id_inverted)"/>
    <param name="inverted"            type="bool"   value="true"/>
    <param name="angle_compensate"    type="bool"   value="$(arg angle_compensate)"/>
    <param name="scan_mode"           type="string" value="$(arg scan_mode)"/>
  </node>
</launch>

It ensures that reverse_data = false and inverts the frame so that the rotation direction is correct (see https://github.com/Slamtec/rplidar_ros/issues/31).