高高度CanSat Space SWANの投下時に使用したプログラム.(IZU2019)
Dependencies: Nichrome_lib mbed ads1115_test BNO055_lib ADXL375_i2c ES920LR CCS811_lib SDFileSystem BME280_lib INA226_lib EEPROM_lib GPS_interrupt
Diff: main.cpp
- Revision:
- 1:6dea30c8b406
- Parent:
- 0:03be138291de
- Child:
- 2:a443df6115bc
--- a/main.cpp Tue Feb 19 15:00:39 2019 +0000 +++ b/main.cpp Tue Feb 19 15:56:55 2019 +0000 @@ -18,7 +18,7 @@ 設定値 投下前に必ず確認!! *******************************************************************************/ - +bool wait_GPS = true; /******************************************************************************* コンストラクタ @@ -109,6 +109,11 @@ float alt_buf[10], alt_ave, alt_ave_old, speed, speed_buf[10], speed_ave; int alt_count = 0, speed_count = 0; +int CO2, TVOCs; + +int16_t bottle_pres_bit; +float bottle_pres; + float gps_lat, gps_lon, gps_alt, gps_utc[6], gps_knot, gps_deg; int gps_sat; bool gps_yn; @@ -157,7 +162,7 @@ /******************************************************************************* 無線のヘッダまとめ(GND -> CANSAT) *******************************************************************************/ -const char HEADER_COMMAND = 0xcd: +const char HEADER_COMMAND = 0xcd; // 0xcd, command // 0 1 // 0 @@ -207,75 +212,199 @@ 状態遷移の判断 無線あり:HEADER_START *******************************************************************************/ -void modeChange(); +void modeChange(){ + +} /******************************************************************************* センサー読み取り *******************************************************************************/ -void readSensor(); +void readSensor(){ + time_read = time_main.read_ms(); + time_min = time_reset * 30 + floor((double)time_read / (60 * 1000)); + time_sec = time_read % (60 * 1000); + time_sec = floor((double)time_sec / 1000); + time_ms = time_read % 1000; + if(time_read >= 30*60*1000){ + time_main.reset(); + time_reset ++; + } + + if(CanSat_phase >= CANSAT_FLIGHT){ + flight_time_read_old = flight_time_read; + flight_time_read = time_flight.read_ms(); + } + else{ + flight_time_read = 0; + } + flight_time_min = flight_time_reset * 30 + floor((double)flight_time_read / (60 * 1000)); + flight_time_sec = flight_time_read % (60 * 1000); + flight_time_sec = floor((double)flight_time_sec / 1000); + flight_time_ms = flight_time_read % 1000; + if(time_read >= 30*60*1000){ + time_flight.reset(); + flight_time_reset ++; + } + + ADXL375.getOutput(adxl_acc); + + INA226.get_Voltage_current(&ina_v, &ina_i); + ina_v = ina_v / 1000; + ina_i = ina_i / 1000; + if(ina_i > 64){ + ina_i = 0.0f; + } + + BME280.getData(&temp, &pres_now, &hum); + if(pres_now != pres){ + pres = pres_now; + alt = BME280.getAlt2(pres_0, temp_0); + + alt_buf[alt_count] = alt; + alt_count ++; + if(alt_count > 10){ + alt_count = 0; + } + float alt_sum = 0; + for(int i = 0; i < 10; i ++){ + alt_sum += alt_buf[i]; + } + alt_ave_old = alt_ave; + alt_ave = alt_sum / 10; + + if(fabs(alt_ave - alt_ave_old) > 0.01){ + speed = (alt_ave - alt_ave_old) / (((float)flight_time_read - (float)speed_time_old) / 1000); + } + if(CanSat_phase <= CANSAT_WAIT){ + speed = 0.0f; + } + + speed_buf[speed_count] = speed; + speed_count ++; + if(speed_count > 10){ + speed_count = 0; + } + float speed_sum = 0; + for(int i = 0; i < 10; i ++){ + speed_sum = speed_buf[i]; + } + speed_ave = speed_sum / 10; + + speed_time_old = flight_time_read; + } + + if(CanSat_phase <= CANSAT_WAIT){ + pres_0 = pres; + temp_0 = temp; + } + + BNO055.getAMG(amg); + BNO055.getQuart(quart); + BNO055.getEulerFromQ(euler); + + CCS811.getData(&CO2, &TVOCs); + + bottle_pres_bit = ADS1115.readADC_SingleEnded(0); + bottle_pres_bit = (float)bottle_pres_bit * 0.125f * 3.0f / 2.0f; + bottle_pres = (float)bottle_pres_bit/1000.0f / 4.0f - 0.25f; +} /******************************************************************************* GPS読み取り *******************************************************************************/ -void readGPS(); +void readGPS(){ + gps_yn = GPS.gps_readable; + if(gps_yn){ + gps_lat = GPS.Latitude(); + gps_lon = GPS.Longitude(); + gps_alt = GPS.Height(); + GPS.getUTC(gps_utc); + gps_utc[3] += 9; + if(gps_utc[3] >= 24){ + gps_utc[3] -= 24; + gps_utc[2] += 1; + } + gps_knot = GPS.Knot(); + gps_deg = GPS.Degree(); + gps_sat = GPS.Number(); + } +} /******************************************************************************* データ表示 *******************************************************************************/ -void printData(); +void printData(){ + +} /******************************************************************************* PC読み取り *******************************************************************************/ -void readPC(); +void readPC(){ + +} /******************************************************************************* ヘルプ表示 *******************************************************************************/ -void printHelp(); +void printHelp(){ + +} /******************************************************************************* ダウンリンク送信 無線あり:HEADER_DATA *******************************************************************************/ -void sendDownLink(); +void sendDownLink(){ + +} /******************************************************************************* アップリンク受信 無線あり:HEADER_COMMAND *******************************************************************************/ -void readUpLink(); +void readUpLink(){ + +} /******************************************************************************* データを1秒ごとに書き込み開始 *******************************************************************************/ -void startRecSlow(); +void startRecSlow(){ + +} /******************************************************************************* データを最速で書き込み開始 *******************************************************************************/ -void startRecFast(); +void startRecFast(){ + +} /******************************************************************************* データ記録停止 *******************************************************************************/ -void stopRec(); +void stopRec(){ + +} /******************************************************************************* データの記録 *******************************************************************************/ -void recData(); +void recData(){ + +} /******************************************************************************* @@ -348,6 +477,7 @@ strcat(setup_string, "BNO055 : NG\r\n"); es920 << (char)0x00; } + BNO055.setOperationMode(BNO055_lib::NDOF); //////////////////////////////////////////////////CCS811 if(CCS811.connectCheck() == 1){