rev_20211121
Dependencies: HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH
main.cpp@27:b4689aa48bf5, 2020-07-22 (annotated)
- Committer:
- MEXT1
- Date:
- Wed Jul 22 03:11:16 2020 +0000
- Revision:
- 27:b4689aa48bf5
- Parent:
- 26:220e5f95168a
- Child:
- 28:60f73cc07244
202007
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
HeptaSatTraining2019 | 25:ccc5ff675e0c | 2 | #include "HEPTA_CDH.h" |
HeptaSatTraining2019 | 25:ccc5ff675e0c | 3 | #include "HEPTA_EPS.h" |
MEXT1 | 27:b4689aa48bf5 | 4 | #include "HEPTA_SENSOR.h" |
MEXT1 | 27:b4689aa48bf5 | 5 | #include "HEPTA_COM.h" |
MEXT1 | 27:b4689aa48bf5 | 6 | DigitalOut cond[]={LED1,LED2,LED3,LED4}; |
MEXT1 | 27:b4689aa48bf5 | 7 | Serial gs(USBTX,USBRX); // for ground station |
HeptaSatTraining2019 | 26:220e5f95168a | 8 | HEPTA_CDH cdh(p5, p6, p7, p8, "sd"); |
HeptaSatTraining2019 | 26:220e5f95168a | 9 | HEPTA_EPS eps(p16,p26); |
MEXT1 | 27:b4689aa48bf5 | 10 | HEPTA_SENSOR sensor(p17, |
MEXT1 | 27:b4689aa48bf5 | 11 | p28,p27,0xD0,0x18, |
MEXT1 | 27:b4689aa48bf5 | 12 | p13,p14,p25,p24); |
MEXT1 | 27:b4689aa48bf5 | 13 | HEPTA_COM com(p9,p10); |
MEXT1 | 27:b4689aa48bf5 | 14 | int rcmd = 0,cmdflag = 0; //command variable |
HeptaSatTraining2019 | 24:3659e0c223c8 | 15 | |
MEXT1 | 27:b4689aa48bf5 | 16 | //getting command and flag |
HeptaSatTraining2019 | 26:220e5f95168a | 17 | void commandget() |
HeptaSatTraining2019 | 26:220e5f95168a | 18 | { |
MEXT1 | 27:b4689aa48bf5 | 19 | rcmd=com.getc(); |
HeptaSatTraining2019 | 26:220e5f95168a | 20 | cmdflag = 1; |
HeptaSatTraining2019 | 26:220e5f95168a | 21 | } |
MEXT1 | 27:b4689aa48bf5 | 22 | //interrupting |
MEXT1 | 27:b4689aa48bf5 | 23 | void receive(int rcmd, int cmdflag) |
HeptaSatTraining2019 | 26:220e5f95168a | 24 | { |
MEXT1 | 27:b4689aa48bf5 | 25 | com.xbee.attach(commandget,Serial::RxIrq); |
HeptaSatTraining2019 | 26:220e5f95168a | 26 | } |
MEXT1 | 27:b4689aa48bf5 | 27 | //initialzing |
HeptaSatTraining2019 | 26:220e5f95168a | 28 | void initialize() |
HeptaSatTraining2019 | 26:220e5f95168a | 29 | { |
HeptaSatTraining2019 | 26:220e5f95168a | 30 | rcmd = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 31 | cmdflag = 0; |
MEXT1 | 27:b4689aa48bf5 | 32 | cond[0] = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 33 | } |
MEXT1 | 27:b4689aa48bf5 | 34 | int main() { |
MEXT1 | 27:b4689aa48bf5 | 35 | gs.baud(9600); |
MEXT1 | 27:b4689aa48bf5 | 36 | float sattime=0.0,btvol,temp; |
MEXT1 | 27:b4689aa48bf5 | 37 | float ax,ay,az; |
MEXT1 | 27:b4689aa48bf5 | 38 | float gx,gy,gz; |
MEXT1 | 27:b4689aa48bf5 | 39 | float mx,my,mz; |
MEXT1 | 27:b4689aa48bf5 | 40 | int quality=0,stnum=0,gps_check=0; |
MEXT1 | 27:b4689aa48bf5 | 41 | char ns='A',ew='B',aunit='m'; |
MEXT1 | 27:b4689aa48bf5 | 42 | float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0; |
MEXT1 | 27:b4689aa48bf5 | 43 | int flag = 0; // condition |
MEXT1 | 27:b4689aa48bf5 | 44 | receive(rcmd,cmdflag); //interupting by ground station command |
MEXT1 | 27:b4689aa48bf5 | 45 | |
MEXT1 | 27:b4689aa48bf5 | 46 | com.printf("From Sat : Operation Start...\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 47 | for(int i = 0; i < 100; i++) { |
MEXT1 | 27:b4689aa48bf5 | 48 | //Sensing and Transmitting HK data , Power Saving Mode |
MEXT1 | 27:b4689aa48bf5 | 49 | eps.power_saving_mode(&flag,&btvol); |
MEXT1 | 27:b4689aa48bf5 | 50 | sensor.temp_sense(&temp); |
MEXT1 | 27:b4689aa48bf5 | 51 | com.printf("HEPTASAT::Condition = %d, Time = %f [s], BatVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime,btvol,temp); |
MEXT1 | 27:b4689aa48bf5 | 52 | //Condition |
MEXT1 | 27:b4689aa48bf5 | 53 | cond[0] = 1; |
MEXT1 | 27:b4689aa48bf5 | 54 | //Warning the status of temperature and battery voltage |
MEXT1 | 27:b4689aa48bf5 | 55 | if(flag == 1) { |
MEXT1 | 27:b4689aa48bf5 | 56 | com.printf("Low Battery\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 57 | } else if(temp > 35.0) { |
MEXT1 | 27:b4689aa48bf5 | 58 | com.printf("High temperature\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 59 | } else if((flag == 1) & (temp > 35.0)) { |
MEXT1 | 27:b4689aa48bf5 | 60 | com.printf("Low Battery and High temperature\n"); |
HeptaSatTraining2019 | 26:220e5f95168a | 61 | } |
MEXT1 | 27:b4689aa48bf5 | 62 | //Contents of command |
HeptaSatTraining2019 | 26:220e5f95168a | 63 | if (cmdflag == 1) { |
HeptaSatTraining2019 | 26:220e5f95168a | 64 | if (rcmd == 'a') { |
MEXT1 | 27:b4689aa48bf5 | 65 | for(int j=0;j<5;j++){ |
MEXT1 | 27:b4689aa48bf5 | 66 | com.printf("HEPTASAT::Hello World!\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 67 | cond[0] = 0; |
MEXT1 | 27:b4689aa48bf5 | 68 | wait(1); |
MEXT1 | 27:b4689aa48bf5 | 69 | cond[0] = 1; |
MEXT1 | 27:b4689aa48bf5 | 70 | } |
HeptaSatTraining2019 | 26:220e5f95168a | 71 | } |
HeptaSatTraining2019 | 26:220e5f95168a | 72 | if (rcmd == 'b') { |
MEXT1 | 27:b4689aa48bf5 | 73 | char str[100]; |
MEXT1 | 27:b4689aa48bf5 | 74 | mkdir("/sd/mydir", 0777); |
MEXT1 | 27:b4689aa48bf5 | 75 | FILE *fp = fopen("/sd/mydir/test.txt","w"); |
MEXT1 | 27:b4689aa48bf5 | 76 | if(fp == NULL) { |
MEXT1 | 27:b4689aa48bf5 | 77 | error("Could not open file for write\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 78 | } |
MEXT1 | 27:b4689aa48bf5 | 79 | else |
MEXT1 | 27:b4689aa48bf5 | 80 | { |
MEXT1 | 27:b4689aa48bf5 | 81 | for(int i = 0; i < 10; i++) { |
MEXT1 | 27:b4689aa48bf5 | 82 | eps.vol(&btvol); |
MEXT1 | 27:b4689aa48bf5 | 83 | fprintf(fp,"%f\r\n",btvol); |
MEXT1 | 27:b4689aa48bf5 | 84 | wait(1.0); |
MEXT1 | 27:b4689aa48bf5 | 85 | } |
MEXT1 | 27:b4689aa48bf5 | 86 | fclose(fp); |
MEXT1 | 27:b4689aa48bf5 | 87 | fp = fopen("/sd/mydir/test.txt","r"); |
MEXT1 | 27:b4689aa48bf5 | 88 | for(int j = 0; j < 10; j++) { |
MEXT1 | 27:b4689aa48bf5 | 89 | fgets(str,100,fp); |
MEXT1 | 27:b4689aa48bf5 | 90 | com.printf("%s",str); |
MEXT1 | 27:b4689aa48bf5 | 91 | } |
MEXT1 | 27:b4689aa48bf5 | 92 | fclose(fp); |
MEXT1 | 27:b4689aa48bf5 | 93 | } |
MEXT1 | 27:b4689aa48bf5 | 94 | cond[0] = 0; |
MEXT1 | 27:b4689aa48bf5 | 95 | wait(1); |
MEXT1 | 27:b4689aa48bf5 | 96 | cond[0] = 1; |
MEXT1 | 27:b4689aa48bf5 | 97 | } |
MEXT1 | 27:b4689aa48bf5 | 98 | if (rcmd == 'c') { |
MEXT1 | 27:b4689aa48bf5 | 99 | sensor.temp_sense(&temp); |
MEXT1 | 27:b4689aa48bf5 | 100 | sensor.sen_gyro(&gx,&gy,&gz); |
MEXT1 | 27:b4689aa48bf5 | 101 | sensor.sen_acc(&ax,&ay,&az); |
MEXT1 | 27:b4689aa48bf5 | 102 | sensor.sen_mag(&mx,&my,&mz); |
MEXT1 | 27:b4689aa48bf5 | 103 | sensor.gga_sensing(&time,&latitude,&ns,&longitude,&ew,&quality,&stnum,&hacu,&altitude,&aunit,&gps_check); |
MEXT1 | 27:b4689aa48bf5 | 104 | com.printf("temp=%f\r\n",temp); |
MEXT1 | 27:b4689aa48bf5 | 105 | com.printf("gx=%f,gy=%f,gz=%f\r\n",gx,gy,gz); |
MEXT1 | 27:b4689aa48bf5 | 106 | com.printf("ax=%f,ay=%f,az=%f\r\n",ax,ay,az); |
MEXT1 | 27:b4689aa48bf5 | 107 | com.printf("mx=%f,my=%f,mz=%f\r\n",mx,my,mz); |
MEXT1 | 27:b4689aa48bf5 | 108 | com.printf("latitude=%f, longtitude=%f, altitude%f\r\n",latitude,longitude,altitude); |
MEXT1 | 27:b4689aa48bf5 | 109 | cond[0] = 0; |
MEXT1 | 27:b4689aa48bf5 | 110 | wait(1); |
MEXT1 | 27:b4689aa48bf5 | 111 | cond[0] = 1; |
MEXT1 | 27:b4689aa48bf5 | 112 | } |
MEXT1 | 27:b4689aa48bf5 | 113 | if (rcmd == 'd') { |
MEXT1 | 27:b4689aa48bf5 | 114 | com.printf("Start to take a picture\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 115 | sensor.Sync(); |
MEXT1 | 27:b4689aa48bf5 | 116 | sensor.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution320x240); |
MEXT1 | 27:b4689aa48bf5 | 117 | com.printf("[ OK ]:Picture taken\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 118 | sensor.test_jpeg_snapshot_picture("/sd/MissionData/picture.jpg"); |
MEXT1 | 27:b4689aa48bf5 | 119 | com.printf("Finish saving in SD\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 120 | cond[0] = 0; |
MEXT1 | 27:b4689aa48bf5 | 121 | wait(1); |
MEXT1 | 27:b4689aa48bf5 | 122 | cond[0] = 1; |
MEXT1 | 27:b4689aa48bf5 | 123 | } |
MEXT1 | 27:b4689aa48bf5 | 124 | if (rcmd == 'e') { |
HeptaSatTraining2019 | 26:220e5f95168a | 125 | |
HeptaSatTraining2019 | 26:220e5f95168a | 126 | |
HeptaSatTraining2019 | 26:220e5f95168a | 127 | |
HeptaSatTraining2019 | 26:220e5f95168a | 128 | } |
HeptaSatTraining2019 | 26:220e5f95168a | 129 | initialize(); |
HeptaSatTraining2019 | 26:220e5f95168a | 130 | } |
MEXT1 | 27:b4689aa48bf5 | 131 | |
MEXT1 | 27:b4689aa48bf5 | 132 | //Operation Interval |
MEXT1 | 27:b4689aa48bf5 | 133 | wait(1.0); |
MEXT1 | 27:b4689aa48bf5 | 134 | sattime = sattime+1.0; |
HeptaSatTraining2019 | 24:3659e0c223c8 | 135 | } |
MEXT1 | 27:b4689aa48bf5 | 136 | com.printf("From Sat : Operation Stop...\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 137 | } |