- Overview
- Project Structure
- Prerequisites
- Task 0: Basic Setup and Robot Interface
- Task 1: Reinforcement Learning with SAC
- Task 2: Vision-Based Food Collection
- Quick Start
- Results
- Troubleshooting
This project consists of three progressive tasks that demonstrate the implementation of reinforcement learning for robot control:
- Task 0: Basic robot interface setup and demonstration
- Task 1: Discrete action space reinforcement learning using Soft Actor-Critic (SAC)
- Task 2: Continuous action space with vision transformer (ViT) for food detection and collection
Each task builds upon the previous one, introducing more sophisticated techniques and capabilities.
Learning_machine/
├── task0/ # Basic setup and robot interface
├── task1/ # SAC with discrete actions
├── task2/ # SAC with continuous actions + ViT vision
├── .venv/ # Python virtual environment
└── README.md # This file
Each task directory contains:
catkin_ws/- ROS workspace with learning_machines packagescenes/- CoppeliaSim simulation scenesscripts/- Setup and run scriptsresults/- Training results and model checkpointsrequirements.txt- Python dependenciesDockerfile- Docker configuration for ROS environment
-
Python 3.8+
python3 --version # Should be 3.8 or higher -
Docker Desktop
- Download from Docker Desktop
- For Apple Silicon Macs: Enable experimental features and set CPU limit to 1
-
CoppeliaSim (Educational version)
- Download from CoppeliaSim Downloads
- Place the
.appfile in each task directory ascoppeliaSim.app
-
Virtual Environment
python3 -m venv .venv source .venv/bin/activate
- macOS (Intel or Apple Silicon), Linux, or Windows
- Minimum 8GB RAM (16GB recommended)
- Docker Desktop with sufficient resources allocated
Purpose: Establish the foundation for robot interaction with both simulation and hardware.
- Basic robot interface setup using
robobo_interface - Connection to CoppeliaSim simulator
- Connection to physical Robobo hardware (via ROS)
- Demonstration of basic robot movements and sensor readings
- IR sensor reading and camera access
robobo_interface: Abstraction layer for hardware/simulation- Basic action scripts demonstrating robot capabilities
- Multiple simulation scenes for testing
-
Setup IP Address:
cd task0 # Get your IP address ipconfig getifaddr en0 # macOS # Update scripts/setup.bash with your IP
-
Start CoppeliaSim:
zsh ./scripts/start_coppelia_sim.zsh ./scenes/Robobo_Scene.ttt
-
Run the Code:
# For Intel Mac or Linux bash ./scripts/run.sh --simulation # For Apple Silicon Mac zsh ./scripts/run_apple_sillicon.zsh --simulation
Purpose: Implement reinforcement learning for obstacle avoidance using discrete action spaces.
- Soft Actor-Critic (SAC) algorithm implementation
- Discrete action space: 6 primitive movements
- State space: 8 normalized IR sensor values
- Gymnasium environment wrapper (
RoboboIREnv) - Experience replay buffer
- Training statistics and model checkpointing
- Agent: SAC with discrete actions using Gumbel-Softmax
- Network Architecture:
- Actor: 2 hidden layers (64 neurons each)
- Critic: 2 Q-networks with target networks
- Training: 150 episodes, 10 steps per episode
- Exploration: Epsilon-greedy with decay
agent.py: SAC agent implementationenv.py: Gymnasium environment wrappertrain.py: Training scriptvalidation.py: Model evaluation script
-
Train the Model:
cd task1 # Start CoppeliaSim first zsh ./scripts/start_coppelia_sim.zsh ./scenes/arena_approach.ttt # Run training (in another terminal) bash ./scripts/run.sh --simulation
-
Validate Trained Model:
# Edit validation.py to set MODEL_PATH python3 catkin_ws/src/learning_machines/scripts/validation.py --simulation
Training results are saved in task1/results/ including:
- Model checkpoints (
.h5files) - Training statistics (JSON)
- Training plots (
.png) - Validation results
Purpose: Extend Task 1 with continuous actions and vision transformer for food detection.
- Continuous action space: Normalized wheel speeds
[-1, 1] - Vision Transformer (ViT): Zero-shot image classification using CLIP
- Enhanced state space:
- 8 IR sensor values
- 3 green detection bands (horizontal image analysis)
- 1 ViT food score
- Food collection task: Collect green/red blocks in simulation
- Reward function: Combines food collection, collision avoidance, and movement
- Agent: SAC with continuous actions (Gaussian policy)
- Vision: CLIP-ViT for zero-shot food detection
- State Processing: Multi-modal (IR sensors + image analysis)
- Action Space: Continuous
[left_speed, right_speed]
- Continuous Control: Smooth wheel speed control instead of discrete movements
- Vision Integration: Real-time food detection using transformer models
- Multi-modal State: Combines proprioceptive (IR) and exteroceptive (vision) sensing
- Task Complexity: Food collection with reward shaping
-
Train the Model:
cd task2 # Start CoppeliaSim with food collection scene zsh ./scripts/start_coppelia_sim.zsh ./scenes/arena_approach_sparse.ttt # Run training bash ./scripts/run.sh --simulation
-
Test Vision Detection:
# Test ViT food detection python3 catkin_ws/src/learning_machines/scripts/test_vit.py
- Observation Space:
Box(0.0, 1.0, shape=(12,))- 8 IR sensors (normalized)
- 3 green detection bands
- 1 ViT food score
- Action Space:
Box(-1.0, 1.0, shape=(2,))- Left wheel speed
- Right wheel speed
- Reward Components:
- +10.0 per food item collected
- -5.0 for collisions
- +0.2 for forward movement
- +0.5 for green detection
- +0.5 for ViT food score
- -0.1 for obstacle proximity
-
Clone and Setup:
git clone <repository-url> cd Learning_machine python3 -m venv .venv source .venv/bin/activate
-
Install CoppeliaSim:
- Download CoppeliaSim for your platform
- Copy to
task0/coppeliaSim.app,task1/coppeliaSim.app,task2/coppeliaSim.app
-
Configure IP Address:
# Get your IP ipconfig getifaddr en0 # Update in each task # Edit task0/scripts/setup.bash # Edit task1/scripts/setup.bash # Edit task2/scripts/setup.bash
-
Run Task 0 (Basic Setup):
cd task0 zsh ./scripts/start_coppelia_sim.zsh ./scenes/Robobo_Scene.ttt # In another terminal: bash ./scripts/run.sh --simulation
-
Run Task 1 (RL Training):
cd task1 zsh ./scripts/start_coppelia_sim.zsh ./scenes/arena_approach.ttt bash ./scripts/run.sh --simulation -
Run Task 2 (Vision RL):
cd task2 zsh ./scripts/start_coppelia_sim.zsh ./scenes/arena_approach_sparse.ttt bash ./scripts/run.sh --simulation
Located in task1/results/:
- Multiple training runs with different configurations
- Model checkpoints saved every 20 episodes
- Training statistics showing:
- Episode rewards
- Episode lengths
- Loss curves
- Exploration rate decay
Located in task2/results/:
- Vision transformer test outputs
- State visualization images
- Food detection examples
-
CoppeliaSim Connection Failed
- Check IP address in
scripts/setup.bash - Ensure CoppeliaSim is running before starting Docker
- Verify network connectivity
- Check IP address in
-
Docker Build Fails
- Ensure Docker Desktop is running
- Check available disk space (Docker needs ~10GB)
- For Apple Silicon: Set CPU limit to 1 in Docker settings
-
Python Import Errors
- Activate virtual environment:
source .venv/bin/activate - Install requirements:
pip install -r requirements.txt - Check Python version (3.8+ required)
- Activate virtual environment:
-
Hardware Connection Issues
- Verify ROS_MASTER_URI in
setup.bash - Ensure phone and computer are on same network
- Check Robobo app is running on phone
- Verify ROS_MASTER_URI in
-
Vision Transformer Not Working
- Install transformers library:
pip install transformers - Check internet connection (downloads model on first use)
- Verify image capture is working
- Install transformers library:
- Check individual task READMEs in
task0/README.md,task1/README.md,task2/README.md - Review
quick_setup_macos.mdin each task directory - Check Docker logs:
docker logs <container_id>
This project is part of the Learning Machines course. See individual task directories for specific licensing information.