Skocz do zawartości

Autonomiczny pojazd sterowany z androida i nawigowany za pomocą GPS


cieszyn

Pomocna odpowiedź

Witam, tworzę właśnie autonomiczny pojazd który będzie miał za zadanie dojechać do punktu a z punktu b i odwrotnie jest jest opcja wskazania innego położenia, wszystko ma być sterowane za pomocą telefonu i aplikacji.

Mam problem z kodem do sterowania GPS, znalazłem jeden w internecie który chciałbym zaadaptować do swojego projektu ale niestety kompilator wywala mi błąd w tym miejscu

double dir = gps.courseTo(dest_latitude, dest_longitude)-gps.course();

proszę pomóżcie mi go naprawić

poniżej zamieszczam cały kod sterowania pojazdu z gps

#include "TinyGPS++.h"
#include <SoftwareSerial.h>

TinyGPSPlus gps;
SoftwareSerial ss(2,3);
int wpt = 0; // define variable wpt and assign a value of zero
double dest_latitude; // define floating point variable destination latitude
double dest_longitude; // define floating point variable destination longitude
int WPT_IN_RANGE= 12;

 int pwmDrive = 11;   
 int pwmTurn = 10;  
 int driveDir = 13;
 int leftRight = 12;
 float dir;

 /* DEFINE GPS WPTS HERE - Create more cases as needed */
void trackWpts() {
 switch(wpt) {
   case 0:
     dest_latitude = 1.0; // switch...case statement used.switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run.
     dest_longitude = 8.0;
     break;
   case 1:
     dest_latitude = 2.0;
     dest_longitude = 3.0;
     break;
   default:
     dest_latitude = 4.0;
     dest_longitude = 5.0;
     break;
 }
 if (gps.distanceBetween(gps.location.lat(),gps.location.lng(),dest_latitude,dest_longitude) < WPT_IN_RANGE)
   wpt++; // important statement - compares data from gprmc string with destination coordinates and switches the dest_lat and dest_lon
}

void setup() {
 Serial.begin(9600);
 ss.begin(9600);
 pinMode(driveDir,OUTPUT);
 pinMode(leftRight,OUTPUT);
}

void loop() { // important loop - trackWpts switches between waypoints depending on distance from current position to waypoint
 trackWpts();
 trackGPS(); // important statement in loop - trackGPS 
}

void trackGPS() {
 if (dest_latitude != 0 && dest_longitude != 0)

 {if(ss.available()>0)

 {
char c = ss.read();
if (gps.encode(c))
{if (gps.location.isUpdated()){

double dir = gps.courseTo(dest_latitude, dest_longitude)-gps.course();

if (dir < 0)
           dir += 360; // increments dir by 360
         if (dir > 180)
           dir -= 360; // subtracts 360 from dir

         if (dir < -75) // after incrementing or decrementing,conditions for turning left or right
         left();
         else if (dir>75)
         right();
         else
         center();
}else
stop();
}
}
}
else stop();
}

void drive_forward(){
digitalWrite(driveDir, HIGH); 
analogWrite(pwmDrive, 255);
delay(25);
}
void drive_backward(){
digitalWrite(driveDir, LOW); 
analogWrite(pwmDrive, 255);
delay(25);
}


void right(){
 digitalWrite(leftRight, HIGH);
 analogWrite(pwmTurn, 255);
 drive_forward();
 delay(25);
}
void left(){
 digitalWrite(leftRight, LOW);
 analogWrite(pwmTurn, 255);
 drive_forward();
 delay(25);
}
void center(){
 digitalWrite(leftRight, HIGH);
 analogWrite(pwmTurn, 0);
 delay(25);
}
Link do komentarza
Share on other sites

double dir = gps.courseTo(dest_latitude, dest_longitude, gps.location.lat(),gps.location.lng());

A tak z ciekawości - sprawdziłeś może jaki błąd daje syngał z GPS? Bo moim zdaniem to nie ma najmniejszych szans działać.

Link do komentarza
Share on other sites

znaczy, błąd daje kompilator

"no matching function for call to 'TinyGPSPlus::courseTo(double&, double&)' "

a masz może jakiś podobny skrypt który miałby na celu doprowadzenie pojazdu do celu??

Link do komentarza
Share on other sites

Zarejestruj się lub zaloguj, aby ukryć tę reklamę.
Zarejestruj się lub zaloguj, aby ukryć tę reklamę.

jlcpcb.jpg

jlcpcb.jpg

Produkcja i montaż PCB - wybierz sprawdzone PCBWay!
   • Darmowe płytki dla studentów i projektów non-profit
   • Tylko 5$ za 10 prototypów PCB w 24 godziny
   • Usługa projektowania PCB na zlecenie
   • Montaż PCB od 30$ + bezpłatna dostawa i szablony
   • Darmowe narzędzie do podglądu plików Gerber
Zobacz również » Film z fabryki PCBWay

Kompilator zgłasza błąd ponieważ metoda courseTo() oczekuje 4 parametrów (o ile dobrze widzę).

Miałem na myśli właściwie 2 problemy z GPS. Po pierwsze dokładność pozycjonowania. Producenci typowych modułów podają np. 5m. Niestety taka dokładność to przypadek mocno optymistyczny. Drugi błąd to typowy szum - jak kiedyś pracowałem przy nawigacji, to żeby przetestować program wystarczyło... siedzieć przy biurku. I tak odczyty "skakały" po okolicy...

To że nawigacje/telefony pokazują stabilne i na oko dokładne wyniki to rezultat ciężkiej i skomplikowanej pracy oprogramowania (i programistów). Chociażby filtr Kalmana jest bardzo często wykorzystywany.

Ostatnio testowałem moduł GPS, licząc że przez kilka lat problemy z systemem zniknęły i teraz wszystko działą pięknie. Napisałem aplikację, która zbiera dane i poszedłem z odbiornikiem na spacer... Po powrocie odkryłem, że chodziłem po dachach okolicznych budynków, przez spory kawałek system zgubił zasięg, a jak kupowałem w sklepie piwo to biegałem wściekle w promieniu kilku metrów...

Możliwe że drogie, specjalistyczne odbiorniki GPS, wyposażone w DGPS zachowują się lepiej, ale nie spodziewałbym się cudów po tanim odbiorniku.

Stąd było moje pytanie - czy sprawdziłeś jakie dane odbierasz z GPS? Czy są one na tyle stabilne żeby według nich nawigować? Czy umiesz napisać odpowiednie filtry?

Link do komentarza
Share on other sites

testowałem ale w miejscu, ogólnie to ma być praca doświadczalna

jeśli faktycznie okaże się, że nie działa tak jak należy to i tak plus, chciałem nabrać doświadczenia a z gps nie mam za dużego

a pomożecie mi poprawić ten kod na tyle żeby działał??

jakich dwóch pozostałych parametrów potrzebuje??

będę bardzo wdzięczny za pomoc

od kilku tygodni szukam informacji na ten temat i szczerze mówiąc są bardzo mało dokładne opisy, to znaczy nie kompletne

Link do komentarza
Share on other sites

przeszło 🙂

dzięki za pomoc

blokuje mnie jeszcze

}else 
stop(); 
} 
} 
} 
else stop(); 
} 

twierdząc, że 'stop' nie jest zdeklarowany

[ Dodano: 26-08-2015, 23:02 ]

cały kod wygląda obecnie tak:

#include "TinyGPS++.h" 
#include <SoftwareSerial.h> 

TinyGPSPlus gps; 
SoftwareSerial ss(2,3); 
int wpt = 0; // define variable wpt and assign a value of zero 
double dest_latitude; // define floating point variable destination latitude 
double dest_longitude; // define floating point variable destination longitude 
int WPT_IN_RANGE= 12; 

 int pwmDrive = 11;    
 int pwmTurn = 10;  
 int driveDir = 13; 
 int leftRight = 12; 
 float dir; 

 /* DEFINE GPS WPTS HERE - Create more cases as needed */ 
void trackWpts() { 
 switch(wpt) { 
   case 0: 
     dest_latitude = 1.0; // switch...case statement used.switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. 
     dest_longitude = 8.0; 
     break; 
   case 1: 
     dest_latitude = 2.0; 
     dest_longitude = 3.0; 
     break; 
   default: 
     dest_latitude = 4.0; 
     dest_longitude = 5.0; 
     break; 
 } 
 if (gps.distanceBetween(gps.location.lat(),gps.location.lng(),dest_latitude,dest_longitude) < WPT_IN_RANGE) 
   wpt++; // important statement - compares data from gprmc string with destination coordinates and switches the dest_lat and dest_lon 
} 

void setup() { 
 Serial.begin(9600); 
 ss.begin(9600); 
 pinMode(driveDir,OUTPUT); 
 pinMode(leftRight,OUTPUT); 
} 

void loop() { // important loop - trackWpts switches between waypoints depending on distance from current position to waypoint 
 trackWpts(); 
 trackGPS(); // important statement in loop - trackGPS 
} 

void trackGPS() { 
 if (dest_latitude != 0 && dest_longitude != 0) 

 {if(ss.available()>0) 

 { 
char c = ss.read(); 
if (gps.encode(c)) 
{if (gps.location.isUpdated()){ 

#include "TinyGPS++.h" 
#include <SoftwareSerial.h> 

TinyGPSPlus gps; 
SoftwareSerial ss(2,3); 
int wpt = 0; // define variable wpt and assign a value of zero 
double dest_latitude; // define floating point variable destination latitude 
double dest_longitude; // define floating point variable destination longitude 
int WPT_IN_RANGE= 12; 

 int pwmDrive = 11;    
 int pwmTurn = 10;  
 int driveDir = 13; 
 int leftRight = 12; 
 float dir; 

 /* DEFINE GPS WPTS HERE - Create more cases as needed */ 
void trackWpts() ;{ 
 switch(wpt) { 
   case 0: 
     dest_latitude = 1.0; // switch...case statement used.switch statement compares the value of a variable to the values specified in case statements. When a case statement is found whose value matches that of the variable, the code in that case statement is run. 
     dest_longitude = 8.0; 
     break; 
   case 1: 
     dest_latitude = 2.0; 
     dest_longitude = 3.0; 
     break; 
   default: 
     dest_latitude = 4.0; 
     dest_longitude = 5.0; 
     break; 
 } 
 if (gps.distanceBetween(gps.location.lat(),gps.location.lng(),dest_latitude,dest_longitude) < WPT_IN_RANGE) 
   wpt++; // important statement - compares data from gprmc string with destination coordinates and switches the dest_lat and dest_lon 
} 

void setup() ;{ 
 Serial.begin(9600); 
 ss.begin(9600); 
 pinMode(driveDir,OUTPUT); 
 pinMode(leftRight,OUTPUT); 
} 

void loop() ;{ // important loop - trackWpts switches between waypoints depending on distance from current position to waypoint 
 trackWpts(); 
 trackGPS(); // important statement in loop - trackGPS 
} 

void trackGPS() ;{ 
 if (dest_latitude != 0 && dest_longitude != 0) 

 {if(ss.available()>0) 

 { 
char c = ss.read(); 
if (gps.encode(c)) 
{if (gps.location.isUpdated()){ 

double dir = gps.courseTo(dest_latitude, dest_longitude, gps.location.lat(),gps.location.lng());

if (dir < 0) 
           dir += 360; // increments dir by 360 
         if (dir > 180) 
           dir -= 360; // subtracts 360 from dir 

         if (dir < -75) // after incrementing or decrementing,conditions for turning left or right 
         left(); 
         else if (dir>75) 
         right(); 
         else 
         center(); 
}else 
stop(); 
} 
} 
} 
else stop(); 
} 

void drive_forward();{ 
digitalWrite(driveDir, HIGH); 
analogWrite(pwmDrive, 255); 
delay(25); 
} 
void drive_backward();{ 
digitalWrite(driveDir, LOW); 
analogWrite(pwmDrive, 255); 
delay(25); 
} 


void right();{ 
 digitalWrite(leftRight, HIGH); 
 analogWrite(pwmTurn, 255); 
 drive_forward(); 
 delay(25); 
} 
void left();{ 
 digitalWrite(leftRight, LOW); 
 analogWrite(pwmTurn, 255); 
 drive_forward(); 
 delay(25); 
} 
void center();{ 
 digitalWrite(leftRight, HIGH); 
 analogWrite(pwmTurn, 0); 
 delay(25); 
} 

if (dir < 0) 
           dir += 360; // increments dir by 360 
         if (dir > 180) 
           dir -= 360; // subtracts 360 from dir 

         if (dir < -75) // after incrementing or decrementing,conditions for turning left or right 
         left(); 
         else if (dir>75) 
         right(); 
         else 
         center(); 
}else 
stop(); 
} 
} 
} 
else stop(); 
} 

void drive_forward(){ 
digitalWrite(driveDir, HIGH); 
analogWrite(pwmDrive, 255); 
delay(25); 
} 
void drive_backward(){ 
digitalWrite(driveDir, LOW); 
analogWrite(pwmDrive, 255); 
delay(25); 
} 


void right(){ 
 digitalWrite(leftRight, HIGH); 
 analogWrite(pwmTurn, 255); 
 drive_forward(); 
 delay(25); 
} 
void left(){ 
 digitalWrite(leftRight, LOW); 
 analogWrite(pwmTurn, 255); 
 drive_forward(); 
 delay(25); 
} 
void center(){ 
 digitalWrite(leftRight, HIGH); 
 analogWrite(pwmTurn, 0); 
 delay(25); 
} 
Link do komentarza
Share on other sites

coś skopany jest ten kod i szczerze mówiąc trochę się pogubiłem bo teraz wyskakuje mi "trackGPS();" że jest nie zdeklarowany

[ Dodano: 26-08-2015, 23:30 ]

ok, chyba powoli dostrzegam błędy tego kodu, stopu faktycznie niema i z niewiadomych przyczyn ruchy zdeklarowane są po przywołaniu, podobnie jest z trackGPS(), podpowiedzcie czzy dobrym tropem idę

Link do komentarza
Share on other sites

Dołącz do dyskusji, napisz odpowiedź!

Jeśli masz już konto to zaloguj się teraz, aby opublikować wiadomość jako Ty. Możesz też napisać teraz i zarejestrować się później.
Uwaga: wgrywanie zdjęć i załączników dostępne jest po zalogowaniu!

Anonim
Dołącz do dyskusji! Kliknij i zacznij pisać...

×   Wklejony jako tekst z formatowaniem.   Przywróć formatowanie

  Dozwolonych jest tylko 75 emoji.

×   Twój link będzie automatycznie osadzony.   Wyświetlać jako link

×   Twoja poprzednia zawartość została przywrócona.   Wyczyść edytor

×   Nie możesz wkleić zdjęć bezpośrednio. Prześlij lub wstaw obrazy z adresu URL.

×
×
  • Utwórz nowe...

Ważne informacje

Ta strona używa ciasteczek (cookies), dzięki którym może działać lepiej. Więcej na ten temat znajdziesz w Polityce Prywatności.