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);
}
Exemple #2
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(")");
  */

}
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);
}
Exemple #4
0
/*
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;
}
Exemple #5
0
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);
}
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);
}
Exemple #7
0
/*
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);  

}
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
    }
  }
}
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;
}
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");

}
Exemple #11
0
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;
}
Exemple #12
0
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()");
  }
}
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);
}
Exemple #14
0
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");
}
Exemple #15
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(")"); 
    }
  }
}
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()");
  }
}
void Communicator::getSerialDataFromGPS() {

    while (GPS_SERIAL.available()) {

        nmeaBuf[nmeaBufInd] = GPS_SERIAL.read();
        //DEBUG_PRINT(nmeaBuf[nmeaBufInd]);
        if (nmeaBuf[nmeaBufInd++] == '\n') { // Increment index after checking if current character signifies the end of a string
            nmeaBuf[nmeaBufInd - 1] = '\0'; // Add null terminating character (note: -1 is because nmeaBufInd is incremented in if statement)
            newParsedData = GPS.parse(nmeaBuf); 	// This parses the string, and updates the values of GPS.lattitude, GPS.longitude etc.
            nmeaBufInd = 0;  // Regardless of it parsing sucessful, we want to reset position back to zero
        }

        if (nmeaBufInd >= MAXLINELENGTH) { // Should never happen. Means a corrupted packed and the newline was missed. Good to have just in case
            nmeaBufInd = 0;  // Note the next packet will then have been corrupted as well. Can't really recover until the next-next packet
        }
        //DEBUG_PRINTLN("");

    }

}
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);
        }
    }
}
void timer_int_handler(void) {
  GPS.read();
}
char* AssetTracker::preNMEA(){
    return gps.lastNMEA();
}