A sophisticated autonomous mobile robot simulation built with Webots R2023b. This project demonstrates advanced navigation algorithms, sensor fusion, dynamic obstacle avoidance, and delivery automation for a four-wheeled differential drive robot.
- Features
- System Architecture
- Hardware & Sensors
- Navigation Algorithm
- Project Structure
- Installation
- Usage
- Configuration
- Demo
- FAQ
- Contributing
- License
- Acknowledgments
- Autonomous Path Following: Predefined waypoint-based navigation system
- Dynamic Obstacle Avoidance: Real-time obstacle detection and semi-circular avoidance maneuvers
- Sensor Fusion: Integration of multiple sensors for robust navigation
- Delivery System: Automated stop-and-deliver functionality at predefined locations
- Gyroscope-based Heading Control: Accurate orientation tracking using yaw angle integration
- Modular Design: Clean, extensible codebase with configurable parameters
┌─────────────────────────────────────────────────────────────────────────────────┐
│ AUTONOMOUS NAVIGATION SYSTEM │
├─────────────────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────┐ ┌──────────────────┐ ┌─────────────────────────┐ │
│ │ SENSORS │ │ PROCESSING │ │ ACTUATORS │ │
│ │ │ │ │ │ │ │
│ │ ┌─────────────┐ │ │ ┌──────────────┐ │ │ ┌─────────────────────┐ │ │
│ │ │ Distance │─┼───►│ │ Obstacle │ │ │ │ Motor Controller │ │ │
│ │ │ Sensor │ │ │ │ Detection │ │ │ │ │ │ │
│ │ └─────────────┘ │ │ └──────────────┘ │ │ │ ┌─────┐ ┌─────┐ │ │ │
│ │ │ │ │ │ │ │ │ FL │ │ FR │ │ │ │
│ │ ┌─────────────┐ │ │ ▼ │ │ │ │Motor│ │Motor│ │ │ │
│ │ │ Gyroscope │─┼───►│ ┌──────────────┐ │ │ │ └─────┘ └─────┘ │ │ │
│ │ │ │ │ │ │ Path │─┼───►│ │ │ │ │
│ │ └─────────────┘ │ │ │ Planner │ │ │ │ ┌─────┐ ┌─────┐ │ │ │
│ │ │ │ └──────────────┘ │ │ │ │ BL │ │ BR │ │ │ │
│ │ ┌─────────────┐ │ │ │ │ │ │ │Motor│ │Motor│ │ │ │
│ │ │ Position │─┼───►│ ▼ │ │ │ └─────┘ └─────┘ │ │ │
│ │ │ Encoders │ │ │ ┌──────────────┐ │ │ └─────────────────────┘ │ │
│ │ └─────────────┘ │ │ │ Velocity │ │ │ │ │
│ │ │ │ │ Controller │─┼───►│ │ │
│ │ ┌─────────────┐ │ │ └──────────────┘ │ │ │ │
│ │ │ Camera │ │ │ │ │ │ │
│ │ │ (Optional) │ │ │ │ │ │ │
│ │ └─────────────┘ │ │ │ │ │ │
│ │ │ │ │ │ │ │
│ │ ┌─────────────┐ │ │ │ │ │ │
│ │ │Accelerometer│ │ │ │ │ │ │
│ │ └─────────────┘ │ │ │ │ │ │
│ └─────────────────┘ └──────────────────┘ └─────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────────────┘
┌──────────────┐
│ START │
└──────┬───────┘
│
▼
┌─────────────────────────┐
│ Initialize Sensors │
│ and Motors │
└────────────┬────────────┘
│
▼
┌─────────────────────────┐
│ Load Movement List │
│ & Delivery Points │
└────────────┬────────────┘
│
┌─────────────────────▼─────────────────────┐
│ MAIN CONTROL LOOP │
│ ┌─────────────────────────────────────┐ │
│ │ Read All Sensor Values │ │
│ └──────────────┬──────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────┐ │
│ │ Check Delivery Location? │ │
│ └──────────────┬──────────────────────┘ │
│ YES │ NO │
│ ┌────────────┘ │ │
│ ▼ │ │
│ ┌─────────┐ │ │
│ │ DELIVER │ │ │
│ └────┬────┘ │ │
│ └──────────────┤ │
│ ▼ │
│ ┌─────────────────────────────────────┐ │
│ │ Obstacle Detected? │ │
│ └──────────────┬──────────────────────┘ │
│ YES │ NO │
│ ┌────────────┘ │ │
│ ▼ ▼ │
│ ┌─────────┐ ┌─────────────┐ │
│ │ AVOID │ │ FOLLOW │ │
│ │OBSTACLE │ │ PATH │ │
│ └────┬────┘ └──────┬──────┘ │
│ └────────────────┤ │
│ ▼ │
│ ┌─────────────────────────────────────┐ │
│ │ Calculate Motor Velocities │ │
│ └──────────────┬──────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────┐ │
│ │ Apply Velocity to Motors │ │
│ └──────────────┬──────────────────────┘ │
│ │ │
└─────────────────┼─────────────────────────┘
│
▼
┌──────────────────┐
│ Destination │──NO──┐
│ Reached? │ │
└────────┬─────────┘ │
YES │ │
▼ │
┌──────────────────┐ │
│ STOP │ │
└──────────────────┘ │
│
┌─────────────────────────┘
│
└──────► (Loop Back to Main Control Loop)
| Component | Specification |
|---|---|
| Platform | 4-Wheel Differential Drive |
| Chassis | Custom CAD Design (STL mesh) |
| Front Wheels | High-torque motors with encoders |
| Rear Wheels | Castor-type support wheels |
| Sensor | Type | Purpose | Update Rate |
|---|---|---|---|
| Distance Sensor (Front) | Ultrasonic/Infrared | Obstacle detection | 16ms |
| Distance Sensor (Left) | Ultrasonic/Infrared | Side obstacle detection | 16ms |
| Position Encoders | Rotary Encoder | Wheel odometry (4x) | 16ms |
| Gyroscope | 3-axis MEMS | Orientation tracking (yaw) | 16ms |
| Accelerometer | 3-axis MEMS | Motion dynamics | 16ms |
| Camera | RGB Camera | Visual perception (optional) | 16ms |
// Distance Sensor Thresholds
#define obstacleUpperThreshold 0.50 // Maximum detection range (meters)
#define obstacleLowerThreshold 0.0 // Minimum detection range (meters)
// Control Parameters
#define TIME_STEP 16 // Simulation timestep (ms)
#define baseSpeed 8 // Base wheel velocity (rad/s)
#define yawnDrive 20 // Yaw correction gainThe robot implements a hybrid navigation system combining:
- Waypoint-based Path Following - For structured environments
- Reactive Obstacle Avoidance - For dynamic obstacle handling
The robot follows a predefined movement list containing waypoints with associated actions:
std::vector<std::pair<std::string, int>> movementList = {
{"start", 0},
{"forward", 245}, // Move forward until encoder = 245
{"left_bend", 375}, // Gradual left turn
{"left", 0}, // 90° left turn
{"forward", 1555}, // Continue forward
// ... more waypoints
{"stop", 5355} // Final destination
};The heading control uses gyroscope feedback for yaw correction:
Motor_L = baseSpeed + (yawAngle - headingAngle) × yawnDrive
Motor_R = baseSpeed - (yawAngle - headingAngle) × yawnDrive
When an obstacle is detected, the robot executes a semi-circular avoidance maneuver:
Obstacle
●
╱ ╲
╱ ╲
Robot ───► ╱ ╲ ───► Continue Path
╱ ╲
╱ Semi- ╲
╱ circular ╲
╱ path ╲
Algorithm Steps:
- Detection: Front distance sensor detects obstacle within threshold
- Registration: Mark obstacle position (encoder value)
- Avoidance: Execute curved trajectory for predefined distance
- Resume: Return to original path with position compensation
// Avoidance trajectory calculation
setVelocity(
baseSpeed + (yawAngle - headingAngle - progressAngle + π/2) × yawnDrive,
baseSpeed - (yawAngle - headingAngle - progressAngle + π/2) × yawnDrive,
motors...
);Autonomous_Navigation_Webots/
├── 📁 controllers/
│ ├── 📁 Robot_controller/ # Main robot controller
│ │ ├── Robot_controller.cpp # Source code
│ │ ├── Makefile # Build configuration
│ │ └── 📁 build/ # Compiled binaries
│ └── 📁 my_controller/ # Alternative controller
│ ├── my_controller.cpp
│ └── Makefile
│
├── 📁 Finalized_Code_Base/ # Production-ready implementation
│ └── 📁 controllers/Robot_controller/
│
├── 📁 Optimized_Finalized_Codebase/ # Performance-optimized version
│ └── 📁 controllers/Robot_controller/
│
├── 📁 Dynaminc_Obstacle_Avoidance_Moving/ # Dynamic obstacle handling
│ └── 📁 controllers/
│ ├── 📁 Robot_controller/
│ └── 📁 pedestrian/ # Moving obstacle simulation
│
├── 📁 protos/
│ ├── RobotAssembly.proto # Robot PROTO definition
│ └── 📁 RobotAssembly_textures/ # Robot textures
│
├── 📁 worlds/
│ └── robot.wbt # Webots world file
│
├── 📁 libraries/ # Custom libraries
├── 📁 plugins/ # Webots plugins
│ ├── 📁 physics/
│ ├── 📁 remote_controls/
│ └── 📁 robot_windows/
│
├── 📁 docs/ # Documentation
│ └── 📁 images/ # Screenshots and diagrams
│
├── README.md # This file
├── CONTRIBUTING.md # Contribution guidelines
├── LICENSE # MIT License
└── .gitignore # Git ignore rules
- Webots R2023b or later (Download)
- C++ Compiler with C++17 support
- Git for version control
-
Clone the repository
git clone https://github.com/yourusername/Autonomous_Navigation_Webots.git cd Autonomous_Navigation_Webots -
Open in Webots
- Launch Webots R2023b
- File → Open World
- Navigate to
worlds/robot.wbt
-
Build the controller (automatic in Webots)
- Webots automatically compiles C++ controllers
- Or manually:
cd controllers/Robot_controller && make
-
Run the simulation
- Press the Play button (▶) in Webots
- Watch the robot navigate autonomously!
- Open
worlds/robot.wbtin Webots - Press Play to start the simulation
- The robot will:
- Initialize sensors
- Begin autonomous navigation
- Stop at delivery points
- Avoid obstacles dynamically
To switch between controllers, modify the robot's controller field in the world file:
RobotAssembly {
controller "Robot_controller" # Change to desired controller
}
| Controller | Description |
|---|---|
Robot_controller |
Basic navigation |
Finalized_Code_Base |
Production implementation |
Optimized_Finalized_Codebase |
Performance optimized |
Dynaminc_Obstacle_Avoidance_Moving |
Dynamic obstacle support |
Edit these constants in Robot_controller.cpp:
#define TIME_STEP 16 // Simulation timestep (ms)
#define baseSpeed 8 // Base wheel velocity
#define yawnDrive 20 // Heading correction gain
#define obstacleUpperThreshold 0.50 // Obstacle detection range
#define obstaclePathLoss 73 // Position compensation per obstacleModify the movement list for different paths:
std::vector<std::pair<std::string, int>> movementList = {
{"start", 0},
{"forward", 245},
{"left", 0},
// Add your waypoints...
{"stop", FINAL_POSITION}
};Configure delivery stops:
int deliveryLocations[] = {1755, 2575, Destination};- Straight Line Navigation - Following road segments
- Curved Path Following - Smooth bend navigation
- 90° Turns - Sharp corner handling
- Obstacle Avoidance - Dynamic obstacle response
- Delivery Stops - Automated pause at waypoints
Q: What version of Webots is required?
A: This project is developed and tested with Webots R2023b. It should be compatible with R2023a and later versions. Earlier versions may require modifications to the PROTO files.
Q: Can I use this with a real robot?
A: Yes! The control logic is hardware-agnostic. You'll need to:
- Replace Webots API calls with your hardware drivers
- Calibrate sensor thresholds for your specific sensors
- Adjust timing parameters for real-world latency
Q: Why does the robot sometimes drift off course?
A: This can be due to:
- Insufficient yaw correction gain (
yawnDrive) - Gyroscope drift over long runs
- Wheel slip on certain surfaces
Try increasing yawnDrive or implementing gyroscope bias compensation.
Q: How does the position compensation work after obstacle avoidance?
A: Each obstacle triggers a position adjustment:
currentFrontLeftPos = currentFrontLeftPos - obstacleCount * obstaclePathLoss;This accounts for the extra distance traveled during the avoidance maneuver.
Q: Can I add more sensors?
A: Yes! The robot PROTO supports additional sensors. Add them in protos/RobotAssembly.proto and initialize in the controller:
webots::DistanceSensor* newSensor = robot.getDistanceSensor("newSensorName");
newSensor->enable(TIME_STEP);Q: How do I create custom waypoints?
A: Run the simulation in debug mode to observe encoder values, then:
- Note encoder positions at desired waypoints
- Determine turn types (left, right, bend)
- Add entries to
movementList
Q: Controller fails to compile
A: Ensure you have:
- C++17 compatible compiler
- Webots properly installed with environment variables set
- Correct include paths in the Makefile
Q: Robot doesn't move
A: Check:
- Motors are properly named in PROTO
- Position is set to INFINITY for velocity mode
TIME_STEPmatches world'sbasicTimeStep
Q: Sensor returns incorrect values
A: Verify:
- Sensor is enabled with correct timestep
- Sensor name matches PROTO definition
- Wait for first simulation step after enabling
We welcome contributions from the community! Whether it's bug fixes, new features, documentation improvements, or new navigation algorithms, your help is appreciated.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- 🗺️ Implement A* or RRT path planning
- 📷 Add computer vision-based lane detection
- 🔋 Implement battery simulation
- 📡 Add multi-robot coordination
- 📊 Create real-time telemetry dashboard
- 🧪 Add unit tests for navigation functions
See CONTRIBUTING.md for detailed guidelines.
This project is licensed under the MIT License - see the LICENSE file for details.
- Cyberbotics - For the amazing Webots simulator
- Open Source Community - For inspiration and resources
- Contributors - For helping improve this project
For questions, suggestions, or collaboration opportunities:
- Issues: GitHub Issues
- Discussions: GitHub Discussions
⭐ If you find this project useful, please consider giving it a star! ⭐
Made with ❤️ for robotics enthusiasts

