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 Tyler Weaver

Files at this revision

API Documentation at this revision

Comitter:
tylerjw
Date:
Thu Jan 10 19:03:34 2013 +0000
Parent:
25:81c3696ba2c9
Child:
27:24fd8e32511c
Commit message:
Tested file append

Changed in this revision

BMP085.lib Show diff for this revision Revisions of this file
TMP36-GZ.lib Show annotated file Show diff for this revision Revisions of this file
config.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/BMP085.lib	Fri Dec 28 17:12:27 2012 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/tylerjw/code/BMP085/#0b4c4632aeb0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TMP36-GZ.lib	Thu Jan 10 19:03:34 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/tylerjw/code/TMP36-GZ/#2b0feb7bdebc
--- a/config.h	Fri Dec 28 17:12:27 2012 +0000
+++ b/config.h	Thu Jan 10 19:03:34 2013 +0000
@@ -3,7 +3,7 @@
 #ifndef HARP_CONFIG_H
 #define HARP_CONFIG_H
 
-#define WAIT_FOR_LOCK   1 // set to 1 to not open log file until gps lock
+#define WAIT_FOR_LOCK   0 // set to 1 to not open log file until gps lock
 #define UNLOCK_ON_FALL  0 // set to 1 to not signal parachute untill falling
 
 const float target_lat = 39.921664;    // for setting the target location!
--- a/main.cpp	Fri Dec 28 17:12:27 2012 +0000
+++ b/main.cpp	Thu Jan 10 19:03:34 2013 +0000
@@ -1,28 +1,31 @@
 /**
 * HARP Version 2
+*
+* TODO: Test Servo Code
+*       Test Watchdog Timer
+*       Test Append file and f_size() macro
 */
 
 #include "mbed.h"
 #include "rtos.h"
 #include "buffered_serial.h"
 #include "ff.h"
-#include "BMP085.h"
+#include "TMP36GZ.h"
 #include "nmea_parser.h"
 #include "watchdog.h"
 #include "Servo.h"
 #include "config.h"
 
-I2C i2c(p9, p10); // sda, scl
-BMP085 alt_sensor(i2c);
-
 Serial pc(USBTX, USBRX);
 BufferedSerial gps;
 AnalogIn gps_battery(p20);
-AnalogIn mbed_battery(p19);
+AnalogIn mbed_battery(p16);
+TMP36GZ temperature(p17);
 
 NmeaParser nmea;
 
 Semaphore parachute_sem(0);
+Semaphore sd_sem(0);
 
 typedef struct {
     char    line[80];
@@ -83,10 +86,12 @@
 
     f_mount(0, &fs);
     f_open(&fp_gps, "0:gps.txt", FA_OPEN_EXISTING | FA_WRITE);
-    f_lseek(&fp_gps, f_size(&fp_gps));                                  // NOT TESTED!!!
+    f_lseek(&fp_gps, f_size(&fp_gps));
     f_open(&fp_sensor, "0:sensors.csv", FA_OPEN_EXISTING | FA_WRITE);
-    f_lseek(&fp_sensor, f_size(&fp_sensor));                            // NOT TESTED!!!
+    f_lseek(&fp_sensor, f_size(&fp_sensor));
 
+    sd_sem.release(); // sd card initialized... start sensor thread
+    
     while(1) {
         log_led = !log_led;
         osEvent evt1 = queue_gps_line.get(1);
@@ -117,8 +122,9 @@
     Timer t;
     float time;
     float gps_battery_voltage, mbed_battery_voltage;
-    float bmp_temperature, bmp_altitude;
-    int bmp_pressure;
+    float temp;
+    
+    sd_sem.wait(); // wait for the sd card to initialize and open files
 
     if(WAIT_FOR_LOCK) {
         while(!nmea.date())  Thread::wait(100); // wait for lock
@@ -127,7 +133,11 @@
     t.start(); // start timer after lock
 
     sensor_line *message = mpool_sensor_line.alloc();
-    sprintf(message->line, "Date: %d, Time: %f\r\nGPS Time (UTC),GPS Battery(V),mbed Battery(V),BMP085 Temperature(C),Pressure,Altitude(ft),GPS Altitude, GPS Course\r\n", nmea.date(), nmea.utc_time());
+    sprintf(message->line, "Date: %d, Time: %f\r\nGPS Time (UTC),GPS Battery(V),mbed Battery(V)", nmea.date(), nmea.utc_time());
+    queue_sensor_line.put(message);
+    
+    message = mpool_sensor_line.alloc();
+    sprintf(message->line, ",Temperature,GPS Altitude,GPS Course \r\n");
     queue_sensor_line.put(message);
 
     while(true) {
@@ -144,13 +154,13 @@
         //mbed battery
         mbed_battery_voltage = mbed_battery.read()*BAT_MBED_MUL;
 
-        //BMP085
-        bmp_temperature = (float)alt_sensor.get_temperature() / 10.0;
-        bmp_pressure = alt_sensor.get_pressure();
-        bmp_altitude = alt_sensor.get_altitude_ft();
+        //temperature
+        temp = temperature.sample_f();
 
-        sprintf(message->line, "%f,%f,%f,%f,%d,%f,%f,%f\r\n", time,gps_battery_voltage,mbed_battery_voltage,bmp_temperature,bmp_pressure,bmp_altitude,nmea.calc_altitude_ft(),nmea.track());
+        sprintf(message->line, "%f,%f,%f,%f,%f,%f\r\n", time,gps_battery_voltage,mbed_battery_voltage,temp,nmea.calc_altitude_ft(),nmea.track());
         queue_sensor_line.put(message);
+        
+        Thread::wait(100);
     }
 }