Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Servo TMP36 GZ buffered-serial1 chan_fatfs_sd nmea_parser watchdog mbed-rtos mbed
Fork of HARP2 by
Diff: main.cpp
- Revision:
- 26:85cdb1031eb1
- Parent:
- 25:81c3696ba2c9
- Child:
- 27:24fd8e32511c
--- 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);
}
}
