Skip to main content

2.4-sensor-simulation


Sensor Simulation: LiDAR, Cameras, and IMUs

Overview​

In this chapter, we'll dive deep into sensor simulation in Gazebo, which is crucial for developing perception algorithms for humanoid robots. Accurate sensor simulation allows us to develop and test perception algorithms before deploying them on real robots, significantly reducing development time and costs.

We'll cover how to simulate various types of sensors including LiDAR, cameras, IMUs, and more, with realistic noise models and performance characteristics.

Learning Objectives​

After completing this chapter, you will be able to:

  1. Configure and simulate various sensor types in Gazebo
  2. Understand the parameters that affect sensor performance in simulation
  3. Implement realistic noise models for sensor simulation
  4. Validate sensor simulation against real sensor data
  5. Create sensor fusion pipelines using simulated sensors

LiDAR Simulation in Gazebo​

Types of LiDAR Sensors​

Gazebo provides several LiDAR simulation options:

  1. Ray-based sensors: Use ray casting to compute distances
  2. Ray sensors: Model laser range finders with multiple rays
  3. GPU ray sensors: GPU-accelerated ray sensors for better performance

Basic LiDAR Configuration​

Here's an example of a 2D LiDAR configuration in SDF:

<model name="lidar_model">
<link name="lidar_link">
<visual>
<geometry>
<cylinder radius="0.05" length="0.05"/>
</geometry>
</visual>
<collision>
<geometry>
<cylinder radius="0.05" length="0.05"/>
</geometry>
</collision>
</link>

<sensor name="2d_lidar" type="ray">
<pose>0 0 0.025 0 0 0</pose>
<ray>
<scan>
<horizontal>
<samples>720</samples>
<resolution>1</resolution>
<min_angle>-3.14159</min_angle>
<max_angle>3.14159</max_angle>
</horizontal>
</scan>
<range>
<min>0.08</min>
<max>10.0</max>
<resolution>0.01</resolution>
</range>
</ray>
<plugin name="lidar_controller" filename="libgazebo_ros_laser.so">
<topic_name>scan</topic_name>
<frame_name>lidar_link</frame_name>
</plugin>
<always_on>1</always_on>
<update_rate>10</update_rate>
</sensor>
</model>

3D LiDAR Configuration​

For 3D LiDAR sensors, we can use the ray sensor with both horizontal and vertical scans:

<sensor name="3d_lidar" type="ray">
<pose>0 0 0 0 0 0</pose>
<ray>
<scan>
<horizontal>
<samples>640</samples>
<resolution>1</resolution>
<min_angle>-1.396263</min_angle>
<max_angle>1.396263</max_angle>
</horizontal>
<vertical>
<samples>16</samples>
<resolution>1</resolution>
<min_angle>-0.349066</min_angle>
<max_angle>0.349066</max_angle>
</vertical>
</scan>
<range>
<min>0.08</min>
<max>30.0</max>
<resolution>0.01</resolution>
</range>
</ray>
<plugin name="velodyne_controller" filename="libgazebo_ros_velodyne_gpu_laser.so">
<topic_name>points</topic_name>
<frame_name>lidar_link</frame_name>
<min_range>0.9</min_range>
<max_range>130.0</max_range>
<gaussian_noise>0.008</gaussian_noise>
</plugin>
</sensor>

LiDAR Noise Modeling​

Real LiDAR sensors have various types of noise and artifacts that should be modeled in simulation:

<sensor name="lidar_with_noise" type="ray">
<ray>
<scan>
<horizontal>
<samples>1080</samples>
<resolution>1</resolution>
<min_angle>-3.14159</min_angle>
<max_angle>3.14159</max_angle>
</horizontal>
</scan>
<range>
<min>0.1</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="lidar_controller" filename="libgazebo_ros_laser.so">
<topic_name>scan</topic_name>
<frame_name>lidar_link</frame_name>
<always_on>true</always_on>
<update_rate>10</update_rate>
</plugin>
</sensor>

Camera Simulation in Gazebo​

Basic Camera Configuration​

Gazebo provides realistic camera simulation with support for RGB, depth, and optical flow sensors:

<sensor name="camera" type="camera">
<pose>0.1 0 0 0 0 0</pose>
<camera>
<horizontal_fov>1.396263</horizontal_fov>
<image>
<width>800</width>
<height>600</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.1</near>
<far>100</far>
</clip>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
</camera>
<plugin name="camera_controller" filename="libgazebo_ros_camera.so">
<camera_name>my_camera</camera_name>
<image_topic_name>image_raw</image_topic_name>
<camera_info_topic_name>camera_info</camera_info_topic_name>
<frame_name>camera_link</frame_name>
<hack_baseline>0.07</hack_baseline>
<distortion_k1>0.0</distortion_k1>
<distortion_k2>0.0</distortion_k2>
<distortion_k3>0.0</distortion_k3>
<distortion_t1>0.0</distortion_t1>
<distortion_t2>0.0</distortion_t2>
</plugin>
</sensor>

Depth Camera Configuration​

For depth sensing applications, Gazebo can simulate depth cameras that provide distance information:

<sensor name="depth_camera" type="depth">
<pose>0.1 0 0 0 0 0</pose>
<camera>
<horizontal_fov>1.047</horizontal_fov>
<image>
<width>640</width>
<height>480</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.1</near>
<far>10</far>
</clip>
</camera>
<plugin name="depth_camera_controller" filename="libgazebo_ros_openni_kinect.so">
<camera_name>my_depth_camera</camera_name>
<image_topic_name>rgb/image_raw</image_topic_name>
<depth_image_topic_name>depth/image_raw</depth_image_topic_name>
<point_cloud_topic_name>depth/points</point_cloud_topic_name>
<camera_info_topic_name>rgb/camera_info</camera_info_topic_name>
<frame_name>depth_camera_frame</frame_name>
<baseline>0.1</baseline>
<distortion_k1>0.0</distortion_k1>
<distortion_k2>0.0</distortion_k2>
<distortion_k3>0.0</distortion_k3>
<distortion_t1>0.0</distortion_t1>
<distortion_t2>0.0</distortion_t2>
</plugin>
</sensor>

IMU Simulation in Gazebo​

Basic IMU Configuration​

IMUs are critical for humanoid robot balance and navigation. Here's how to configure an IMU in Gazebo:

<sensor name="imu_sensor" type="imu">
<always_on>1</always_on>
<update_rate>100</update_rate>
<pose>0 0 0 0 0 0</pose>
<plugin name="imu_plugin" filename="libgazebo_ros_imu.so">
<topicName>imu</topicName>
<bodyName>imu_link</bodyName>
<frameName>imu_link</frameName>
<serviceName>imu_service</serviceName>
<gaussianNoise>0.001</gaussianNoise>
<updateRateHZ>100.0</updateRateHZ>
</plugin>
<imu>
<angular_velocity>
<x>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>0.001</stddev>
</noise>
</x>
<y>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>0.001</stddev>
</noise>
</y>
<z>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>0.001</stddev>
</noise>
</z>
</angular_velocity>
<linear_acceleration>
<x>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>1.7e-2</stddev>
</noise>
</x>
<y>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>1.7e-2</stddev>
</noise>
</y>
<z>
<noise type="gaussian">
<mean>0.0</mean>
<stddev>1.7e-2</stddev>
</noise>
</z>
</linear_acceleration>
</imu>
</sensor>

Sensor Fusion in Simulation​

Implementing Multi-Sensor Systems​

For humanoid robotics applications, you often need to combine multiple sensors for better perception. Here's how to set up a multi-sensor system in Gazebo:

<model name="multi_sensor_robot">
<!-- Links and joints omitted for brevity -->

<!-- IMU for orientation -->
<sensor name="imu_sensor" type="imu">
<!-- IMU configuration as shown above -->
</sensor>

<!-- 2D LiDAR for navigation -->
<sensor name="navigation_lidar" type="ray">
<!-- LiDAR configuration as shown above -->
</sensor>

<!-- RGBD camera for object recognition -->
<sensor name="rgbd_camera" type="depth">
<!-- Camera configuration as shown above -->
</sensor>

<!-- Additional sensors can be added as needed -->
</model>

Realistic Sensor Noise and Delay​

For more realistic simulation, it's important to include sensor-specific noise models and timing characteristics:

<!-- Example of realistic sensor parameters -->
<sensor name="realistic_camera" type="camera">
<camera>
<!-- Camera parameters -->
<horizontal_fov>1.047</horizontal_fov>
<image>
<width>640</width>
<height>480</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.2</near>
<far>50.0</far>
</clip>
<noise>
<type>gaussian</type>
<mean>0.0</mean>
<stddev>0.007</stddev>
</noise>
</camera>
<always_on>true</always_on>
<!-- Add update period to simulate frame rate -->
<update_rate>30</update_rate>
<!-- Add plugin with realistic camera parameters -->
<plugin name="realistic_camera_controller" filename="libgazebo_ros_camera.so">
<camera_name>realistic_camera</camera_name>
<image_topic_name>image_raw</image_topic_name>
<camera_info_topic_name>camera_info</camera_info_topic_name>
<frame_name>camera_frame</frame_name>
<!-- Add realistic distortion parameters -->
<distortion_k1>0.1</distortion_k1>
<distortion_k2>-0.2</distortion_k2>
<distortion_k3>0.05</distortion_k3>
<distortion_t1>0.01</distortion_t1>
<distortion_t2>0.02</distortion_t2>
</plugin>
</sensor>

Hands-on Lab: Creating a Multi-Sensor Robot Model​

In this lab, you will create a robot model with multiple sensors and test their functionality in simulation.

Step 1: Create the Robot URDF with Sensors​

Create a file sensor_robot.urdf with:

  1. A base body
  2. 2D LiDAR on top
  3. RGB-D camera
  4. IMU for orientation

Step 2: Launch the Robot in Gazebo​

  1. Create a Gazebo world file that includes your robot
  2. Launch using:
    roslaunch your_robot_description gazebo.launch

Step 3: Verify Sensor Topics​

  1. Check that all sensor topics are being published:

    rostopic list | grep your_robot
  2. Verify sensor data quality:

    rostopic echo /your_robot/lidar/scan
    rostopic echo /your_robot/camera/image_raw
    rostopic echo /your_robot/imu/data

Step 4: Test Sensor Fusion​

  1. Use ROS tools to visualize multiple sensor streams
  2. Implement a simple sensor fusion example to combine LiDAR and camera data

Advanced Sensor Simulation Techniques​

Dynamic Sensor Reconfiguration​

Gazebo allows for dynamic reconfiguration of sensors during simulation:

<sensor name="adaptive_sensor" type="camera">
<camera>
<horizontal_fov>1.047</horizontal_fov>
<image>
<width>640</width>
<height>480</height>
<format>R8G8B8</format>
</image>
<clip>
<near>0.2</near>
<far>50.0</far>
</clip>
</camera>
<plugin name="dynamic_camera" filename="libgazebo_ros_camera.so">
<!-- Enable dynamic reconfiguration -->
<always_on>true</always_on>
<update_rate>30</update_rate>
</plugin>
</sensor>

Performance Optimization​

For complex multi-sensor robots, consider these performance optimization techniques:

  1. Reduce update rates for sensors that don't require high frequency
  2. Limit sensor range to what's necessary for your application
  3. Reduce resolution of sensors when possible
  4. Use GPU-accelerated sensors when available
  5. Disable visualizations when not needed for performance testing

Troubleshooting Notes​

  1. Sensor data not published: Check that the sensor plugin is correctly loaded and that topic names match between Gazebo and ROS.

  2. High CPU usage: Reduce sensor update rates or resolution if experiencing performance issues.

  3. Artifacts in sensor data: Verify noise parameters match your real-world sensor specifications.

  4. Coordinate frame issues: Ensure sensor frames are properly defined and TF transforms are available.

Summary​

In this chapter, we've explored sensor simulation in Gazebo, covering LiDAR, cameras, IMUs, and the integration of multiple sensors for humanoid robot perception. We've learned how to configure sensors with realistic noise models and performance characteristics.

Next Steps​

The next chapter will cover Unity integration for high-fidelity visualization, exploring how to use Unity for humanoid robot simulation alongside Gazebo for physics simulation.

References​

  1. Gazebo Sensors Documentation: http://gazebosim.org/tutorials?tut=ros_gzplugins#Sensor
  2. ROS Sensor Integration: http://wiki.ros.org/sensor_msgs
  3. NVIDIA Isaac ROS Sensors: https://developer.nvidia.com/isaac-ros/isaac-ros-sensors
  4. Sensor Fusion Techniques: https://docs.ros.org/en/rolling/p/sensor_fusion/
💬
🤖
ROBO-ASSISTANT
Hello! I'm your AI assistant for Physical AI & Humanoid Robotics. How can I help you today?