Autonomous Parallel Parking Vehicle
Autonomous Parallel Parking Vehicle
by David Guigou, Evan Hopf, and Franklin Maxwell
Project Description
This project mimics the process of a two wheel drive automobile parallel parking itself. The vehicle we designed is 15 inches long and the parking space is 21 inches or approximately 1::12 scale model. To make it as realistic as possible the back wheels spin at the same rate using an H-Bridge to regulate two DC motors. The front wheels are connected to a makeshift axle created using K'Nex and are controlled by a Servo motor. To avoid the vehicle crashing into another vehicle or object while auto-parking program is running several sonar sensors are used for object detection. We based our parking algorithm off this link.


Parts Used
Pin Assignments
| mbed | H-Bridge |
|---|---|
| p22 | PWMA |
| p20 | AIN2 |
| p19 | AIN1 |
| Vout | STBY |
| p17 | BIN1 |
| p16 | BIN2 |
| P23 | PWMB |
| 5V | VM |
| Vout | VCC |
| motor 1 | + AO1 |
| motor 1 | - A02 |
| motor 2 | + BO1 |
| motor 2 | - BO2 |
| GND | GND |
| mBed | Servo |
|---|---|
| +5V | Vcc |
| gnd | gnd |
| p24 | Trigger |
| mBed | Bluetooth |
|---|---|
| +5V | Vin |
| gnd | gnd |
| gnd | CTS |
| p14 | TXI |
| p13 | RXI |
| Sonar Connections | mBed (Back Sonar) | mBed (Side Sonar) | mBed (Front Sonar) |
|---|---|---|---|
| Vcc | +5V | +5V | +5V |
| gnd | gnd | gnd | gnd |
| Trigger | p6 | p8 | p10 |
| Echo | p7 | p9 | p11 |
Code
Complete Code for Program
#include "mbed.h"
#include "motordriver.h"
#include "rtos.h"
#include "Speaker.h"
#include "Servo.h"
#include "Ultrasonic.h"
// Initialize bluetooth chip
RawSerial blue(p13,p14);
// Initialize LED's
BusOut myled(LED1,LED2,LED3,LED4);
// Initialize motors (pwm, fwd, rev, can brake)
Motor A(p22, p20, p19, 1); // LEFT working
Motor B(p23, p16, p17, 1); // RIGHT working
// Create Autopilot mode
bool autopilot = 0;
// Initialize servo
Servo myservo(p24);
float pos = 0.52;
float pos2;
//.52 - center
//.77 - right
//.27 - left
// Create variable for start position of servo
float startPos;
// Optional speaker for sound effects
//Speaker mySpeaker(p21);
// Initialize sonar sensors
Ultrasonic sonarBack(p6, p7);//p6 = trigger. p7 = echo
Ultrasonic sonarSide(p8, p9);
Ultrasonic sonarFront(p10, p11);
int cm;
long int count = 0;
void fullRight()
{
while(pos > 0.27) {
pos = pos - 0.05;
myservo = pos;
}//end of while
}//end of full right
void fullLeft()
{
while(pos < 0.77) {
pos = pos + 0.05;
myservo = pos;
}//end of while
}//end of full right
void straight()
{
for (int i=0; i<5; i++) {
pos2 = myservo.read();
if (pos2 <= 0.52) {
pos = pos + 0.05;
myservo = pos;
wait(.1);
pos = pos + 0.05;
myservo = pos;
wait(.1);
pos = pos + 0.05;
myservo = pos;
wait(.1);
pos = 0.52;
myservo = pos;
//myservo = .6;
//wait(.1);
//myservo = 0.52;
} else if (pos2 > 0.52) {
pos = pos - 0.05;
myservo = pos;
wait(.1);
pos = pos - 0.05;
myservo = pos;
wait(.1);
pos = pos - 0.05;
myservo = pos;
wait(.1);
pos = 0.52;
myservo = pos;
//myservo = .44;
//wait(.1);
//myservo = 0.52;
}
}//end of for
pos = 0.52;
} //end of straight
void backward()
{
A.speed(-0.5);
B.speed(-0.5);
}// end backwards
void forward()
{
A.speed(0.5);
B.speed(0.5);
}// end forward
void brake()
{
A.stop(0.5);
B.stop(0.5);
}//end brake
void park()
{
fullRight();
backward();
//sonar info for when to turn left
wait(1.9);//before 1.6
brake();
wait(1);
straight();
wait(1);
while(1) {
cm = sonarBack.read_cm();
if (cm > 15) {
backward();
if (count > 0) {
count = count - 20;
}
} else {
count++;
if (count > 1000) {
brake();
break;
}
}//end of else
}//end of while
count = 0;
fullLeft();
wait(1);
while(1) {
cm = sonarBack.read_cm();
if (cm > 1) {
backward();
if (count > 0) {
count = count - 20;
}
} else {
count++;
if (count > 700000) {
brake();
break;
}
}//end of else
}//end of while
count = 0;
fullRight();
wait(1);
while(1) {
cm = sonarFront.read_cm();
if (cm > 5) {
forward();
if (count > 0) {
count = count - 20;
}
} else {
count++;
if (count > 80000) {
brake();
break;
}
}//end of else
}//end of while
count = 0;
straight();
wait(1);
while(1) {
cm = sonarBack.read_cm();
if (cm > 1) {
backward();
if (count > 0) {
count = count - 20;
}
} else {
count++;
if (count > 700000) {
brake();
break;
}
}//end of else
}//end of while
}//end park
Thread thread1;
int main()
{
myservo = 0.6;
straight();
char bnum=0;
char bhit=0;
while(1) {
if (blue.getc()=='!') {
if (blue.getc()=='B') { //button data packet
bnum = blue.getc(); //button number
bhit = blue.getc(); //1=hit, 0=release
{
myled = bnum - '0'; //current button number will appear on LEDs
if (bnum == '4' && bhit == '1') { //if autopilot button pressed
autopilot = !autopilot;
}
if (autopilot == 1) { //if autopilot on, then go to code for auto parking
//***INSERT CODE FOR AUTOPILOT PARKING HERE***
park();
autopilot = 0;
} else { //if autopilot is turned off, then drive car normally with bluetooth
switch (bnum) {
case '1': //number button 1
if (bhit=='1') {
A.speed(0.7);
B.speed(0.7);
} else {
A.speed(0);
B.speed(0);
}
break;
case '2': //number button 2
if (bhit=='1') {
A.speed(-0.7);
B.speed(-0.7);
} else {
A.speed(0);
B.speed(0);
}
break;
//need to change code to turn left and right
case '5': //button 5 up arrow
if (bhit=='1') {
straight();
/*pos2 = myservo.read();
if (pos2 < 0.52) {
myservo = .6;
wait(.1);
myservo = 0.52;
} else if (pos2 > 0.52) {
myservo = .44;
wait(.1);
myservo = 0.52;
}
pos = 0.52;*/
} else {
//add release code here
}
break;
case '8': //button 8 right arrow
if (bhit=='1') {
if (pos > 0.27) {
pos = pos - 0.05;
myservo = pos;
}
} else {
}
break;
case '7': //button 7 left arrow
if (bhit=='1') {
// for (int i=0, i<10, i++0
if (pos < 0.77) {
pos = pos + 0.05;
myservo = pos;
}
} else {
}
break;
default:
break;
}
}
}//end of if autopilot == true
}
}
}//end of while(1)
}//end of main
Videos
Demo
Steering System Design
Future Work
- Improve front steering system for reliability
- Hack an RC and make it autonomously park
- LIDAR Sensors instead of Sonar
Please log in to post comments.
