This repository contains the Arduino-based robot controller for the CZ3004 Multidisciplinary Design Project (MDP) from 2020, Group 20. The project implements an autonomous robot capable of navigating a maze environment using sensor feedback and PID-controlled motor movement.
The MDP robot is designed to navigate a grid-based arena autonomously. It uses infrared sensors for obstacle detection and distance measurement, PID control for precise motor movement, and serial communication for interfacing with higher-level control systems.
- PID Motor Control: Dual motor control with independent PID tuning for precise movement
- Sensor Integration: 6 infrared sensors for obstacle detection and distance measurement
- Movement Functions:
- Forward movement with grid-based positioning
- Left and right turns with adjustable angles
- Wall-hugging navigation for exploration
- Communication: Serial communication protocol for command execution
- Calibration Tools: Built-in sensor and movement calibration routines
- Microcontroller: Arduino (compatible board with sufficient I/O pins)
- Motor Driver: Dual VNH5019 Motor Shield
- Motors: 2x DC motors with encoders
- Sensors: 6x Sharp IR distance sensors
- Power: Battery pack (voltage specifications in code comments)
- Motor Pins:
- Left Motor: EN A1 (Pin 3), EN B1 (Pin 5)
- Right Motor: EN A2 (Pin 11), EN B2 (Pin 13)
- Sensor Pins: A0-A5 (6 analog pins for IR sensors)
DualVNH5019MotorShield- Motor driver controlEnableInterrupt- Interrupt handling for encodersPID- PID control implementationSharpIR- IR sensor readings
- Arduino IDE (version 1.8.x or higher recommended)
- MATLAB (for PID tuning calculations) - optional
MDP_Arduino/
├── Aleem Arduino/ # Development and testing code
│ ├── PID-Motor/ # Motor control tests
│ ├── Sensor/ # Sensor reading tests
│ └── libraries/ # Additional libraries
├── Arduino Code/ # Complete implementation (legacy)
│ ├── Main.ino # Main Arduino sketch
│ ├── Movement.cpp/h # Movement control functions
│ ├── Sensor.cpp/h # Sensor reading functions
│ ├── PID.cpp/h # PID controller implementation
│ └── SharpIR.cpp/h # IR sensor library
├── Main/ # Main production code
│ ├── Main.ino # Main Arduino sketch
│ ├── Movement.cpp/h # Movement control functions
│ └── Sensor.cpp/h # Sensor reading functions
└── Matlab/ # PID tuning scripts
└── matlabscript # RPM vs Speed analysis and PID calculation
git clone https://github.com/SeaBoiii/MDP_Arduino.git
cd MDP_Arduino- Open Arduino IDE
- Install the following libraries via Library Manager:
- EnableInterrupt
- (Other libraries are included in the repository)
- Connect the Dual VNH5019 Motor Shield to your Arduino
- Wire the motors to the motor shield outputs
- Connect IR sensors to analog pins A0-A5
- Connect motor encoders to interrupt-capable pins
- Ensure proper power supply for motors
- Open
Main/Main.inoin Arduino IDE - Select your Arduino board and port
- Verify and upload the sketch
The PID constants are defined in Main.ino and should be tuned for your specific hardware:
// Left motor PID constants
float lkP = 1.3688; // Proportional gain
float lkI = 0; // Integral gain
float lkD = 0.0517 * lkP; // Derivative gain
// Right motor PID constants
float rkP = 1.2444;
float rkI = 0;
float rkD = 0.0507 * rkP;Use the MATLAB script in the Matlab/ directory to calculate optimal PID values based on your motor characteristics.
Run the calibration routine on first setup:
sensor.caliSensor(); // Calibrates IR sensor readings
movement.calibrate(numIterations, md); // Calibrates movement distancesThe robot can be controlled via serial commands or programmatically:
// Move forward N grids
movement.moveForward(setLSpeed, setRSpeed, md, pid, gridNum, sensor);
// Turn left 90 degrees
movement.moveLeft(setLSpeed, setRSpeed, md, pid, 90, sensor, cal);
// Turn right 90 degrees
movement.moveRight(setLSpeed, setRSpeed, md, pid, 90, sensor, cal);
// Wall hugging mode
movement.wallHugging(setLSpeed, setRSpeed, md, pid, sensor);The robot listens for commands over serial connection. Refer to the communication protocol in the code comments.
- Battery voltage affects motor performance; PID values may need adjustment for different battery levels
- Sensor readings should be calibrated for the specific arena lighting conditions
- The encoder tick calculations are tuned for specific wheel and motor configurations
- Multiple sets of PID values are preserved in comments for reference with different battery packs
CZ3004 MDP Group 20 (2020)
This project is part of an academic course at NTU. Please respect academic integrity policies if you're a current student.
- Nanyang Technological University
- CZ3004 Multidisciplinary Design Project Course
- Pololu for the Dual VNH5019 Motor Shield
For questions or issues, please open an issue on the GitHub repository.