Complete Docker-based ROS2 system for Arduino Alvik robot mapping and click-to-navigate control via rviz2.
π Apple Silicon Users (M1/M2/M3): Use the optimized build script for better performance:
./scripts/build-arm64.shSee APPLE_SILICON.md for detailed Apple Silicon setup and troubleshooting.
- πΊοΈ Real-time room mapping using Alvik's ToF sensor
- π±οΈ Click-to-navigate - Click anywhere on the map in rviz2 to send the robot there
- π‘ Wireless MQTT communication between Mac and Alvik
- π³ Fully Dockerized - No local ROS2 installation needed
- π Live visualization in rviz2
-
Docker Desktop
# Install via Homebrew brew install --cask docker -
XQuartz (X11 server for GUI support)
brew install --cask xquartz
After installing:
- Start XQuartz
- Go to Preferences β Security
- Enable "Allow connections from network clients"
- Restart XQuartz
- Run:
xhost + localhost
- MicroPython MQTT library (
umqtt) - WiFi credentials configured
cd alvik-ros2-docker
chmod +x scripts/*.sh
./scripts/build.shThis will:
- Create necessary directories
- Configure MQTT broker
- Build the Docker image (~5-10 minutes first time)
Edit alvik_firmware/main.py and update:
WIFI_SSID = "YourWiFiNetwork"
WIFI_PASSWORD = "YourPassword"
MQTT_BROKER = "192.168.1.XXX" # Your Mac's IP (shown when you run the container)Upload main.py to your Alvik using Arduino Lab or Thonny.
Terminal 1 - Start Docker container:
./scripts/run.shNote the IP address shown - you'll need this for the Alvik.
Terminal 2 - Inside the container:
# Build ROS2 workspace (first time only)
cd /ros2_ws
colcon build --symlink-install
source install/setup.bash
# Launch the full system
ros2 launch alvik_mapping alvik_system.launch.pyThis starts:
- ToF receiver node
- Room mapper node
- Alvik bridge node (odometry)
- Goal commander node
- rviz2 visualization
Run the main.py script on your Alvik. It should:
- Connect to WiFi
- Connect to MQTT broker
- Print "Alvik ready! Waiting for commands..."
In rviz2, you should see:
- Red laser scan points
- Occupancy grid map building up
- Robot's position (TF frames)
To trigger a 360Β° scan manually:
# In another terminal, inside the Docker container
mosquitto_pub -h localhost -t "alvik/command" -m '{"type":"scan"}'The robot will:
- Rotate 360Β° in place
- Take ToF readings every 5Β°
- Send data to ROS2
- Display map in rviz2
- In rviz2, click the "2D Goal Pose" button in the toolbar
- Click anywhere on the map
- Drag to set the desired robot orientation
- Release - the robot will navigate to that position!
The robot will:
- Rotate to face the goal
- Drive forward
- Align to final orientation
- Stop when arrived
Send commands via MQTT:
# Move forward 50cm
mosquitto_pub -h localhost -t "alvik/command" -m '{"type":"move", "distance":50}'
# Rotate 90Β° left
mosquitto_pub -h localhost -t "alvik/command" -m '{"type":"rotate", "angle":-90}'
# Emergency stop
mosquitto_pub -h localhost -t "alvik/command" -m '{"type":"stop"}'alvik-ros2-docker/
βββ Dockerfile # ROS2 container definition
βββ docker-compose.yml # Multi-container orchestration
βββ scripts/
β βββ build.sh # Build script
β βββ run.sh # Run script
βββ ros2_ws/src/alvik_mapping/
β βββ alvik_mapping/
β β βββ tof_receiver.py # Receives ToF scans via MQTT
β β βββ room_mapper.py # Builds occupancy grid
β β βββ alvik_bridge.py # Publishes odometry
β β βββ goal_commander.py # Click-to-navigate
β βββ launch/
β β βββ alvik_system.launch.py
β βββ config/
β βββ rviz_config.rviz
βββ alvik_firmware/
βββ main.py # Upload this to Alvik
- Ensure XQuartz is running
- Run
xhost + localhost - Check
echo $DISPLAYshowshost.docker.internal:0
- Verify Mac and Alvik are on same WiFi network
- Check firewall isn't blocking port 1883
- Confirm MQTT_BROKER IP in
main.pymatches Mac's IP - Test with:
mosquitto_sub -h localhost -t "alvik/#" -v
- Check ToF receiver is running:
ros2 node list - Verify MQTT messages:
mosquitto_sub -t "alvik/scan" -v - Check topic:
ros2 topic echo /scan
- Ensure goal_commander node is running
- Check odometry is being published:
ros2 topic echo /odom - Verify MQTT broker is receiving commands
- Ensure room_mapper node is running
- Check it's receiving scans:
ros2 topic hz /scan - Verify map is being published:
ros2 topic echo /map
Edit ros2_ws/src/alvik_mapping/launch/alvik_system.launch.py:
parameters=[{
'map_size_meters': 5.0, # 5m x 5m map
'map_resolution': 0.02 # 2cm per cell
}]Edit goal_commander.py:
def send_move_command(self, distance):
twist.linear.x = 0.1 # Increase for faster movement# Save map to file
ros2 service call /map_saver/save_map nav2_msgs/srv/SaveMap "{map_topic: /map, map_url: /ros2_ws/my_maze_map, image_format: pgm, map_mode: trinary, free_thresh: 0.25, occupied_thresh: 0.65}"To map multiple rooms, trigger scans at different positions and the mapper will combine them.
Future enhancement: Add camera feed visualization alongside ToF mapping.
- Lighting: Ensure consistent lighting for color sensor accuracy
- Surface: Place Alvik on flat, level surface
- Obstacles: ToF works best on solid walls, may struggle with:
- Transparent surfaces (glass)
- Very dark surfaces (absorb IR)
- Thin poles
- Calibration: Robot position drifts over time (odometry error) - perform new scans periodically
- WiFi: Strong signal needed for reliable MQTT communication
- Setup Tutorial: Step-by-step guide to get this running
- Live Mapping Demo: Show robot scanning maze rooms
- Click-to-Navigate: Interactive control demonstration
- Troubleshooting Tips: Common issues and solutions
- Custom Maze Challenge: Design maze and navigate autonomously
MIT License - Feel free to adapt for kevsrobots.com tutorials!
Created for Arduino Alvik maze-solving project By Kev @ kevsrobots.com