Generation 3 of the Harp project
Dependencies: Servo TMP36 GZ buffered-serial1 chan_fatfs_sd nmea_parser watchdog mbed-rtos mbed
Fork of HARP2 by
Revision 6:204487243310, committed 2012-02-24
- Comitter:
- tylerjw
- Date:
- Fri Feb 24 21:28:33 2012 +0000
- Parent:
- 5:8444ec4245e7
- Child:
- 7:d8ecabe16c9e
- Commit message:
- altitude if ft, updated and fixed bugs
Changed in this revision
--- a/GPS/GPS.cpp Thu Feb 23 05:40:54 2012 +0000 +++ b/GPS/GPS.cpp Fri Feb 24 21:28:33 2012 +0000 @@ -30,6 +30,8 @@ speed_k_unit = ' '; speed_km = 0.0; // speek km/hr speed_km_unit = ' '; + + altitude_ft = 0.0; #ifdef OPEN_LOG is_logging = false; #endif @@ -63,29 +65,30 @@ int GPS::sample() { int line_parsed = 0; - while (_gps.readable()) { + if (_gps.readable()) { getline(); - + #ifdef OPEN_LOG if (is_logging && lock) { - _openLog.write(msg); + format_for_log(); + _openLog.write(bfr); } #endif // Check if it is a GPGGA msg (matches both locked and non-locked msg) - if (sscanf(msg, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c", &utc_time, &nmea_latitude, &ns, &nmea_longitude, &ew, &lock, &satelites, &hdop, &msl_altitude, &msl_units) >= 1) { + if (sscanf(msg, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c", &utc_time, &nmea_latitude, &ns, &nmea_longitude, &ew, &lock, &satelites, &hdop, &msl_altitude, &msl_units) >= 1) { line_parsed = GGA; } // Check if it is a GPRMC msg - else if (sscanf(msg, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,%f,%d", &utc_time, &rmc_status, &nmea_latitude, &ns, &nmea_longitude, &ew, &speed_k, &course_d, &date) >= 1) { + else if (sscanf(msg, "GPRMC,%f,%c,%f,%c,%f,%c,%f,%f,%d", &utc_time, &rmc_status, &nmea_latitude, &ns, &nmea_longitude, &ew, &speed_k, &course_d, &date) >= 1) { line_parsed = RMC; } // GLL - Geographic Position-Lat/Lon - else if (sscanf(msg, "$GPGLL,%f,%c,%f,%c,%f,%c", &nmea_latitude, &ns, &nmea_longitude, &ew, &utc_time, &gll_status) >= 1) { + else if (sscanf(msg, "GPGLL,%f,%c,%f,%c,%f,%c", &nmea_latitude, &ns, &nmea_longitude, &ew, &utc_time, &gll_status) >= 1) { line_parsed = GLL; } // VTG-Course Over Ground and Ground Speed - else if (sscanf(msg, "$GPVTG,%f,%c,%f,%c,%f,%c,%f,%c", &course_t, &course_t_unit, &course_m, &course_m_unit, &speed_k, &speed_k_unit, &speed_km, &speed_km_unit) >= 1) { + else if (sscanf(msg, "GPVTG,%f,%c,%f,%c,%f,%c,%f,%c", &course_t, &course_t_unit, &course_m, &course_m_unit, &speed_k, &speed_k_unit, &speed_km, &speed_km_unit) >= 1) { line_parsed = VTG; } } @@ -110,15 +113,29 @@ } void GPS::getline() { - for(int i=0; i<1022; i++) { + while (_gps.getc() != '$'); // wait for the start of a line + for (int i=0; i<1022; i++) { msg[i] = _gps.getc(); - if(msg[i] == '\r') { - msg[i+1] = '\n'; - msg[i+2] = 0; + if (msg[i] == '\r') { + msg[i] = 0; return; } } - error("Overflowed message limit"); + error("Overflow in getline"); +} + +void GPS::format_for_log() { + bfr[0] = '$'; + for (int i = 0; i < 1022; i++) { + bfr[i+1] = msg[i]; + if (msg[i] == 0) { + bfr[i+1] = '\r'; + bfr[i+2] = '\n'; + bfr[i+3] = 0; + return; + } + } + error("Overflow in format"); } float GPS::get_msl_altitude() { @@ -191,4 +208,11 @@ return 0.0; else return speed_km; +} + +float GPS::get_altitude_ft() { + if (!lock) + return 0.0; + else + return 3.280839895*msl_altitude; } \ No newline at end of file
--- a/GPS/GPS.h Thu Feb 23 05:40:54 2012 +0000 +++ b/GPS/GPS.h Fri Feb 24 21:28:33 2012 +0000 @@ -34,6 +34,10 @@ float get_speed_k(); float get_speed_km(); int get_satelites(); + float get_altitude_ft(); + + //float calc_course_to(float, float); + //float calc_dist_to(float, float); #ifdef OPEN_LOG void start_log(void); @@ -45,9 +49,11 @@ float nmea_to_dec(float, char); float trunc(float v); void getline(); + void format_for_log(void); Serial _gps; char msg[1024]; + char bfr[1030]; bool is_logging; #ifdef OPEN_LOG Logger _openLog; @@ -55,6 +61,7 @@ // calculated values float dec_longitude; float dec_latitude; + float altitude_ft; // GGA - Global Positioning System Fixed Data float nmea_longitude;
--- a/main.cpp Thu Feb 23 05:40:54 2012 +0000 +++ b/main.cpp Fri Feb 24 21:28:33 2012 +0000 @@ -6,6 +6,7 @@ GPS gps(p9, p10); int main() { + pc.baud(9600); int gps_message; gps.start_log(); while (1) { @@ -14,6 +15,7 @@ pc.printf("Responding to GGA message.\n"); pc.printf("I'm at %f, %f\n", gps.get_dec_latitude(), gps.get_dec_longitude()); pc.printf("%d satelites used\n", gps.get_satelites()); + pc.printf("altitude = %f ft\n", gps.get_altitude_ft()); pc.printf("altitude = %f M\n\n", gps.get_msl_altitude()); } else if (gps_message == VTG) { pc.printf("Responding to VTG message.\n"); @@ -29,6 +31,8 @@ pc.printf("I'm at %f, %f\n", gps.get_dec_latitude(), gps.get_dec_longitude()); pc.printf("True heading = %f deg\n", gps.get_course_t()); pc.printf("Speed = %f knots\n\n", gps.get_speed_k()); + } else if (gps_message == NOT_PARSED) { + pc.printf("Message not parsed!\n"); } else if (gps_message == NO_LOCK) { pc.printf("Oh Dear! No lock :(\n"); }