Skip to content

SeaBoiii/MDP_Arduino

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MDP Arduino Robot Controller

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.

Project Overview

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.

Key Features

  • 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

Hardware Requirements

Main Components

  • 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)

Pin Configuration

  • 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)

Software Requirements

Arduino Libraries

  • DualVNH5019MotorShield - Motor driver control
  • EnableInterrupt - Interrupt handling for encoders
  • PID - PID control implementation
  • SharpIR - IR sensor readings

Additional Tools

  • Arduino IDE (version 1.8.x or higher recommended)
  • MATLAB (for PID tuning calculations) - optional

Project Structure

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

Installation & Setup

1. Clone the Repository

git clone https://github.com/SeaBoiii/MDP_Arduino.git
cd MDP_Arduino

2. Install Arduino Libraries

  1. Open Arduino IDE
  2. Install the following libraries via Library Manager:
    • EnableInterrupt
    • (Other libraries are included in the repository)

3. Hardware Setup

  1. Connect the Dual VNH5019 Motor Shield to your Arduino
  2. Wire the motors to the motor shield outputs
  3. Connect IR sensors to analog pins A0-A5
  4. Connect motor encoders to interrupt-capable pins
  5. Ensure proper power supply for motors

4. Upload the Code

  1. Open Main/Main.ino in Arduino IDE
  2. Select your Arduino board and port
  3. Verify and upload the sketch

Configuration

PID Tuning

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.

Sensor Calibration

Run the calibration routine on first setup:

sensor.caliSensor();  // Calibrates IR sensor readings
movement.calibrate(numIterations, md);  // Calibrates movement distances

Usage

Basic Movement Commands

The 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);

Serial Communication

The robot listens for commands over serial connection. Refer to the communication protocol in the code comments.

Development Notes

  • 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

Contributors

CZ3004 MDP Group 20 (2020)

License

This project is part of an academic course at NTU. Please respect academic integrity policies if you're a current student.

Acknowledgments

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

About

2020 MDP Arduino

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 77.3%
  • C 22.2%
  • Assembly 0.5%