Skip to content

Autonomous mobile robot navigation simulation using Webots R2023b. Features sensor fusion, dynamic obstacle avoidance, and delivery automation.

License

Notifications You must be signed in to change notification settings

ThulzDin/Autonomous_Navigation_Webots

Repository files navigation

🤖 Autonomous Navigation Robot - Webots Simulation

License: MIT Webots C++ Contributions Welcome

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.

Robot Simulation


📋 Table of Contents


✨ Features

  • 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

🏗️ System Architecture

Block Diagram

┌─────────────────────────────────────────────────────────────────────────────────┐
│                           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│ │    │                  │    │                         │    │
│  │ └─────────────┘ │    │                  │    │                         │    │
│  └─────────────────┘    └──────────────────┘    └─────────────────────────┘    │
│                                                                                 │
└─────────────────────────────────────────────────────────────────────────────────┘

Control Flow Diagram

                            ┌──────────────┐
                            │    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)

🔧 Hardware & Sensors

Robot Configuration

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 Suite

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

Sensor Specifications

// 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 gain

🧠 Navigation Algorithm

Overview

The robot implements a hybrid navigation system combining:

  1. Waypoint-based Path Following - For structured environments
  2. Reactive Obstacle Avoidance - For dynamic obstacle handling

Path Following Algorithm

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
};

Heading Control (PID-inspired)

The heading control uses gyroscope feedback for yaw correction:

Motor_L = baseSpeed + (yawAngle - headingAngle) × yawnDrive
Motor_R = baseSpeed - (yawAngle - headingAngle) × yawnDrive

Obstacle Avoidance Strategy

When an obstacle is detected, the robot executes a semi-circular avoidance maneuver:

                    Obstacle
                       ●
                      ╱ ╲
                     ╱   ╲
        Robot ───►  ╱     ╲  ───► Continue Path
                   ╱       ╲
                  ╱ Semi-   ╲
                 ╱ circular  ╲
                ╱   path      ╲

Algorithm Steps:

  1. Detection: Front distance sensor detects obstacle within threshold
  2. Registration: Mark obstacle position (encoder value)
  3. Avoidance: Execute curved trajectory for predefined distance
  4. 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...
);

📁 Project Structure

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

🚀 Installation

Prerequisites

  • Webots R2023b or later (Download)
  • C++ Compiler with C++17 support
  • Git for version control

Setup Steps

  1. Clone the repository

    git clone https://github.com/yourusername/Autonomous_Navigation_Webots.git
    cd Autonomous_Navigation_Webots
  2. Open in Webots

    • Launch Webots R2023b
    • File → Open World
    • Navigate to worlds/robot.wbt
  3. Build the controller (automatic in Webots)

    • Webots automatically compiles C++ controllers
    • Or manually: cd controllers/Robot_controller && make
  4. Run the simulation

    • Press the Play button (▶) in Webots
    • Watch the robot navigate autonomously!

💻 Usage

Basic Operation

  1. Open worlds/robot.wbt in Webots
  2. Press Play to start the simulation
  3. The robot will:
    • Initialize sensors
    • Begin autonomous navigation
    • Stop at delivery points
    • Avoid obstacles dynamically

Controller Selection

To switch between controllers, modify the robot's controller field in the world file:

RobotAssembly {
  controller "Robot_controller"  # Change to desired controller
}

Available Controllers

Controller Description
Robot_controller Basic navigation
Finalized_Code_Base Production implementation
Optimized_Finalized_Codebase Performance optimized
Dynaminc_Obstacle_Avoidance_Moving Dynamic obstacle support

⚙️ Configuration

Tunable Parameters

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 obstacle

Waypoint Configuration

Modify 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}
};

Delivery Locations

Configure delivery stops:

int deliveryLocations[] = {1755, 2575, Destination};

🎬 Demo

Simulation Preview

Navigation Demo

Key Demonstrations

  1. Straight Line Navigation - Following road segments
  2. Curved Path Following - Smooth bend navigation
  3. 90° Turns - Sharp corner handling
  4. Obstacle Avoidance - Dynamic obstacle response
  5. Delivery Stops - Automated pause at waypoints

❓ Frequently Asked Questions

General Questions

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:

  1. Replace Webots API calls with your hardware drivers
  2. Calibrate sensor thresholds for your specific sensors
  3. 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.

Technical Questions

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:

  1. Note encoder positions at desired waypoints
  2. Determine turn types (left, right, bend)
  3. Add entries to movementList

Troubleshooting

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:

  1. Motors are properly named in PROTO
  2. Position is set to INFINITY for velocity mode
  3. TIME_STEP matches world's basicTimeStep
Q: Sensor returns incorrect values

A: Verify:

  1. Sensor is enabled with correct timestep
  2. Sensor name matches PROTO definition
  3. Wait for first simulation step after enabling

🤝 Contributing

We welcome contributions from the community! Whether it's bug fixes, new features, documentation improvements, or new navigation algorithms, your help is appreciated.

How to Contribute

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Contribution Ideas

  • 🗺️ 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.


📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments

  • Cyberbotics - For the amazing Webots simulator
  • Open Source Community - For inspiration and resources
  • Contributors - For helping improve this project

📬 Contact

For questions, suggestions, or collaboration opportunities:


⭐ If you find this project useful, please consider giving it a star! ⭐

Made with ❤️ for robotics enthusiasts

About

Autonomous mobile robot navigation simulation using Webots R2023b. Features sensor fusion, dynamic obstacle avoidance, and delivery automation.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published