I am trying to construct an autonomous rover using the Arduino red board and the ardumoto shield along with an Adafruit GPS. It is a two wheeled rover with two separate motors. As far as the construction is concerned I have finished, however, the programming of this rover is giving me a lot of trouble. I feel like I am missing integral parts of the code, but I am still learning how to write and think in terms of programming. I did use other codes I have found on the internet to try and build something. The general idea I am looking for is to initially input the destination coordinates, then for the GPS to receive the current coordinates, the rover to create a waypoint, and subsequently drive to it. I tried to figure out some conditional statements to input, but I'm getting to a point where the more I try, the farther away I am getting.
Any help would be greatly appreciated.
#include "nmea.h"
#include "motors.h"
#include "math.h"
int wpt = 0; //indicates initial zero value for waypoints
float lat;//this is the latitude coordinate from the adafruit
float lon;//this is the longitude coordinate from the adafruit
float dest_latitude; //variable to be input at competition
float dest_longitude;//variable to be input at competition
NMEA gps(GPRMC); //standard for initializing GPS library
#define WPT_IN_RANGE //defines range of waypoints for GPS
#define MOTOR_A 0 //definitions for both motors
#define MOTOR_B 1
const byte PWMA = 3; //Pin assignments assigned based on schematic of Arudomoto
const byte PWMB = 11;
const byte DIRA = 12;
const byte DIRB = 13;
void setupArdumoto()//Initializes all of the pins on the Ardumoto and sets them as outputs.
{
Serial.begin(9600);
Serial.println("Starting Program")
Serial2.begin(9600);
pinMode(PWMA,OUTPUT);
pinMode(PWMB,OUTPUT);
pinMode(DIRA,OUTPUT);
pinMode(DIRB,OUTPUT);
digitalWrite(PWMA,HIGH);
digitalWrite(PWMB,HIGH);
digitalWrite(DIRA,HIGH);
digitalWrite(DIRB,HIGH);
}
void loop()//This loop gathers the coordinates from the GPS and relays them to processing
{
drive();
delay();
if (Serial2.available() > 0)
{
char c = Serial2.read();
if (gps.decode(c))
{ Serial.println("Latitude:");
float lat = gps.gprmc_latitude()
Serial.println(lat,3);
Serial.println("Longitude : ");
float lon =gps.gprmc_longitude();
Serial.println(lon,3);{
trackWpts();
trackGPS();{
void (trackWpts){
switch(wpt){
case 0:
dest_latitude=
dest_longitude=
break;
case 1:
dest_latitude=
dest_longitude=
break;
default:
dest_latitude = 0;
dest_longitude = 0;{
if (gps.gprmc_distance_to(dest_latitude,dest_longitude)<WPT_IN_RANGE),wpt++;
driveArdumoto(MOTOR_A,CCW,255);
delay();
driveArdumoto(MOTOR_B,CCW,255);
delay()
else(
stopArdumoto(MOTOR_1);
stopArdumoto(MOTOR_2);
Serial.println("Destination Arrived...")}}}}}}
else (
serial.println("Loop cannot iniate")
}