Вы находитесь на странице: 1из 19

Course No : EEE 310

Course Name: Communication Laboratory

Submitted To:
Md. Hadiur Rahman Khan
Lecturer, EEE Department
BUET

Project Name : gps

guided

car

Date of Submission : 04/06/2016

Student ID: 1206017-24


Group NO : #03

Abstract:
The future of transport is self-driving cars. Advances in the use of GPS mean that
the technology could not only emerge in the next few years, but is already being
road tested by companies such as Google. There will come a time when you go
down the highway and you don't have to have your hand on the steering wheel at
all. It'll be a combination of GPS, radar and other sensors. GPS also has massive
implications in military intelligence.
What we have tried to show in our experiment is a basic version of the paradigm
shifting technological advancement that will have unnerving implications in
driving safety and comfort. While driving on low traffic roads we might not have
to touch our steering wheels at all. We have used a combination of a GPS module,
accelerometer and processing via Arduino Mega to guide the drive of the car.

Component List
1. Arduino Mega
2. GPS module
3. 6-axis Accelerometer
4. LCD display
5. DC Motor
6. Arduino Shield
7. 3 cell Lithium-Polymer battery
Some components of the experiment which deserve special
mention are:

Arduino Mega :

The Mega 2560 is a microcontroller board based on the ATmega2560.We used


this as the processing unit of the car.It has 54 digital input/output pins (of which
15 can be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial
ports), a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP
header, and a reset button.

GPS Module : ( GY-GPS 6Mv2)

This GPS is a very capable GPS for the price and size. Compatible with UART
capable devices including Arduino, Raspberry Pi, and MSP430. We have a
customized and tested Arduino library for this GPS module

6-axis Accelerometer (MPU 6050)

The MPU-6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer


on the same silicon die, together with an onboard Digital Motion Processor
(DMP), which processes complex 6-axis MotionFusion algorithms. The device
can access external magnetometers or other sensors through an auxiliary
master IC bus, allowing the devices to gather a full set of sensor data without
intervention from the system processor.

Adruino Shield :
We have designed a custom Arduino shield which contains on board motor
driver using L293D IC , an onboard buck module. This also contains a full
interfacing media with 16X2 LCD display .

Working principle

GPS Module

Error Calculation
and further
movement

Satellite

Movement using PID


control

Position Mapping and


Accelerometer Data

Arduino Mega
processor

When the GPS module is powered up , it sends signals to a number of


satellites in close proximity. After receiving data of its positions from
several satellites it determines its precise location and it automatically
conveys its latitude, longitude and angle inclination to the Arduino
Mega processor. Based on control code and proportional integral
derivative (PID) calculations Arduino controls the movement of the
motor such that it advances towards the target position we have
initialized. The accelerometer continuously analyzes and senses data to
the Arduino Mega in order to control speed, acceleration and motor
rotations.

Arduino Code
#include <TinyGPS++.h>
#include <Wire.h>
#include <math.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(47, 43, 33, 31, 29, 27);

#define HMC5883_WriteAddress 0x1E


#define HMC5883_ModeRegisterAddress 0x02
#define HMC5883_ContinuousModeCommand 0x00
#define HMC5883_DataOutputXMSBAddress 0x03
#define pi 3.1416
#define Right_en 9
#define Left_en 6

#define Right_1 10
#define Right_2 8
#define Left_1 4
#define Left_2 50

TinyGPSPlus gps;
volatile float current_latitude=0,current_longitude=0;
//float target_latitude=23.7252,target_longitude=90.3922;

//aula; angle=270~290(latest)

//float target_latitude=23.7249,target_longitude=90.3922;

//aula road, angle=165~180

//float target_latitude=23.7260,target_longitude=90.3880;
angle=270~290(latest)

// jidpus motorcycle,

float target_latitude=23.72610,target_longitude=90.38835;

//towards jidpus, angle= 155~160(latest)

float latitude_difference=0,longitude_difference=0;
float prev_latitude=0,prev_longitude=0;
float x1,y1;

int regb=0x01;
int regbdata=0x40;
int outputAngle[6];
int x=0,y=0,z=0,i=0,j=0,k=0,l=0,m=1,n=0;
float CompassAngle=0;
float target_angular_positon=0;
int correction_L=0;
int correction_R=0;
int Max_L=225,Max_R=230;

int TrigPin=2;
int EchoPin=3;

int Error=0;
int LeftPulse=0,RightPulse=0;

int timer1_counter;
int count=0;

void setup()
{
Serial.begin(9600);
Serial3.begin(9600);
Wire.begin();
pinMode(Right_en,OUTPUT);
pinMode(Left_en,OUTPUT);
pinMode(Right_1,OUTPUT);
pinMode(Right_2,OUTPUT);
pinMode(Left_1,OUTPUT);
pinMode(Left_2,OUTPUT);

pinMode(TrigPin,OUTPUT);
pinMode(EchoPin,INPUT);

lcd.begin(16, 2);

lcd.print("GPS GUIDED ROVER");


delay(5000);
lcd.clear();

noInterrupts();
TCCR1A = 0;
TCCR1B = 0;
timer1_counter = 49911;

// preload timer 65536-16MHz/1024/1Hz

TCNT1 = timer1_counter;

// preload timer

TCCR1B |= (1 << CS10) | (1 << CS12); // 1024 prescaler


TIMSK1 |= (1 << TOIE1);
interrupts();

// enable timer overflow interrupt


// enable all interrupts

GPSRead();
DriveAngle();
CompassRead();
}

ISR(TIMER1_OVF_vect)

// interrupt service routine

{
TCNT1 = timer1_counter;
count++;
}

// preload timer

void loop()
{

for (k=0;k<200;k++)
{
GPSRead();
DriveAngle();

lcd.setCursor(0, 2);
lcd.print(k);
lcd.setCursor(6,2);
lcd.print(target_angular_positon);
}
lcd.clear();
//target_angular_positon=280;
int goal=0;
int num=0;

while(goal<3)
{
CompassRead();
Error=target_angular_positon-CompassAngle;
PIDCalculation();
LeftPulse=Max_L-correction_L;
RightPulse=Max_R-correction_R;

MotorDrive(LeftPulse,RightPulse);
GPSRead();

if ( (abs(target_latitude-current_latitude))<=0.00008 && (abs(target_longitudecurrent_longitude))<=0.00008 )


goal++;

if (count>10)
{
DriveAngle();
count=0;
num=num+1;
}

lcd.setCursor(0, 0);
lcd.print(abs(target_latitude-current_latitude)*1e5);
lcd.setCursor(7, 0);
lcd.print(" ");
lcd.print(abs(target_longitude-current_longitude)*1e5);

//lcd.setCursor(0, 1);
//lcd.print(goal);
lcd.setCursor(0,1);
lcd.print(num);

lcd.setCursor(3, 1);

lcd.print(" ");
lcd.print(target_angular_positon);

lcd.setCursor(10, 1);
lcd.print(" ");
lcd.print(CompassAngle);
}
MotorStop();
lcd.clear();
while(1)
{
lcd.setCursor(0, 0);
lcd.print(current_latitude*1e4);
lcd.setCursor(0, 1);
lcd.print(current_longitude*1e4);
}
}

void GPSRead()
{
n=1;
while(n)
{
while (Serial3.available() > 0)
if (gps.encode(Serial3.read()))

if (gps.location.isValid())
{
current_latitude=gps.location.lat();
current_longitude=gps.location.lng();
n=0;
}
else
{
Serial.println("Searching....");
lcd.setCursor(1,0);
lcd.print("Searching....");
}
}
}
if (millis() > 5000 && gps.charsProcessed() < 10)
{
Serial.println("No GPS detected: check wiring.");
while(true);
}
}

void CompassRead()
{

Wire.beginTransmission(HMC5883_WriteAddress);
Wire.write(regb);
Wire.write(regbdata);
Wire.endTransmission();
delay(100);

Wire.beginTransmission(HMC5883_WriteAddress); //Initiate a transmission with HMC5883 (Write


address).
Wire.write(HMC5883_ModeRegisterAddress); //Place the Mode Register Address in send-buffer.
Wire.write(HMC5883_ContinuousModeCommand); //Place the command for Continuous operation
Mode in send-buffer.
Wire.endTransmission(); //Send the send-buffer to HMC5883 and end the I2C transmission.
delay(100);

Wire.beginTransmission(HMC5883_WriteAddress); //Initiate a transmission with HMC5883 (Write


address).
Wire.requestFrom(HMC5883_WriteAddress,6); //Request 6 bytes of data from the address specified.
delay(500);

//Read the value of magnetic components X,Y and Z


if(6 <= Wire.available()) // If the number of bytes available for reading be <=6.
{
for(i=0;i<6;i++)
{
outputAngle[i]=Wire.read(); //Store the data in outputAngle buffer
}
}

x=outputAngle[0] << 8 | outputAngle[1]; //Combine MSB and LSB of X Data output register
z=outputAngle[2] << 8 |outputAngle[3]; //Combine MSB and LSB of Z Data output register
y=outputAngle[4] << 8 |outputAngle[5]; //Combine MSB and LSB of Y Data output register

CompassAngle= atan2((double)y,(double)x) * (180 / 3.14159265) + 180; // angle in degrees


}

void MotorStop()
{
digitalWrite(Right_en,LOW);
digitalWrite(Left_en,LOW);
}

void DriveAngle()
{
target_angular_positon=gps.courseTo(current_latitude, current_longitude, target_latitude,
target_longitude);
// if(target_angular_positon<0)
// target_angular_positon = target_angular_positon + 360;
}

void PIDCalculation()
{
if ((Error>=0 && Error<180) || (Error<=-180 && Error>-360))
{

correction_R=0;
if ((Error<90 && Error >=0))
correction_L=Error*Max_L/90;
else if((Error<-270 && Error >-360))
correction_L=(Error+360)*Max_L/90;
else
{
correction_L=Max_L;
correction_R=30;
}
}
else if ((Error>=180 && Error<360) || (Error<=0 && Error>-180))
{
correction_L=0;
if ((Error>270 && Error <360))
correction_R=(360-Error)*Max_R/90;
else if((Error<=0 && Error >-90))
correction_R=(-Error)*Max_R/90;
else
{
correction_R=Max_R;
correction_L=30;
}
}
}

void MotorDrive(int LeftPulse, int RightPulse)


{
analogWrite(Right_en,LeftPulse);
analogWrite(Left_en,RightPulse);
digitalWrite(Right_1,HIGH);
digitalWrite(Right_2,LOW);
digitalWrite(Left_1,HIGH);
digitalWrite(Left_2,LOW);
}

Potential Applications
Many civilian applications use one or more of GPS's three basic components:
absolute location, relative movement, and time transfer. Here are a few possible
civilian and military implementations of the concept used in our project:
Automated vehicle: applying location and routes for cars and trucks to
function without a human driver.
Geofencing: vehicle tracking systems, person tracking systems, and pet
tracking systems use GPS to locate a vehicle, person, or pet. These devices
are attached to the vehicle, person, or the pet collar.
Missile and projectile guidance: GPS allows accurate targeting of various
military weapons including ICBMs, cruise missiles, precision-guided
munitions and Artillery projectiles. Embedded GPS receivers able to
withstand accelerations of 12,000 g or about 118 km/s2 have been
developed for use in 155-millimeter (6.1 in)

Вам также может понравиться