A Python implementation of wall-following algorithms for the Pioneer P3DX robot in the V-REP (CoppeliaSim) simulation environment, featuring PID control for smooth navigation.
This project implements various wall-following algorithms for autonomous robot navigation in the V-REP (now known as CoppeliaSim) simulation environment. The primary focus is on a PID (Proportional-Integral-Derivative) controller that enables a Pioneer P3DX robot to follow walls smoothly while maintaining a safe distance.
The implementation includes several wall-following methods:
- PID control-based wall following
- Minimum sensor reading-based wall following
- Multi-sensor weighted approach
- Python 3.x
- V-REP/CoppeliaSim (Educational or Pro version)
- V-REP Python API (included with V-REP installation)
- Python packages:
- numpy
- math
- logging
- Multiple Wall-Following Algorithms:
- PID controller with tunable parameters
- Minimum sensor reading approach
- Multi-sensor weighted approach
- Comprehensive Sensor Integration:
- Ultrasonic proximity sensors
- Compass for orientation
- Odometry for distance tracking
- Data Logging and Analysis:
- Detailed logging of robot state
- CSV output for position, motor velocity, and error history
- Performance statistics (distance traveled, average speed, etc.)
- Configurable Scenarios:
- Customizable robot tasks (turn, move, wall follow)
- Adjustable parameters (minimum distance, maximum distance, velocity)
- Install V-REP/CoppeliaSim and ensure the Python API is properly configured
- Clone this repository to your local machine
- Create
logs
andoutput
directories in the project root:mkdir logs output
- Open V-REP/CoppeliaSim and load a scene with the Pioneer P3DX robot
- Start V-REP/CoppeliaSim and load a scene with the Pioneer P3DX robot
- Run the scenario script:
python scenario.py
- The robot will execute the defined tasks:
- Turn to a specified orientation
- Move in a straight line until near a wall
- Follow the wall perimeter for one complete loop
- Stop
The project is organized into several Python modules:
- scenario.py: Main entry point that defines the robot's tasks and parameters
- controller.py: Manages the connection to V-REP and executes the control loop
- robots.py: Implements the Pioneer P3DX robot with various movement methods
- sensors.py: Provides classes for proximity sensors and compass
- helper.py: Contains utility functions for V-REP interaction
- logger.py: Handles logging of robot state and events
The main control loop follows a sense-think-act paradigm:
- Sense: Update robot state (position, proximity, compass, odometry)
- Think: Process sensor data and determine appropriate action
- Act: Execute movement commands based on the current task
The PID wall-following algorithm uses:
- Proportional (P): Responds to the current error (distance from wall)
- Integral (I): Accounts for accumulated error over time
- Derivative (D): Responds to the rate of change of error
Default PID parameters:
- kp: 7.29
- ki: 0.0
- kd: -7.0
The simulation generates several CSV files in the output
directory:
- abs_pos_all.csv: Absolute position of the robot throughout the simulation
- motor_all_v: Motor velocity data
- error_history: PID controller error history
This project is licensed under the MIT License - see the LICENSE file for details.