本文整理汇总了C++中Adafruit_GPS类的典型用法代码示例。如果您正苦于以下问题:C++ Adafruit_GPS类的具体用法?C++ Adafruit_GPS怎么用?C++ Adafruit_GPS使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Adafruit_GPS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void setup()
{
setup_timer_int();
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data for high update rates!
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// uncomment this line to turn on all the available data - for 9600 baud you'll want 1 Hz rate
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_ALLDATA);
// Set the update rate
// 1 Hz update rate
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
// 5 Hz update rate- for 9600 baud you'll have to set the output to RMC or RMCGGA only (see above)
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_5HZ);
// 10 Hz update rate - for 9600 baud you'll have to set the output to RMC only (see above)
//GPS.sendCommand(PMTK_SET_NMEA_UPDATE_10HZ);
// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);
delay(1000);
}
示例2: loop
void loop() {
// in case you are not using the interrupt above, you'll
// need to 'hand query' the GPS, not suggested :(
/*
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) Serial.print(c);
}
*/
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
if (timer > millis()) timer = millis();
if (millis() - timer > 1000) {
timer = millis();
if (1) {//(GPS.fix) {
Serial.print("(123,");
Serial.print(GPS.latitudeDegrees, 6);
Serial.print(", ");
Serial.print(GPS.longitudeDegrees, 6);
Serial.print(",");
Serial.print(GPS.speed);
Serial.print(",");
Serial.print((int)GPS.fixquality);
Serial.println(")");
}
}
sensors_event_t event;
mma.getEvent(&event);
Serial.print("(456,");
Serial.print(event.acceleration.x); Serial.print(",");
Serial.print(event.acceleration.y); Serial.print(",");
Serial.print(event.acceleration.z); Serial.print(")");
Serial.println();
delay(1000/100);
/*
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print("('ping', ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println(")");
*/
}
示例3: initialize
void GpsController::initialize()
{
//GPS code
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
// the parser doesn't care about other sentences at this time
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// For the parsing code to work nicely and have time to sort thru the data, and
// print it out we don't suggest using anything higher than 1 Hz
// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);
// the nice thing about this code is you can have a timer0 interrupt go off
// every 1 millisecond, and read data from the GPS for you. that makes the
// loop code a heck of a lot easier!
useInterrupt(true);
delay(1000);
// Ask for firmware version
Serial1.println(PMTK_Q_RELEASE);
}
示例4: get_position_GPS
/*
Gibt die aktuelle Position als Längen- und Breitengrad, die Höhe über dem Meeresspiegel und ob eine Satellitenverbindung besteht zurück.
Parameters:
ReturnValue: gps_data.longitude; //Längengrad
gps_data.latitude; //Breitengrad
gps_data.altitude; //Höhe über mittlerem Meeresspiegel
gps_data.fix; // Satellitenverbindung vorhanden
*/
struct gps_data get_position_GPS(){
short data_received = 0;
char c;
struct gps_data output;
char * nmeaSentence = NULL;
int loop_count=0;
#if DEBUG_GPS
int debug_nmea_count=0;
#endif
/*Der Aufruf von read() muss in einer Schleife erfolgen. Durch die Festlegung der Aktualisierungsrate während der Initialisierung wird die Rate festgelegt, mit der neue Daten zur Verfügung stehen. Der Aufruf von read() muss solange wiederholt werden, bis ein vollständiger Datensatz vorgefunden wird. Es werden auch NMEA empfangen die Statusinformationen enthalten. Beispielsweise die verwendete Firmware Version. Die Variable data_received wird dann zu eins, wenn eine NMEA empfangen wurde, der eine gültige Position enthält. Ist kein fix vorhanden, kommt es zu einer Endlosschleife. Mit Loopcount wird der Vorgang abgebrochen, wenn kein fix vorhanden ist und die vorgegebene Zyklenzahl überschritten wird.*/
while(data_received == 0 && loop_count < LCGETGPS ){
loop_count++;
c = GPS.read();
/* newNMEAreceived() wertet ein Flag aus, welches indiziert, ob ein neues NMEA empfangen wurde.*/
if (GPS.newNMEAreceived()) {
/*lastNMEA() liefert den letzten empfangenen NMEA Satz zurück.*/
nmeaSentence = GPS.lastNMEA();
#if DEBUG_GPS
Serial.println(nmeaSentence); Serial.print("\n");
#endif
/*parse() extrahiert die Informationen und macht diese im GPS Objekt verfügbar.*/
GPS.parse(nmeaSentence);
/* Es muss sichergestellt werden, dass der Empfangene NMEA-Satz auch Positionsdaten
enthält. Weiterhin muss abgefragt werden, ob die Positionsdaten gültig sind.(fix vorhanden)*/
if(strstr(nmeaSentence,"GPGGA") != NULL && (short)GPS.fix == 1){
data_received=1;
}
#if DEBUG_GPS
debug_nmea_count++;
#endif
}
if((short)GPS.fix == 1){
output.longitude = GPS.longitude;
output.latitude = GPS.latitude;
output.fix = (short)GPS.fix;
output.altitude = GPS.altitude;
}
else{
output.longitude = 0.0f;
output.latitude = 0.0f;
output.fix = 0;
output.altitude = 0.0f;
}
}
#if DEBUG_GPS
Serial.print("Anzahl read() : "); Serial.print(loop_count); Serial.print("\n");
Serial.print("Anzahl empfangene NMAEA: "); Serial.print(debug_nmea_count); Serial.print("\n");
#endif
return output;
}
示例5: GPS_setup
void GPS_setup()
{
//Serial.begin(115200);
Serial.println("Adafruit GPS library basic test!");
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
GPS.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(1000);
mySerial.println(PMTK_Q_RELEASE);
}
示例6: gpsOn
void AssetTracker::gpsOn(){
// Power to the GPS is controlled by a FET connected to D6
pinMode(D6,OUTPUT);
digitalWrite(D6,LOW);
gps.begin(9600);
gps.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
delay(500);
// Default is 1 Hz update rate
gps.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
delay(500);
gps.sendCommand(PGCMD_NOANTENNA);
delay(500);
}
示例7: init_GPS
/*
Initialisiert das GPS Modul. Muss vor der Verwendung von get_position_GPS() einmalig aufgerufen werden.
*/
void init_GPS(){
/*Definiere den Ausgang zur Aktivierung des GPS-Moduls als Ausgang.*/
pinMode(PIND_ENABLE_GPS, OUTPUT);
/*Aktiviere GPS-Modul*/
enable_GPS();
/* Setze Baudrate des verwendeten HW-Serial und die interne Baudrate des Moduls.*/
GPS.begin(BAUD_GPS);
GPS_SERIAL.begin(BAUD_GPS);
/* Aktiviere RMC (Recommended Minimum) + GGA Datenstring, Der auch die Höheninformation enthält*/
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
/* Setze Updaterate des GPS-Modul auf 1Hz.*/
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
}
示例8: updateGPS
void AssetTracker::updateGPS(){
char c = gps.read();
// if a sentence is received, we can check the checksum, parse it...
if (gps.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
//Serial.println(gps.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!gps.parse(gps.lastNMEA())) {
// this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
}
}
示例9: GetData
bool GpsSensor::GetData(float array[])
{
// in case you are not using the interrupt above, you'll
// need to 'hand query' the GPS, not suggested :(
if (!usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
/*if (GPSECHO)
if (c) Serial.print(c);*/
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
//Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return 0; // we can fail to parse a sentence in which case we should just wait for another
}
array[0] = millis();
array[1] = GPS.fix;
array[2] = GPS.fixquality;
if (GPS.fix)
{
array[3] = GPS.latitude;
array[4] = GPS.longitude;
array[5] = GPS.satellites;
array[6] = GPS.altitude;
array[7] = GPS.angle;
array[8] = GPS.speed;
}
else
{
//if no fix, then set the values to 0
array[3] = 0;
array[4] = 0;
array[5] = 0;
array[6] = 0;
array[7] = 0;
array[8] = 0;
}
return 1;
}
示例10: setupGPS
void Communicator::setupGPS() {
// Initialize the variables in GPS class object
GPS.init();
// Start the serial communication
GPS_SERIAL.begin(GPS_BAUD);
// Commands to configure GPS:
GPS_SERIAL.println(PMTK_SET_NMEA_OUTPUT_RMCONLY); // Set to only output GPRMC (has all the info we need),
GPS_SERIAL.println(SET_NMEA_UPDATE_RATE_5HZ); // Increase rate strings sent over serial
GPS_SERIAL.println(PMTK_API_SET_FIX_CTL_5HZ); // Increase rate GPS 'connects' and syncs with satellites
GPS_SERIAL.println(ENABLE_SBAB_SATELLITES); // Enable using a more accurate type of satellite
GPS_SERIAL.println(ENABLE_USING_WAAS_WITH_SBSB_SATS); // Enable the above satellites in 'fix' mode (I think)
delay(3000); //Not really sure if needed.
// Flush the GPS input (still unsure if the GPS sends response to the above commands)
while (GPS_SERIAL.available()) {
//GPS_SERIAL.read();
DEBUG_PRINT("FLUSH RESPONSE: ");
DEBUG_PRINT(GPS_SERIAL.read());
DEBUG_PRINTLN("");
}
DEBUG_PRINTLN("DONE FLUSHING");
}
示例11: getCurrentLocation
Coordinate Navigation::getCurrentLocation()
{
Coordinate coord;
GPS.read();
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA()));
}
if (GPS.fix) {
coord.latitude = GPS.latitudeDegrees;
coord.longitude = GPS.longitudeDegrees;
} else {
coord.latitude = 0.000;
coord.longitude = 0.000;
}
return coord;
}
示例12: loop
void loop()
{
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
//SerialUSB.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
if (!GPS.parse(GPS.lastNMEA())) { // this also sets the newNMEAreceived() flag to false
SerialUSB.println("parsed: FAILED");
return;// continue; // we can fail to parse a sentence in which case we should just wait for another
}
else {
SerialUSB.print("\nTime: ");
SerialUSB.print(GPS.hour, DEC); SerialUSB.print(':');
SerialUSB.print(GPS.minute, DEC); SerialUSB.print(':');
SerialUSB.print(GPS.seconds, DEC); SerialUSB.print('.');
SerialUSB.println(GPS.milliseconds);
SerialUSB.print("Date: ");
SerialUSB.print(GPS.day, DEC); SerialUSB.print('/');
SerialUSB.print(GPS.month, DEC); SerialUSB.print('/');
SerialUSB.print("20"); SerialUSB.println(GPS.year, DEC);
SerialUSB.print("Fix: "); SerialUSB.print((int)GPS.fix);
SerialUSB.print(" quality: "); SerialUSB.println((int)GPS.fixquality);
if (GPS.fix) {
SerialUSB.print("Location: ");
SerialUSB.print(GPS.latitude, 4); SerialUSB.print(GPS.lat);
SerialUSB.print(", ");
SerialUSB.print(GPS.longitude, 4); SerialUSB.println(GPS.lon);
SerialUSB.print("Speed (knots): "); SerialUSB.println(GPS.speed);
SerialUSB.print("Angle: "); SerialUSB.println(GPS.angle);
SerialUSB.print("Altitude: "); SerialUSB.println(GPS.altitude);
SerialUSB.print("Satellites: "); SerialUSB.println((int)GPS.satellites);
}
}
}
else {
SerialUSB.println("!GPS.newNMEAreceived()");
}
}
示例13: Init
void GpsSensor::Init()
{
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences.
#define GPSECHO false
// this keeps track of whether we're using the interrupt
// off by default!
usingInterrupt = false;
//void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
Serial.begin(115200);
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's- some use 4800
GPS.begin(9600);
// uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// uncomment this line to turn on only the "minimum recommended" data
//GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
// For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
// the parser doesn't care about other sentences at this time
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// For the parsing code to work nicely and have time to sort thru the data, and
// print it out we don't suggest using anything higher than 1 Hz
// Request updates on antenna status, comment out to keep quiet
GPS.sendCommand(PGCMD_ANTENNA);
// the nice thing about this code is you can have a timer0 interrupt go off
// every 1 millisecond, and read data from the GPS for you. that makes the
// loop code a heck of a lot easier!
useInterrupt(true);
delay(1000);
// Ask for firmware version
mySerial.println(PMTK_Q_RELEASE);
}
示例14: setup
void setup()
{
Serial.begin(9600);
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
GPS.sendCommand(PGCMD_ANTENNA);
useInterrupt(true);
delay(1000);
mySerial.println(PMTK_Q_RELEASE);
//Serial.println("Adafruit MMA8451 test!");
if (! mma.begin()) {
//Serial.println("Couldnt start");
while (1);
}
//Serial.println("MMA8451 found!");
mma.setRange(MMA8451_RANGE_2_G);
Serial.print("Range = "); Serial.print(2 << mma.getRange());
Serial.println("G");
}
示例15: GPS_loop
void GPS_loop() // run over and over again
{
if (! usingInterrupt) {
char c = GPS.read();
if (GPSECHO)
if (c) Serial.print(c);
}
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
if (timer > millis()) timer = millis();
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
if (1){//(GPS.fix) {
Serial.print("(-1,");
Serial.print(GPS.latitudeDegrees, 5);
Serial.print(", ");
Serial.print(GPS.longitudeDegrees, 5);
Serial.println(")");
}
}
}