![](/media/cache/profiles/2e74f94b232c5a0cc3e75b4eaaf64c90.jpg.50x50_q85.jpg)
simulate satellite program structure
Dependencies: mbed HeptaBattery SDFileSystem HeptaCamera_GPS Hepta9axis HeptaTemp HeptaXbee
Fork of Lab7-01_template by
main.cpp@25:b9b1257f6e9a, 2019-08-21 (annotated)
- Committer:
- HEPTA
- Date:
- Wed Aug 21 09:49:18 2019 +0000
- Revision:
- 25:b9b1257f6e9a
- Parent:
- 24:8bdc026b996f
- Child:
- 26:b246e83efad4
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
umeume | 2:1c5cdb2c3e0f | 3 | #include "HeptaXbee.h" |
umeume | 2:1c5cdb2c3e0f | 4 | #include "HeptaCamera_GPS.h" |
umeume | 2:1c5cdb2c3e0f | 5 | #include "Hepta9axis.h" |
umeume | 2:1c5cdb2c3e0f | 6 | #include "HeptaTemp.h" |
umeume | 2:1c5cdb2c3e0f | 7 | #include "HeptaBattery.h" |
umeume | 2:1c5cdb2c3e0f | 8 | |
umeume | 2:1c5cdb2c3e0f | 9 | Serial pc(USBTX,USBRX); |
HEPTA | 9:942eb6e8c117 | 10 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
umeume | 2:1c5cdb2c3e0f | 11 | HeptaXbee xbee(p9,p10); |
umeume | 2:1c5cdb2c3e0f | 12 | HeptaCamera_GPS cam_gps(p13, p14,p25,p24); |
HEPTA | 10:4d6870d0caa0 | 13 | Hepta9axis n_axis(p28,p27,0xD0,0x18); |
HEPTA | 7:fab080b8be64 | 14 | HeptaTemp temp(p17); |
HEPTA | 13:a1fa75a002f6 | 15 | HeptaBattery battery(p16,p26); |
umeume | 2:1c5cdb2c3e0f | 16 | |
HEPTA | 17:e83f07212ed3 | 17 | DigitalOut myleds[] = {LED1,LED2,LED3,LED4};; |
umeume | 5:c5ccb1b07e8f | 18 | |
umeume | 2:1c5cdb2c3e0f | 19 | int main() |
umeume | 2:1c5cdb2c3e0f | 20 | { |
HEPTA | 17:e83f07212ed3 | 21 | pc.baud(9600); |
HEPTA | 17:e83f07212ed3 | 22 | float bt; |
HEPTA | 17:e83f07212ed3 | 23 | float temper; |
HEPTA | 20:8bc48b6ac23d | 24 | const char* warning; |
HEPTA | 17:e83f07212ed3 | 25 | char str[100]; |
HEPTA | 20:8bc48b6ac23d | 26 | float gx,gy,gz,mx,my,mz; |
HEPTA | 20:8bc48b6ac23d | 27 | |
HEPTA | 20:8bc48b6ac23d | 28 | int quality=0,stnum=0,gps_check=0; |
HEPTA | 20:8bc48b6ac23d | 29 | char ns='A',ew='B',aunit='m'; |
HEPTA | 20:8bc48b6ac23d | 30 | float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0; |
HEPTA | 20:8bc48b6ac23d | 31 | |
HEPTA | 17:e83f07212ed3 | 32 | int flag = 0; |
HEPTA | 17:e83f07212ed3 | 33 | int rcmd=0,cmdflag=0; |
HEPTA | 25:b9b1257f6e9a | 34 | FILE *dummy = fopen("/sd/MissionData/dum.txt","w"); |
HEPTA | 25:b9b1257f6e9a | 35 | fclose(dummy); |
HEPTA | 17:e83f07212ed3 | 36 | while(1) { |
HEPTA | 25:b9b1257f6e9a | 37 | //battery.power_saving_mode(&flag,&bt); |
HEPTA | 17:e83f07212ed3 | 38 | temp.temp_sense(&temper); |
HEPTA | 17:e83f07212ed3 | 39 | wait(0.5); |
HEPTA | 17:e83f07212ed3 | 40 | xbee.printf("flag = %d, bt = %.2f [V], temp = %.1f [C]\r\n",flag,bt,temper); |
HEPTA | 24:8bdc026b996f | 41 | xbee.xbee_receive(&rcmd,&cmdflag); |
HEPTA | 20:8bc48b6ac23d | 42 | |
HEPTA | 17:e83f07212ed3 | 43 | if(flag == 1) { |
HEPTA | 20:8bc48b6ac23d | 44 | warning = "Low Battery\r\n"; |
HEPTA | 20:8bc48b6ac23d | 45 | xbee.printf("%s",warning); |
HEPTA | 17:e83f07212ed3 | 46 | } else if(temper > 35.0) { |
HEPTA | 20:8bc48b6ac23d | 47 | warning = "High Temperature\r\n"; |
HEPTA | 20:8bc48b6ac23d | 48 | xbee.printf("%s",warning); |
HEPTA | 17:e83f07212ed3 | 49 | } else if((flag == 1) & (temper > 35.0)) { |
HEPTA | 20:8bc48b6ac23d | 50 | warning = "Low Battery and High Temperature\r\n"; |
HEPTA | 20:8bc48b6ac23d | 51 | xbee.printf("%s",warning); |
HEPTA | 20:8bc48b6ac23d | 52 | }else{} |
HEPTA | 20:8bc48b6ac23d | 53 | |
HEPTA | 17:e83f07212ed3 | 54 | if (cmdflag == 1) { |
HEPTA | 17:e83f07212ed3 | 55 | xbee.printf("Command Get = %d\r\n",rcmd); |
HEPTA | 20:8bc48b6ac23d | 56 | |
HEPTA | 17:e83f07212ed3 | 57 | if (rcmd == 'a') { |
HEPTA | 20:8bc48b6ac23d | 58 | mkdir("/sd/MissionData", 0777); |
HEPTA | 20:8bc48b6ac23d | 59 | FILE *fp = fopen("/sd/MissionData/GyroMag.txt","w"); |
HEPTA | 17:e83f07212ed3 | 60 | if(fp == NULL) { |
HEPTA | 17:e83f07212ed3 | 61 | error("Could not open file for write\r\n"); |
HEPTA | 17:e83f07212ed3 | 62 | } else { |
HEPTA | 17:e83f07212ed3 | 63 | for(int i = 0; i < 10; i++) { |
HEPTA | 20:8bc48b6ac23d | 64 | n_axis.sen_gyro(&gx,&gy,&gz); |
HEPTA | 20:8bc48b6ac23d | 65 | n_axis.sen_mag(&mx,&my,&mz); |
HEPTA | 20:8bc48b6ac23d | 66 | fprintf(fp,"Wx = %f, Wy = %f, Wz = %f, mx = %f, my = %f, mz = %f\r\n",gx,gy,gz,mx,my,mz); |
HEPTA | 17:e83f07212ed3 | 67 | wait(1.0); |
HEPTA | 17:e83f07212ed3 | 68 | } |
HEPTA | 17:e83f07212ed3 | 69 | fclose(fp); |
HEPTA | 17:e83f07212ed3 | 70 | } |
HEPTA | 20:8bc48b6ac23d | 71 | FILE *fp1 = fopen("/sd/MissionData/GyroMag.txt","r"); |
HEPTA | 17:e83f07212ed3 | 72 | if(fp1 == NULL) { |
HEPTA | 17:e83f07212ed3 | 73 | error("Could not open file for read\r\n"); |
HEPTA | 17:e83f07212ed3 | 74 | } else { |
HEPTA | 17:e83f07212ed3 | 75 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:e83f07212ed3 | 76 | fgets(str,100,fp1); |
HEPTA | 17:e83f07212ed3 | 77 | xbee.printf("%s",str); |
HEPTA | 17:e83f07212ed3 | 78 | wait(1.0); |
HEPTA | 17:e83f07212ed3 | 79 | } |
HEPTA | 17:e83f07212ed3 | 80 | fclose(fp1); |
HEPTA | 17:e83f07212ed3 | 81 | } |
HEPTA | 17:e83f07212ed3 | 82 | |
HEPTA | 17:e83f07212ed3 | 83 | } |
HEPTA | 20:8bc48b6ac23d | 84 | if (rcmd == 'b') { |
HEPTA | 20:8bc48b6ac23d | 85 | mkdir("/sd/mydir", 0777); |
HEPTA | 20:8bc48b6ac23d | 86 | FILE *fp = fopen("/sd/MissionData/Position.txt","w"); |
HEPTA | 20:8bc48b6ac23d | 87 | if(fp == NULL) { |
HEPTA | 20:8bc48b6ac23d | 88 | error("Could not open file for write\r\n"); |
HEPTA | 20:8bc48b6ac23d | 89 | } else { |
HEPTA | 20:8bc48b6ac23d | 90 | cam_gps.gps_setting(); |
HEPTA | 20:8bc48b6ac23d | 91 | for(int i = 0; i < 10; i++) { |
HEPTA | 20:8bc48b6ac23d | 92 | cam_gps.gga_sensing(&time, &latitude, &ns, &longitude, &ew, &quality, &stnum, &hacu, &altitude, &aunit, &gps_check); |
HEPTA | 20:8bc48b6ac23d | 93 | fprintf(fp,"time: %f, lat: %f,%c, long: %f,%c, altitude:%f\r\n",time,latitude,ns,longitude,ew,altitude); |
HEPTA | 20:8bc48b6ac23d | 94 | wait(1.0); |
HEPTA | 20:8bc48b6ac23d | 95 | } |
HEPTA | 20:8bc48b6ac23d | 96 | fclose(fp); |
HEPTA | 20:8bc48b6ac23d | 97 | } |
HEPTA | 20:8bc48b6ac23d | 98 | |
HEPTA | 20:8bc48b6ac23d | 99 | FILE *fp1 = fopen("/sd/MissionData/Position.txt","r"); |
HEPTA | 20:8bc48b6ac23d | 100 | if(fp1 == NULL) { |
HEPTA | 20:8bc48b6ac23d | 101 | error("Could not open file for read\r\n"); |
HEPTA | 20:8bc48b6ac23d | 102 | } else { |
HEPTA | 20:8bc48b6ac23d | 103 | for(int i = 0; i < 10; i++) { |
HEPTA | 20:8bc48b6ac23d | 104 | fgets(str,100,fp1); |
HEPTA | 20:8bc48b6ac23d | 105 | xbee.printf("%s",str); |
HEPTA | 20:8bc48b6ac23d | 106 | wait(1.0); |
HEPTA | 20:8bc48b6ac23d | 107 | } |
HEPTA | 20:8bc48b6ac23d | 108 | fclose(fp1); |
HEPTA | 20:8bc48b6ac23d | 109 | } |
HEPTA | 20:8bc48b6ac23d | 110 | }//b |
HEPTA | 20:8bc48b6ac23d | 111 | |
HEPTA | 20:8bc48b6ac23d | 112 | if (rcmd == 'c') { |
HEPTA | 17:e83f07212ed3 | 113 | cam_gps.Sync(); |
HEPTA | 17:e83f07212ed3 | 114 | cam_gps.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution320x240); |
HEPTA | 23:68758ba22c86 | 115 | cam_gps.test_jpeg_snapshot_picture("/sd/MissionData/picture.jpg"); |
HEPTA | 25:b9b1257f6e9a | 116 | |
HEPTA | 20:8bc48b6ac23d | 117 | }//c |
HEPTA | 17:e83f07212ed3 | 118 | xbee.initialize(); |
HEPTA | 17:e83f07212ed3 | 119 | } |
HEPTA | 17:e83f07212ed3 | 120 | } |
HEPTA | 17:e83f07212ed3 | 121 | } |