From e8a7fd1002f10f8641dcc02036a6eda6dcebdcb5 Mon Sep 17 00:00:00 2001 From: tm2904 Date: Sun, 13 Jun 2021 14:15:16 +0900 Subject: [PATCH 1/4] testing barometer --- lib/baro/lps25hb.cpp | 4 +++ lib/buzzer/buzzer.h | 4 +++ platformio.ini | 20 ++++++++---- src/config.h | 24 +++++++++----- src/main.cpp | 78 ++++++++++++++++++++++++++++++++------------ 5 files changed, 95 insertions(+), 35 deletions(-) diff --git a/lib/baro/lps25hb.cpp b/lib/baro/lps25hb.cpp index 13c39d7..923032a 100644 --- a/lib/baro/lps25hb.cpp +++ b/lib/baro/lps25hb.cpp @@ -26,6 +26,7 @@ float Barometer::getPressure() bool Barometer::measurementReady() { + Serial.println("Barometer measurement ready."); long current_time = millis(); if (current_time - this->previous_time >= this->measurement_delay) { @@ -37,6 +38,7 @@ bool Barometer::measurementReady() bool Barometer::Callback() { + Serial.println("inside barometer callback"); if (measurementReady()) { sensors_event_t pressure; @@ -45,6 +47,7 @@ bool Barometer::Callback() this->pressure_driver->getEvent(&pressure); this->temperature = temp.temperature; this->pressure = pressure.pressure; + Serial.println(this->pressure); return true; } return false; @@ -63,5 +66,6 @@ void Barometer::OnDisable() bool Barometer::checkStatus() { + Serial.println("Barometer Checking status"); return this->lps_driver->begin_SPI(this->LPS_CS, &this->spi_dev); } \ No newline at end of file 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/platformio.ini b/platformio.ini index 2ef7012..b888ba8 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,13 @@ 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 +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 +42,18 @@ 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 + # 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 +67,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..b064f48 100644 --- a/src/config.h +++ b/src/config.h @@ -2,16 +2,19 @@ #define CONFIG_H #include -#include +#include +// #include #include -#include +// #include #include #include -#include -#include -#include +// #include +// // #include +// #include #include +// #define BUZZER PC3 + #if defined(HALOSHIP) #if !defined(STM32F4) @@ -47,10 +50,13 @@ #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 +#endif + // #define LED PC1 // // LPS25 pin definition diff --git a/src/main.cpp b/src/main.cpp index aa65207..e387b12 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,16 @@ #include "config.h" -#include "util.h" +// #include "util.h" // Instantiate objects Buzzer *buzzer; -PWMControl *pwm; +// PWMControl *pwm; Barometer *barometer; -Blink *blinker; +// Blink *blinker; Transceiver *transceiver; -IMU *imu; -Flash *flash; -Servo main_chute_servo; -Servo drogue_chute_servo; +// IMU *imu; +// Flash *flash; +// Servo main_chute_servo; +// Servo drogue_chute_servo; // SERVO USES STM32F4 TIMER 1 THAT OPERATES AT TWICE THE EXPECTED FREQUENCY // HENCE WRITE ALL MICROSECONDS IN DOUBLE @@ -29,13 +29,48 @@ enum state END }; +bool check_sensors_feather( + Barometer *barometer, + 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; + } + + // 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,23 +80,26 @@ 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); + // 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(); + // // Run sensor check + // check_sensors(pwm, barometer, transceiver, imu, flash) + // ? buzzer->signalSuccess() + // : buzzer->signalFail(); + check_sensors_feather(barometer, transceiver) + ? Serial.println("sensors success") + : Serial.println("sensors failed"); - // Enable chips + // // Enable chips barometer->enable(); - imu->enable(); - transceiver->enable(); + // imu->enable(); + // transceiver->enable(); } void loop() From 8f52647c4530fb12ac029a2c468ebf9a6ad8ad44 Mon Sep 17 00:00:00 2001 From: Takumi Date: Mon, 14 Jun 2021 00:33:01 +0900 Subject: [PATCH 2/4] setup barometer for feather_board --- lib/baro/lps25hb.cpp | 4 +-- lib/baro/lps25hb.h | 8 +++++ lib/gps/gps.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++ lib/gps/gps.h | 53 +++++++++++++++++++++++++++++++++ src/config.h | 3 ++ src/main.cpp | 3 +- 6 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 lib/gps/gps.cpp create mode 100644 lib/gps/gps.h diff --git a/lib/baro/lps25hb.cpp b/lib/baro/lps25hb.cpp index 923032a..1bf1332 100644 --- a/lib/baro/lps25hb.cpp +++ b/lib/baro/lps25hb.cpp @@ -26,7 +26,7 @@ float Barometer::getPressure() bool Barometer::measurementReady() { - Serial.println("Barometer measurement ready."); + long current_time = millis(); if (current_time - this->previous_time >= this->measurement_delay) { @@ -38,7 +38,7 @@ bool Barometer::measurementReady() bool Barometer::Callback() { - Serial.println("inside barometer callback"); + // Serial.println("inside barometer callback"); if (measurementReady()) { sensors_event_t pressure; diff --git a/lib/baro/lps25hb.h b/lib/baro/lps25hb.h index 4278a64..795d5d9 100644 --- a/lib/baro/lps25hb.h +++ b/lib/baro/lps25hb.h @@ -8,9 +8,17 @@ #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 Barometer : public Task, public Chip { diff --git a/lib/gps/gps.cpp b/lib/gps/gps.cpp new file mode 100644 index 0000000..4b29fd3 --- /dev/null +++ b/lib/gps/gps.cpp @@ -0,0 +1,71 @@ +#include "gps.h" + +GPS::GPS(int LPS_CS, long measurement_delay) : Task(TASK_MILLISECOND, TASK_FOREVER, &scheduler, false), + measurement_delay(measurement_delay), + previous_time(0), + pressure(-1), + temperature(-1) +{ + // this->spi_dev = SPIClass(LPS_MOSI, LPS_MISO, LPS_SCK); + // this->spi_dev.begin(); + this->LPS_CS = LPS_CS; + this->lps_driver = new Adafruit_LPS25(); +} + +GPS::~GPS() {} + +float GPS::getTemperature() +{ + return this->temperature; +} + +float GPS::getPressure() +{ + return this->pressure; +} + +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() +{ + // Serial.println("inside barometer callback"); + if (measurementReady()) + { + sensors_event_t pressure; + sensors_event_t temp; + this->temp_driver->getEvent(&temp); + this->pressure_driver->getEvent(&pressure); + this->temperature = temp.temperature; + this->pressure = pressure.pressure; + Serial.println(this->pressure); + return true; + } + return false; +} + +bool GPS::OnEnable() +{ + this->temp_driver = this->lps_driver->getTemperatureSensor(); + this->pressure_driver = this->lps_driver->getPressureSensor(); + return true; +} + +void GPS::OnDisable() +{ +} + +bool GPS::checkStatus() +{ + Serial.println("Barometer Checking status"); + return this->lps_driver->begin_SPI(this->LPS_CS, &this->spi_dev); +} \ No newline at end of file diff --git a/lib/gps/gps.h b/lib/gps/gps.h new file mode 100644 index 0000000..c024502 --- /dev/null +++ b/lib/gps/gps.h @@ -0,0 +1,53 @@ +#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 Barometer : public Task, public Chip +{ +private: + Adafruit_LPS25 *lps_driver; + Adafruit_Sensor *temp_driver, *pressure_driver; + SPIClass spi_dev; + int LPS_CS; + long measurement_delay; + long previous_time = 0; + float pressure; + float temperature; + +public: + Barometer(int LPS_CS, long measurement_delay); + ~Barometer(); + + bool measurementReady(); + float getTemperature(); + float getPressure(); + + // Task virtual methods + bool Callback(); + bool OnEnable(); + void OnDisable(); + + // Chip virtual methods + bool checkStatus(); +}; + +#endif \ No newline at end of file diff --git a/src/config.h b/src/config.h index b064f48..e2f6d2b 100644 --- a/src/config.h +++ b/src/config.h @@ -55,6 +55,9 @@ #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 diff --git a/src/main.cpp b/src/main.cpp index e387b12..2b6ae60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,7 +88,7 @@ void setup() // blinker = new Blink(pwm); - // // Run sensor check + // Run sensor check // check_sensors(pwm, barometer, transceiver, imu, flash) // ? buzzer->signalSuccess() // : buzzer->signalFail(); @@ -104,4 +104,5 @@ void setup() void loop() { + scheduler.execute(); } \ No newline at end of file From f1e08bb6d09e04e3869e7b87d6fbf3f90edaef00 Mon Sep 17 00:00:00 2001 From: Takumi Date: Wed, 16 Jun 2021 18:09:28 +0900 Subject: [PATCH 3/4] craete gps lib and communicate data to ground software --- lib/baro/lps25hb.cpp | 1 - lib/baro/lps25hb.h | 10 +++--- lib/gps/gps.cpp | 48 +++++++++++++-------------- lib/gps/gps.h | 54 +++++++++++++++--------------- lib/transceiver/rfm69.cpp | 37 ++++++++++++++++++++- lib/transceiver/rfm69.h | 10 +++++- platformio.ini | 70 +++++++++++++++++++++++++++------------ src/config.h | 1 + src/main.cpp | 20 +++++++++-- 9 files changed, 168 insertions(+), 83 deletions(-) diff --git a/lib/baro/lps25hb.cpp b/lib/baro/lps25hb.cpp index 1bf1332..5c23c53 100644 --- a/lib/baro/lps25hb.cpp +++ b/lib/baro/lps25hb.cpp @@ -47,7 +47,6 @@ bool Barometer::Callback() this->pressure_driver->getEvent(&pressure); this->temperature = temp.temperature; this->pressure = pressure.pressure; - Serial.println(this->pressure); return true; } return false; diff --git a/lib/baro/lps25hb.h b/lib/baro/lps25hb.h index 795d5d9..f1af689 100644 --- a/lib/baro/lps25hb.h +++ b/lib/baro/lps25hb.h @@ -8,11 +8,11 @@ #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 PA5 +// #define LPS_MISO PA6 +// #define LPS_MOSI PA7 +// #endif #if defined(FEATHER_BOARD) #define LPS_SCK PB13 diff --git a/lib/gps/gps.cpp b/lib/gps/gps.cpp index 4b29fd3..83bc2f7 100644 --- a/lib/gps/gps.cpp +++ b/lib/gps/gps.cpp @@ -1,27 +1,33 @@ -#include "gps.h" +#include "gps.h"; -GPS::GPS(int LPS_CS, long measurement_delay) : Task(TASK_MILLISECOND, TASK_FOREVER, &scheduler, false), - measurement_delay(measurement_delay), - previous_time(0), - pressure(-1), - temperature(-1) +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->lps_driver = new Adafruit_LPS25(); + // this->LPS_CS = LPS_CS; + this->gps_driver = new SFE_UBLOX_GNSS(); } GPS::~GPS() {} -float GPS::getTemperature() +long GPS::getAltitude() { - return this->temperature; + return this->altitudeMSL; } -float GPS::getPressure() +long GPS::getLatitude() { - return this->pressure; + return this->latitude; +} + +long GPS::getLongitude() +{ + return this->longitude; } bool GPS::measurementReady() @@ -38,16 +44,12 @@ bool GPS::measurementReady() bool GPS::Callback() { - // Serial.println("inside barometer callback"); + this->gps_driver->checkUblox(); if (measurementReady()) { - sensors_event_t pressure; - sensors_event_t temp; - this->temp_driver->getEvent(&temp); - this->pressure_driver->getEvent(&pressure); - this->temperature = temp.temperature; - this->pressure = pressure.pressure; - Serial.println(this->pressure); + this->altitudeMSL = this->gps_driver->getAltitudeMSL(); + this->latitude = this->gps_driver->getLatitude(); + this->longitude = this->gps_driver->getLongitude(); return true; } return false; @@ -55,8 +57,6 @@ bool GPS::Callback() bool GPS::OnEnable() { - this->temp_driver = this->lps_driver->getTemperatureSensor(); - this->pressure_driver = this->lps_driver->getPressureSensor(); return true; } @@ -66,6 +66,6 @@ void GPS::OnDisable() bool GPS::checkStatus() { - Serial.println("Barometer Checking status"); - return this->lps_driver->begin_SPI(this->LPS_CS, &this->spi_dev); + 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 index c024502..59fbbe5 100644 --- a/lib/gps/gps.h +++ b/lib/gps/gps.h @@ -1,45 +1,47 @@ -#ifndef LPS25HB_H -#define LPS25HB_H +// #ifndef LPS25HB_H +// #define LPS25HB_H #include #include -#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 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 +// #if defined(FEATHER_BOARD) +// #define LPS_SCK PB13 +// #define LPS_MISO PB14 +// #define LPS_MOSI PB15 +// #endif -class Barometer : public Task, public Chip +class GPS : public Task, public Chip { private: - Adafruit_LPS25 *lps_driver; - Adafruit_Sensor *temp_driver, *pressure_driver; - SPIClass spi_dev; - int LPS_CS; + SFE_UBLOX_GNSS *gps_driver; + // Adafruit_Sensor *temp_driver, *pressure_driver; + // SPIClass spi_dev; + // int LPS_CS; long measurement_delay; long previous_time = 0; - float pressure; - float temperature; + long altitudeMSL; + long latitude; + long longitude; public: - Barometer(int LPS_CS, long measurement_delay); - ~Barometer(); + GPS(long measurement_delay); + ~GPS(); bool measurementReady(); - float getTemperature(); - float getPressure(); + long getAltitude(); + long getLatitude(); + long getLongitude(); // Task virtual methods bool Callback(); @@ -50,4 +52,4 @@ class Barometer : public Task, public Chip bool checkStatus(); }; -#endif \ No newline at end of file +// #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 b888ba8..3357e6f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,27 +8,28 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -[env:haloship] -platform = ststm32@13.0.0 -board = haloship -framework = arduino -upload_protocol = stlink -debug_tool = stlink -debug_speed = 480 -build_flags = - -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF - -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC - -D USBCON -lib_deps = - arkhipenko/TaskScheduler @ ^3.2.2 - robtillaart/PCA9635 @ ^0.3.1 - adafruit/Adafruit LPS2X @ ^2.0.1 - lowpowerlab/SPIFlash @ ^101.1.3 - https://github.com/haloship/RadioHead.git - niniack/BMX055@^0.1.0 -lib_extra_dirs = - /home/dunstan/git/bmx055 -lib_ldf_mode = deep +# [env:haloship] +# platform = ststm32@13.0.0 +# board = haloship +# framework = arduino +# upload_protocol = stlink +# debug_tool = stlink +# debug_speed = 480 +# build_flags = +# -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF +# -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC +# -D USBCON +# lib_deps = +# arkhipenko/TaskScheduler @ ^3.2.2 +# robtillaart/PCA9635 @ ^0.3.1 +# adafruit/Adafruit LPS2X @ ^2.0.1 +# lowpowerlab/SPIFlash @ ^101.1.3 +# https://github.com/haloship/RadioHead.git +# 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@13.0.0 @@ -47,7 +48,7 @@ lib_deps = 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 + sparkfun/SparkFun u-blox GNSS Arduino Library@^2.0.5 # niniack/BMX055@^0.1.0 https://github.com/haloship/bmx055.git lib_extra_dirs = @@ -55,6 +56,31 @@ lib_extra_dirs = # /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 board = adafruit_feather_f405 diff --git a/src/config.h b/src/config.h index e2f6d2b..d4f38ff 100644 --- a/src/config.h +++ b/src/config.h @@ -7,6 +7,7 @@ #include // #include #include +// #include #include // #include // // #include diff --git a/src/main.cpp b/src/main.cpp index 2b6ae60..86092d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ Buzzer *buzzer; // PWMControl *pwm; Barometer *barometer; // Blink *blinker; +GPS *gps; Transceiver *transceiver; // IMU *imu; // Flash *flash; @@ -31,6 +32,7 @@ enum state bool check_sensors_feather( Barometer *barometer, + GPS *gps, Transceiver *transceiver) { Serial.println("************************************"); @@ -50,6 +52,16 @@ bool check_sensors_feather( 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()) { @@ -82,7 +94,8 @@ void setup() buzzer = new Buzzer(); // pwm = new PWMControl(); barometer = new Barometer(LPS_CS, 500); - transceiver = new Transceiver(RFM69_CS, RFM69_INT); + gps = new GPS(500); + transceiver = new Transceiver(RFM69_CS, RFM69_INT, barometer, gps, 500); // imu = new IMU(500); // flash = new Flash(FLASH_CS); @@ -92,14 +105,15 @@ void setup() // check_sensors(pwm, barometer, transceiver, imu, flash) // ? buzzer->signalSuccess() // : buzzer->signalFail(); - check_sensors_feather(barometer, transceiver) + check_sensors_feather(barometer, gps, transceiver) ? Serial.println("sensors success") : Serial.println("sensors failed"); // // Enable chips barometer->enable(); + gps->enable(); // imu->enable(); - // transceiver->enable(); + transceiver->enable(); } void loop() From e49d9dc7ee96afb871ebcadf1af00ea3dff1dd27 Mon Sep 17 00:00:00 2001 From: Takumi Date: Fri, 18 Jun 2021 00:37:21 +0900 Subject: [PATCH 4/4] clean up before pull request --- lib/baro/lps25hb.cpp | 2 -- lib/baro/lps25hb.h | 10 +++++----- platformio.ini | 44 ++++++++++++++++++++++---------------------- src/config.h | 13 +++++++------ src/main.cpp | 18 ++++++++++-------- src/util.h | 13 ++++++++++++- 6 files changed, 56 insertions(+), 44 deletions(-) diff --git a/lib/baro/lps25hb.cpp b/lib/baro/lps25hb.cpp index 5c23c53..aacb84f 100644 --- a/lib/baro/lps25hb.cpp +++ b/lib/baro/lps25hb.cpp @@ -38,7 +38,6 @@ bool Barometer::measurementReady() bool Barometer::Callback() { - // Serial.println("inside barometer callback"); if (measurementReady()) { sensors_event_t pressure; @@ -65,6 +64,5 @@ void Barometer::OnDisable() bool Barometer::checkStatus() { - Serial.println("Barometer Checking status"); return this->lps_driver->begin_SPI(this->LPS_CS, &this->spi_dev); } \ No newline at end of file diff --git a/lib/baro/lps25hb.h b/lib/baro/lps25hb.h index f1af689..57d76a1 100644 --- a/lib/baro/lps25hb.h +++ b/lib/baro/lps25hb.h @@ -8,11 +8,11 @@ #include #include "chip.h" -// #if defined(FEATHER_BOARD) -// #define LPS_SCK PA5 -// #define LPS_MISO PA6 -// #define LPS_MOSI PA7 -// #endif +#if defined(HALOSHIP) +#define LPS_SCK PA5 +#define LPS_MISO PA6 +#define LPS_MOSI PA7 +#endif #if defined(FEATHER_BOARD) #define LPS_SCK PB13 diff --git a/platformio.ini b/platformio.ini index 3357e6f..ce20e7f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,28 +8,28 @@ ; Please visit documentation for the other options and examples ; https://docs.platformio.org/page/projectconf.html -# [env:haloship] -# platform = ststm32@13.0.0 -# board = haloship -# framework = arduino -# upload_protocol = stlink -# debug_tool = stlink -# debug_speed = 480 -# build_flags = -# -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF -# -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC -# -D USBCON -# lib_deps = -# arkhipenko/TaskScheduler @ ^3.2.2 -# robtillaart/PCA9635 @ ^0.3.1 -# adafruit/Adafruit LPS2X @ ^2.0.1 -# lowpowerlab/SPIFlash @ ^101.1.3 -# https://github.com/haloship/RadioHead.git -# 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:haloship] +platform = ststm32@13.0.0 +board = haloship +framework = arduino +upload_protocol = stlink +debug_tool = stlink +debug_speed = 480 +build_flags = + -D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF + -D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC + -D USBCON +lib_deps = + arkhipenko/TaskScheduler @ ^3.2.2 + robtillaart/PCA9635 @ ^0.3.1 + adafruit/Adafruit LPS2X @ ^2.0.1 + lowpowerlab/SPIFlash @ ^101.1.3 + https://github.com/haloship/RadioHead.git + 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@13.0.0 diff --git a/src/config.h b/src/config.h index d4f38ff..dc7719b 100644 --- a/src/config.h +++ b/src/config.h @@ -3,16 +3,17 @@ #include #include -// #include #include -// #include #include -// #include #include -// #include -// // #include -// #include #include +#include + +#include +#include +#include +#include +#include // #define BUZZER PC3 diff --git a/src/main.cpp b/src/main.cpp index 86092d6..8a8768e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,17 +1,18 @@ #include "config.h" -// #include "util.h" +#include "util.h" // Instantiate objects Buzzer *buzzer; -// PWMControl *pwm; Barometer *barometer; -// Blink *blinker; GPS *gps; Transceiver *transceiver; + +PWMControl *pwm; +Blink *blinker; // IMU *imu; -// Flash *flash; -// Servo main_chute_servo; -// Servo drogue_chute_servo; +Flash *flash; +Servo main_chute_servo; +Servo drogue_chute_servo; // SERVO USES STM32F4 TIMER 1 THAT OPERATES AT TWICE THE EXPECTED FREQUENCY // HENCE WRITE ALL MICROSECONDS IN DOUBLE @@ -102,9 +103,10 @@ void setup() // blinker = new Blink(pwm); // Run sensor check - // check_sensors(pwm, barometer, transceiver, imu, flash) + // 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"); @@ -112,8 +114,8 @@ void setup() // // Enable chips barometer->enable(); gps->enable(); - // imu->enable(); transceiver->enable(); + // imu->enable(); } void loop() 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; }