Hepta
Dependencies: Hepta2_9axis HeptaBattery HeptaTemp HeptaXbee SDHCFileSystem mbed
Fork of HEPTA2_ALL_ver0803_02 by
main.cpp@2:726072016da1, 2017-07-21 (annotated)
- Committer:
- hepta2ume
- Date:
- Fri Jul 21 10:38:11 2017 +0000
- Revision:
- 2:726072016da1
- Parent:
- 1:890188e041da
- Child:
- 3:4854731e663d
Hepta??.Ver1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hepta2ume | 2:726072016da1 | 1 | /* |
hepta2ume | 2:726072016da1 | 2 | ************************************************************* |
hepta2ume | 2:726072016da1 | 3 | H29/07_20/T.Umezawa |
hepta2ume | 2:726072016da1 | 4 | 1:SD.....OK! |
hepta2ume | 2:726072016da1 | 5 | 2:MPU9250(Accel) = |
hepta2ume | 2:726072016da1 | 6 | 3:MPU9250(Gyro) = |
hepta2ume | 2:726072016da1 | 7 | 4:MPU9250(Mag_compass) = |
hepta2ume | 2:726072016da1 | 8 | 5:GPS sensing Mode = |
hepta2ume | 2:726072016da1 | 9 | 6:CAM Mode = OK! |
hepta2ume | 2:726072016da1 | 10 | 7:Temperature sensing = |
hepta2ume | 2:726072016da1 | 11 | 8:Xbee mode = |
hepta2ume | 2:726072016da1 | 12 | ************************************************************* |
hepta2ume | 2:726072016da1 | 13 | */ |
sunifu | 0:0482779cd78e | 14 | |
sunifu | 0:0482779cd78e | 15 | #include "mbed.h" |
hepta2ume | 1:890188e041da | 16 | #include "SDHCFileSystem.h" |
hepta2ume | 2:726072016da1 | 17 | #include "HeptaXbee.h" |
hepta2ume | 1:890188e041da | 18 | #include "HeptaSerial.h" |
hepta2ume | 2:726072016da1 | 19 | #include "Hepta9axis.h" |
hepta2ume | 2:726072016da1 | 20 | #include "HeptaTemp.h" |
sunifu | 0:0482779cd78e | 21 | #define USE_JPEG_HIGH_RESOLUTION 1 |
sunifu | 0:0482779cd78e | 22 | |
hepta2ume | 2:726072016da1 | 23 | Serial pc(USBTX,USBRX); |
hepta2ume | 2:726072016da1 | 24 | SDFileSystem sd(p5, p6, p7, p8, "fs"); |
hepta2ume | 2:726072016da1 | 25 | HeptaXbee xbee(p9,p10); |
hepta2ume | 2:726072016da1 | 26 | HeptaSerial camera(p13, p14); |
hepta2ume | 2:726072016da1 | 27 | HeptaMPU9250 MPU9250(p28,p27,0xD0,0x18);//sda,scl,acc&gyro_address,mag_gyro |
hepta2ume | 2:726072016da1 | 28 | HeptaTemp heptatemp(p17); |
hepta2ume | 2:726072016da1 | 29 | DigitalOut CAM_SW(p25);//CAM_control |
hepta2ume | 2:726072016da1 | 30 | DigitalOut GPS_SW(p24);//GPS_control |
hepta2ume | 2:726072016da1 | 31 | |
hepta2ume | 2:726072016da1 | 32 | int main() |
hepta2ume | 2:726072016da1 | 33 | { |
hepta2ume | 2:726072016da1 | 34 | char mode; |
hepta2ume | 2:726072016da1 | 35 | pc.baud(9600); |
hepta2ume | 2:726072016da1 | 36 | |
hepta2ume | 2:726072016da1 | 37 | while(1) { |
hepta2ume | 2:726072016da1 | 38 | |
hepta2ume | 2:726072016da1 | 39 | /* |
hepta2ume | 2:726072016da1 | 40 | ************ |
hepta2ume | 2:726072016da1 | 41 | Mode select |
hepta2ume | 2:726072016da1 | 42 | *********** |
hepta2ume | 2:726072016da1 | 43 | */ |
hepta2ume | 2:726072016da1 | 44 | pc.printf("\r\n"); |
hepta2ume | 2:726072016da1 | 45 | pc.printf("*********************************\r\n"); |
hepta2ume | 2:726072016da1 | 46 | pc.printf("Hello world.\r\n"); |
hepta2ume | 2:726072016da1 | 47 | pc.printf("My name is HEPTA2\r\n"); |
hepta2ume | 2:726072016da1 | 48 | pc.printf("Please select mode.\r\n"); |
hepta2ume | 2:726072016da1 | 49 | pc.printf("1:SD test Mode\r\n"); |
hepta2ume | 2:726072016da1 | 50 | pc.printf("2:Gyro sening ModeE\r\n"); |
hepta2ume | 2:726072016da1 | 51 | pc.printf("3:Accel sensing Mode\r\n"); |
hepta2ume | 2:726072016da1 | 52 | pc.printf("4:Magnet sensig Mode\r\n"); |
hepta2ume | 2:726072016da1 | 53 | pc.printf("5:GPS sensing Mode\r\n"); |
hepta2ume | 2:726072016da1 | 54 | pc.printf("6:CAM mode\r\n"); |
hepta2ume | 2:726072016da1 | 55 | pc.printf("7:Temperature sensing Mode\r\n"); |
hepta2ume | 2:726072016da1 | 56 | pc.printf("8:Xbee Mode\r\n"); |
hepta2ume | 2:726072016da1 | 57 | pc.printf("9:Xbee & Temperature Mode\r\n");//恒温槽用 |
hepta2ume | 2:726072016da1 | 58 | pc.printf("10:All Transmitting Mode Mode\r\n"); |
hepta2ume | 2:726072016da1 | 59 | pc.printf("*********************************\r\n"); |
hepta2ume | 2:726072016da1 | 60 | |
hepta2ume | 2:726072016da1 | 61 | mode = pc.getc(); |
hepta2ume | 2:726072016da1 | 62 | pc.printf("\r\n"); |
hepta2ume | 2:726072016da1 | 63 | pc.printf("Your select Mode = %c\r\n",mode); |
hepta2ume | 2:726072016da1 | 64 | wait(0.5); |
hepta2ume | 2:726072016da1 | 65 | switch(mode) { |
hepta2ume | 2:726072016da1 | 66 | case'1': { |
hepta2ume | 2:726072016da1 | 67 | |
hepta2ume | 2:726072016da1 | 68 | printf("=============\r\n"); |
hepta2ume | 2:726072016da1 | 69 | printf("SD test Mode\r\n"); |
hepta2ume | 2:726072016da1 | 70 | printf("=============\r\n"); |
hepta2ume | 2:726072016da1 | 71 | FILE *fp = fopen("/fs/myfile.txt", "w"); |
hepta2ume | 2:726072016da1 | 72 | if(fp == NULL) { |
hepta2ume | 2:726072016da1 | 73 | pc.printf("Could not open file for write\r\n"); |
hepta2ume | 2:726072016da1 | 74 | } else { |
hepta2ume | 2:726072016da1 | 75 | fprintf(fp, "\n\rHello World!\n\r"); |
hepta2ume | 2:726072016da1 | 76 | printf("SD Check Complete!!\r\n"); |
hepta2ume | 2:726072016da1 | 77 | fclose(fp); |
hepta2ume | 2:726072016da1 | 78 | } |
hepta2ume | 2:726072016da1 | 79 | |
hepta2ume | 2:726072016da1 | 80 | |
hepta2ume | 2:726072016da1 | 81 | break; |
hepta2ume | 2:726072016da1 | 82 | }//case'1' |
hepta2ume | 2:726072016da1 | 83 | |
hepta2ume | 2:726072016da1 | 84 | /* |
hepta2ume | 2:726072016da1 | 85 | ****************** |
hepta2ume | 2:726072016da1 | 86 | Gyro sensing mode |
hepta2ume | 2:726072016da1 | 87 | ****************** |
hepta2ume | 2:726072016da1 | 88 | */ |
sunifu | 0:0482779cd78e | 89 | |
hepta2ume | 2:726072016da1 | 90 | case'2': { |
hepta2ume | 2:726072016da1 | 91 | printf("===================\r\n"); |
hepta2ume | 2:726072016da1 | 92 | printf("Gyro sensing Mode\r\n"); |
hepta2ume | 2:726072016da1 | 93 | printf("===================\r\n"); |
hepta2ume | 2:726072016da1 | 94 | float gx,gy,gz; |
hepta2ume | 2:726072016da1 | 95 | for(int i = 0; i < 10; i++) { |
hepta2ume | 2:726072016da1 | 96 | MPU9250.sen_gyro(&gx,&gy,&gz); |
hepta2ume | 2:726072016da1 | 97 | pc.printf("GX = %f,GY = %f,GZ = %f\r\n",gx,gy,gz); |
hepta2ume | 2:726072016da1 | 98 | wait(0.5); |
hepta2ume | 2:726072016da1 | 99 | } |
hepta2ume | 2:726072016da1 | 100 | break; |
hepta2ume | 2:726072016da1 | 101 | }//case'2' |
hepta2ume | 2:726072016da1 | 102 | |
hepta2ume | 2:726072016da1 | 103 | /* |
hepta2ume | 2:726072016da1 | 104 | ****************** |
hepta2ume | 2:726072016da1 | 105 | Accel sensing mode |
hepta2ume | 2:726072016da1 | 106 | ****************** |
hepta2ume | 2:726072016da1 | 107 | */ |
hepta2ume | 2:726072016da1 | 108 | |
hepta2ume | 2:726072016da1 | 109 | case'3': { |
hepta2ume | 2:726072016da1 | 110 | printf("===================\r\n"); |
hepta2ume | 2:726072016da1 | 111 | printf("Accel sensing Mode\r\n"); |
hepta2ume | 2:726072016da1 | 112 | printf("===================\r\n"); |
hepta2ume | 2:726072016da1 | 113 | float ax,ay,az; |
hepta2ume | 2:726072016da1 | 114 | for(int i = 0; i < 10; i++) { |
hepta2ume | 2:726072016da1 | 115 | MPU9250.sen_acc(&ax,&ay,&az); |
hepta2ume | 2:726072016da1 | 116 | pc.printf("AX = %f,AY = %f,AZ = %f\r\n",ax,ay,az); |
hepta2ume | 2:726072016da1 | 117 | wait(0.5); |
hepta2ume | 2:726072016da1 | 118 | } |
hepta2ume | 2:726072016da1 | 119 | break; |
hepta2ume | 2:726072016da1 | 120 | }//case'3' |
hepta2ume | 2:726072016da1 | 121 | |
hepta2ume | 2:726072016da1 | 122 | /* |
hepta2ume | 2:726072016da1 | 123 | ****************** |
hepta2ume | 2:726072016da1 | 124 | Magnet sensing mode |
hepta2ume | 2:726072016da1 | 125 | ****************** |
hepta2ume | 2:726072016da1 | 126 | */ |
hepta2ume | 2:726072016da1 | 127 | |
hepta2ume | 2:726072016da1 | 128 | case'4': { |
hepta2ume | 2:726072016da1 | 129 | float mx,my,mz; |
hepta2ume | 2:726072016da1 | 130 | printf("===================\r\n"); |
hepta2ume | 2:726072016da1 | 131 | printf("Magnet sensing Mode\r\n"); |
hepta2ume | 2:726072016da1 | 132 | printf("===================\r\n"); |
hepta2ume | 2:726072016da1 | 133 | for(int i = 0; i < 10; i++) { |
hepta2ume | 2:726072016da1 | 134 | MPU9250.sen_mag(&mx,&my,&mz); |
hepta2ume | 2:726072016da1 | 135 | pc.printf("MX = %f,MY = %f,MZ = %f\r\n",mx,my,mz); |
hepta2ume | 2:726072016da1 | 136 | wait(0.5); |
hepta2ume | 2:726072016da1 | 137 | } |
hepta2ume | 2:726072016da1 | 138 | break; |
hepta2ume | 2:726072016da1 | 139 | }//case'4' |
hepta2ume | 2:726072016da1 | 140 | |
hepta2ume | 2:726072016da1 | 141 | /* |
hepta2ume | 2:726072016da1 | 142 | ****************** |
hepta2ume | 2:726072016da1 | 143 | Cam Snapshot mode |
hepta2ume | 2:726072016da1 | 144 | ****************** |
hepta2ume | 2:726072016da1 | 145 | */ |
hepta2ume | 2:726072016da1 | 146 | |
hepta2ume | 2:726072016da1 | 147 | case'6': { |
hepta2ume | 2:726072016da1 | 148 | GPS_SW = 0; |
hepta2ume | 2:726072016da1 | 149 | CAM_SW = 1; |
hepta2ume | 2:726072016da1 | 150 | printf("\r\n"); |
hepta2ume | 2:726072016da1 | 151 | printf("==========\r\n"); |
hepta2ume | 2:726072016da1 | 152 | printf("CameraC1098\r\n"); |
hepta2ume | 2:726072016da1 | 153 | printf("==========\r\n"); |
hepta2ume | 2:726072016da1 | 154 | camera.Sync(); |
hepta2ume | 2:726072016da1 | 155 | camera.initialize(HeptaSerial::Baud115200, HeptaSerial::JpegResolution320x240); |
hepta2ume | 2:726072016da1 | 156 | camera.test_jpeg_snapshot_picture(1); |
sunifu | 0:0482779cd78e | 157 | |
hepta2ume | 2:726072016da1 | 158 | break; |
hepta2ume | 2:726072016da1 | 159 | }//case'6' |
hepta2ume | 2:726072016da1 | 160 | |
hepta2ume | 2:726072016da1 | 161 | /* |
hepta2ume | 2:726072016da1 | 162 | ****************** |
hepta2ume | 2:726072016da1 | 163 | Temp sensing mode |
hepta2ume | 2:726072016da1 | 164 | ****************** |
hepta2ume | 2:726072016da1 | 165 | */ |
hepta2ume | 2:726072016da1 | 166 | |
hepta2ume | 2:726072016da1 | 167 | case'7': { |
hepta2ume | 2:726072016da1 | 168 | printf("==================\r\n"); |
hepta2ume | 2:726072016da1 | 169 | printf("Temp sensing Mode\r\n"); |
hepta2ume | 2:726072016da1 | 170 | printf("==================\r\n"); |
hepta2ume | 2:726072016da1 | 171 | float temp; |
hepta2ume | 2:726072016da1 | 172 | for(int i = 0; i<100; i++) { |
hepta2ume | 2:726072016da1 | 173 | heptatemp.temp_sense(&temp); |
hepta2ume | 2:726072016da1 | 174 | pc.printf("%f\r\n",temp); |
hepta2ume | 2:726072016da1 | 175 | //xbee.printf("%f\r\n",temp); |
hepta2ume | 2:726072016da1 | 176 | } |
hepta2ume | 2:726072016da1 | 177 | break; |
hepta2ume | 2:726072016da1 | 178 | }//case'7' |
hepta2ume | 2:726072016da1 | 179 | |
hepta2ume | 2:726072016da1 | 180 | /* |
hepta2ume | 2:726072016da1 | 181 | *********** |
hepta2ume | 2:726072016da1 | 182 | Xbee mode |
hepta2ume | 2:726072016da1 | 183 | *********** |
hepta2ume | 2:726072016da1 | 184 | */ |
hepta2ume | 2:726072016da1 | 185 | |
hepta2ume | 2:726072016da1 | 186 | case'8': { |
hepta2ume | 2:726072016da1 | 187 | |
hepta2ume | 2:726072016da1 | 188 | int i=0,rcmd=0,cmdflag=0; |
hepta2ume | 2:726072016da1 | 189 | xbee.printf("Count Up!\r"); |
hepta2ume | 2:726072016da1 | 190 | while(1) { |
hepta2ume | 2:726072016da1 | 191 | xbee.printf("num = %d\r",i); |
hepta2ume | 2:726072016da1 | 192 | i++; |
hepta2ume | 2:726072016da1 | 193 | wait(1.0); |
hepta2ume | 2:726072016da1 | 194 | xbee.xbee_recieve(&rcmd,&cmdflag); |
hepta2ume | 2:726072016da1 | 195 | pc.printf("rcmd=%d, cmdflag=%d\r\n",rcmd, cmdflag); |
hepta2ume | 2:726072016da1 | 196 | if (cmdflag == 1) { |
hepta2ume | 2:726072016da1 | 197 | if (rcmd == 'a') { |
hepta2ume | 2:726072016da1 | 198 | pc.printf("Command Get %d\r\n",rcmd); |
hepta2ume | 2:726072016da1 | 199 | xbee.printf("HEPTA Uplink OK\r"); |
hepta2ume | 2:726072016da1 | 200 | } |
hepta2ume | 2:726072016da1 | 201 | xbee.initialize(); |
hepta2ume | 2:726072016da1 | 202 | } |
hepta2ume | 2:726072016da1 | 203 | } |
hepta2ume | 2:726072016da1 | 204 | |
hepta2ume | 2:726072016da1 | 205 | break; |
hepta2ume | 2:726072016da1 | 206 | }//case'8' |
hepta2ume | 2:726072016da1 | 207 | |
hepta2ume | 2:726072016da1 | 208 | /* |
hepta2ume | 2:726072016da1 | 209 | ****************** |
hepta2ume | 2:726072016da1 | 210 | Temp sensing mode by Xbbe |
hepta2ume | 2:726072016da1 | 211 | ****************** |
hepta2ume | 2:726072016da1 | 212 | */ |
hepta2ume | 2:726072016da1 | 213 | |
hepta2ume | 2:726072016da1 | 214 | case'9': { |
hepta2ume | 2:726072016da1 | 215 | |
hepta2ume | 2:726072016da1 | 216 | printf("==================\r\n"); |
hepta2ume | 2:726072016da1 | 217 | printf("Temp sensing Mode & Xbee\r\n"); |
hepta2ume | 2:726072016da1 | 218 | printf("==================\r\n"); |
hepta2ume | 2:726072016da1 | 219 | |
hepta2ume | 2:726072016da1 | 220 | float temp; |
hepta2ume | 2:726072016da1 | 221 | //FILE *fp = fopen("/fs/myfile.csv", "a"); |
hepta2ume | 2:726072016da1 | 222 | // if(fp == NULL) { |
hepta2ume | 2:726072016da1 | 223 | // pc.printf("Could not open file for write\r\n"); |
hepta2ume | 2:726072016da1 | 224 | // } else { |
hepta2ume | 2:726072016da1 | 225 | while(1) |
hepta2ume | 2:726072016da1 | 226 | { |
hepta2ume | 2:726072016da1 | 227 | //for(int i = 0; i<100; i++) { |
hepta2ume | 2:726072016da1 | 228 | FILE *fp = fopen("/fs/myfile.csv", "a"); |
hepta2ume | 2:726072016da1 | 229 | heptatemp.temp_sense(&temp); |
hepta2ume | 2:726072016da1 | 230 | pc.printf("%f\r\n",temp); |
hepta2ume | 2:726072016da1 | 231 | xbee.printf("%f\r\n",temp); |
hepta2ume | 2:726072016da1 | 232 | fprintf(fp, "%f\n",temp); |
hepta2ume | 2:726072016da1 | 233 | fclose(fp); |
hepta2ume | 2:726072016da1 | 234 | } |
hepta2ume | 2:726072016da1 | 235 | // fclose(fp); |
hepta2ume | 2:726072016da1 | 236 | // } |
hepta2ume | 2:726072016da1 | 237 | break; |
hepta2ume | 2:726072016da1 | 238 | }//case'9' |
hepta2ume | 2:726072016da1 | 239 | |
hepta2ume | 2:726072016da1 | 240 | /* |
hepta2ume | 2:726072016da1 | 241 | ********************* |
hepta2ume | 2:726072016da1 | 242 | All Transmitting Mode |
hepta2ume | 2:726072016da1 | 243 | ********************* |
hepta2ume | 2:726072016da1 | 244 | */ |
hepta2ume | 2:726072016da1 | 245 | |
hepta2ume | 2:726072016da1 | 246 | case'a': { |
hepta2ume | 2:726072016da1 | 247 | |
hepta2ume | 2:726072016da1 | 248 | printf("==================\r\n"); |
hepta2ume | 2:726072016da1 | 249 | printf("All Transmitting Mode\r\n"); |
hepta2ume | 2:726072016da1 | 250 | printf("==================\r\n"); |
hepta2ume | 2:726072016da1 | 251 | char gx[4],gy[4],gz[4],ax[4],ay[4],az[4],mx[4],my[4],mz[4],lad[8],log[8],bt[4],temp[4]; |
hepta2ume | 2:726072016da1 | 252 | char ddata[60]; |
hepta2ume | 2:726072016da1 | 253 | int dsize[6]; |
hepta2ume | 2:726072016da1 | 254 | while(1) { |
hepta2ume | 2:726072016da1 | 255 | /* |
hepta2ume | 2:726072016da1 | 256 | MPU9250.sen_gyro_u16(gx,gy,gz,&dsize[0]); |
hepta2ume | 2:726072016da1 | 257 | MPU9250.sen_acc_u16(ax,ay,az,&dsize[1]); |
hepta2ume | 2:726072016da1 | 258 | MPU9250.sen_mag_u16(mx,my,mz,&dsize[2]); |
hepta2ume | 2:726072016da1 | 259 | gps.sensing_u16(lad,log,&dsize[3]); |
hepta2ume | 2:726072016da1 | 260 | battery.vol_u16(bt,&dsize[4]); |
hepta2ume | 2:726072016da1 | 261 | heptatemp.temp_sense_u16(temp,&dsize[5]); |
hepta2ume | 2:726072016da1 | 262 | */ |
hepta2ume | 2:726072016da1 | 263 | //gyro.x_u16(gx,4); |
hepta2ume | 2:726072016da1 | 264 | xbee.xbee_transmit(ddata,60,gx,gy,gz,ax,ay,az,mx,my,mz,lad,log,bt,temp,dsize[0],dsize[0],dsize[0],dsize[1],dsize[1],dsize[1],dsize[2],dsize[2],dsize[2],dsize[3],dsize[3],dsize[4],dsize[5],13); |
hepta2ume | 2:726072016da1 | 265 | } |
hepta2ume | 2:726072016da1 | 266 | break; |
hepta2ume | 2:726072016da1 | 267 | }//case'9' |
hepta2ume | 2:726072016da1 | 268 | /* |
hepta2ume | 2:726072016da1 | 269 | ****************** |
hepta2ume | 2:726072016da1 | 270 | Cam Snapshot mode |
hepta2ume | 2:726072016da1 | 271 | ****************** |
hepta2ume | 2:726072016da1 | 272 | */ |
hepta2ume | 2:726072016da1 | 273 | |
hepta2ume | 2:726072016da1 | 274 | case'b': { |
hepta2ume | 2:726072016da1 | 275 | GPS_SW = 0; |
hepta2ume | 2:726072016da1 | 276 | CAM_SW = 1; |
hepta2ume | 2:726072016da1 | 277 | printf("\r\n"); |
hepta2ume | 2:726072016da1 | 278 | printf("==========\r\n"); |
hepta2ume | 2:726072016da1 | 279 | printf("CameraC1098\r\n"); |
hepta2ume | 2:726072016da1 | 280 | printf("==========\r\n"); |
hepta2ume | 2:726072016da1 | 281 | camera.Sync(); |
hepta2ume | 2:726072016da1 | 282 | camera.initialize(HeptaSerial::Baud115200, HeptaSerial::JpegResolution320x240); |
hepta2ume | 2:726072016da1 | 283 | camera.test_jpeg_snapshot_data(1); |
hepta2ume | 2:726072016da1 | 284 | |
hepta2ume | 2:726072016da1 | 285 | break; |
hepta2ume | 2:726072016da1 | 286 | }//case'6' |
hepta2ume | 2:726072016da1 | 287 | |
hepta2ume | 2:726072016da1 | 288 | default: |
hepta2ume | 2:726072016da1 | 289 | break; |
hepta2ume | 2:726072016da1 | 290 | |
hepta2ume | 2:726072016da1 | 291 | |
hepta2ume | 2:726072016da1 | 292 | } |
hepta2ume | 2:726072016da1 | 293 | } |
hepta2ume | 2:726072016da1 | 294 | } |