For Cansat EM

Dependencies:   IMU_I2C IMUfilter SCP1000 SDFileSystem mbed nmea0813 myCAN_logger

Files at this revision

API Documentation at this revision

Comitter:
YSB
Date:
Sun Jul 21 07:03:02 2013 +0000
Parent:
1:ecddbd10ab4c
Child:
3:33a9e207e309
Commit message:
latest version at 0721

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
myCAN.lib Show annotated file Show diff for this revision Revisions of this file
nmea0813.lib Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sat Jul 13 17:02:51 2013 +0000
+++ b/main.cpp	Sun Jul 21 07:03:02 2013 +0000
@@ -4,6 +4,8 @@
 #include "IMU_I2C.h"
 #include "nmea0813.h"
 #include "SCP1000.h"
+#include "myCAN.h"
+#include "IDDATA.h"
 
 //for debug
     DigitalOut myled(LED1);
@@ -11,6 +13,7 @@
     Ticker pc_msg;
 //for logging
     SDFileSystem sd(p5, p6, p7, p8, "sd");
+    DigitalIn SD(p17);
     IMUfilter imuFilter(FILTER_RATE, 0.3);
     IMU_I2C accelerometer(p9, p10);
     GPS gps(p28,p27);
@@ -20,24 +23,19 @@
     Ticker accelerometerTicker;
     Ticker gyroscopeTicker;
     Ticker filterTicker;
+    Ticker logging;
 //for communication with mission_mbed
-    CAN can(p30, p29);
-    Ticker can_msg;
+    myCAN can(p30, p29);
 
 //for pc_msg
     #define PC_BAUD 9600
     #define PC_RATE 0.3
     void pc_flg_on(void);
     char pc_flg = 0;
-    
-//for CAN
-    #define CAN_BAUD 4000000
-    #define CAN_RATE 0.05
-    void can_flg_on(void);
-    char can_flg,can_flg2;
-    int  id;
-    char dmsg[8];
-
+//for logging
+    #define LOG_RATE 0.3//0.04
+    char log_flg;
+    void log_flg_on(void);
 
 //Offsets for the gyroscope and the accelerometer.
     double w_xBias;
@@ -216,8 +214,8 @@
     pc_flg = 1;
 }
 
-void can_flg_on(void) {
-    can_flg = 1;
+void log_flg_on(void){
+    log_flg = 1;
 }
 
 int main() {
@@ -244,63 +242,46 @@
         pc.baud(PC_BAUD);
         pc_msg.attach(&pc_flg_on,PC_RATE);
     
-    //for CAN
-        can.frequency(CAN_BAUD);
-        can_msg.attach(&can_flg_on,CAN_RATE);
-        CANMessage msg;
+    //for logging
+        logging.attach(&log_flg_on,LOG_RATE);
+    
+    int a_zi;
+    a_zi=0;
     
     while(1){
-    
-        if(can.read(msg)) {
-            pc.printf("Message received: %d\n\r", msg.data[0]);
-            if(msg.data[0]==1){can_flg2=1;}
-        } 
-    
+        //for can send
+            if(a_z > 9.6){a_zi=1;}
+            else{a_zi=0;}         
+            can.make_logger_senddata(gps.get_time(),gps.get_satelite_number(),gps.get_str_latitude(),gps.get_str_longitude(),a_zi,(int)(scp1000.readTemperature()*20),scp1000.readPressure());
+            can.send(LOGGER);
         //for logging
-            
-            mkdir("/sd/mydir", 0777);
-            FILE *fp = fopen("/sd/mydir/kikyuu.txt", "a");
-            if(fp == NULL){error("Could not open file for write\n");}
-            fprintf(fp,"time:%s,latitude:%f,longitude:%f,status:%c,satelite:%c,speed:%f,",gps.get_time(),gps.get_latitude(),gps.get_longitude(),gps.get_status(),gps.get_satelite_number(),gps.get_speed());
-            //fprintf(fp,"roll:%f,pitch:%f,",toDegrees(imuFilter.getRoll()),toDegrees(imuFilter.getPitch()));
-            fprintf(fp,"pressure:%d,temperature:%f\r\n", scp1000.readPressure(), scp1000.readTemperature());
-            fprintf(fp,"%s,%f,%f,%f,%f,%f,%f\r\n",gps.get_time(),w_y, w_x, w_z, a_y, a_x, a_z);
-            fclose(fp);
-            
+            if(log_flg == 1){
+                if(SD == 1){
+                    mkdir("/sd/mydir", 0777);
+                    FILE *fp = fopen("/sd/mydir/ver2.txt", "a");
+                    if(fp == NULL){
+                        //error("Could not open file for write\n");
+                        pc.printf("SD_error");
+                    }else{
+                        fprintf(fp,"time:%s,latitude:%f,longitude:%f,status:%c,satelite:%c,speed:%f,",gps.get_time(),gps.get_latitude(),gps.get_longitude(),gps.get_status(),gps.get_satelite_number(),gps.get_speed());
+                        //fprintf(fp,"roll:%f,pitch:%f,",toDegrees(imuFilter.getRoll()),toDegrees(imuFilter.getPitch()));
+                        fprintf(fp,"pressure:%d,temperature:%f\r\n", scp1000.readPressure(), scp1000.readTemperature());
+                        fprintf(fp,"%s,%f,%f,%f,%f,%f,%f\r\n",gps.get_time(),w_y, w_x, w_z, a_y, a_x, a_z);
+                        fclose(fp);
+                    }
+                }
+            }
         
         //for pc debug
             if(pc_flg == 1){
                 pc.printf("%f,%f,%f,%f,%f,%f\r\n",w_y, w_x, w_z, a_y, a_x, a_z);
+                pc.printf("%d\r\n",a_zi);
                 //pc.printf("%f,%f,%f,%f,%f,%f\r\n",a_xBias, a_yBias, a_zBias, w_xBias, w_yBias, w_zBias);
-                pc.printf("pressure:%d,temperature:%f\r\n", scp1000.readPressure(), scp1000.readTemperature());
+                //pc.printf("pressure:%d,temperature:%f\r\n", scp1000.readPressure(), scp1000.readTemperature());
                 pc.printf("time:%s,latitude:%f,longitude:%f,status:%c,satelite:%c,speed:%f\r\n",gps.get_time(),gps.get_latitude(),gps.get_longitude(),gps.get_status(),gps.get_satelite_number(),gps.get_speed());
                 //pc.printf("%f,%f,%d,%f\r\n",toDegrees(imuFilter.getRoll()),toDegrees(imuFilter.getPitch()),scp1000.readPressure(), scp1000.readTemperature());
                 pc.printf("\n\r");
-                //pc.printf("%i,%i\n\r",dmsg[0],dmsg[2]);
-                //pc.printf("\n\r");
                 pc_flg =0;
             }
-        //for can send
-            if(can_flg == 1){
-                if(can_flg2==1){
-                    id = 1;
-                    if(a_z > 9.5){
-                        dmsg[0]=1;//roll}
-                        dmsg[2]=1;
-                    }
-                    else{dmsg[0]=0;}
-                    dmsg[1]=0;//pitch
-                    //msg[2]=0;
-                    /*
-                    dmsg[3]=0;
-                    dmsg[4]=0;
-                    dmsg[5]=0;
-                    dmsg[6]=0;
-                    dmsg[7]=0;
-                    */
-                    can.write(CANMessage(id,dmsg)); 
-                    can_flg=0;
-                }
-            }
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/myCAN.lib	Sun Jul 21 07:03:02 2013 +0000
@@ -0,0 +1,1 @@
+myCAN#89073e0112db
--- a/nmea0813.lib	Sat Jul 13 17:02:51 2013 +0000
+++ b/nmea0813.lib	Sun Jul 21 07:03:02 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/YSB/code/nmea0813/#7870c69fa58c
+http://mbed.org/users/YSB/code/nmea0813/#84d63345eb80