When we add the "float a1,b1;" this program can not into "void setup".
We just set the variable. But we can't run the program.
#include <NewSoftSerial.h> // Add to library folder
#include <TinyGPS.h> // Add to library folder
#include <string.h>
float a1,b1; //add this row,the program can not into the "void setup"
double d1,d2;
char *pEnd;
TinyGPS gps;
NewSoftSerial nss(7, 255); // Yellow wire to pin 6
char value[20];
int i;
void setup()
{
Serial.begin(9600);
nss.begin(4800);
Serial.println("Reading GPS");
delay(1000);
wait:
if(Serial.available()>0)
{
for(i=0;i<20;i++)
{
value[i] = Serial.read();
}
Serial.println(value);
char *pEnd;
d1=strtod(value,&pEnd);
d2=strtod(pEnd,NULL);
Serial.println(d1,6);
Serial.println(d2,6);
goto wait2;
}
else
{
//Serial.println('1');
goto wait;
}
wait2:delay(500);
}
void loop() {
Serial.println('2');
bool newdata = false;
unsigned long start = millis();
while (millis() - start < 5000) { // Update every 5 seconds
if (feedgps())
newdata = true;
}
if (newdata) {
gpsdump(gps);
}
}
// Get and process GPS data
void gpsdump(TinyGPS &gps) {
float flat, flon, x,y,lat2,long2,d3,d4,d5,d6,d7,a3,a4,a5,a6,a7,c;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
x=flat,y=flon;
Serial.print(x, 6); Serial.print(", ");
Serial.println(y, 6);
float course_to (float x, float y, float d1, float d2);
{
if ((d2-y)<0)
{
d3=(24-x)*111.11111*1000;
d4=(sqrt(sq(d1-x)+sq(d2-y)))*111.11111*1000;
d5=(sqrt(sq(d2-y)+sq(d1-24)))*111.11111*1000;
d6=((sq(d3)+sq(d4)-sq(d5))/(2*d3*d4));
d7=((acos(d6))*57.29578)*(-1);
}
else
{
d3=(24-x)*111.11111*1000;
d4=(sqrt(sq(d1-x)+sq(d2-y)))*111.11111*1000;
d5=(sqrt(sq(d2-y)+sq(d1-24)))*111.11111*1000;
d6=((sq(d3)+sq(d4)-sq(d5))/(2*d3*d4));
d7=((acos(d6))*57.29578);
}
if((y-b1)<0)
{
a3=(24-a1)*111.11111*1000;
a4=(sqrt(sq(x-a1)+sq(y-b1)))*111.11111*1000;
a5=(sqrt(sq(y-b1)+sq(x-24)))*111.11111*1000;
a6=((sq(a3)+sq(a4)-sq(a5))/(2*a3*a4));
a7=((acos(a6))*57.29578)*(-1);
}
else if((y-b1)>0)
{
a3=(24-a1)*111.11111*1000;
a4=(sqrt(sq(x-a1)+sq(y-b1)))*111.11111*1000;
a5=(sqrt(sq(y-b1)+sq(x-24)))*111.11111*1000;
a6=((sq(a3)+sq(a4)-sq(a5))/(2*a3*a4));
a7=((acos(a6))*57.29578);
}
else
{
a7=0;
}
c=a7-d7;
Serial.println(c,6); //delta angle,H-T
Serial.println(d4,6); //car to target distance
Serial.println(d7,6); //cat to target angle
a1==x,b1==y;
}
}
// Feed data as it becomes available
bool feedgps(){
while (nss.available()) {
if (gps.encode(nss.read()))
return true;
}
return false;
}
Moderator edit: Replace quote tags with