Professional Documents
Culture Documents
Line Tracing Car
Line Tracing Car
Students:
Ganesh S S
Shriram Narayan K
Dinesh Babu V
Teacher:
Hariharan K
ABSTRACT
In this report we discuss about the SMART CAR, which was programmed to
participate in the competition Smart car race. Besides the hardware necessary to
sense, we adopted a speed control and wheel steering methodology based on
the PWM technique, implemented in a microcontroller of the HC12 family. The
Smart car is a car line follower consisting of a microcontroller HCSXTD512, which
is responsible for controlling the car through the interpretation of the signals
received from sensors CNY70, which will track a black line of specified thickness
marked on a white platform. This road must be travelled in the shortest possible
time, in addition to turn and climb certain slopes without violating the rules of
the racing event.
The mechanical design of the smart car is the base for the rules of competition.
Fig. 1. Smart Car Model
Model description
1. Suspension
2. Engine Friction
3. Rear Axle
4. Chassis
5. Mechanism Ackerman
6. Servomotor
7. Front Axle
8. Battery holder
The basic elements that are part of a control system and allow their
manipulation are:
The control system used here is a basic feed-back system. The seven sensor
panel in the front of the car forms the first component of this control circuit. The
input data is the voltage drop across the sensor fed to the ADC. The analog to
digital converter processes each of these analog voltages to 8 bit digital values
so that the programmer can handle the data to his comfort. The controller
further quantises the seven 8 bit values to a single 7 bit data. The data is
compared to a standard look up table of values. A primary decision is taken
based on this 7bit value. A feed-back system stores the decision taken initially.
When the next input arrives the control signal is given from the feed-back loop.
The decision device now takes a decision based on the present input and
previous output.
DECISIO
SENSOR 8 BIT STEERIN
N
INPUT ADC G AND
DEVICE
SPEED
FEEDBAC
K
SYSTEM
CONTROL STRATEGY
The control strategy refers to the nature and direction of the linkages between
the variables measured and/or controlled and control variables. We strictly adopt
a closed loop sytem.
Closed Loop: The control action is calculated based on the measured error
between the controlled variable and the desired set-point. Perturbations, but are
unknown are considered indirectly through its effects on output variables. This
type of control strategy can be applied whatever the controlled variable. The
vast majority of the control systems being developed today are closed loop.
Design Methods
The development and implementation of the software was based on the needs
that were presented, divided by modules, this in order to cope with each of the
needs independently. The following describes each of the modules are the need
and the solution suggested.
The Code
#include <hidef.h>
#include "derivative.h"
/*Function declaration*/
void servomotor(int);
void turnright(void);
void turnleft(void);
void servocentre(void);
void delay(int a);
void dcmotorinit(void);
int readsensors(void);
void servoff(void);
void servoinit(void);
void dcmotorfw(int);
void dcmotoroff(void);
void dcmotorbw(void);
void counterinit(void);
/*Variable declaration*/
int
sensor[7],ppsteervalue=1410,i,sensorleft,j,sensorright,steervalue=1410,psteerv
alue=1410;
int steeringcentre=1410,steeringleft[6],steeringright[6];
int flag1=1,speed=45 ,whiteflag=0, count=0,
speed0,speed1,speed2,speed3,speed4;
int extremeleft,extremeright,mediumleft,mediumright;
void main(void)
{
int temp=0;
steeringleft[0]=steeringcentre-15;
steeringleft[1]=steeringleft[0]-9;
steeringleft[2]=steeringleft[1]-18;
steeringleft[3]=steeringleft[2]-36;
steeringleft[4]=steeringleft[3]-72;
steeringleft[5]=steeringleft[4]-144;
steeringright[0]=steeringcentre+15;
steeringright[1]=steeringright[0]+9;
steeringright[2]=steeringright[1]+18;
steeringright[3]=steeringright[2]+36;
steeringright[4]=steeringright[3]+72;
steeringright[5]=steeringright[4]+144;
extremeleft=steeringcentre-200;
extremeright=steeringcentre+200;
/*medium turns*/
mediumleft=steeringcentre-100;
mediumright=steeringcentre+100;
/*initialisations*/
servoinit();
dcmotorinit();
counterinit();
DDRP_DDRP5=0;
DDRP_DDRP7=0;
PERP_PERP5=1; //Port P Pin 5 & 7 Pullup Enable
PERP_PERP7=1;
DDRT=0xF0; // Setting Port T pin 4,5,6,7 as output
PTT=0x0F; // Turning on all LEDs
delay(1000);
if(PTP_PTP5==0)
{
flag1=0;
delay(1000);
PTT_PTT4=0; //LED 1 On
}
}
delay(2000);
PTT_PTT4=0;
speed=speed+5;
count=count+1;
switch(count)
{
case 1: PTT_PTT5=0;
break;
case 2: PTT_PTT5=1;
PTT_PTT6=0;
break;
case 3: PTT_PTT5=0;
PTT_PTT6=0;
break;
case 4: PTT_PTT5=1;
PTT_PTT6=1;
PTT_PTT7=0;
break;
case 5: PTT_PTT5=0;
PTT_PTT6=1;
PTT_PTT7=0;
break;
case 6: PTT_PTT5=1;
PTT_PTT6=0;
PTT_PTT7=0;
break;
case 7: PTT_PTT5=0;
PTT_PTT6=0;
PTT_PTT7=0;
break;
default: PTT_PTT5=1;
PTT_PTT6=1;
PTT_PTT7=1;
break;
}
}
if(PTP_PTP5==0)
{
flag1=1;
}
}
speed0=speed-(speed/5);
speed1=speed-(speed/8);
speed2=speed+(speed/6);
speed3=speed+(speed/3);
speed4=speed+speed+(speed/2);
delay(2000);
servocentre();
delay(1000);
while(flag1)
{
i=readsensors();
temp=i;
if(temp==127)
servomotor(steervalue);
else if(temp==28|| temp==8)
servocentre();
else if(sensorleft>15)
turnleft();
else if(sensorright<15)
turnright();
else if(i==0)
whiteflag=1;
}
void counterinit(void)
{
void dcmotorinit(void)
delay(40);
DDRE_DDRE2=1; // Port E pin 2 & 3 set to output
DDRE_DDRE3=1;
DDRP_DDRP0=1;
DDRP_DDRP1=1;
PORTE_PE2=0;
PORTE_PE3=1;
PWMDTY0 = 0;
PWMDTY1 = 0;
}
void dcmotorfw(int dutycycle)
{
PWMDTY0 = dutycycle;
PWMDTY1 = 0;
}
void dcmotorbw(void)
{
PWMDTY0 = 0;
PWMDTY1 = 50;
}
void dcmotoroff(void)
{
PWMDTY0 = 0;
PWMDTY1 = 0;
}
void delay(int a)
{
unsigned int i,j;
}
void servomotor(int a)
{
int b=a;
steervalue=a;
PWMDTY3 = b;
PWMDTY2 = b>>8;
if(a<steeringleft[4]||a>steeringright[4] )
if(a==psteervalue && psteervalue==ppsteervalue) {
if(whiteflag==1)
dcmotorfw(speed0);
else
dcmotorfw(speed3);
}
else if(a==psteervalue) {
if(whiteflag==1)
dcmotorfw(speed0);
else
dcmotorfw(speed1);
}
else {
if(whiteflag==1)
dcmotorfw(speed0);
else
dcmotorfw(speed1);
}
else if (a<mediumleft||a>mediumright) {
if(whiteflag==1)
dcmotorfw(speed0);
else
dcmotorfw(speed1);
}
else {
if(whiteflag==1)
dcmotorfw(speed1);
else
dcmotorfw(speed0);
}
psteervalue=steervalue;
ppsteervalue=psteervalue;
psteervalue=a;
whiteflag=0;
// Previous Pulse Widths are recorded
//delay(2);
}
void servoff(void)
{
PWME_PWME2=0; //Stoping PWM
PWME_PWME3=0;
int readsensors(void)
{
int t_hold,sensorinput=0;
sensorright=sensorinput;
return(sensorinput);
}
void servoinit(void)
{
PWMCTL_CON23=1;
}
void turnleft(void)
{
int increment;
switch(sensorleft)
{
case 24:
increment=(steeringleft[0]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 56:
increment=(steeringleft[1]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 48:
increment=(steeringleft[2]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 112:
increment=(steeringleft[3]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 96:
increment=(steeringleft[4]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 64:
increment=(steeringleft[5]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
}
psteervalue=steervalue;
}
void turnright(void)
{
int increment;
switch(sensorright)
{
case 12:
increment=(steeringright[0]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 14:
increment=(steeringright[1]-psteervalue)/8;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 6:
increment=(steeringright[2]-psteervalue)/16;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 2:
case 7:
increment=(steeringright[3]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 3:
increment=(steeringright[4]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
case 1:
increment=(steeringright[5]-psteervalue)/4;
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
servomotor(steervalue+increment);
break;
psteervalue=steervalue;
}
void servocentre(void)
{
if (psteervalue>steeringright[3])
{
sensorleft=48;
turnleft();
}
else if (psteervalue<steeringleft[3])
{
sensorright=6;
turnright();
}
PWMDTY2 = 0x05;
PWMDTY3 = 0x82;
dcmotorfw(speed4);
}
The main description of the parameters of the dimensions of the smart car race
are specified by the rules of competition, so here are the parameters in Table I,
where we can appreciate the reengineered Car Model parameters with the
assembly of all components.
Power Consumption
The line follower consists of basic electrical systems and sensors for control. We
carried out a control system to build the follower system, governed by the HC12
microcontroller that is capable of following the black line inside a white track or
platform.
The sensor has been used for the development of this function has been the
CNY70, which is a reflective infrared sensor type. To form the sensor signals
CNY70 entry have enabled microcontroller ADC module.
• When a sensor detects the white background, the line input of ATD PORT it is
connected goes to 0.
• When a sensor is on the black line, the line input of ATD PORT it is connected
comes a 1.
• The entrance to the servomotor is connected to Microcontroller’s PWM output.
• The output of the servomotor is connected to the vehicle steering system.