Obstacle Avoidance Robot
Obstacle Detection Robot
Project By Siddhanth Ganesan and Iftekhar Choudhury
Purpose
Designed an autonomous robot which when detects any obstacles in its path, would change direction to avoid collision.
Description
The robot is designed to move towards a certain path until it detects an obstacle using the ultrasonic or IR sensors. It swerves away from it and starts moving towards the new obstacle. The EasyVR module is used t give simple voice commands to the robot like forward, backward, left, right etc. The Nokia LCD displays the last voice command executed, two IR sensor readings, forward sonar sensor reading, and speed of motors. To run the motos, dual H-bridge has been used. Separate power source for mbed, sensors, and motors are used in this project.
Equipment
- Mbed NXP LPC1768
- Magician Chassis Robot
- Sharp IR sensor GP2Y0A21YK0F x 2
- H-Bridge md03a x 1
- 130x130 Nokia LCD Display LCD6610
- sonar x 1
- EasyVR Module
- 9V battery x 2
- 1.5V battery x 4
Images
Demo 1
Demo 2
Connections
Nokia LCD connections
MBED | Nokia LCD Display |
---|---|
p8 | cs |
p7 | sck |
p5 | DIO |
p9 | reset |
gnd | gnd |
Vout | 3.3V |
Vout | Vbatt |
Motor connections using Dual H-Bridge
MBED | Dual H-Bridge | Motor(Left) | Motor(Right) | Battery |
---|---|---|---|---|
gnd | gnd | Negative (-) | ||
p21 | 1PWM | |||
p22 | 1INa | |||
p23 | 1INb | |||
p24 | 2INb | |||
p25 | 2INa | |||
p26 | 2PWM | |||
+5V (IN) | Positive (+) | |||
Vin | Positive (+) | |||
OUT 1A | Red Wire | |||
OUT 1B | Black Wire | |||
OUT 2A | Red Wire | |||
OUT 2B | Black Wire |
Sensor connections
MBED | Left IR Sensor | Right IR Sensor | Front Sonar | Battery |
---|---|---|---|---|
p18 | Control | |||
p17 | Control | |||
p20 | Control | |||
gnd | gnd | gnd | gnd | Negative (-) |
Vcc | Vcc | Vcc | Positive (+) |
EasyVR connections
MBED | EasyVR |
---|---|
gnd | gnd (black) |
Vout | Vcc (red) |
p14 | ETX (white) |
p13 | ERX (blue) |
#include "mbed.h" #include "motordriver.h" #include "NokiaLCD.h" #include "HMC6352.h" Serial pc(USBTX, USBRX); AnalogIn sonarf(p20); AnalogIn IRl(p18); AnalogIn IRr(p17); NokiaLCD lcd(p5, p7, p8, p9, NokiaLCD::LCD6610); // mosi, sclk, cs, rst, type Motor left(p26, p25, p24, 1); // pwm, fwd, rev, has brake feature Motor right(p21, p22, p23, 1);// left is right and right is left DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); Serial device(p13, p14); // tx, rx char *str = "Forward"; int loc; float speed; int limit = 280; int lcheck, rcheck; int main() { float distancer, distancel; int distancef; float basel, baser, lvar, rvar; float ls, rs, speed; char rchar=0; //wake up device - needs more work and a timeout device.putc('b'); while (device.getc()!='o') { device.putc('b'); led1 = 1; wait(0.3); } led2=1; while (1) { device.putc('i'); //Start Recognition device.putc('C'); //Use Wordset 2 //Use built-in speaker independent commands while (device.readable()!=0) {} if (device.getc()=='s') { device.putc(' '); rchar=device.getc(); if (rchar=='A') { led1=!led1; ls=0; rs=0.5; left.speed(ls); right.speed(rs); str = "Left"; speed = (ls+rs)/2; lcd.background(0x0000FF); lcd.cls(); lcd.locate(0,1); lcd.printf("Last voice command: %s", str); loc+=3; lcd.locate(0, loc); lcd.printf("Base speed: %f", speed); //implement timer }//left if (rchar=='B') { led2=!led2; ls=0.5; rs=0; left.speed(ls); right.speed(rs); str = "Right"; speed = (ls+rs)/2; lcd.background(0x0000FF); lcd.cls(); lcd.locate(0,1); lcd.printf("Last voice command: %s", str); loc+=3; lcd.locate(0, loc); lcd.printf("Base speed: %f", speed); //implement timer }//right if (rchar=='E') { led3=!led3; basel = 0.3; //Obstacle Avoidance baser = 0.3; left.speed(basel); right.speed(baser); ls=0.3; rs=0.3; while(1) { lcheck=0; rcheck=0; ls=0.3; rs=0.3; distancer = 100*(IRr); distancel = 100*(IRl); if(distancer >= 80 || distancel>=80) { if(distancel<=distancer) { lvar = (80-distancel)/20; ls = 0.3 + lvar/4; rs= 0.3-lvar/4; lcheck=1 ; } if(distancel>=distancer) { rvar = (80-distancer)/20; rs = 0.3 + rvar/4; ls = 0.3-rvar/4; rcheck=1; } } distancef = 10000*sonarf; if(distancef<=limit && distancer >= 80 && distancel>=80) { if(distancel<=distancer) { ls=0.3; rs=-0.3; } else { ls=-0.3; rs=0.3; } } if(distancef<=limit &&distancer>=80) { rs=0.3; ls=0; } if(distancef<=limit &&distancer>=80) { ls=0.3; rs=0; } if(distancef<=limit && distancer <= 60 && distancel<=60) { ls = 0; rs = 0; } left.speed(ls); right.speed(rs); str = "Forward"; loc = 1; speed = (rs +ls)/2; lcd.background(0x0000FF); lcd.cls(); lcd.locate(0,1); lcd.printf("Last voice command: %s", str); loc+=3; lcd.locate(0, loc); lcd.printf("Base speed: %f", speed); loc+=2; lcd.locate(0, loc); lcd.printf("left %f right %f", distancel, distancer); loc+=2; lcd.locate(0, loc); lcd.printf("ultrasound %d ", distancef); wait(0.1); lcd.cls(); } }//fwd if (rchar=='F') { led4=!led4; left.speed(0); right.speed(0); lcd.background(0x0000FF); lcd.cls(); lcd.locate(0,1); lcd.printf("Thank you!"); return 0; }//bckwd } } }
Problems Encountered and Possible Solutions
The initial design included the use of a compass to be mounted high over the robot. This plan failed because the rod would swerve causing the compass values to fluctuate. This would make the robot swerve. Due to time constraint we were unable to implement a compass module to our robot.
The sonars were to be used for obstacle avoidance from the sides but the sonars were inaccurate so they were replaced with sharp distance IR sensors instead.
Future Work
Future work would include implementing the compass module to provide a heading to the robot to control its steering when not avoiding obstacles.
Please log in to post comments.