GPS GUIDED ROBOT

0
864
gps guided robot
gps guided robot

Introduction:

GPS GUIDED ROBOT is a self-piloted vehicle that does not require an operator to navigate and accomplish its tasks. Autonomous vehicles are a recently developed subset of robotics and can come in three general forms

  • Air
  • Ground
  • Submarine

Working explanation:

Our GPS controlled autonomous vehicle is presented which employs a GPS receiver module to capture the GPS signal and determine the current location of the vehicle. The system is controlled using an Arduino ATMega2560 microcontroller which interfaces to a magnetic compass, sensor, and DC motors. The compass determines the vehicle direction by continuously providing a measurement of heading.

The microcontroller drives the DC motors to move the vehicle to a manually entered destination coordinates. Obstacle detection and avoidance are achieved by incorporating an ultrasonic sensor to measure the distance between the vehicle and the obstacle, and avoidance is implemented by the microcontroller.

The designed GPS autonomous vehicle is able to navigate itself independently from one location to a second, user-prescribed location, using GPS-location data. The vehicle measures the bearing angle, and changes its heading towards the destination, and repeats the process as it moves to the destination. The performance of the vehicle is enhanced with the capability to detect and avoid unexpected obstructions placed in its path.

To navigate a vehicle autonomously, the control system must have the ability to determine its present location and direction of travel. Location can be determined either from an outside source with technology such as the (GPS), or by calculating a traveled path from a known starting point with the use of electronic compasses, inclinometers, and rotational counters. While neither option is perfect, GPS offers the benefit of retrieving location information that has no bearing upon previous results. This prevents calculation errors from accumulating throughout the path. For this reason, low cost, and easy to use, GPS was selected as the method of location retrieval for this autonomous vehicle project.

Components used in GPS GUIDED ROBOT:

  • GPS 
  • Compass
  • Vehicle
  • Motor driver
  • Arduino
  • Sensors
  • Wi-Fi module
  • Regulator IC
  • Camera

First, we have to find the map values (longitude, latitude) of our destination point by Google map then these values we have to program in the Arduino board and start the robot.

After starting the robot first obtains its current coordinates from the GPS readings. Next, the robot computes its distance away from the target. If the distance is less than 5 meters, the robot will determine that it has arrived at the target. On the other hand, if the distance is greater than 5 meters the robot will get the compass reading from the GPS then compare the compass reading with the calculated bearing angle. If the angles are matched, the robot will proceed to the next command to check for obstacles in front of it. If the angles are not matched, the robot will make the necessary adjustments by rotating clockwise or counterclockwise to face the target.

Next, the robot will check for the reading from the range of sensors. If either the left or right range sensor returns a value less than 100, which indicates that there is an obstacle in front of the robot within 1 meter, the robot will call the avoid object program to instruct the robot to get around the object and move forward for a short distance. If there are no obstacles in front of the robot, it will move forward for a short distance without turning around an object and repeat the entire procedure until it arrived at the target.

Direction Decision

The first step toward getting to the target is to have the robot facing towards the target. Next, the robot will be rotated clockwise or counterclockwise depending on the bearing angle until the compass reading matches the bearing angle which indicates that the robot is heading in the right direction and it’s ready to move forward.

In the Figure below, the robot is represented in the red square and the target is represented in the red star. Compass is the direction of the robot relative to the north (which is also the compass reading) and is the angle relative to the north of the robot and the target.  As shown in Figure, when the compass is equal to the robot it is heading in the direction of the target. The direction decisions program allows the robot to decide which direction to turn (CW/CCW) to face the target.

Direction Decision to Face the Target, GPS guided Robot
 
Direction Decision to Face the Target

Hardware Implementation:

circuit diagram of GPS guided robot, GPS guided Robot using arduino
GPS guided robot(circuit diagram) 

Hardware Design (GPS Guided Robot), GPS guided Robot
Hardware Design

GPS GUIDED ROBOT (Coding)

String pack;// string variable for bluetooth communication
doublelats;
double longs;
//----------------------------------------------------------------------
intobsf; //front obstical distance in cm
intobsl; // left
intobsr; // right
#include "Ultrasonic.h" // library header file
Ultrasonic ultrasonic(9,8); //Ultrasonic ultrasonic(Trig,Echo);
Ultrasonic ultrasoniccc(31,33);
Ultrasonic ultrasonicccc(35,37);
//-----------------------------------------------------------------------
#include 
//create two objects
EasyTransferETin, ETout; 
struct RECEIVE_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
floatdelat;  //distinationlat
floatdelon;  //dis long from map iot
};
struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
floatactlat; //current lat of hardwere sending to map
floatactlon;  // current long
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;
//------------------------------------------------------
#include <TinyGPS++.h>
#include 
#include 
constint ENA = 15; // motor 1 enable
constint IN1 = 3;
constint IN2 = 2;
constint IN3 = 4;
constint IN4 = 5;
constint ENB = 14; // motor 2 enable
L298N driver(ENA,IN1,IN2,IN3,IN4,ENB); 
inttime_delay = 150; // delay between two commands
int speed = 130;  // speed of all motors
floatdiggl; // rotation decition variables
floatdiggr;
unsigned long distanceKmToLondon;  // distance calculated 
///////////////////////////////////////////////////////
//const double LONDON_LAT , LONDON_LON ; 
doublelatt;
floatlongg;
//////////////////////////////////////////////////////
////////////////////////compass diclearation///////////////////////
#include 
#include 
HMC5883L compass;
///////////////////gps pins and baud rate//////////////////////
staticconstintRXPin = 11, TXPin = 10;
staticconst uint32_t GPSBaud = 9600;
//////////////////////////////////////////////////////////////
// The TinyGPS++ object
TinyGPSPlusgps;  // gps library
// The serial connection to the GPS device
SoftwareSerialss(RXPin, TXPin);// gps serial comm defined here
/////////////////////////////////////////////////////////
void setup()
{
Serial.begin(115200);  // usb com port baud rate
ss.begin(GPSBaud);    // gps baud rate ie:4800
Serial1.begin(115200);  // esp8266 communication baud rate
Serial2.begin(115200);  // serial port 2 baud rate
ETin.begin(details(rxdata), &Serial1);  // data reciving from esp8266
ETout.begin(details(txdata), &Serial1); // data sending to esp8266
  ///////////////////////////////////////////////////////////////
while (!compass.begin())
  {
    //Serial.println("Could not find a valid HMC5883L sensor, check wiring!");
delay(500);
  }
  // Set measurement range
compass.setRange(HMC5883L_RANGE_1_3GA);
  // Set measurement mode
compass.setMeasurementMode(HMC5883L_CONTINOUS);
  // Set data rate
compass.setDataRate(HMC5883L_DATARATE_30HZ);
  // Set number of samples averaged
compass.setSamples(HMC5883L_SAMPLES_8);
  // Set calibration offset. See HMC5883L_calibration.ino
compass.setOffset(0, 0);
  //////////////////////////////////////////////////////
}
void loop()
{
  ////////////////////////////////
float ss1 =(gps.location.lat());  // getting current lat
txdata.actlat = ss1;     /sending to map
txdata.actlon = (gps.location.lng());
ETout.sendData();
ETin.receiveData();
double LONDON_LAT = rxdata.delon;
double LONDON_LON = rxdata.delat;     // target location.
////////////////////////////////////////////////////////////////
latt  =gps.location.lat();  ///                           lat
longg = gps.location.lng();    // lon of target placed in longg float variable
 /////////////////////////////////////////////////////////////////////
if(diggl> 6){
driver.turn_right(speed,time_delay);
driver.full_stop(time_delay);
 }
else if(diggr>6){
driver.turn_left(speed,time_delay);
driver.full_stop(time_delay);
 }
/////////////////////////////////////////////////////////////////
if(distanceKmToLondon> 10 &&diggr< 10 &&diggl<10){
obsf = ultrasonic.Ranging(CM);  reading obstical distance front
obsr = ultrasoniccc.Ranging(CM);  //left
obsl = ultrasonicccc.Ranging(CM);   right
Serial.println(obsf);
Serial.println(obsr);
Serial.println(obsl); 
    //here the range is 50 cm for the three sides
    //front 50 right 50 and left 50 cm
if (obsf> 50 &&obsr>50 &&obsl> 50){  // front clear 
Serial.println("-x-x-x-x-x-"); 
driver.backward(speed,time_delay);
driver.backward(speed,time_delay);
driver.backward(speed,time_delay);
driver.backward(speed,time_delay);
driver.backward(speed,time_delay);
driver.backward(speed,time_delay);
driver.full_stop(time_delay);
}
else if(obsf> 50 &&obsr> 50 &&obsl<30){
Serial.print("Left clear = ");
Serial.println(obsl);
driver.turn_right(speed,time_delay);                                   /////////////////////
driver.full_stop(time_delay);
obsl = ultrasonicccc.Ranging(CM);
if (obsl> 50){
driver.backward(speed,time_delay);
driver.backward(speed,time_delay);
driver.full_stop(time_delay);
  }}
else if(obsf> 50 &&obsr< 50 &&obsl>50){
Serial.print("Right clear = ");
Serial.println(obsr);
driver.turn_left(speed,time_delay);
driver.turn_left(speed,time_delay);
driver.full_stop(time_delay);
obsr = ultrasoniccc.Ranging(CM);
if(obsr> 50){
driver.backward(speed,time_delay);
driver.backward(speed,time_delay);
driver.full_stop(time_delay);
    }
  }}
/////////gps////gps//////////////gps////gps//////gps//////////////
distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
gps.location.lat(),
gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON) ;
printInt(distanceKmToLondon, gps.location.isValid(), 9);// distnce
doublecourseToLondon =
TinyGPSPlus::courseTo(
gps.location.lat(),
gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON);
const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);
smartDelay(1000);
  Vector norm = compass.readNormalize();
  // Calculate heading
float heading = atan2(norm.YAxis, norm.XAxis);
floatdeclinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI);
heading += declinationAngle;
  // Correct for heading < 0deg and heading > 360deg
if (heading < 0)
  {
heading += 2 * PI;
  }
if (heading > 2 * PI)
  {
heading -= 2 * PI;
  }
  // Convert to degrees
floatheadingDegrees = heading * 180/M_PI; 
if(headingDegrees>courseToLondon){
diggl = headingDegrees- courseToLondon;
diggr = 0;
 }
else if(headingDegrees<courseToLondon){
diggr = courseToLondon - headingDegrees;
diggl = 0;
 }
 ////////distance measurment and going towards target/////////////////////
 //  /////////bluetooth terminal//////////////////////////////////
Serial.println("-----------------------------------");
Serial.print("Angle = ");
Serial.println(headingDegrees, 3);
Serial.print("Cur Lat = ");
Serial.println(gps.location.lat() ,6);
Serial.print("Cur Long = ");
Serial.println(gps.location.lng() , 6);
Serial.print("Target Angle=");
Serial.println(courseToLondon ,3);
Serial.print("Target lat=");
Serial.println(LONDON_LAT , 6);
Serial.print("Target lon=");
Serial.println(LONDON_LON , 6);
Serial.print("Distance=");
Serial.println(distanceKmToLondon , 4);
if(diggl == 0){
Serial.print("Angle diff=");
Serial.println(diggr , 4);
        }
else{
Serial.print("Angle diff=");
Serial.println(diggl , 4);
        }
 /////////////////loop ended here////////////////////////
}
////////////////////functions starts from here/////////////////////////
// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
  {
while (ss.available())
gps.encode(ss.read());
  } while (millis() - start < ms);
}
static void printFloat(float val, bool valid, intlen, intprec)
{
if (!valid)
  {
while (len-- > 1)
Serial.print('*');
Serial1.print(' ');
  }
else
  {
Serial.print(val, prec);
int vi = abs((int)val);
intflen = prec + (val< 0.0 ? 2 : 1); // . and -
flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
for (int i=flen; i<len; ++i)
Serial.print(' ');
  }
smartDelay(0);
}
static void printInt(unsigned long val, bool valid, intlen)
{
charsz[32] = "*****************";
if (valid)
    //sprintf(sz, "%ld", val);
sz[len] = 0;
for (int i=strlen(sz); i<len; ++i)
sz[i] = ' ';
if (len> 0) 
sz[len-1] = ' ';
  //Serial.print(sz);
smartDelay(0);
}
static void printDateTime(TinyGPSDate&d, TinyGPSTime&t)
{
if (!d.isValid())
  {
    //Serial.print(F("********** "));
  }
else
  {
charsz[32];
    //sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
   // Serial.print(sz);
  }
if (!t.isValid())
  {
    //Serial.print(F("******** "));
  }
else
  {
charsz[32];
    //sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
   // Serial.print(sz);
  }
printInt(d.age(), d.isValid(), 5);
smartDelay(0);
}
static void printStr(const char *str, intlen)
{
intslen = strlen(str);
for (int i=0; i<len; ++i)
    //Serial.print(i

Leave a Reply