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

