test

Dependencies:   mbed Lab5-03_create_satcode_step6_lite HEPTA_CDH_lite HEPTA_COM_lite LPS25HB_I2C HEPTA_SENSOR_lite HEPTA_EPS_lite

Files at this revision

API Documentation at this revision

Comitter:
RyusukeIwata
Date:
Sat Aug 20 11:38:09 2022 +0000
Parent:
3:e5ae22e02335
Commit message:
test;

Changed in this revision

LPS25HB_I2C.lib Show annotated file Show diff for this revision Revisions of this file
Lab5-03_create_satcode_step6_lite.lib 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
diff -r e5ae22e02335 -r a4ea741ca530 LPS25HB_I2C.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LPS25HB_I2C.lib	Sat Aug 20 11:38:09 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/tajiri1999/code/LPS25HB_I2C/#4ea758df868a
diff -r e5ae22e02335 -r a4ea741ca530 Lab5-03_create_satcode_step6_lite.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Lab5-03_create_satcode_step6_lite.lib	Sat Aug 20 11:38:09 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/heptasat2021/code/Lab5-03_create_satcode_step6_lite/#e5ae22e02335
diff -r e5ae22e02335 -r a4ea741ca530 main.cpp
--- a/main.cpp	Tue Aug 17 11:07:04 2021 +0000
+++ b/main.cpp	Sat Aug 20 11:38:09 2022 +0000
@@ -3,103 +3,131 @@
 #include "HEPTA_CDH.h"
 #include "HEPTA_SENSOR.h"
 #include "HEPTA_COM.h"
+#include "LPS.h"
 HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd");
 HEPTA_EPS eps(PA_0,PA_4);
 HEPTA_SENSOR sensor(PA_7,PB_7,PB_6,0xD0);
 HEPTA_COM com(PA_9,PA_10,9600);
 DigitalOut condition(PB_1);
-Serial sat(USBTX,USBRX, 38400);
+DigitalOut analog_switch(PA_3);
+Serial sat(USBTX,USBRX, 9600);
+//I2C i2c(PB_7, PB_6);
+I2C i2c(D4,D5);
 Timer sattime;
+
+LPS ps(i2c);
+DigitalOut sp1(PA_1);
+Ticker press;
+Ticker sound;
+int flag = 0;            //condition flag
+float batvol, temp;      //voltage, temperature 
+int rcmd=0,cmdflag=0;    //command variable
+int i, ct = 0;
+float pressure = 0.0, altitude = 0.0, temperature = 0.0;
+float ax,ay,az,gx,gy,gz;
+char cmd1,cmd2,cmd3;
+int oto = 0;
+#define mC 261.626
+#define mD 293.665
+#define mE 329.628
+#define mF 349.228
+#define mG 391.995
+#define mA 440.000
+#define mB 493.883
+float mm[]={mC*4,mD*4,mE*4,mF*4,mG*4,mA*4,mB*4,mC*8};   //timbre
+
+void tick(void)
+{
+    sp1.write(oto);
+    oto=!oto;
+}
+
+void pre() {
+    com.printf("HEPTASAT::Time = %.4f [s], batvol = %.4f [V], temp = %.4f [deg C], altitude = %.4f [m]\r\n",sattime.read(),batvol,temp,altitude);
+    com.printf("        ::ax = %.4f, ay = %.4f, az = %.4f, gx = %.4f, gy = %.4f, gz = %.4f\r\n",ax,ay,az,gx,gy,gz);   
+    
+}
+
 int main()
 {
     sat.printf("From Sat : Nominal Operation\r\n");
     com.printf("From Sat : Nominal Operation\r\n");
-    int flag = 0; //condition flag
-    float batvol, temp; //voltage, temperature 
-    int rcmd=0,cmdflag=0;  //command variable
     sattime.start();
-    eps.turn_on_regulator();//turn on 3.3V conveter    
-    for(int i=0;i<50;i++){
+    eps.turn_on_regulator(); //turn on 3.3V conveter  
+    analog_switch = 1;       //turn on analog switch (transceiver mode)
+    
+    mkdir("/sd/mydir", 0777);
+    FILE *fp = fopen("/sd/mydir/sdtest.csv", "w");
+    if(fp == NULL) {
+        error("Could not open file for write\r\n");
+    }
+    fclose(fp);
+    
+    // initialize the pressure sensor 
+    if (!ps.init()){
+        printf("Failed to autodetect pressure sensor!\r\n");
+        while (1);
+    }
+    ps.enableDefault();     // setting the pressure sensor 
+    while(1){
         com.xbee_receive(&rcmd,&cmdflag);
-        
-        //satellite condition led
-        condition = !condition;
-        
-        //senssing HK data
-        eps.vol(&batvol);
-        sensor.temp_sense(&temp);
-        
-        //Transmitting HK data to Ground Station(GS)
-        com.printf("HEPTASAT::Condition = %d, Time = %f [s], batvol = %2f [V], temp = %2f [deg C]\r\n",flag,sattime.read(),batvol,temp);
-        wait_ms(1000);
-        
-        //Power Saving Mode 
-        if((batvol <= 3.5)  | (temp > 35.0)){
-            eps.shut_down_regulator();
-            com.printf("Power saving mode ON\r\n"); 
-            flag = 1;
-        } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) {
-            eps.turn_on_regulator();
-            com.printf("Power saving mode OFF\r\n");
-            flag = 0;
-        }
-        
         if(cmdflag == 1){
-            if(rcmd == 'a'){
-                sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
-                com.printf("Hepta-Sat Lite Uplink Ok\r\n");
-                for(int j=0;j<5;j++){
-                    com.printf("Hello World!\r\n");
-                    condition = 1;
-                    wait_ms(1000);
+            if(rcmd == 'm'){
+                com.initialize(); //initializing
+                FILE *fp = fopen("/sd/mydir/sdtest.csv", "a");
+                int count = 0;
+                press.attach(&pre, 1.0);
+                while(1){
+                    com.xbee_receive(&rcmd,&cmdflag);
+                    //satellite condition led
+                    condition = !condition;
+                    //sensing HK data
+                    eps.vol(&batvol);
+                    sensor.temp_sense(&temp);
+                    
+                    //sensing the 
+                    sensor.sen_acc(&ax,&ay,&az);
+                    sensor.sen_gyro(&gx,&gy,&gz);
+                    pressure = ps.readPressureMillibars();
+                    altitude = ps.pressureToAltitudeMeters(pressure);
+                    temperature = ps.readTemperatureC();
+                    //if((count % 10) == 0){
+//                        com.printf("HEPTASAT::Time = %.4f [s], batvol = %.4f [V], temp = %.4f [deg C], altitude = %.4f [m]\r\n",sattime.read(),batvol,temp,altitude);
+//                        com.printf("        ::ax = %.4f, ay = %.4f, az = %.4f, gx = %.4f, gy = %.4f, gz = %.4f\r\n",ax,ay,az,gx,gy,gz);
+//                    }
+                    fprintf(fp,"%f, %f, %f, %f, %f, %f, %f, %f, %f, %f\r\n",sattime.read(),batvol,temp,altitude,ax,ay,az,gx,gy,gz);
+                    wait_ms(100);
+                    if(rcmd == 'f'){
+                        fclose(fp); 
+                        press.detach();
+                        sat.printf("finish sensing\r\n");
+                        com.printf("finish sensing\r\n");
+                        break;
+                    } 
+                    count++;
                 }
-            }else if(rcmd == 'b') {
-                sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
-                com.printf("Hepta-Sat Lite Uplink Ok\r\n");
-                char str[100];
-                mkdir("/sd/mydir", 0777);
-                FILE *fp = fopen("/sd/mydir/satdata.txt","w");
-                if(fp == NULL) {
-                    error("Could not open file for write\r\n");
-                }
-                for(int i = 0; i < 10; i++) {
-                    eps.vol(&batvol);
-                    fprintf(fp,"%f\r\n",batvol);
-                    condition = 1;
-                    wait_ms(1000);
-                }
-                fclose(fp);
-                fp = fopen("/sd/mydir/satdata.txt","r");
-                for(int i = 0; i < 10; i++) {
-                    fgets(str,100,fp);
-                    com.puts(str);
+            }
+        }
+        if(rcmd == 'e'){
+            sat.printf("From Sat : End of while\r\n");
+            com.printf("From Sat : End of while\r\n");
+            com.initialize(); //initializing
+            while(1){
+                com.xbee_receive(&rcmd,&cmdflag);
+                if(rcmd == 'z'){
+                    oto = 0;
+                    break;
                 }
-                fclose(fp);
-            }else if(rcmd == 'c'){
-                sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
-                com.printf("Hepta-Sat Lite Uplink Ok\r\n");
-                float ax,ay,az;
-                for(int i = 0; i < 10; i++) {
-                    sensor.sen_acc(&ax,&ay,&az);
-                    com.printf("%f,%f,%f\r\n",ax,ay,az);
-                    wait_ms(1000); 
+                for(i=0;i < sizeof(mm)/sizeof(mm[0]);i++) {
+                    sound.attach(&tick,1.0/mm[i]/2.0);  //If warning appear, ignore
+                    wait(0.5f);
                 }
-            }else if(rcmd == 'd'){
-                sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
-                com.printf("Hepta-Sat Lite Uplink Ok\r\n");
-                float gx,gy,gz;
-                for(int i = 0; i < 10; i++) {
-                    sensor.sen_gyro(&gx,&gy,&gz);
-                    com.printf("%f,%f,%f\r\n",gx,gy,gz); 
-                    wait_ms(1000);   
-                }            
-            }else if(rcmd == 'e'){
-                
-                
-                
+                sound.detach();
+                i = 0;
             }
-            com.initialize(); //initializing
+            break;
         }
+        com.initialize(); //initializing
     }
     sattime.stop();
     sat.printf("From Sat : End of operation\r\n");