TurtleBot LiDAR Occlusion Simulator Tutorial
Repository: link
This tutorial explains the TurtleBot LiDAR Occlusion Simulator, a web-based dashboard application that simulates a TurtleBot4 robot with LiDAR sensor capabilities. You can test navigation algorithms, study LiDAR occlusion effects, and visualize robot movement in real-time.
Overview
The TurtleBot LiDAR Occlusion Simulator provides:
Real-time robot simulation with position tracking
LiDAR sensor simulation with configurable occlusion
Interactive web dashboard built with Dash and Plotly
Multiple navigation modes (Standard and Spin Configuration)
Path planning using A* algorithm
MQTT/Redis communication for external control
Live data visualization with polar LiDAR plots and 2D maps
Prerequisites
Python 3.7 or higher
Redis server (optional, for external communication)
Web browser (Chrome, Firefox, Safari, Edge)
Required packages:
pip install dash dash-bootstrap-components plotly numpy paho-mqtt redis rpio
Getting Started
Clone or download the repository containing
dash_turtlebotsim.pyInstall dependencies:
pip install -r requirements.txt
Run the simulator:
python dash_turtlebotsim.py
Open your web browser and navigate to
http://localhost:8050
Configuration
Environment Variables (optional):
# Set Redis connection (default: localhost:6379)
set REDIS_HOST=localhost
set REDIS_PORT=6379
# Set Dash server configuration (default: 0.0.0.0:8050)
set DASH_HOST=0.0.0.0
set DASH_PORT=8050
set DASH_DEBUG=False
Optional: Set up Redis server (for external communication):
# On Windows (using Chocolatey)
choco install redis-64
# On Linux
sudo apt-get install redis-server
# On macOS
brew install redis
Examples
Start the simulator:
python dash_turtlebotsim.py
Open your web browser and navigate to:
http://localhost:8050
The dashboard should load showing: - Control panel (left) - Map visualization (center) - LiDAR data plot (right)
User Interface
Control Panel (left side):
Status Indicators: LiDAR status and navigation mode
Control Buttons: Toggle LiDAR occlusion, navigation mode, stop navigation
Manual Navigation: Target X/Y inputs and navigate button
Robot Status: Current position, heading, navigation state, obstacles
Map Visualization (center):
Robot position (blue circle with “TurtleBot4” label)
Heading direction (blue arrow)
Planned trajectory (green dashed line)
Obstacles (red X markers)
Interactive clicking for navigation targets
LiDAR Data Plot
The right panel displays:
Polar plot of LiDAR sensor readings
360-degree coverage with distance measurements
Real-time updates showing occlusion effects
Using the Simulator
Testing LiDAR Occlusion
Start with normal LiDAR: Observe the red line in the polar plot
Click “Toggle LiDAR Occlusion”: Notice how readings change
Observe the effects: First 300 degrees show infinite readings
Test navigation: See how occlusion affects movement
Advanced Features
External Communication
The simulator supports external control via Redis/MQTT:
- Topic Structure:
/pose: Robot position and orientation/Scan: LiDAR sensor data/spin_config: Navigation configuration commands
Sending Commands:
import json
import redis
# Connect to Redis
r = redis.StrictRedis(host='localhost', port=6379, decode_responses=True)
# Send spin configuration
command = {
"commands": [{
"duration": 2.0,
"omega": 45 # degrees
}]
}
r.publish("/spin_config", json.dumps(command))
Logging and Monitoring
The simulator provides comprehensive logging:
Console output: Real-time status messages
Redis logging: Centralized log storage
Event tracking: Navigation events, mode changes, etc.
Customization
Modifying Map Parameters
Edit the TurtleBotSim class initialization:
def __init__(self):
self.map_size = 20 # Increase map size
self.obstacles = self.generate_obstacles(num_obstacles=10) # More obstacles
Adjusting Update Frequency
Modify the Dash interval component:
dcc.Interval(
id='interval-component',
interval=500, # Update every 0.5 seconds
n_intervals=0
)
Customizing LiDAR Parameters
Edit the publish_scan method:
lidar_data = {
'angle_min': -3.14159, # Adjust scan range
'angle_max': 3.14159,
'angle_increment': 0.01745, # Higher resolution
'range_max': 15.0, # Longer range
'ranges': self.lidar_data
}
Troubleshooting
Common Issues
- Dashboard won’t load
Check if port 8050 is available
Verify all dependencies are installed
Look for error messages in console
- Redis connection errors
Ensure Redis server is running
Check REDIS_HOST and REDIS_PORT environment variables
Simulator will work without Redis for basic functionality
- Navigation not working
Check for JavaScript errors in browser console
Verify map coordinates are within bounds
Ensure navigation isn’t already active
- Performance issues
Reduce update frequency in interval component
Close other browser tabs
Check system resources
Development and Extension
Code Structure
- Main Components:
TurtleBotSim: Core simulation logicDash app: Web interface and callbacksMQTT/Redis: External communicationA* pathfinding: Navigation algorithm
Adding New Features:
New sensors: Extend
TurtleBotSimclassUI components: Add Dash components and callbacks
Communication protocols: Modify
CommunicationManagerusageVisualization: Create new Plotly figures
Example Extensions
Adding Camera Simulation:
def simulate_camera(self):
# Generate synthetic camera data
return {
'image_data': np.random.rand(480, 640, 3),
'timestamp': time.time()
}
Custom Path Planning:
def rrt_pathfinding(start, goal, obstacles):
# Implement RRT algorithm
# Return optimized path
pass
Troubleshooting
Common Issues:
Port 8050 already in use: Change the port in the Dash configuration or stop other applications using this port
Redis connection failed: Ensure Redis server is running if using external communication features
Dashboard not loading: Check that all dependencies are installed correctly
LiDAR visualization issues: Verify browser compatibility (Chrome/Firefox recommended)
Additional Resources:
The TurtleBot LiDAR Occlusion Simulator provides a comprehensive platform for testing robot navigation algorithms, studying sensor occlusion effects, and developing real-time monitoring dashboards.
For additional support or feature requests, refer to the project documentation.