Hi,
I am trying to use TinyGPS++ (TinyGPS++ | Arduiniana) custom objects. I create them like this:
TinyGPSCustom dimension(gps,"GPGSA",2);
TinyGPSCustom vdop(gps, "GPGSA", 17);
(entire code below)
Then when I try to use them in an if statement:
if (dimension.value()==3 && vdop.value()<=5)
I get error: "ISO C++ forbids comparison between pointer and integer"
I know almost nothing about pointers but after some searching I found out about the dereference operator, adding it like this
if (*dimension.value()==3 && *vdop.value()<=5)
solves this error, but I'm not sure if it would give the desired result, since I've seen it used on variables, not on functions?
Secondly, I don't understand why it is throwing an error in the first place, since I've included the parenthesis it is a function call and not a pointer. what am I missing? Would much appreciate any help.
A little about the project: the main goal here is to provide an odometer for a scooter. It receives coordinates from a GPS unit, and by comparing them to the last coordinates (as long as the precision - DOP - is good enough) it calculates the distance passed. If there is an accurate 3D fix, it is also being considered when calculating the distance.
Here is the code:
#include <TinyGPS++.h>
#include <LiquidCrystal.h>
#include <EEPROMex.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
TinyGPSPlus gps;
TinyGPSCustom dimension(gps,"GPGSA",2);
TinyGPSCustom vdop(gps, "GPGSA", 17);
boolean firstFix = true;
boolean firstAltFix = true;
float lastLat;
float lastLong;
float lastAlt;
volatile long odometer;
long trip=0;
int mode=0;
volatile int x=0;
volatile float tempOdometer = 0.0;
unsigned long intervalTimer=0;
void setup()
{
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
odometer = EEPROM.readLong( 0 );
trip = EEPROM.readLong( 4 );
mode = EEPROM.readInt( 8 );
lcd.begin(8,2);
Serial.begin(9600);
attachInterrupt(0,turnOff,FALLING);
attachInterrupt(1,rpm,FALLING);
Serial.write("$PMTK314,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29<CR><LF>");
}
void loop()
{
while(Serial.available()>0)
{
gps.encode(Serial.read());
}
if (dimension.value()==3 && vdop.value()<=5) // --------- Error is thrown here----------
{
if (gps.location.isUpdated() && gps.altitude.isUpdated() && gps.hdop.value()<=500)
{
if (!firstFix && !firstAltFix)
{
tempOdometer += distance3D(lastLat , lastLong , gps.location.lat() , gps.location.lng() , lastAlt , gps.altitude.meters());
lastLat = gps.location.lat();
lastLong = gps.location.long();
lastAlt = gps.altitude.meters();
if (tempOdometer > 900)
{
odometer += int(tempOdometer + 0.5);
tempOdometer = 0.0;
}
}
else if (!firstFix && firstAltFix)
{
tempOdometer += distance2D(lastLat , lastLong , gps.location.lat() , gps.location.lng());
lastLat = gps.location.lat();
lastLong = gps.location.long();
lastAlt = gps.altitude.meters();
firstAltFix = false;
if (tempOdometer > 900)
{
odometer += int(tempOdometer + 0.5);
tempOdometer = 0.0;
}
}
else
{
lastLat = gps.location.lat();
lastLong = gps.location.lng();
lastAlt = gps.altitude.meters();
firstFix = false;
firstAltFix = false;
}
}
}
else
{
if (dimension.value()==2 && gps.location.isUpdated() && gps.hdop.value()<=500)
{
if (!firstFix)
{
tempOdometer += distance2D(lastLat , lastLong , gps.location.lat() , gps.location.lng());
lastLat = gps.location.lat();
lastLong = gps.location.lng();
if (tempOdometer > 900){
odometer += int(tempOdometer + 0.5);
tempOdometer = 0.0;
}
}
else
{
lastLat = gps.location.lat();
lastLong = gps.location.lng();
firstFix = false;
}
}
}
}
float distance2D(float lat1,float long1,float lat2,float long2)
{
float delLat = abs(lat2-lat1)*111194.9;
float delLong = 111194.9*abs(long2-long1)*cos(radians((lat2+lat1)/2));
float distance = sqrt(pow(delLat,2)+pow(delLong,2));
return distance;
}
float distance3D(float lat1,float long1,float lat2,float long2,float alt1,float alt2)
{
float delLat = abs(lat2-lat1)*111194.9;
float delLong = 111194.9*abs(long2-long1)*cos(radians((lat2+lat1)/2));
float distance = sqrt(pow(delLat,2)+pow(delLong,2));
float delAlt = alt2 - alt1;
distance = sqrt(pow(distance,2)+pow(delAlt,2));
return distance;
}
void rpm()
{
x++;
}
void turnOff()
{
digitalWrite(4,LOW);
odometer += int(tempOdometer + 0.5);
tempOdometer = 0.0;
while( !EEPROM.updateLong( 0 , odometer )) {}
while( !EEPROM.updateLong( 4 , trip )) {}
while( !EEPROM.updateInt( 8 , mode )) {}
for( int i=0 ;i <310 ; i++ ){
delayMicroseconds(16383);
}
digitalWrite(4,HIGH);
}