diff --git a/lib/baro/lps25hb.cpp b/lib/baro/lps25hb.cpp index 13c39d7..aacb84f 100644 --- a/lib/baro/lps25hb.cpp +++ b/lib/baro/lps25hb.cpp @@ -26,6 +26,7 @@ float Barometer::getPressure() bool Barometer::measurementReady() { + long current_time = millis(); if (current_time - this->previous_time >= this->measurement_delay) { diff --git a/lib/baro/lps25hb.h b/lib/baro/lps25hb.h index 4278a64..57d76a1 100644 --- a/lib/baro/lps25hb.h +++ b/lib/baro/lps25hb.h @@ -8,9 +8,17 @@ #include #include "chip.h" +#if defined(HALOSHIP) #define LPS_SCK PA5 #define LPS_MISO PA6 #define LPS_MOSI PA7 +#endif + +#if defined(FEATHER_BOARD) +#define LPS_SCK PB13 +#define LPS_MISO PB14 +#define LPS_MOSI PB15 +#endif class Barometer : public Task, public Chip { diff --git a/lib/buzzer/buzzer.h b/lib/buzzer/buzzer.h index 14d75aa..076bc95 100644 --- a/lib/buzzer/buzzer.h +++ b/lib/buzzer/buzzer.h @@ -1,6 +1,10 @@ #ifndef BUZZER_H #define BUZZER_H +#if defined(FEATHER_BOARD) +#define BUZZER PC3 +#endif + #include #include #include diff --git a/lib/gps/gps.cpp b/lib/gps/gps.cpp new file mode 100644 index 0000000..83bc2f7 --- /dev/null +++ b/lib/gps/gps.cpp @@ -0,0 +1,71 @@ +#include "gps.h"; + +GPS::GPS(long measurement_delay) : Task(TASK_MILLISECOND, TASK_FOREVER, &scheduler, false), + measurement_delay(measurement_delay), + previous_time(0), + altitudeMSL(-1), + latitude(-1), + longitude(-1) +{ + // this->spi_dev = SPIClass(LPS_MOSI, LPS_MISO, LPS_SCK); + // this->spi_dev.begin(); + // this->LPS_CS = LPS_CS; + this->gps_driver = new SFE_UBLOX_GNSS(); +} + +GPS::~GPS() {} + +long GPS::getAltitude() +{ + return this->altitudeMSL; +} + +long GPS::getLatitude() +{ + return this->latitude; +} + +long GPS::getLongitude() +{ + return this->longitude; +} + +bool GPS::measurementReady() +{ + + long current_time = millis(); + if (current_time - this->previous_time >= this->measurement_delay) + { + this->previous_time = current_time; + return true; + } + return false; +} + +bool GPS::Callback() +{ + this->gps_driver->checkUblox(); + if (measurementReady()) + { + this->altitudeMSL = this->gps_driver->getAltitudeMSL(); + this->latitude = this->gps_driver->getLatitude(); + this->longitude = this->gps_driver->getLongitude(); + return true; + } + return false; +} + +bool GPS::OnEnable() +{ + return true; +} + +void GPS::OnDisable() +{ +} + +bool GPS::checkStatus() +{ + Serial.println("gps Checking status"); + return this->gps_driver->begin(); +} \ No newline at end of file diff --git a/lib/gps/gps.h b/lib/gps/gps.h new file mode 100644 index 0000000..59fbbe5 --- /dev/null +++ b/lib/gps/gps.h @@ -0,0 +1,55 @@ +// #ifndef LPS25HB_H +// #define LPS25HB_H + +#include +#include +// #include +// #include +#include +#include +#include "chip.h" + +// #if defined(FEATHER_BOARD) +// #define LPS_SCK PA5 +// #define LPS_MISO PA6 +// #define LPS_MOSI PA7 +// #endif + +// #if defined(FEATHER_BOARD) +// #define LPS_SCK PB13 +// #define LPS_MISO PB14 +// #define LPS_MOSI PB15 +// #endif + +class GPS : public Task, public Chip +{ +private: + SFE_UBLOX_GNSS *gps_driver; + // Adafruit_Sensor *temp_driver, *pressure_driver; + // SPIClass spi_dev; + // int LPS_CS; + long measurement_delay; + long previous_time = 0; + long altitudeMSL; + long latitude; + long longitude; + +public: + GPS(long measurement_delay); + ~GPS(); + + bool measurementReady(); + long getAltitude(); + long getLatitude(); + long getLongitude(); + + // Task virtual methods + bool Callback(); + bool OnEnable(); + void OnDisable(); + + // Chip virtual methods + bool checkStatus(); +}; + +// #endif \ No newline at end of file diff --git a/lib/transceiver/rfm69.cpp b/lib/transceiver/rfm69.cpp index 3cddfb7..6c73f04 100644 --- a/lib/transceiver/rfm69.cpp +++ b/lib/transceiver/rfm69.cpp @@ -1,14 +1,49 @@ #include "rfm69.h" -Transceiver::Transceiver(int RFM69_CS, int RFM69_INT) : Task(TASK_MILLISECOND, TASK_FOREVER, &scheduler, false) +Transceiver::Transceiver(int RFM69_CS, int RFM69_INT, Barometer *barometer, GPS *gps, long measurement_delay) : Task(TASK_MILLISECOND, TASK_FOREVER, &scheduler, false), + measurements_delay(measurement_delay), + previous_time(0) { this->driver = new RH_RF69(RFM69_CS, RFM69_INT); + this->barometer = barometer; + this->gps = gps; } Transceiver::~Transceiver() {} +bool Transceiver::measurementsReady() +{ + + long current_time = millis(); + if (current_time - this->previous_time >= this->measurements_delay) + { + this->previous_time = current_time; + return true; + } + return false; +} + bool Transceiver::Callback() { + long current_time = millis(); + if (measurementsReady()) + { + char radiopacket[RH_RF69_MAX_MESSAGE_LEN]; + snprintf(radiopacket, RH_RF69_MAX_MESSAGE_LEN, "%f\n%f\n%d\n%d\n%d\n ", + this->barometer->getPressure(), + this->barometer->getTemperature(), + this->gps->getAltitude(), + this->gps->getLatitude(), + this->gps->getLongitude()); + // Send a message! + this->driver->send((uint8_t *)radiopacket, sizeof(radiopacket)); + this->driver->waitPacketSent(); + this->previous_time = current_time; + return true; + } + return false; + ; + if (this->driver->available()) { // Should be a message for us now diff --git a/lib/transceiver/rfm69.h b/lib/transceiver/rfm69.h index e6444b3..a9c719f 100644 --- a/lib/transceiver/rfm69.h +++ b/lib/transceiver/rfm69.h @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "chip.h" class Transceiver : public Task, public Chip @@ -15,11 +17,17 @@ class Transceiver : public Task, public Chip private: RH_RF69 *driver; uint8_t *buffer; + Barometer *barometer; + GPS *gps; + long measurements_delay; + long previous_time = 0; public: - Transceiver(int RFM69_CS, int RFM69_INT); + Transceiver(int RFM69_CS, int RFM69_INT, Barometer *barometer, GPS *gps, long measurements_delay); ~Transceiver(); + bool measurementsReady(); + // Task virtual methods bool Callback(); bool OnEnable(); diff --git a/platformio.ini b/platformio.ini index 2ef7012..ce20e7f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,7 +13,6 @@ platform = ststm32@13.0.0 board = haloship framework = arduino upload_protocol = stlink -; upload_protocol = dfu debug_tool = stlink debug_speed = 480 build_flags = @@ -26,14 +25,14 @@ lib_deps = adafruit/Adafruit LPS2X @ ^2.0.1 lowpowerlab/SPIFlash @ ^101.1.3 https://github.com/haloship/RadioHead.git - ; https://github.com/haloship/bmx055.git - ; sparkfun/SparkFun u-blox GNSS Arduino Library@^2.0.5 -lib_extra_dirs= + niniack/BMX055@^0.1.0 + sparkfun/SparkFun u-blox GNSS Arduino Library@^2.0.5 +lib_extra_dirs = /home/dunstan/git/bmx055 lib_ldf_mode = deep [env:feather] -platform = ststm32 +platform = ststm32@13.0.0 board = adafruit_feather_f405 framework = arduino upload_protocol = dfu @@ -44,9 +43,43 @@ build_flags = -D FEATHER_BOARD -Wall lib_deps = + arkhipenko/TaskScheduler @ ^3.2.2 + robtillaart/PCA9635 @ ^0.3.1 https://github.com/haloship/RadioHead.git + lowpowerlab/SPIFlash @ ^101.1.3 adafruit/Adafruit LPS2X@^2.0.1 sparkfun/SparkFun u-blox GNSS Arduino Library@^2.0.5 + # niniack/BMX055@^0.1.0 + https://github.com/haloship/bmx055.git +lib_extra_dirs = + # /home/takumi/Development/Haloship/flight-software/lib + # /home/dunstan/git/bmx055 +lib_ldf_mode = deep + +# [env:feather_ground] +# platform = ststm32@13.0.0 +# board = adafruit_feather_f405 +# framework = arduino +# upload_protocol = dfu +# build_flags = +# -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF +# -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC +# -D USBCON +# -D FEATHER_BOARD_GROUND +# -Wall +# lib_deps = +# arkhipenko/TaskScheduler @ ^3.2.2 +# robtillaart/PCA9635 @ ^0.3.1 +# https://github.com/haloship/RadioHead.git +# lowpowerlab/SPIFlash @ ^101.1.3 +# adafruit/Adafruit LPS2X@^2.0.1 +# # sparkfun/SparkFun u-blox GNSS Arduino Library@^2.0.5 +# # niniack/BMX055@^0.1.0 +# https://github.com/haloship/bmx055.git +# lib_extra_dirs = +# # /home/takumi/Development/Haloship/flight-software/lib +# # /home/dunstan/git/bmx055 +# lib_ldf_mode = deep [env:nucleo] platform = ststm32 @@ -60,3 +93,4 @@ lib_deps = https://github.com/haloship/RadioHead.git adafruit/Adafruit LPS2X@^2.0.1 sparkfun/SparkFun u-blox GNSS Arduino Library@^2.0.5 + niniack/BMX055@^0.1.0 diff --git a/src/config.h b/src/config.h index 1a63061..dc7719b 100644 --- a/src/config.h +++ b/src/config.h @@ -2,15 +2,20 @@ #define CONFIG_H #include -#include +#include #include -#include #include #include +#include +#include + +#include +#include #include #include #include -#include + +// #define BUZZER PC3 #if defined(HALOSHIP) @@ -47,10 +52,16 @@ #endif // // RFM69 pin definition for stm32F4 -// #if defined (FEATHER_BOARD) // Defined in Arduino framework -// #define RFM69_INT PC6 // -// #define RFM69_CS PB9 // -// #define RFM69_RST PB8 // "A" +#if defined(FEATHER_BOARD) // Defined in Arduino framework +#define RFM69_INT PC6 // +#define RFM69_CS PB9 // +#define RFM69_RST PB8 // "A" +#define LPS_CS PC7 +#define LPS_SCK PB13 +#define LPS_MISO PB14 +#define LPS_MOSI PB15 +#endif + // #define LED PC1 // // LPS25 pin definition diff --git a/src/main.cpp b/src/main.cpp index aa65207..8a8768e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,11 +3,13 @@ // Instantiate objects Buzzer *buzzer; -PWMControl *pwm; Barometer *barometer; -Blink *blinker; +GPS *gps; Transceiver *transceiver; -IMU *imu; + +PWMControl *pwm; +Blink *blinker; +// IMU *imu; Flash *flash; Servo main_chute_servo; Servo drogue_chute_servo; @@ -29,13 +31,59 @@ enum state END }; +bool check_sensors_feather( + Barometer *barometer, + GPS *gps, + Transceiver *transceiver) +{ + Serial.println("************************************"); + Serial.println("Conducting status check on all ICs..."); + Serial.println("************************************"); + + bool error = true; + + // Check status of LPS25HB Barometer + if (barometer->checkStatus()) + { + Serial.println("Barometer connection success! \xE2\x9C\x93"); + } + else + { + Serial.println("Barometer connection failed \xE2\x9C\x97"); + error = false; + } + + if (gps->checkStatus()) + { + Serial.println("GPS connection success! \xE2\x9C\x93"); + } + else + { + Serial.println("GPS connection failed \xE2\x9C\x97"); + error = false; + } + + // Check status of RFM69HW Transceiver + if (transceiver->checkStatus()) + { + Serial.println("Transceiver connection success! \xE2\x9C\x93"); + } + else + { + Serial.println("Transceiver connection failed \xE2\x9C\x97"); + error = false; + } + + return error; +} + void setup() { // Initialize communication Wire.begin(); Serial.begin(115200); - main_chute_servo.attach(MAIN_CHUTE_SERVO_PIN); - drogue_chute_servo.attach(DROGUE_CHUTE_SERVO_PIN); + // main_chute_servo.attach(MAIN_CHUTE_SERVO_PIN); + // drogue_chute_servo.attach(DROGUE_CHUTE_SERVO_PIN); // Wait until serial console is open, remove if not tethered to computer while (!Serial) @@ -45,25 +93,32 @@ void setup() // Define all needed submodules buzzer = new Buzzer(); - pwm = new PWMControl(); + // pwm = new PWMControl(); barometer = new Barometer(LPS_CS, 500); - transceiver = new Transceiver(RFM69_CS, RFM69_INT); - imu = new IMU(500); - flash = new Flash(FLASH_CS); + gps = new GPS(500); + transceiver = new Transceiver(RFM69_CS, RFM69_INT, barometer, gps, 500); + // imu = new IMU(500); + // flash = new Flash(FLASH_CS); - blinker = new Blink(pwm); + // blinker = new Blink(pwm); // Run sensor check - check_sensors(pwm, barometer, transceiver, imu, flash) - ? buzzer->signalSuccess() - : buzzer->signalFail(); + // check_sensors(pwm, barometer, transceiver, imu, flash, gps) + // ? buzzer->signalSuccess() + // : buzzer->signalFail(); + + check_sensors_feather(barometer, gps, transceiver) + ? Serial.println("sensors success") + : Serial.println("sensors failed"); - // Enable chips + // // Enable chips barometer->enable(); - imu->enable(); + gps->enable(); transceiver->enable(); + // imu->enable(); } void loop() { + scheduler.execute(); } \ No newline at end of file diff --git a/src/util.h b/src/util.h index 7fff5a5..15eaa51 100644 --- a/src/util.h +++ b/src/util.h @@ -7,7 +7,8 @@ bool check_sensors(PWMControl *pwm, Barometer *barometer, Transceiver *transceiver, IMU *imu, - Flash *flash) + Flash *flash, + GPS *gps) { Serial.println("************************************"); Serial.println("Conducting status check on all ICs..."); @@ -71,6 +72,16 @@ bool check_sensors(PWMControl *pwm, error = false; } + if (gps->checkStatus()) + { + Serial.println("GPS connection success! \xE2\x9C\x93"); + } + else + { + Serial.println("GPS connection failed \xE2\x9C\x97"); + error = false; + } + return error; }