Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 15

THIAGARAJAR COLLEGE OF ENGINEERING

Smart Car Race


September 27-29, 2010

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.

DESCRIPTION OF MECHANICAL DESIGN OF CAR MODEL

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

DESCRIPTION OF CONTROL CIRCUIT DESIGN


A dynamic system can be defined conceptually as an entity that receives some
external actions or input variables, and whose answer to these external actions
are called output variables. Actions outside the system are divided into two
groups, control variables, which can be manipulated, and disturbance on which it
is not possible any control. Within systems is the concept of control system.

A control system is a type of system that is characterized by the presence of a


number of elements which allow influencing the operation of the system. The
purpose of a control system is achieved, by manipulating the control variables, a
domain on the output variables, so they reach predetermined values (slogan). An
ideal control system should be able to achieve its goal to satisfy the following
requirements:

• Ensuring stability and, particularly, be robust against disturbances and errors in


the models.
• Be as efficient as possible, according to a predetermined criterion. Usually this
criterion is that the control action on the input variables is achievable, avoiding
abrupt and unrealistic behaviour.
• Be easily implemented and convenient to operate in real time using a
computer.

The basic elements that are part of a control system and allow their
manipulation are:

• Sensors. Senses the presence of black line


• Controller. Using the values measured by sensors quantisation is performed to
modify the control variables based on environment specific strategies.
• Actuator. It is the mechanism that performs the action calculated by the
controller and modifying the control variables. The primary actions are steering
and acceleration.

CONTROL SYSTEM USED IN THE SMART CAR

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 methods of systems analysis and design of controllers have evolved


the same way that most of the tools used in engineering. The evolution in
computer systems has enabled environments currently available that can
perform dynamic simulations such as CodeWarrior. That is why in recent
years, these advances have enabled research and applications in
automatic control theory are gone from using an implementation mono
variable analog and digital implementation of a multivariable. In an analog
scheme, all variables are functions of a continuous time, whereas in a
digital pattern variables are known at some instant, in a discrete time.

Digital control systems have a number of advantages such as lower


susceptibility to deterioration due to the passage of time or environmental
factors, presents some components less sensitive to noise or vibration
signals have greater flexibility when program, or have better sensitivity to
parameter variation. In contrast, the evolution of computers and
computing capabilities to reduce the disadvantages of digital controllers,
so its use has recently spread in large amounts. The variables measured
in the system via the sensors reach the controller in analog form, so that
in the case of a digital controller is necessary to use two signal converters,
one analog-digital, which allows the signal to discretize the controller can
perform necessary calculations, and a digital-analog conversion of the
control commands calculated by the controller in continuous signals, so
that the actuators can execute the necessary changes.

DESCRIPTION OF CONTROL SOFTWARE DESIGN

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

Controller specific header files are declared.

/*Header file declaration*/

#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;

/*servo pulse width settings*/


/*calculating left values*/

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;

/*calculating right values*/

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;

/*extreme turns values*/

extremeleft=steeringcentre-200;
extremeright=steeringcentre+200;

/*medium turns*/

mediumleft=steeringcentre-100;
mediumright=steeringcentre+100;

/*initialisations*/

servoinit();
dcmotorinit();
counterinit();

/*Port P Pin 5 & 7 used for setting speed level*/

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

PTT=0xFF; //Turning Off all LEDs


while(flag1==1) //USING PORT PIN 5 TO START SET SPEED
{

if(PTP_PTP5==0)
{

flag1=0;
delay(1000);
PTT_PTT4=0; //LED 1 On

}
}

delay(2000);
PTT_PTT4=0;

while(flag1==0) //USING PORT PIN 7 TO SET SPEED


{
if(PTP_PTP7==0)
{
delay(2000);

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;

/*Primary decision based on sensor input*/

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

PBCTL_PBEN=1; //pulse counter initialisation


TCTL4_EDG0B=1;
TCTL4_EDG0A=0;
DLYCT_DLY0=1;
DLYCT_DLY1=1;
PACN10=0;
}

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;

PWMPOL_PPOL0=1; //PWM pulse High at beginning of Period


PWMPOL_PPOL1=1; //PWM pulse High at beginning of Period

PWMCLK_PCLK0=1; // clock SA as clock source for PWM


PWMCLK_PCLK1=1; // clock SB as clock source for PWM

PWMPRCLK =0x00; //clock A = 2MHz clockB = 2MHz

PWMSCLA =1; //clock SA = clock A / (2 * 5) = 200KHz


PWMSCLB =1; //clock SB = clock B / (2 * 5) = 200KHz

PWMPER0 = 200; // PWM Period 1KHz


PWMPER1 = 200; // PWM Period 1KHz

PWMDTY0 = 0;
PWMDTY1 = 0;

PWME_PWME0=1; //PWM channel 0 Enable


PWME_PWME1=1; //PWM channel 1 Enable

}
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;

for(j=1;j<=a;j++) //Delay to allow the processor do its job


for(i=0;i<=100;i++);

}
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;

ATD0CTL1=0x87; // no external trigger


ATD0CTL2_ADPU=1; // ATD Enable
ATD0CTL2_ETRIGE=0; // no external trigger
ATD0CTL3_S8C=1; // 8 adc channels sequence
ATD0CTL4_SRES8=1; // 8-bit Resolution
ATD0CTL5=0x10; // multisequence
delay(5);

if(ATD0DR6H > 12) //thresholding sensor inputs


sensorinput=sensorinput|1;

if(ATD0DR5H > 14)


sensorinput=sensorinput|2;

if(ATD0DR4H > 14)


sensorinput=sensorinput|4;

if(ATD0DR3H > 14)


sensorinput=sensorinput|8;

sensorright=sensorinput;

if(ATD0DR2H > 15)


sensorinput=sensorinput|16;

if(ATD0DR1H > 12)


sensorinput=sensorinput|32;

if(ATD0DR0H > 14)


sensorinput=sensorinput|64;

sensorleft=sensorinput&120; //masking lower 3 bits

sensor[0]= ATD0DR0H; //getting sensor values for manual


calibration
sensor[1]= ATD0DR1H;
sensor[2]= ATD0DR2H;
sensor[3]= ATD0DR3H;
sensor[4]= ATD0DR4H;
sensor[5]= ATD0DR5H;
sensor[6]= ATD0DR6H;

return(sensorinput);
}

void servoinit(void)
{

PWMCTL_CON23=1;

PWME_PWME2=1; //PWM channel 2 Enable


PWME_PWME3=1; //PWM channel 3 Enable

PWMPOL_PPOL2=1; //PWM pulse High at beginning of Period


PWMPOL_PPOL3=1; //PWM pulse High at beginning of Period

PWMCLK_PCLK2=1; // clock SA as clock source for PWM


PWMCLK_PCLK3=1; // clock SB as clock source for PWM

PWMPRCLK =0x00; //clock A = 2MHz clockB = 2MHz

PWMSCLA =1; //clock SA = clock A / (2 * 100) = 10KHz


PWMSCLB =1; //clock SB = clock B / (2 * 100) = 10KHz

PWMPER2 = 0x4E; // PWM Period 20ms 50Hz


PWMPER3 = 0x20; // PWM Period 20ms 50Hz

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

DESCRIPTIONS OF KEY TECHNICAL PARAMETERS OF


CAR MODELS
The main descriptions of the parameters of the smart car are as follows;
Total Weight And Dimensions (Length And Width) Of The
Reengineered Car Model

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.

Total Weight Dimensions: Load 870gr 31.2cm X 17cm x 11cm

Power Consumption

• Voltage ENTRY 7.1 Volts


• Output voltage setting 5 Volts
• Power generated by the batteries 7.12 Volts
• Amps Current consumption 0.43
• Power consumed by the engine 3.05 Watts
• Sensor 260mA
• Microcontroller 50mA
• Power module 10mA
• Servomotor 110mA
• Motor 980mA

Count And Type Of Sensors Used

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.

You might also like