コード例 #1
0
ファイル: gps_acc_good.cpp プロジェクト: karlzipser/kzpy3.0
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(")");
  */

}
コード例 #2
0
ファイル: gps_module.cpp プロジェクト: marv/Wetterstation
/*
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;
}
コード例 #3
0
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
    }
  }
}
コード例 #4
0
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;
}
コード例 #5
0
ファイル: Navigation.cpp プロジェクト: johngroves/SCOUT
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;
}
コード例 #6
0
ファイル: test-1.cpp プロジェクト: hendruw/crim-flapping-bot
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()");
  }
}
コード例 #7
0
ファイル: core.cpp プロジェクト: karlzipser/kzpy3.0
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(")"); 
    }
  }
}
コード例 #8
0
void loop()
{
  //// Using this, instead of timer_interrupt
  //if (Serial1.available()) {
    //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
    //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 {
      // Format the data
      crim::GPSData gps_data;
      gps_data.set_time(GPS.hour, GPS.minute, GPS.seconds, GPS.milliseconds);
      gps_data.set_date(GPS.year, GPS.month, GPS.day);
      gps_data.set_pose(GPS.latitude, GPS.lat, GPS.longitude, GPS.lon, GPS.altitude);
      gps_data.set_misc(GPS.speed, GPS.angle);
      gps_data.set_note(GPS.fix, GPS.fixquality, GPS.satellites);

      crim::FlymaplePacketHandler packet_handler("Serial1", SERIAL1_BAUD_RATE);
      packet_handler.wrap(gps_data);
      packet_handler.send();
    }
  }
  else {
    SerialUSB.println("!GPS.newNMEAreceived()");
  }
}
コード例 #9
0
char* AssetTracker::preNMEA(){
    return gps.lastNMEA();
}
コード例 #10
0
void GpsController::process()
{
    // 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 millis() or timer wraps around, we'll just reset it
    if (timer > millis())  timer = millis();

    // approximately every 2 seconds or so, print out the current stats
    if (millis() - timer > 2000) {
        timer = millis(); // reset the timer

        Serial.print("\nTime: ");
        Serial.print(GPS.hour, DEC);
        Serial.print(':');
        Serial.print(GPS.minute, DEC);
        Serial.print(':');
        Serial.print(GPS.seconds, DEC);
        Serial.print('.');
        Serial.println(GPS.milliseconds);
        Serial.print("Date: ");
        Serial.print(GPS.day, DEC);
        Serial.print('/');
        Serial.print(GPS.month, DEC);
        Serial.print("/20");
        Serial.println(GPS.year, DEC);
        Serial.print("Fix: ");
        Serial.print((int)GPS.fix);
        Serial.print(" quality: ");
        Serial.println((int)GPS.fixquality);
        if (GPS.fix) {
            Serial.print("Location: ");
            Serial.print(GPS.latitude, 4);
            Serial.print(GPS.lat);
            Serial.print(", ");
            Serial.print(GPS.longitude, 4);
            Serial.println(GPS.lon);
            Serial.print("Location (in degrees, works with Google Maps): ");
            Serial.print(GPS.latitudeDegrees, 4);
            Serial.print(", ");
            Serial.println(GPS.longitudeDegrees, 4);

            Serial.print("Speed (knots): ");
            Serial.println(GPS.speed);
            Serial.print("Angle: ");
            Serial.println(GPS.angle);
            Serial.print("Altitude: ");
            Serial.println(GPS.altitude);
            Serial.print("Satellites: ");
            Serial.println((int)GPS.satellites);
        }
    }
}