You are on page 1of 13

15th

Nov
2011

Self-parking Robot
Embedded Hardware Design



Shreya Agrawal - 200901090
Siddharth Jain - 200901070

Contents
Objective ................................................................................................................................................. 3
Components ............................................................................................................................................ 4
Motor Controlled Car .......................................................................................................................... 4
H-Bridge (L293D) ................................................................................................................................. 4
Distance Sensor ................................................................................................................................... 4
Microcontroller (ATMEGA32) Board ................................................................................................... 5
Constant Voltage Source ..................................................................................................................... 5
Architecture ............................................................................................................................................ 6
Strategy ................................................................................................................................................... 7
FLOWCHART: ....................................................................................................................................... 7
Code ........................................................................................................................................................ 9
Conclusion ............................................................................................................................................. 15
Acknowledgement ................................................................................................................................ 15

Objective
The objective of this project is to build a self-parking car which can identify a parking space
and carry out parallel parking next to the last detected obstruction.
It uses distance sensors, to detect the parking space, checks to see whether the space is
large enough and manoeuvres itself automatically in the space to park next to the last
successfully detected project. It uses information from the distance sensors about the
distance from the other objects in the way and directs the information to the
microcontroller which in turn runs the motors of the vehicle. The distance sensor is placed
to the left side of the robot to detect parking space on that side.

Components
The hardware consists of four main components:
x
x
x
x

Motor controlled car


H-Bridge
Distance Sensor
ATMEGA 32

Motor Controlled Car


These motors are connected by a simple DC input. A positive input turns the front wheels
forward. As soon as power supply was given directly to the motors of the car the, the car
works perfectly as it is supposed to do.

H-Bridge (L293D)
The motor driver chip(L293D) is a monolithic integrated high voltage, high current four
channel driver designed to accept standard DTL or TTL logic levels and drive inductive loads
such as relays solenoids, DC and stepping motors. This single chip is used to drive both the
motors.
The H-bridge is used to control the two motors, connected to the left and right wheel, of the
robot. Two outputs from the microcontroller need to be given as inputs for each wheel.
Following are the port configurations for input :
Pin
In1(left wheel)
In2(left wheel)
In3(right wheel)
In4(right wheel)
ENABLE1 and ENABLE2

Connected to
PD7
PD6
PD5
PD4
PB3

Pin 4, 5, 12, and 13 are ground while pin 8 and 16 (V ss) are given 5V input from the
microcontroller.

Distance Sensor
Sharp GP2Y0A21YK is an analog distance sensor that uses infrared to detect an object
between cm and 80 cm away. The GP2Y0A21YK provides a non-linear voltage output in
relation to the distance an object is from the sensor and interfaces easily using any analog
to digital converter. It is shown below. The graph shown below provides the relationship
between analog output voltages of sensor Vs Distance to reflective object.


We have used a sensor with a larger range for the side so that we could easily detect a
parking space. The challenge with using these sensors is that their voltage output is non-
linear and since there maybe unwanted objects in the way we are unable to get a stable
reading for a particular distance. Therefore we plotted an analog to digital conversion of the
most probable values.
Distance (cm)
4
6
8
10
12
14
16

Sensor Output (V)


3.02
2.6
2.06
1.54
1.22
1.03
0.87

Microcontroller (ATMEGA32) Board


Atmel's AVR microcontrollers have a RISC core running single cycle instructions and a well-
defined I/O structure that limits the need for external components. Internal oscillators,
timers, UART, SPI, pull-up resistors, pulse width modulation, ADC, analog comparator and
watch-dog timers are some of the features you will find in AVR devices. AVR instructions are
tuned to decrease the size of the program whether the code is written in C or Assembly.
With onchip in-system programmable Flash and EEPROM, the AVR is a perfect choice in
order to optimize cost and get product to the market quickly.

Constant Voltage Source


Either a rechargeable battery could be used or a constant voltage could be taken for here.

Architecture


Distance
Sensor

ATMEGA 32
Microcontroller
er

Motor Driver
Chip (L293D)

Motors (Left
and Right)

The output of the distance sensor is given to ADC channel 7 which is PA7 of the
microcontroller. ADC of the microcontroller converts the analog signal received to digital
DWd
motor driver gives input to the motors from pins 3, 6, 11 and 14 of the chip.

Strategy
Pulse Width Modulation (PWM) of Timer0 of ATMEGA32 has been used to give enable to
the L293D chip. This helps us in controlling the speed of the robot.

Left Motor
1
0
0
1
0
0
0

Forward
Backward
Left forward
Right forward
Left Backward
Right Backward
Stop

Right Motor
1
0
1
0
0
0
0

0
1
0
0
0
1
0

0
1
0
0
1
0
0

FLOWCHART:

Variable Count: It is a counter which is initially set to 0 and starts incrementing when the
robot senses a gap.
Variable b : It has a value of 0 when the distance sensor detects that the nearest object is
at a distance of less than 10cm.

START

Distance
Sensor Input

Forward
No

Forward

If b=1

No

Yes

Count =
count + 1

If
count
>15

Yes


STOP

Park car

Park Car Method:


This function is called when the robot detects sufficient parking space for it to park. Since
the object is at this time positioned ahead of the parking space, it first moves backward for a
few counts and then stops. The robot then makes a left backward turn, about 90 o so that it
is aligned parallel to the parking space. Once it is aligned properly it again moves backward
for a few counts till it is correctly parked in the space.

# include
# include
# include
# include

<avr / io.h>
<util / delay.h>
<avr / interrupt.h>
<inttypes.h>

# define ADC 2
void
void
void
void
void
void
void
void
{

stop();
left_forward();
right_forward();
left_backward();
right_backward();
forward();
backward();
wait()
int i;
for(i=0;i<2;i++)
_delay_ms(150);

}
void pwm(int duty)
{
OCR0=duty;//output on PB3;
}
void initADC()
{
ADMUX=(1<<REFS0)|(0<<ADLAR);// For Aref=AVcc;
ADCSRA=(1<<ADEN)|(7<<ADPS0); //division factor 128
}
int ReadADC(int count)
{
//Select ADC Channel ch must be 0-7
ADMUX|=0x07;
//Start Single conversion
ADCSRA|=(1<<ADSC);
//Wait for conversion to complete
while(!(ADCSRA & (1<<ADIF)));
int a=ADCW;
//Clear ADIF by writing one to it
ADCSRA|=(1<<ADIF);
int b;
int backcnt;

if(a<((1023*2)/5)) {
b=1;
count++;
if(count>15)
{
backcnt=4;
stop();
wait();
backward();
while(backcnt>=0)
{
wait();
backcnt--;
}
backcnt=5;
stop();
wait();
left_backward();
while(backcnt>=0)
{
wait();
backcnt--;
}
stop();
wait();
backcnt=2;
backward();
while(backcnt>=0)
{
wait();
backcnt--;
}
stop();
wait();
count=100;
}

else {
forward();
wait();
}
}
else {
forward();
wait();
2

b = 0;
}
return count;
}
int main()
{
int count=0;
DDRC=0xff;
PORTC=0x00;
MCUCSR |= (1<<JTD);
TCCR0=0x6A;
TCNT0=0;
DDRB=0x08;//0b00001000
DDRD = 0xff;
PORTD = 0xff;
initADC();
while(1)
{
count = ReadADC(count);
if(count==100)
break;
}
}
void forward()
{
pwm(80);
PORTD = 0b01010000;
}
void backward()
{
pwm(80);
PORTD = 0b10100000;
}
void left_forward()
{
pwm(80);
PORTD = 0b01000000;
}
void left_backward()
3

{
pwm(80);
PORTD = 0b10000000;
}
void right_forward()
{
pwm(80);
PORTD = 0b00010000;
}
void right_backward()
{
pwm(80);
PORTD = 0b00100000;
}
void stop()
{
pwm(0);
PORTD = 0x00;
}

Conclusion
We have been thus able to make an autonomous car which can detect the parking space
and parallel park itself. We were not able to make the parking possible for different possible
direction. But to do this we have to properly calibrate the sensors so that we can have
accurate reading and also get better results. We were able to use the H-bridge to drive the
motor efficiently, varying its speed using different PWMs.
To calibrate the RC-car more efficiently, more states can be defined to control the motion of
the RC-car in different directions using more sensors. We must also ensure steady current
flow in the motors.
We would like to further work on the RC-car, by adding wireless features to park and un-
park the car, and also make the car optimal for different parking directions.

Acknowledgement
We would like to thank Prof. Prabhat Ranjan and Prof. Rahul Dubey for their guidance in the
course Embedded Hardware Design. We would also like to thank the Teaching assistants
and the lab assistants for helping us whenever it was required. The following students
deserve a special mention, Parth Mehta, Nikhil Marathe, Maullik Padia and Pavas Kant from
the B.Tech 2008 batch, for their support and guidance throughout.

You might also like