From 3e3346ff59faf1c758b1e7802692978ab81bd28b Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 19 Nov 2023 13:34:42 -0800 Subject: [PATCH 01/21] make buzzer sing on entry to landed state --- avionics/common/include/buzzer_interface.h | 3 +- avionics/common/include/states/landed.h | 12 ++++++ avionics/envs/board/src/buzzer.cpp | 42 +++++++++++++++++++ avionics/envs/x86/include/buzzer.h | 7 ++++ .../rockets/hollyburn/include/scheduler.hpp | 1 + .../rockets/silvertip/include/scheduler.hpp | 1 + .../tantalus_stage_1/include/scheduler.hpp | 1 + .../tantalus_stage_2/include/scheduler.hpp | 1 + avionics/tests/fake_include/scheduler.hpp | 1 + 9 files changed, 68 insertions(+), 1 deletion(-) diff --git a/avionics/common/include/buzzer_interface.h b/avionics/common/include/buzzer_interface.h index 3f2056eb..d93861fa 100644 --- a/avionics/common/include/buzzer_interface.h +++ b/avionics/common/include/buzzer_interface.h @@ -3,7 +3,8 @@ enum SongTypes { SongTypes_SUCCESS, SongTypes_NONCRITFAIL, - SongTypes_CRITICALFAIL + SongTypes_CRITICALFAIL, + SongTypes_LANDED, }; /*Classes--------------------------------------------------------------*/ diff --git a/avionics/common/include/states/landed.h b/avionics/common/include/states/landed.h index 9ae98e8f..52b3c13f 100644 --- a/avionics/common/include/states/landed.h +++ b/avionics/common/include/states/landed.h @@ -24,6 +24,18 @@ class Landed : public IState { * codes and used states. Note that the returned code may be the same state. */ StateId getNewState(Calculator const &) { return StateId::LANDED; } + + + void onEntry() override { + // create instance of buzzer + Buzzer landedBuzzer = Buzzer(); + + // create buzzer task + Scheduler::Task buzzer(Buzzer::landBuzzer, &landedBuzzer, Hal::ms(15000)); + + // register the task + Scheduler::registerTask(static_cast(TaskID::BuzzerBeacon) , buzzer); + } }; } // namespace State diff --git a/avionics/envs/board/src/buzzer.cpp b/avionics/envs/board/src/buzzer.cpp index 62251fca..49f7e934 100644 --- a/avionics/envs/board/src/buzzer.cpp +++ b/avionics/envs/board/src/buzzer.cpp @@ -158,6 +158,48 @@ void Buzzer::sing(SongTypes song) const { buzz(NOTE_A6, 2500); break; } + case SongTypes_LANDED: { + // Play the 2001: A Space Odyssey theme + buzz(NOTE_C5, 500); + buzz(NOTE_G5, 500); + buzz(NOTE_C6, 500); + + buzz(NOTE_E5, 100); + buzz(NOTE_DS5, 400); + Hal::sleep_ms(1000); + + buzz(NOTE_C5, 500); + buzz(NOTE_G5, 500); + buzz(NOTE_C6, 500); + Hal::sleep_ms(500); + + buzz(NOTE_E5, 100); + buzz(NOTE_A6, 400); // not correct + Hal::sleep_ms(500); + + buzz(NOTE_A6, 100); + buzz(NOTE_B6, 100); + buzz(NOTE_C6, 300); + Hal::sleep_ms(500) + + buzz(NOTE_D6, 250); + Hal::sleep_ms(250); + buzz(NOTE_E6, 100); + buzz(NOTE_F6, 100); + buzz(NOTE_G6, 300); + Hal::sleep_ms(500) + + buzz(NOTE_E6, 100); + buzz(NOTE_F6, 100); + buzz(NOTE_G6, 300); + Hal::sleep_ms(500) + + buzz(NOTE_A6, 500); + buzz(NOTE_B6, 250); + Hal::sleep_ms(250); + buzz(NOTE_C6, 750); + Hal::sleep_ms(1000); + break; } } diff --git a/avionics/envs/x86/include/buzzer.h b/avionics/envs/x86/include/buzzer.h index afb63c0f..0811e61d 100644 --- a/avionics/envs/x86/include/buzzer.h +++ b/avionics/envs/x86/include/buzzer.h @@ -10,4 +10,11 @@ class Buzzer : public IBuzzer { uint8_t tmpsong = static_cast(song); StdIoController::putPacket(0x07, &tmpsong, tmp); } + + /** + * \brief function that can be called in a task for buzzer when landed + */ + static void landBuzzer(void *self){ + reinterpret_cast(self)->sing(SongTypes_SUCCESS); + } }; diff --git a/avionics/rockets/hollyburn/include/scheduler.hpp b/avionics/rockets/hollyburn/include/scheduler.hpp index 7c672f0c..f2f63922 100644 --- a/avionics/rockets/hollyburn/include/scheduler.hpp +++ b/avionics/rockets/hollyburn/include/scheduler.hpp @@ -8,6 +8,7 @@ enum class TaskID { RadioTxBulk = 1, LEDBlinker = 2, RestartCamera = 3, + BuzzerBeacon = 4, kNum, }; diff --git a/avionics/rockets/silvertip/include/scheduler.hpp b/avionics/rockets/silvertip/include/scheduler.hpp index 7c672f0c..f2f63922 100644 --- a/avionics/rockets/silvertip/include/scheduler.hpp +++ b/avionics/rockets/silvertip/include/scheduler.hpp @@ -8,6 +8,7 @@ enum class TaskID { RadioTxBulk = 1, LEDBlinker = 2, RestartCamera = 3, + BuzzerBeacon = 4, kNum, }; diff --git a/avionics/rockets/tantalus_stage_1/include/scheduler.hpp b/avionics/rockets/tantalus_stage_1/include/scheduler.hpp index 7c672f0c..f2f63922 100644 --- a/avionics/rockets/tantalus_stage_1/include/scheduler.hpp +++ b/avionics/rockets/tantalus_stage_1/include/scheduler.hpp @@ -8,6 +8,7 @@ enum class TaskID { RadioTxBulk = 1, LEDBlinker = 2, RestartCamera = 3, + BuzzerBeacon = 4, kNum, }; diff --git a/avionics/rockets/tantalus_stage_2/include/scheduler.hpp b/avionics/rockets/tantalus_stage_2/include/scheduler.hpp index 7c672f0c..f2f63922 100644 --- a/avionics/rockets/tantalus_stage_2/include/scheduler.hpp +++ b/avionics/rockets/tantalus_stage_2/include/scheduler.hpp @@ -8,6 +8,7 @@ enum class TaskID { RadioTxBulk = 1, LEDBlinker = 2, RestartCamera = 3, + BuzzerBeacon = 4, kNum, }; diff --git a/avionics/tests/fake_include/scheduler.hpp b/avionics/tests/fake_include/scheduler.hpp index 32a9bd40..96fb5eb1 100644 --- a/avionics/tests/fake_include/scheduler.hpp +++ b/avionics/tests/fake_include/scheduler.hpp @@ -9,6 +9,7 @@ enum class TaskID { RadioTxBulk = 1, LEDBlinker = 2, RestartCamera = 3, + BuzzerBeacon = 4, kNum, }; From 575845a82c1f63f055b80d1702d61928c3256ffa Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 19 Nov 2023 13:47:55 -0800 Subject: [PATCH 02/21] fix pitch on buzzer --- avionics/envs/board/src/buzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avionics/envs/board/src/buzzer.cpp b/avionics/envs/board/src/buzzer.cpp index 49f7e934..00def661 100644 --- a/avionics/envs/board/src/buzzer.cpp +++ b/avionics/envs/board/src/buzzer.cpp @@ -174,7 +174,7 @@ void Buzzer::sing(SongTypes song) const { Hal::sleep_ms(500); buzz(NOTE_E5, 100); - buzz(NOTE_A6, 400); // not correct + buzz(NOTE_F6, 400); Hal::sleep_ms(500); buzz(NOTE_A6, 100); From ed5b5f49255c50535b124d37ad3e783f06d96377 Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 19 Nov 2023 15:57:02 -0800 Subject: [PATCH 03/21] move implementation to board version from x86 --- avionics/envs/board/include/buzzer.h | 5 +++++ avionics/envs/board/src/buzzer.cpp | 21 +++++++++++++-------- avionics/envs/x86/include/buzzer.h | 7 ------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/avionics/envs/board/include/buzzer.h b/avionics/envs/board/include/buzzer.h index 87606d4f..d107698b 100644 --- a/avionics/envs/board/include/buzzer.h +++ b/avionics/envs/board/include/buzzer.h @@ -56,6 +56,11 @@ class Buzzer : public IBuzzer { */ void buzz(long frequency, long length) const; + /** + * \brief function that can be called in a task for buzzer when landed + */ + static void landBuzzer(void *self); + private: const Pin M_MELODY_PIN; }; diff --git a/avionics/envs/board/src/buzzer.cpp b/avionics/envs/board/src/buzzer.cpp index 00def661..2ceefa8a 100644 --- a/avionics/envs/board/src/buzzer.cpp +++ b/avionics/envs/board/src/buzzer.cpp @@ -174,32 +174,33 @@ void Buzzer::sing(SongTypes song) const { Hal::sleep_ms(500); buzz(NOTE_E5, 100); - buzz(NOTE_F6, 400); + buzz(NOTE_F6, 400); Hal::sleep_ms(500); buzz(NOTE_A6, 100); buzz(NOTE_B6, 100); buzz(NOTE_C6, 300); - Hal::sleep_ms(500) + Hal::sleep_ms(500); buzz(NOTE_D6, 250); Hal::sleep_ms(250); buzz(NOTE_E6, 100); buzz(NOTE_F6, 100); buzz(NOTE_G6, 300); - Hal::sleep_ms(500) + Hal::sleep_ms(500); buzz(NOTE_E6, 100); buzz(NOTE_F6, 100); buzz(NOTE_G6, 300); - Hal::sleep_ms(500) + Hal::sleep_ms(500); buzz(NOTE_A6, 500); buzz(NOTE_B6, 250); Hal::sleep_ms(250); buzz(NOTE_C6, 750); Hal::sleep_ms(1000); - break; + break; + } } } @@ -214,11 +215,15 @@ void Buzzer::buzz(long frequency, long length) const { for (long i = 0; i < numCycles; i++) { // for the calculated length of time Hal::digitalWrite( M_MELODY_PIN, - Hal::PinDigital::HI); // write high to push out the diaphram - Hal::sleep_us(delayValue); // wait for the calculated delay value + Hal::PinDigital::HI); // write high to push out the diaphram + Hal::sleep_us(delayValue); // wait for the calculated delay value Hal::digitalWrite( M_MELODY_PIN, - Hal::PinDigital::LO); // write low to pull back the diaphram + Hal::PinDigital::LO); // write low to pull back the diaphram Hal::sleep_us(delayValue); // wait for the calculated delay value } } + +void Buzzer::landBuzzer(void *self){ + reinterpret_cast(self)->sing(SongTypes_SUCCESS); +} \ No newline at end of file diff --git a/avionics/envs/x86/include/buzzer.h b/avionics/envs/x86/include/buzzer.h index 0811e61d..afb63c0f 100644 --- a/avionics/envs/x86/include/buzzer.h +++ b/avionics/envs/x86/include/buzzer.h @@ -10,11 +10,4 @@ class Buzzer : public IBuzzer { uint8_t tmpsong = static_cast(song); StdIoController::putPacket(0x07, &tmpsong, tmp); } - - /** - * \brief function that can be called in a task for buzzer when landed - */ - static void landBuzzer(void *self){ - reinterpret_cast(self)->sing(SongTypes_SUCCESS); - } }; From 1121c8997d10383ed9e0a5c09b470d983e690e36 Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sat, 2 Dec 2023 19:32:25 -0800 Subject: [PATCH 04/21] add landBuzzer to .h file --- avionics/envs/x86/include/buzzer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/avionics/envs/x86/include/buzzer.h b/avionics/envs/x86/include/buzzer.h index afb63c0f..eb7f8b37 100644 --- a/avionics/envs/x86/include/buzzer.h +++ b/avionics/envs/x86/include/buzzer.h @@ -10,4 +10,6 @@ class Buzzer : public IBuzzer { uint8_t tmpsong = static_cast(song); StdIoController::putPacket(0x07, &tmpsong, tmp); } + + static void landBuzzer(void *self); }; From 419fa040e2e6b53ea452dd53b3440aa226a1e943 Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Tue, 5 Dec 2023 11:27:03 -0800 Subject: [PATCH 05/21] include buzzer.h in landed.h --- avionics/common/include/states/landed.h | 1 + avionics/envs/x86/include/buzzer.h | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/avionics/common/include/states/landed.h b/avionics/common/include/states/landed.h index 52b3c13f..454b1bdb 100644 --- a/avionics/common/include/states/landed.h +++ b/avionics/common/include/states/landed.h @@ -4,6 +4,7 @@ #include "cameras.h" #include "scheduler.hpp" #include "state_interface.h" +#include "buzzer.h" namespace State { diff --git a/avionics/envs/x86/include/buzzer.h b/avionics/envs/x86/include/buzzer.h index eb7f8b37..afb63c0f 100644 --- a/avionics/envs/x86/include/buzzer.h +++ b/avionics/envs/x86/include/buzzer.h @@ -10,6 +10,4 @@ class Buzzer : public IBuzzer { uint8_t tmpsong = static_cast(song); StdIoController::putPacket(0x07, &tmpsong, tmp); } - - static void landBuzzer(void *self); }; From 7f0c96f5021edfc33e9b1eec636a8775e63c49ed Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Tue, 5 Dec 2023 19:47:26 -0800 Subject: [PATCH 06/21] fix no landBuzzer in buzzer --- avionics/common/include/states/landed.h | 4 ++-- avionics/envs/x86/include/buzzer.h | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/avionics/common/include/states/landed.h b/avionics/common/include/states/landed.h index 454b1bdb..b031a701 100644 --- a/avionics/common/include/states/landed.h +++ b/avionics/common/include/states/landed.h @@ -32,10 +32,10 @@ class Landed : public IState { Buzzer landedBuzzer = Buzzer(); // create buzzer task - Scheduler::Task buzzer(Buzzer::landBuzzer, &landedBuzzer, Hal::ms(15000)); + Scheduler::Task buzzer = Scheduler::Task(Buzzer::landBuzzer , &landedBuzzer, Hal::ms(15000)); // register the task - Scheduler::registerTask(static_cast(TaskID::BuzzerBeacon) , buzzer); + Scheduler::registerTask(static_cast(TaskID::BuzzerBeacon), buzzer); } }; diff --git a/avionics/envs/x86/include/buzzer.h b/avionics/envs/x86/include/buzzer.h index afb63c0f..a33cd069 100644 --- a/avionics/envs/x86/include/buzzer.h +++ b/avionics/envs/x86/include/buzzer.h @@ -10,4 +10,8 @@ class Buzzer : public IBuzzer { uint8_t tmpsong = static_cast(song); StdIoController::putPacket(0x07, &tmpsong, tmp); } + + void landBuzzer(void *self){ + reinterpret_cast(self)->sing(SongTypes_SUCCESS); + } }; From 8ed52368aeb709ce889a15ee9dcba7b21007296c Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Tue, 5 Dec 2023 19:57:11 -0800 Subject: [PATCH 07/21] make x86 landBuzzer static --- avionics/envs/x86/include/buzzer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avionics/envs/x86/include/buzzer.h b/avionics/envs/x86/include/buzzer.h index a33cd069..bcd8f674 100644 --- a/avionics/envs/x86/include/buzzer.h +++ b/avionics/envs/x86/include/buzzer.h @@ -11,7 +11,7 @@ class Buzzer : public IBuzzer { StdIoController::putPacket(0x07, &tmpsong, tmp); } - void landBuzzer(void *self){ + static void landBuzzer(void *self){ reinterpret_cast(self)->sing(SongTypes_SUCCESS); } }; From a5026ed4204dd703b9c2211038d3de4af48dec3c Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 10 Dec 2023 15:32:00 -0800 Subject: [PATCH 08/21] add landed_buzzer.hpp --- avionics/common/include/states/landed.h | 10 +------- .../common/include/tasks/landed_buzzer.hpp | 23 +++++++++++++++++ avionics/common/src/avionics.cpp | 12 +++++++++ avionics/common/src/radio.cpp | 2 +- avionics/envs/board/include/buzzer.h | 8 +++--- .../envs/board/include/sensors/barometer.h | 2 ++ avionics/envs/board/src/buzzer.cpp | 16 +++++++++--- avionics/envs/board/src/sensors/barometer.cpp | 25 ++++++++++++------- avionics/envs/x86/include/buzzer.h | 7 +++--- 9 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 avionics/common/include/tasks/landed_buzzer.hpp diff --git a/avionics/common/include/states/landed.h b/avionics/common/include/states/landed.h index b031a701..547010d2 100644 --- a/avionics/common/include/states/landed.h +++ b/avionics/common/include/states/landed.h @@ -26,16 +26,8 @@ class Landed : public IState { */ StateId getNewState(Calculator const &) { return StateId::LANDED; } - void onEntry() override { - // create instance of buzzer - Buzzer landedBuzzer = Buzzer(); - - // create buzzer task - Scheduler::Task buzzer = Scheduler::Task(Buzzer::landBuzzer , &landedBuzzer, Hal::ms(15000)); - - // register the task - Scheduler::registerTask(static_cast(TaskID::BuzzerBeacon), buzzer); + Scheduler::scheduleTask(Hal::now_ms() + Hal::ms(1), static_cast(TaskID::BuzzerBeacon)); } }; diff --git a/avionics/common/include/tasks/landed_buzzer.hpp b/avionics/common/include/tasks/landed_buzzer.hpp new file mode 100644 index 00000000..11a21075 --- /dev/null +++ b/avionics/common/include/tasks/landed_buzzer.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "HAL/time.h" +#include "buzzer.h" + + +/** + * @brief R + */ +class LandedBuzzer{ + private: + Buzzer buzzer_; + + public: + LandedBuzzer(Buzzer &buzzer) : buzzer_(buzzer){ + + } + static void run(void * self) { + reinterpret_cast(self)->buzzer_.sing(SongTypes_CRITICALFAIL); + + } + static constexpr Hal::ms freq{500}; +}; diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 9c5ccc83..6031e2dd 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -69,6 +69,7 @@ PLEASE READ ME! #include "tasks/led_blinker.hpp" #include "tasks/main_tasks.hpp" #include "tasks/restart_camera.hpp" +#include "tasks/landed_buzzer.hpp" #include "radio.h" #include "rocket.h" @@ -135,6 +136,8 @@ int main(void) { auto &sensors = rocket.sensors; auto &ignitors = rocket.ignitors; + LandedBuzzer landedBuzzer(rocket.buzzer); + if (init_status == RocketStatus::CRITICAL_FAILURE) { LOG_ERROR("Critical failure; aborting in state machine"); state_machine.abort(); @@ -217,6 +220,15 @@ int main(void) { Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::HI); break; } + + Task buzzer(LandedBuzzer::run, nullptr, Hal::ms(1500)); + Scheduler::preregisterTask(static_cast(TaskID::BuzzerBeacon), buzzer, true, false); + //Scheduler::preregisterTask(static_cast(TaskID::BuzzerBeacon), led_blink, true, false); + rocket.buzzer.buzz(1760, 2500); + Scheduler::scheduleTask(Hal::now_ms() + Hal::ms(1), static_cast(TaskID::BuzzerBeacon)); + rocket.buzzer.buzz(1000, 5000); + + // RestartCamera restart_camera_(rocket.cam); // // This tasks sets its own reschedule interval (since the same task is run diff --git a/avionics/common/src/radio.cpp b/avionics/common/src/radio.cpp index 087dad9e..54393525 100644 --- a/avionics/common/src/radio.cpp +++ b/avionics/common/src/radio.cpp @@ -130,7 +130,7 @@ void Radio::addIdTime(command_t id, uint32_t time) { void Radio::send() { if (!self.tx_q_.empty()) { self.tx_packet_.setPayloadLength(self.tx_q_.fillPayload(self.payload_)); - self.xbee_.send(self.tx_packet_); + //self.xbee_.send(self.tx_packet_); } } diff --git a/avionics/envs/board/include/buzzer.h b/avionics/envs/board/include/buzzer.h index d107698b..574157bf 100644 --- a/avionics/envs/board/include/buzzer.h +++ b/avionics/envs/board/include/buzzer.h @@ -56,10 +56,10 @@ class Buzzer : public IBuzzer { */ void buzz(long frequency, long length) const; - /** - * \brief function that can be called in a task for buzzer when landed - */ - static void landBuzzer(void *self); + // /** + // * \brief function that can be called in a task for buzzer when landed + // */ + // static void landBuzzer(void *self); private: const Pin M_MELODY_PIN; diff --git a/avionics/envs/board/include/sensors/barometer.h b/avionics/envs/board/include/sensors/barometer.h index 4aee0433..223c05cf 100644 --- a/avionics/envs/board/include/sensors/barometer.h +++ b/avionics/envs/board/include/sensors/barometer.h @@ -20,6 +20,8 @@ class Barometer : public SensorBase { private: MS5xxx barometer; + int fakePressure; + int negative; }; #endif diff --git a/avionics/envs/board/src/buzzer.cpp b/avionics/envs/board/src/buzzer.cpp index 2ceefa8a..88068b69 100644 --- a/avionics/envs/board/src/buzzer.cpp +++ b/avionics/envs/board/src/buzzer.cpp @@ -121,6 +121,11 @@ * @return void. */ void Buzzer::sing(SongTypes song) const { + // Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::HI); + // Hal::sleep_ms(1000); + // Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO); + // return; + switch (song) { case SongTypes_SUCCESS: { buzz(NOTE_C1, 500); @@ -161,6 +166,7 @@ void Buzzer::sing(SongTypes song) const { case SongTypes_LANDED: { // Play the 2001: A Space Odyssey theme buzz(NOTE_C5, 500); + /* buzz(NOTE_G5, 500); buzz(NOTE_C6, 500); @@ -199,12 +205,16 @@ void Buzzer::sing(SongTypes song) const { Hal::sleep_ms(250); buzz(NOTE_C6, 750); Hal::sleep_ms(1000); + */ break; } } } void Buzzer::buzz(long frequency, long length) const { + Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::HI); + Hal::sleep_ms(1000); + Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO); long delayValue = 1000000 / frequency / 2; // delay between transitions // 1 000 000 microseconds, divided by the frequency, divided by 2 b/c @@ -224,6 +234,6 @@ void Buzzer::buzz(long frequency, long length) const { } } -void Buzzer::landBuzzer(void *self){ - reinterpret_cast(self)->sing(SongTypes_SUCCESS); -} \ No newline at end of file +// void Buzzer::landBuzzer(void *self){ +// reinterpret_cast(self)->sing(SongTypes_SUCCESS); +// } \ No newline at end of file diff --git a/avionics/envs/board/src/sensors/barometer.cpp b/avionics/envs/board/src/sensors/barometer.cpp index cc8c8364..72c50d38 100644 --- a/avionics/envs/board/src/sensors/barometer.cpp +++ b/avionics/envs/board/src/sensors/barometer.cpp @@ -2,7 +2,7 @@ #include "sensors/barometer.h" #include "options.h" -Barometer::Barometer(float *const buf) : SensorBase(buf) , barometer(&Wire) { +Barometer::Barometer(float *const buf) : SensorBase(buf) , barometer(&Wire) , fakePressure(101300), negative(-1) { /*init barometer*/ barometer.setI2Caddr(0b1110111); @@ -24,16 +24,23 @@ Barometer::Barometer(float *const buf) : SensorBase(buf) , barometer(&Wire) { void Barometer::readData() { - barometer.ReadProm(); - barometer.Readout(); + // barometer.ReadProm(); + // barometer.Readout(); - data_[0] = barometer.GetPres(); + // data_[0] = barometer.GetPres(); - // Re-read in case of overflow - while (data_[0] < 0 || data_[0] > 102000) { - barometer.ReadProm(); - barometer.Readout(); - data_[0] = barometer.GetPres(); + // // Re-read in case of overflow + // while (data_[0] < 0 || data_[0] > 102000) { + // barometer.ReadProm(); + // barometer.Readout(); + // data_[0] = barometer.GetPres(); + // } + fakePressure += 500 * negative; + data_[0] = fakePressure; + if(fakePressure < 60000){ + negative = 1; + }else if(fakePressure > 101400){ + negative = 0; } data_[1] = barometer.GetTemp(); diff --git a/avionics/envs/x86/include/buzzer.h b/avionics/envs/x86/include/buzzer.h index bcd8f674..ddd9bc39 100644 --- a/avionics/envs/x86/include/buzzer.h +++ b/avionics/envs/x86/include/buzzer.h @@ -10,8 +10,7 @@ class Buzzer : public IBuzzer { uint8_t tmpsong = static_cast(song); StdIoController::putPacket(0x07, &tmpsong, tmp); } - - static void landBuzzer(void *self){ - reinterpret_cast(self)->sing(SongTypes_SUCCESS); - } + // static void landBuzzer(void *self){ + // reinterpret_cast(self)->sing(SongTypes_SUCCESS); + // } }; From fb916410b6e3a0e5bdb07525fd87c00a20815728 Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 10 Dec 2023 15:53:37 -0800 Subject: [PATCH 09/21] Working landed buzzer! Song needs some work. --- avionics/common/include/tasks/landed_buzzer.hpp | 4 ++-- avionics/common/src/avionics.cpp | 8 +------- avionics/envs/board/src/buzzer.cpp | 6 ------ 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/avionics/common/include/tasks/landed_buzzer.hpp b/avionics/common/include/tasks/landed_buzzer.hpp index 11a21075..a016968c 100644 --- a/avionics/common/include/tasks/landed_buzzer.hpp +++ b/avionics/common/include/tasks/landed_buzzer.hpp @@ -16,8 +16,8 @@ class LandedBuzzer{ } static void run(void * self) { - reinterpret_cast(self)->buzzer_.sing(SongTypes_CRITICALFAIL); - + //reinterpret_cast(self)->buzzer_.sing(SongTypes_CRITICALFAIL); + reinterpret_cast(self)->buzzer_.sing(SongTypes_LANDED); } static constexpr Hal::ms freq{500}; }; diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 6031e2dd..9d721f6b 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -221,14 +221,8 @@ int main(void) { break; } - Task buzzer(LandedBuzzer::run, nullptr, Hal::ms(1500)); + Task buzzer(LandedBuzzer::run, &landedBuzzer, Hal::ms(15000)); Scheduler::preregisterTask(static_cast(TaskID::BuzzerBeacon), buzzer, true, false); - //Scheduler::preregisterTask(static_cast(TaskID::BuzzerBeacon), led_blink, true, false); - rocket.buzzer.buzz(1760, 2500); - Scheduler::scheduleTask(Hal::now_ms() + Hal::ms(1), static_cast(TaskID::BuzzerBeacon)); - rocket.buzzer.buzz(1000, 5000); - - // RestartCamera restart_camera_(rocket.cam); // // This tasks sets its own reschedule interval (since the same task is run diff --git a/avionics/envs/board/src/buzzer.cpp b/avionics/envs/board/src/buzzer.cpp index 88068b69..6b9f6021 100644 --- a/avionics/envs/board/src/buzzer.cpp +++ b/avionics/envs/board/src/buzzer.cpp @@ -166,7 +166,6 @@ void Buzzer::sing(SongTypes song) const { case SongTypes_LANDED: { // Play the 2001: A Space Odyssey theme buzz(NOTE_C5, 500); - /* buzz(NOTE_G5, 500); buzz(NOTE_C6, 500); @@ -205,17 +204,12 @@ void Buzzer::sing(SongTypes song) const { Hal::sleep_ms(250); buzz(NOTE_C6, 750); Hal::sleep_ms(1000); - */ break; } } } void Buzzer::buzz(long frequency, long length) const { - Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::HI); - Hal::sleep_ms(1000); - Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO); - long delayValue = 1000000 / frequency / 2; // delay between transitions // 1 000 000 microseconds, divided by the frequency, divided by 2 b/c // there are two phases to each cycle From 41988b69f6dbac4bd1bdbc748e752d8673d91099 Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 14 Jan 2024 12:58:00 -0800 Subject: [PATCH 10/21] updated song --- .../common/include/tasks/landed_buzzer.hpp | 25 +++-- avionics/common/src/avionics.cpp | 3 +- avionics/envs/board/include/buzzer.h | 5 - avionics/envs/board/src/buzzer.cpp | 99 ++++++++++--------- avionics/envs/x86/include/buzzer.h | 3 - 5 files changed, 68 insertions(+), 67 deletions(-) diff --git a/avionics/common/include/tasks/landed_buzzer.hpp b/avionics/common/include/tasks/landed_buzzer.hpp index a016968c..b21f3fa9 100644 --- a/avionics/common/include/tasks/landed_buzzer.hpp +++ b/avionics/common/include/tasks/landed_buzzer.hpp @@ -1,23 +1,28 @@ +/** + * Landed Buzzer + * + * @file landed_buzzer.hpp + * @author UBC Rocket Avionics 2023/2024 + * @description Class that allows landed buzzer to be run within a task + */ + #pragma once +/*Includes------------------------------------------------------------*/ #include "HAL/time.h" #include "buzzer.h" +class LandedBuzzer { -/** - * @brief R - */ -class LandedBuzzer{ private: Buzzer buzzer_; public: - LandedBuzzer(Buzzer &buzzer) : buzzer_(buzzer){ - - } - static void run(void * self) { - //reinterpret_cast(self)->buzzer_.sing(SongTypes_CRITICALFAIL); - reinterpret_cast(self)->buzzer_.sing(SongTypes_LANDED); + LandedBuzzer(Buzzer &buzzer) : buzzer_(buzzer) {} + + // run function to be called by a task + static void run(void *self) { + reinterpret_cast(self)->buzzer_.sing(SongTypes_LANDED); } static constexpr Hal::ms freq{500}; }; diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 9d721f6b..04a79e07 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -136,6 +136,7 @@ int main(void) { auto &sensors = rocket.sensors; auto &ignitors = rocket.ignitors; + // Create instance of landed buzzer LandedBuzzer landedBuzzer(rocket.buzzer); if (init_status == RocketStatus::CRITICAL_FAILURE) { @@ -221,7 +222,7 @@ int main(void) { break; } - Task buzzer(LandedBuzzer::run, &landedBuzzer, Hal::ms(15000)); + Task buzzer(LandedBuzzer::run, &landedBuzzer, Hal::ms(64000)); Scheduler::preregisterTask(static_cast(TaskID::BuzzerBeacon), buzzer, true, false); // RestartCamera restart_camera_(rocket.cam); diff --git a/avionics/envs/board/include/buzzer.h b/avionics/envs/board/include/buzzer.h index 574157bf..87606d4f 100644 --- a/avionics/envs/board/include/buzzer.h +++ b/avionics/envs/board/include/buzzer.h @@ -56,11 +56,6 @@ class Buzzer : public IBuzzer { */ void buzz(long frequency, long length) const; - // /** - // * \brief function that can be called in a task for buzzer when landed - // */ - // static void landBuzzer(void *self); - private: const Pin M_MELODY_PIN; }; diff --git a/avionics/envs/board/src/buzzer.cpp b/avionics/envs/board/src/buzzer.cpp index 6b9f6021..45d1b32a 100644 --- a/avionics/envs/board/src/buzzer.cpp +++ b/avionics/envs/board/src/buzzer.cpp @@ -121,11 +121,6 @@ * @return void. */ void Buzzer::sing(SongTypes song) const { - // Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::HI); - // Hal::sleep_ms(1000); - // Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO); - // return; - switch (song) { case SongTypes_SUCCESS: { buzz(NOTE_C1, 500); @@ -165,45 +160,57 @@ void Buzzer::sing(SongTypes song) const { } case SongTypes_LANDED: { // Play the 2001: A Space Odyssey theme - buzz(NOTE_C5, 500); - buzz(NOTE_G5, 500); - buzz(NOTE_C6, 500); - - buzz(NOTE_E5, 100); - buzz(NOTE_DS5, 400); - Hal::sleep_ms(1000); - - buzz(NOTE_C5, 500); - buzz(NOTE_G5, 500); - buzz(NOTE_C6, 500); - Hal::sleep_ms(500); - - buzz(NOTE_E5, 100); - buzz(NOTE_F6, 400); - Hal::sleep_ms(500); - - buzz(NOTE_A6, 100); - buzz(NOTE_B6, 100); - buzz(NOTE_C6, 300); - Hal::sleep_ms(500); - - buzz(NOTE_D6, 250); - Hal::sleep_ms(250); - buzz(NOTE_E6, 100); - buzz(NOTE_F6, 100); - buzz(NOTE_G6, 300); - Hal::sleep_ms(500); - - buzz(NOTE_E6, 100); - buzz(NOTE_F6, 100); - buzz(NOTE_G6, 300); - Hal::sleep_ms(500); - - buzz(NOTE_A6, 500); - buzz(NOTE_B6, 250); - Hal::sleep_ms(250); - buzz(NOTE_C6, 750); - Hal::sleep_ms(1000); + buzz(NOTE_C5, 2000); + buzz(NOTE_G5, 2000); + buzz(NOTE_C6, 3500); + buzz(NOTE_E6, 250); + buzz(NOTE_DS6, 4000); + + buzz(NOTE_C4, 500); + buzz(NOTE_G3, 500); + buzz(NOTE_C4, 500); + buzz(NOTE_G3, 500); + buzz(NOTE_C4, 500); + buzz(NOTE_G3, 500); + buzz(NOTE_C4, 500); + buzz(NOTE_G3, 500); + + buzz(NOTE_C5, 2000); + buzz(NOTE_G5, 2000); + buzz(NOTE_C6, 3500); + buzz(NOTE_DS6, 250); + buzz(NOTE_E6, 4000); + + buzz(NOTE_C4, 500); + buzz(NOTE_G3, 500); + buzz(NOTE_C4, 500); + buzz(NOTE_G3, 500); + buzz(NOTE_C4, 500); + buzz(NOTE_G3, 500); + buzz(NOTE_C4, 500); + buzz(NOTE_G3, 500); + + buzz(NOTE_C5, 2000); + buzz(NOTE_G5, 2000); + buzz(NOTE_C6, 3500); + buzz(NOTE_E6, 250); + buzz(NOTE_A6, 4000); + + buzz(NOTE_A5, 250); + buzz(NOTE_B5, 250); + buzz(NOTE_C6, 2500); + buzz(NOTE_D6, 1000); + + buzz(NOTE_E6, 500); + buzz(NOTE_F6, 500); + buzz(NOTE_G6, 2500); + buzz(NOTE_E6, 250); + buzz(NOTE_F6, 250); + + buzz(NOTE_G6, 2000); + buzz(NOTE_A6, 1000); + buzz(NOTE_B6, 1000); + buzz(NOTE_C7, 8000); break; } } @@ -227,7 +234,3 @@ void Buzzer::buzz(long frequency, long length) const { Hal::sleep_us(delayValue); // wait for the calculated delay value } } - -// void Buzzer::landBuzzer(void *self){ -// reinterpret_cast(self)->sing(SongTypes_SUCCESS); -// } \ No newline at end of file diff --git a/avionics/envs/x86/include/buzzer.h b/avionics/envs/x86/include/buzzer.h index ddd9bc39..afb63c0f 100644 --- a/avionics/envs/x86/include/buzzer.h +++ b/avionics/envs/x86/include/buzzer.h @@ -10,7 +10,4 @@ class Buzzer : public IBuzzer { uint8_t tmpsong = static_cast(song); StdIoController::putPacket(0x07, &tmpsong, tmp); } - // static void landBuzzer(void *self){ - // reinterpret_cast(self)->sing(SongTypes_SUCCESS); - // } }; From 2fbd505f42e08a5d79d6dc677619ebaa347db452 Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 14 Jan 2024 14:15:35 -0800 Subject: [PATCH 11/21] faster song pause --- avionics/common/src/avionics.cpp | 2 +- avionics/envs/board/src/buzzer.cpp | 89 ++++++++++--------- avionics/envs/board/src/sensors/barometer.cpp | 2 +- 3 files changed, 47 insertions(+), 46 deletions(-) diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 04a79e07..6123cc0a 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -222,7 +222,7 @@ int main(void) { break; } - Task buzzer(LandedBuzzer::run, &landedBuzzer, Hal::ms(64000)); + Task buzzer(LandedBuzzer::run, &landedBuzzer, Hal::ms(45000)); Scheduler::preregisterTask(static_cast(TaskID::BuzzerBeacon), buzzer, true, false); // RestartCamera restart_camera_(rocket.cam); diff --git a/avionics/envs/board/src/buzzer.cpp b/avionics/envs/board/src/buzzer.cpp index 45d1b32a..acbfeb03 100644 --- a/avionics/envs/board/src/buzzer.cpp +++ b/avionics/envs/board/src/buzzer.cpp @@ -160,57 +160,58 @@ void Buzzer::sing(SongTypes song) const { } case SongTypes_LANDED: { // Play the 2001: A Space Odyssey theme - buzz(NOTE_C5, 2000); - buzz(NOTE_G5, 2000); - buzz(NOTE_C6, 3500); - buzz(NOTE_E6, 250); - buzz(NOTE_DS6, 4000); + int tempo = 2; + buzz(NOTE_C5, 2000 / tempo); + buzz(NOTE_G5, 2000 / tempo); + buzz(NOTE_C6, 3500 / tempo); + buzz(NOTE_E6, 250 / tempo); + buzz(NOTE_DS6, 4000 / tempo); - buzz(NOTE_C4, 500); - buzz(NOTE_G3, 500); - buzz(NOTE_C4, 500); - buzz(NOTE_G3, 500); - buzz(NOTE_C4, 500); - buzz(NOTE_G3, 500); - buzz(NOTE_C4, 500); - buzz(NOTE_G3, 500); + buzz(NOTE_C4, 500 / tempo); + buzz(NOTE_G3, 500 / tempo); + buzz(NOTE_C4, 500 / tempo); + buzz(NOTE_G3, 500 / tempo); + buzz(NOTE_C4, 500 / tempo); + buzz(NOTE_G3, 500 / tempo); + buzz(NOTE_C4, 500 / tempo); + buzz(NOTE_G3, 500 / tempo); - buzz(NOTE_C5, 2000); - buzz(NOTE_G5, 2000); - buzz(NOTE_C6, 3500); - buzz(NOTE_DS6, 250); - buzz(NOTE_E6, 4000); + buzz(NOTE_C5, 2000 / tempo); + buzz(NOTE_G5, 2000 / tempo); + buzz(NOTE_C6, 3500 / tempo); + buzz(NOTE_DS6, 250 / tempo); + buzz(NOTE_E6, 4000 / tempo); - buzz(NOTE_C4, 500); - buzz(NOTE_G3, 500); - buzz(NOTE_C4, 500); - buzz(NOTE_G3, 500); - buzz(NOTE_C4, 500); - buzz(NOTE_G3, 500); - buzz(NOTE_C4, 500); - buzz(NOTE_G3, 500); + buzz(NOTE_C4, 500 / tempo); + buzz(NOTE_G3, 500 / tempo); + buzz(NOTE_C4, 500 / tempo); + buzz(NOTE_G3, 500 / tempo); + buzz(NOTE_C4, 500 / tempo); + buzz(NOTE_G3, 500 / tempo); + buzz(NOTE_C4, 500 / tempo); + buzz(NOTE_G3, 500 / tempo); - buzz(NOTE_C5, 2000); - buzz(NOTE_G5, 2000); - buzz(NOTE_C6, 3500); - buzz(NOTE_E6, 250); - buzz(NOTE_A6, 4000); + buzz(NOTE_C5, 2000 / tempo); + buzz(NOTE_G5, 2000 / tempo); + buzz(NOTE_C6, 3500 / tempo); + buzz(NOTE_E6, 250 / tempo); + buzz(NOTE_A6, 4000 / tempo); - buzz(NOTE_A5, 250); - buzz(NOTE_B5, 250); - buzz(NOTE_C6, 2500); - buzz(NOTE_D6, 1000); + buzz(NOTE_A5, 250 / tempo); + buzz(NOTE_B5, 250 / tempo); + buzz(NOTE_C6, 2500 / tempo); + buzz(NOTE_D6, 1000 / tempo); - buzz(NOTE_E6, 500); - buzz(NOTE_F6, 500); - buzz(NOTE_G6, 2500); - buzz(NOTE_E6, 250); - buzz(NOTE_F6, 250); + buzz(NOTE_E6, 500 / tempo); + buzz(NOTE_F6, 500 / tempo); + buzz(NOTE_G6, 2500 / tempo); + buzz(NOTE_E6, 250 / tempo); + buzz(NOTE_F6, 250 / tempo); - buzz(NOTE_G6, 2000); - buzz(NOTE_A6, 1000); - buzz(NOTE_B6, 1000); - buzz(NOTE_C7, 8000); + buzz(NOTE_G6, 2000 / tempo); + buzz(NOTE_A6, 1000 / tempo); + buzz(NOTE_B6, 1000 / tempo); + buzz(NOTE_C7, 8000 / tempo); break; } } diff --git a/avionics/envs/board/src/sensors/barometer.cpp b/avionics/envs/board/src/sensors/barometer.cpp index 72c50d38..10098899 100644 --- a/avionics/envs/board/src/sensors/barometer.cpp +++ b/avionics/envs/board/src/sensors/barometer.cpp @@ -35,7 +35,7 @@ void Barometer::readData() { // barometer.Readout(); // data_[0] = barometer.GetPres(); // } - fakePressure += 500 * negative; + fakePressure += 2000 * negative; data_[0] = fakePressure; if(fakePressure < 60000){ negative = 1; From f155fc4d8796c35d83f8b3a8fceda651da339151 Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 14 Jan 2024 14:18:46 -0800 Subject: [PATCH 12/21] remove testing code --- avionics/common/src/radio.cpp | 2 +- .../envs/board/include/sensors/barometer.h | 2 -- avionics/envs/board/src/sensors/barometer.cpp | 27 +++++++------------ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/avionics/common/src/radio.cpp b/avionics/common/src/radio.cpp index 54393525..087dad9e 100644 --- a/avionics/common/src/radio.cpp +++ b/avionics/common/src/radio.cpp @@ -130,7 +130,7 @@ void Radio::addIdTime(command_t id, uint32_t time) { void Radio::send() { if (!self.tx_q_.empty()) { self.tx_packet_.setPayloadLength(self.tx_q_.fillPayload(self.payload_)); - //self.xbee_.send(self.tx_packet_); + self.xbee_.send(self.tx_packet_); } } diff --git a/avionics/envs/board/include/sensors/barometer.h b/avionics/envs/board/include/sensors/barometer.h index 223c05cf..4aee0433 100644 --- a/avionics/envs/board/include/sensors/barometer.h +++ b/avionics/envs/board/include/sensors/barometer.h @@ -20,8 +20,6 @@ class Barometer : public SensorBase { private: MS5xxx barometer; - int fakePressure; - int negative; }; #endif diff --git a/avionics/envs/board/src/sensors/barometer.cpp b/avionics/envs/board/src/sensors/barometer.cpp index 10098899..151bcf83 100644 --- a/avionics/envs/board/src/sensors/barometer.cpp +++ b/avionics/envs/board/src/sensors/barometer.cpp @@ -2,7 +2,7 @@ #include "sensors/barometer.h" #include "options.h" -Barometer::Barometer(float *const buf) : SensorBase(buf) , barometer(&Wire) , fakePressure(101300), negative(-1) { +Barometer::Barometer(float *const buf) : SensorBase(buf) , barometer(&Wire) { /*init barometer*/ barometer.setI2Caddr(0b1110111); @@ -24,25 +24,18 @@ Barometer::Barometer(float *const buf) : SensorBase(buf) , barometer(&Wire) , fa void Barometer::readData() { - // barometer.ReadProm(); - // barometer.Readout(); + barometer.ReadProm(); + barometer.Readout(); - // data_[0] = barometer.GetPres(); + data_[0] = barometer.GetPres(); - // // Re-read in case of overflow - // while (data_[0] < 0 || data_[0] > 102000) { - // barometer.ReadProm(); - // barometer.Readout(); - // data_[0] = barometer.GetPres(); - // } - fakePressure += 2000 * negative; - data_[0] = fakePressure; - if(fakePressure < 60000){ - negative = 1; - }else if(fakePressure > 101400){ - negative = 0; + // Re-read in case of overflow + while (data_[0] < 0 || data_[0] > 102000) { + barometer.ReadProm(); + barometer.Readout(); + data_[0] = barometer.GetPres(); } - + data_[1] = barometer.GetTemp(); #ifdef TESTING From 54f2d768ee0155b5d8ce7a09dc2b36588f11e47a Mon Sep 17 00:00:00 2001 From: Edward Li Date: Sun, 9 Jun 2024 02:18:31 -0700 Subject: [PATCH 13/21] Initial support for Garibaldi --- avionics/common/include/gpio.h | 26 +++++++++++++------------- avionics/common/src/avionics.cpp | 6 +++++- avionics/common/src/gpio.cpp | 8 ++++---- platformio.ini | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/avionics/common/include/gpio.h b/avionics/common/include/gpio.h index 1151b0ee..7ff91799 100644 --- a/avionics/common/include/gpio.h +++ b/avionics/common/include/gpio.h @@ -24,19 +24,19 @@ /*Constants------------------------------------------------------------*/ // Double, triple check pin assignments enum class Pin { - POWER_LED = 33, // kept in one place w/ FLIGHT_LED - FLIGHT_LED = 33, // required by state machine - BUILTIN_LED = 31, // PC13 - STATUS_LED = 31, // uses BUILTIN_LED - BUZZER = 25, // PB9 - MAIN_IGNITOR = 20, // PB4 - MAIN_CONTINUITY_TEST = 33, - MAIN_CONTINUITY_READ = 200, // PB_0 - DROGUE_IGNITOR = 15, // PA15 - DROGUE_CONTINUITY_TEST = 33, - DROGUE_CONTINUITY_READ = 193, // PA_1 - VOLTAGE_SENSOR = 33, // PC15 (unused) - SD_CHIP_SELECT = 196, // PA_4 + // POWER_LED = 0, // N/A on Rev 2 board + // FLIGHT_LED = 0, // N/A on Rev 2 board + BUILTIN_LED = 33, // PC6 + STATUS_LED = 33, // PC6, uses BUILTIN_LED + BUZZER = 41, // PB14 + MAIN_IGNITOR = 0, // PB4 + MAIN_CONTINUITY_TEST = 0, + MAIN_CONTINUITY_READ = 0, // PB_0 + DROGUE_IGNITOR = 0, // PA15 + DROGUE_CONTINUITY_TEST = 0, + DROGUE_CONTINUITY_READ = 0, // PA_1 + VOLTAGE_SENSOR = 0, // PC15 (unused) + SD_CHIP_SELECT = 0, // PA_4 }; /*Functions------------------------------------------------------------*/ diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index a3d62b8a..4ad8e538 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -40,6 +40,9 @@ #include "WProgram.h" #endif +// Set Serial to use UART5 +#define Serial Serial5 + /** * @brief Helper function that makes things less verbose; basically saves the * static_cast call @@ -53,7 +56,7 @@ void registerTask(TaskID id, Scheduler::Task task, bool repeat = true, int main(void) { // Initialize Arduino init(); - + // Before anything else there's some environment specific setup to be done env_initialize(); LOG_INFO("Everything is starting now"); @@ -70,6 +73,7 @@ int main(void) { Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO); Hal::sleep_ms(100); } + Hal::sleep_ms(500); Serial.println("Initializing..."); #endif diff --git a/avionics/common/src/gpio.cpp b/avionics/common/src/gpio.cpp index 68cab757..58b24693 100644 --- a/avionics/common/src/gpio.cpp +++ b/avionics/common/src/gpio.cpp @@ -55,12 +55,12 @@ */ void initPins(void) { /* Initialize and startup power status LEDs */ - Hal::pinMode(Pin::POWER_LED, Hal::PinMode::OUTPUT); - Hal::digitalWrite(Pin::POWER_LED, Hal::PinDigital::HI); + // Hal::pinMode(Pin::POWER_LED, Hal::PinMode::OUTPUT); + // Hal::digitalWrite(Pin::POWER_LED, Hal::PinDigital::HI); /* Initialize and startup flight status LEDs */ - Hal::pinMode(Pin::FLIGHT_LED, Hal::PinMode::OUTPUT); - Hal::digitalWrite(Pin::FLIGHT_LED, Hal::PinDigital::LO); + // Hal::pinMode(Pin::FLIGHT_LED, Hal::PinMode::OUTPUT); + // Hal::digitalWrite(Pin::FLIGHT_LED, Hal::PinDigital::LO); /* Initialize status LED - writing is performed in acutal status evaluation */ diff --git a/platformio.ini b/platformio.ini index 7ed20117..dc92c952 100644 --- a/platformio.ini +++ b/platformio.ini @@ -90,6 +90,27 @@ build_flags = -I avionics/envs/board/lib -I avionics/extra +[env:Garibaldi] +board = nucleo_l476rg +framework = arduino +monitor_speed = 9600 + +src_filter = + + + + + + + +build_flags = + -D SERIAL1_RX_BUFFER_SIZE=1024 + -D RADIO_CONFIG_PACKET_ROCKET_ID=3 + -D RADIO_CONFIG_PACKET_SIM_ACTIVE=0 + -D ENABLE_HWSERIAL5 + -D EIGEN_NO_DEBUG ; for linear algrbra library + -I avionics/common/lib + -I avionics/common/lib/RocketScheduler/include + -I avionics/rockets/hollyburn/include + -I avionics/envs/board/include + -I avionics/envs/board/lib + -I avionics/extra + [env:test] board = nucleo_l476rg framework = arduino From fc464b44c6afca05b55d05dd1fbd040a256a3993 Mon Sep 17 00:00:00 2001 From: Edward Li Date: Sun, 9 Jun 2024 03:19:31 -0700 Subject: [PATCH 14/21] Added initial changes to get state machine working --- avionics/common/include/log.hpp | 28 +++++++++++++------ avionics/common/include/rocket.h | 2 +- avionics/common/include/state_machine.hpp | 12 ++++---- avionics/common/src/avionics.cpp | 31 +++++++++++---------- avionics/common/src/hardware/ignitor.cpp | 14 +++++----- avionics/common/src/ignitor_collection.cpp | 4 +-- avionics/common/src/sensor_collection.cpp | 4 +-- avionics/envs/board/include/log_control.hpp | 3 +- platformio.ini | 3 +- 9 files changed, 59 insertions(+), 42 deletions(-) diff --git a/avionics/common/include/log.hpp b/avionics/common/include/log.hpp index 21e5375a..ad5ef792 100644 --- a/avionics/common/include/log.hpp +++ b/avionics/common/include/log.hpp @@ -17,21 +17,33 @@ Defined logging levels. Usage: LOG_WARN("Warning message; warning code: " << 123 << " addnl string") */ -#ifndef LOG_CONTROL_DISABLE_LOGGING +#ifdef LOG_CONTROL_DISABLE_LOGGING // LOG_CONTROL_DISABLE_LOGGING + +#define LOG_DEBUG(expr) +#define LOG_INFO(expr) +#define LOG_WARN(expr) +#define LOG_ERROR(expr) + +#else // LOG_CONTROL_DISABLE_LOGGING + +// This is kinda a hack to get logging through serial +#ifdef LOG_CONTROL_SERIAL_LOGGING // LOG_CONTROL_SERIAL_LOGGING + +#define LOG_DEBUG(expr) Serial.print("DEBUG: "); Serial.println(expr) +#define LOG_INFO(expr) Serial.print("INFO: "); Serial.println(expr) +#define LOG_WARN(expr) Serial.print("WARN: "); Serial.println(expr) +#define LOG_ERROR(expr) Serial.print("ERROR: "); Serial.println(expr) + +#else // LOG_CONTROL_SERIAL_LOGGING #define LOG_DEBUG(expr) LOG_AT_SPECIFIED_LEVEL(rktlog::Level::kDebug, expr) #define LOG_INFO(expr) LOG_AT_SPECIFIED_LEVEL(rktlog::Level::kInfo, expr) #define LOG_WARN(expr) LOG_AT_SPECIFIED_LEVEL(rktlog::Level::kWarn, expr) #define LOG_ERROR(expr) LOG_AT_SPECIFIED_LEVEL(rktlog::Level::kErr, expr) -#else // LOG_CONTROL_DISABLE_LOGGING - -#define LOG_DEBUG(expr) -#define LOG_INFO(expr) -#define LOG_WARN(expr) -#define LOG_ERROR(expr) +#endif // LOG_CONTROL_SERIAL_LOGGING -#endif // LOG_CONTROL_DISABLE_LOGGING +#endif // LOG_CONTROL_DISABLE_LOGGING // Log at a specified level. Strongly recommended to instead use the defined log // level macros instead of this. diff --git a/avionics/common/include/rocket.h b/avionics/common/include/rocket.h index 8cfa7e54..996fcdda 100644 --- a/avionics/common/include/rocket.h +++ b/avionics/common/include/rocket.h @@ -48,7 +48,7 @@ class CommandReceiver { CommandReceiver(Rocket &rocket) : rocket_(rocket) {} /** - * @brief performs some action depedning on the information from sensors based on command + * @brief performs some action depedning on the information from sensors based on command * @param command selects which information is sent */ void run_command(Radio::command_t command) { diff --git a/avionics/common/include/state_machine.hpp b/avionics/common/include/state_machine.hpp index 2ca05150..8a211973 100644 --- a/avionics/common/include/state_machine.hpp +++ b/avionics/common/include/state_machine.hpp @@ -17,8 +17,8 @@ class StateMachine { /** * @brief Construct a new State Machine object - * @param map - * @param initial_state_ + * @param map + * @param initial_state_ */ StateMachine(StateMap map, StateId initial_state_) : current_id_(initial_state_), state_map_(map) { @@ -41,10 +41,10 @@ class StateMachine { IState *current_state = state_map_[old_id]; const StateId new_id = current_state->getNewState(calc); if (new_id != old_id) { - LOG_INFO("State changed (previous state " - << static_cast(old_id) << ", new state " - << static_cast(new_id) << ", time is " - << static_cast(Hal::millis()) << "ms)"); + LOG_INFO(("State changed (previous state " + + std::to_string(static_cast(old_id)) + ", new state " + + std::to_string(static_cast(new_id)) + ", time is " + + std::to_string(static_cast(Hal::millis())) + "ms)").c_str()); state_map_[new_id]->onEntry(); Radio::sendState(Hal::tpoint_to_uint(Hal::now_ms()), static_cast(new_id)); diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 4ad8e538..b9151d99 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -16,6 +16,7 @@ */ /* Includes------------------------------------------------------------*/ +#define TESTING #include "HAL/pin_util.h" #include "HAL/time.h" @@ -74,6 +75,7 @@ int main(void) { Hal::sleep_ms(100); } Hal::sleep_ms(500); + Serial.println("[ TESTING MODE ]"); Serial.println("Initializing..."); #endif @@ -98,24 +100,25 @@ int main(void) { /* Register all tasks */ typedef Scheduler::Task Task; - ReadEvalLog read_eval_logger(rocket); - Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(50)); - registerTask(TaskID::ReadEvalLog, read_eval_log); + // ReadEvalLog read_eval_logger(rocket); + // Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(50)); + // registerTask(TaskID::ReadEvalLog, read_eval_log); - // Radio needs to be scheduled later; sensors need to be read first - RadioTxBulk radio_txer(rocket); - Task radio_tx(RadioTxBulk::run, &radio_txer, RadioTxBulk::freq); - Scheduler::preregisterTask(static_cast(TaskID::RadioTxBulk), radio_tx, - true, false); - Scheduler::scheduleTask(Hal::now_ms() + Hal::ms(1), - static_cast(TaskID::RadioTxBulk)); + // // Radio needs to be scheduled later; sensors need to be read first + // RadioTxBulk radio_txer(rocket); + // Task radio_tx(RadioTxBulk::run, &radio_txer, RadioTxBulk::freq); + // Scheduler::preregisterTask(static_cast(TaskID::RadioTxBulk), radio_tx, + // true, false); + // Scheduler::scheduleTask(Hal::now_ms() + Hal::ms(1), + // static_cast(TaskID::RadioTxBulk)); Task led_blink(LEDBlinker::toggle, nullptr, LEDBlinker::freq); + registerTask(TaskID::LEDBlinker, led_blink); - displayStatus(init_status, rocket.buzzer); - if (init_status == RocketStatus::NONCRITICAL_FAILURE) { - registerTask(TaskID::LEDBlinker, led_blink); - } + // displayStatus(init_status, rocket.buzzer); + // if (init_status == RocketStatus::NONCRITICAL_FAILURE) { + // registerTask(TaskID::LEDBlinker, led_blink); + // } // RestartCamera restart_camera_(rocket.cam); // // This tasks sets its own reschedule interval (since the same task is run diff --git a/avionics/common/src/hardware/ignitor.cpp b/avionics/common/src/hardware/ignitor.cpp index 2cb59bc7..93bb1d3f 100644 --- a/avionics/common/src/hardware/ignitor.cpp +++ b/avionics/common/src/hardware/ignitor.cpp @@ -18,12 +18,12 @@ Ignitor::Ignitor(Pin ignitePin, Pin continuityPin, Pin continuityADCPin) int continuity = Hal::analogRead(continuityADCPin_); #ifdef TESTING - Serial.print("Continuity read for ignitor on pin "); + Serial.print("Continuity read for ignitor on pin "); Serial.print(static_cast(ignitePin_)); - Serial.print(": "); + Serial.print(": "); Serial.println(continuity); #endif - + if (continuity <= DISCONTINUOUS_THRESHOLD) { status = HardwareStatus::FAILURE; @@ -41,7 +41,7 @@ void Ignitor::fire() { // different ignitions. Radio::sendEvent(Hal::tpoint_to_uint(Hal::now_ms()), EventId::IGNITOR_FIRED); - LOG_INFO("Firing ignitor at pin " - << static_cast(ignitePin_) << " at time " - << static_cast(Hal::millis()) << "ms"); -} \ No newline at end of file + LOG_INFO(("Firing ignitor at pin " + + std::to_string(static_cast(ignitePin_)) + " at time " + + std::to_string(static_cast(Hal::millis())) + "ms").c_str()); +} diff --git a/avionics/common/src/ignitor_collection.cpp b/avionics/common/src/ignitor_collection.cpp index ba883864..fb03f8d9 100644 --- a/avionics/common/src/ignitor_collection.cpp +++ b/avionics/common/src/ignitor_collection.cpp @@ -21,7 +21,7 @@ IgnitorCollection::IgnitorCollection() Serial.println("Main parachute ignitor failed"); #endif - LOG_ERROR("Broken ignitor for main parachute"); + // LOG_ERROR("Broken ignitor for main parachute"); status_bitfield_[0] |= 0x80; // status_ = RocketStatus::CRITICAL_FAILURE; } @@ -30,7 +30,7 @@ IgnitorCollection::IgnitorCollection() Serial.println("Drogue parachute ignitor failed"); #endif - LOG_ERROR("Broken ignitor for drogue parachute"); + // LOG_ERROR("Broken ignitor for drogue parachute"); status_bitfield_[0] |= 0x40; // status_ = RocketStatus::CRITICAL_FAILURE; } diff --git a/avionics/common/src/sensor_collection.cpp b/avionics/common/src/sensor_collection.cpp index 43f2448b..44e75fa5 100644 --- a/avionics/common/src/sensor_collection.cpp +++ b/avionics/common/src/sensor_collection.cpp @@ -11,11 +11,11 @@ constexpr char SensorCollection::LOG_FILE_HEADER[]; SensorCollection::SensorCollection() : barometer(BEGIN + BAROMETER_INDEX), gps(Hal::SerialInst::GPS, BEGIN + GPS_INDEX), - accelerometer(BEGIN + ACCEL_INDEX), + accelerometer(BEGIN + ACCEL_INDEX), imuSensor(BEGIN + IMU_INDEX), // battery(Pin::VOLTAGE_SENSOR, BEGIN + BATTERY_INDEX), // No voltage sensor for 2022/23 temperature(BEGIN + TEMP_INDEX) { - + updateStatus(); } diff --git a/avionics/envs/board/include/log_control.hpp b/avionics/envs/board/include/log_control.hpp index 60ab2299..ea04fb7f 100644 --- a/avionics/envs/board/include/log_control.hpp +++ b/avionics/envs/board/include/log_control.hpp @@ -1,6 +1,7 @@ #ifndef LOG_CONTROL_HPP_69AACC47E45A456AB18C82C1F98F5B7B #define LOG_CONTROL_HPP_69AACC47E45A456AB18C82C1F98F5B7B -#define LOG_CONTROL_DISABLE_LOGGING +// #define LOG_CONTROL_DISABLE_LOGGING +#define LOG_CONTROL_SERIAL_LOGGING #endif diff --git a/platformio.ini b/platformio.ini index dc92c952..a3763608 100644 --- a/platformio.ini +++ b/platformio.ini @@ -99,10 +99,11 @@ src_filter = + + + + build_flags = - -D SERIAL1_RX_BUFFER_SIZE=1024 + -D SERIAL5_RX_BUFFER_SIZE=2048 -D RADIO_CONFIG_PACKET_ROCKET_ID=3 -D RADIO_CONFIG_PACKET_SIM_ACTIVE=0 -D ENABLE_HWSERIAL5 + ; -D TESTING -D EIGEN_NO_DEBUG ; for linear algrbra library -I avionics/common/lib -I avionics/common/lib/RocketScheduler/include From 51273f94c29738dd84f419b6d3f98c0da81890e5 Mon Sep 17 00:00:00 2001 From: Edward Li Date: Sun, 9 Jun 2024 03:52:30 -0700 Subject: [PATCH 15/21] Get core loop working --- avionics/common/include/gpio.h | 18 +++++++++--------- avionics/common/include/log.hpp | 3 +++ avionics/common/include/radio.h | 1 + avionics/common/include/tasks/main_tasks.hpp | 5 +++-- avionics/common/src/avionics.cpp | 9 +++------ platformio.ini | 3 +-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/avionics/common/include/gpio.h b/avionics/common/include/gpio.h index 7ff91799..d04c6896 100644 --- a/avionics/common/include/gpio.h +++ b/avionics/common/include/gpio.h @@ -28,15 +28,15 @@ enum class Pin { // FLIGHT_LED = 0, // N/A on Rev 2 board BUILTIN_LED = 33, // PC6 STATUS_LED = 33, // PC6, uses BUILTIN_LED - BUZZER = 41, // PB14 - MAIN_IGNITOR = 0, // PB4 - MAIN_CONTINUITY_TEST = 0, - MAIN_CONTINUITY_READ = 0, // PB_0 - DROGUE_IGNITOR = 0, // PA15 - DROGUE_CONTINUITY_TEST = 0, - DROGUE_CONTINUITY_READ = 0, // PA_1 - VOLTAGE_SENSOR = 0, // PC15 (unused) - SD_CHIP_SELECT = 0, // PA_4 + BUZZER = 41, // PB15 + MAIN_IGNITOR = 14, // PB9, TODO! + MAIN_CONTINUITY_TEST = 2, // PA10, TODO! + MAIN_CONTINUITY_READ = 2, // PA10, TODO! + DROGUE_IGNITOR = 15, // PB8, TODO! + DROGUE_CONTINUITY_TEST = 8, // PA9, TODO! + DROGUE_CONTINUITY_READ = 8, // PA9, TODO! + VOLTAGE_SENSOR = 42, // PB14, unused + SD_CHIP_SELECT = 31, // PC9 }; /*Functions------------------------------------------------------------*/ diff --git a/avionics/common/include/log.hpp b/avionics/common/include/log.hpp index ad5ef792..ee973f6b 100644 --- a/avionics/common/include/log.hpp +++ b/avionics/common/include/log.hpp @@ -13,6 +13,9 @@ // x86 configurations. #include "log_control.hpp" +// Set the serial port to use UART5 +#define Serial Serial5 + /* Defined logging levels. Usage: LOG_WARN("Warning message; warning code: " << 123 << " addnl string") diff --git a/avionics/common/include/radio.h b/avionics/common/include/radio.h index 30d703bf..de9b592e 100644 --- a/avionics/common/include/radio.h +++ b/avionics/common/include/radio.h @@ -101,6 +101,7 @@ class Radio { */ template static void forwardCommand(Actor &command_receiver) { + return; // Hack to get this to work static_assert( can_receive_command::value, "act_upon does not have the expected signature void(uint8_t)"); diff --git a/avionics/common/include/tasks/main_tasks.hpp b/avionics/common/include/tasks/main_tasks.hpp index efdcd4f8..c5813390 100644 --- a/avionics/common/include/tasks/main_tasks.hpp +++ b/avionics/common/include/tasks/main_tasks.hpp @@ -18,6 +18,7 @@ class ReadEvalLog { * @brief polss sensors, logs data, and updates state machine */ void run() { + LOG_DEBUG("ReadEvalLog task started"); auto &state_machine = rocket_.state_machine; auto &init_status = rocket_.init_status; auto &sensors = rocket_.sensors; @@ -43,7 +44,7 @@ class ReadEvalLog { std::tie(old_state, new_state) = state_machine.update(calc); if (old_state != new_state) { // state transition has occurred - + // if (new_state == StateId::MAIN_DESCENT) { // // restart the camera periodically once in main descent // Scheduler::scheduleTask( @@ -88,7 +89,7 @@ class RadioTxBulk { /** * @brief Construct a new Radio Tx Bulk object - * @param rkt + * @param rkt */ RadioTxBulk(Rocket &rkt) : rocket(rkt) {} static constexpr Hal::ms freq{500}; diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index b9151d99..88cd0632 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -41,9 +41,6 @@ #include "WProgram.h" #endif -// Set Serial to use UART5 -#define Serial Serial5 - /** * @brief Helper function that makes things less verbose; basically saves the * static_cast call @@ -100,9 +97,9 @@ int main(void) { /* Register all tasks */ typedef Scheduler::Task Task; - // ReadEvalLog read_eval_logger(rocket); - // Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(50)); - // registerTask(TaskID::ReadEvalLog, read_eval_log); + ReadEvalLog read_eval_logger(rocket); + Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(50)); + registerTask(TaskID::ReadEvalLog, read_eval_log); // // Radio needs to be scheduled later; sensors need to be read first // RadioTxBulk radio_txer(rocket); diff --git a/platformio.ini b/platformio.ini index a3763608..14ec45ff 100644 --- a/platformio.ini +++ b/platformio.ini @@ -99,11 +99,10 @@ src_filter = + + + + build_flags = - -D SERIAL5_RX_BUFFER_SIZE=2048 + -D SERIAL5_RX_BUFFER_SIZE=1024 -D RADIO_CONFIG_PACKET_ROCKET_ID=3 -D RADIO_CONFIG_PACKET_SIM_ACTIVE=0 -D ENABLE_HWSERIAL5 - ; -D TESTING -D EIGEN_NO_DEBUG ; for linear algrbra library -I avionics/common/lib -I avionics/common/lib/RocketScheduler/include From 529f9fa6671b8dc4614e6ae23ddea1ac4577bfa7 Mon Sep 17 00:00:00 2001 From: Edward Li Date: Sun, 9 Jun 2024 04:22:35 -0700 Subject: [PATCH 16/21] Fixed Serial Communication! --- avionics/common/include/log.hpp | 3 --- avionics/common/include/options.h | 5 ++++- avionics/common/src/avionics.cpp | 3 +-- avionics/envs/board/src/sensors/barometer.cpp | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/avionics/common/include/log.hpp b/avionics/common/include/log.hpp index ee973f6b..ad5ef792 100644 --- a/avionics/common/include/log.hpp +++ b/avionics/common/include/log.hpp @@ -13,9 +13,6 @@ // x86 configurations. #include "log_control.hpp" -// Set the serial port to use UART5 -#define Serial Serial5 - /* Defined logging levels. Usage: LOG_WARN("Warning message; warning code: " << 123 << " addnl string") diff --git a/avionics/common/include/options.h b/avionics/common/include/options.h index aca163fd..53ff5a4d 100644 --- a/avionics/common/include/options.h +++ b/avionics/common/include/options.h @@ -23,9 +23,12 @@ #define BODY // enable or disable body-avionics specific functionality // #define SERVO //if drogue release utilizes CO2 canister #define POW // if drogue release utilizes black powder charge -// #define TESTING //enable or disable debug output +#define TESTING //enable or disable debug output // #define GROUND_TEST // #define THERMOCOUPLE // if thermocouple is utilized or not +// Set the serial port to use UART5 +#define Serial Serial5 + // Refer to README or the wiki for more information. diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 88cd0632..f740502c 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -16,7 +16,6 @@ */ /* Includes------------------------------------------------------------*/ -#define TESTING #include "HAL/pin_util.h" #include "HAL/time.h" @@ -73,8 +72,8 @@ int main(void) { } Hal::sleep_ms(500); Serial.println("[ TESTING MODE ]"); - Serial.println("Initializing..."); #endif + Serial.println("Initializing..."); Radio::initialize(); LOG_INFO("Initialized radio"); diff --git a/avionics/envs/board/src/sensors/barometer.cpp b/avionics/envs/board/src/sensors/barometer.cpp index f701acb0..159264d5 100644 --- a/avionics/envs/board/src/sensors/barometer.cpp +++ b/avionics/envs/board/src/sensors/barometer.cpp @@ -16,7 +16,7 @@ Barometer::Barometer(float *const buf) : SensorBase(buf) , barometer(&Wire) { if (barometer.connect() > 0) { status = SensorStatus::FAILURE; } - + #endif status = SensorStatus::NOMINAL; From 0566cca4b2c184b2e5f54d36dd6c469dc9032ebd Mon Sep 17 00:00:00 2001 From: Edward Li Date: Sun, 9 Jun 2024 10:44:51 -0700 Subject: [PATCH 17/21] Reduced compiler warnings --- avionics/common/include/options.h | 1 + 1 file changed, 1 insertion(+) diff --git a/avionics/common/include/options.h b/avionics/common/include/options.h index 53ff5a4d..d7db8785 100644 --- a/avionics/common/include/options.h +++ b/avionics/common/include/options.h @@ -29,6 +29,7 @@ // #define THERMOCOUPLE // if thermocouple is utilized or not // Set the serial port to use UART5 +#undef Serial #define Serial Serial5 // Refer to README or the wiki for more information. From 2f95ef546f4eb33154ce865075358ad38a31d513 Mon Sep 17 00:00:00 2001 From: Edward Li Date: Sat, 3 Aug 2024 17:32:35 -0700 Subject: [PATCH 18/21] SD Card Working! --- avionics/common/src/avionics.cpp | 18 +++++++++++++----- platformio.ini | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 46d97209..9f580c27 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -68,16 +68,18 @@ int main(void) { while (!Serial) { Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::HI); Hal::sleep_ms(100); - Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO); + Hal::digitalWrite(Pin::BUILTIN_LED, Hal::PinDigital::LO); Hal::sleep_ms(100); - } - Hal::sleep_ms(500); +} + Hal::sleep_ms(1000); Serial.println("[ TESTING MODE ]"); #endif Serial.println("Initializing..."); - Radio::initialize(); - LOG_INFO("Initialized radio"); + PB10; + + // Radio::initialize(); + // LOG_INFO("Initialized radio"); Rocket rocket; // Logically, these are all unrelated variables - but to allow the command // receiver to function, they need to be coalesced into one POD struct. @@ -86,6 +88,12 @@ int main(void) { auto &sensors = rocket.sensors; auto &ignitors = rocket.ignitors; + if (rocket.datalog.ok()) { + Serial.println("Datalogging initialized"); + } else { + Serial.println("Datalogging failed to initialize"); + } + // Create instance of landed buzzer LandedBuzzer landedBuzzer(rocket.buzzer); diff --git a/platformio.ini b/platformio.ini index 14ec45ff..53bf2e96 100644 --- a/platformio.ini +++ b/platformio.ini @@ -104,6 +104,9 @@ build_flags = -D RADIO_CONFIG_PACKET_SIM_ACTIVE=0 -D ENABLE_HWSERIAL5 -D EIGEN_NO_DEBUG ; for linear algrbra library + -D PIN_SPI_MOSI=201 ; PC3 on Nucleo L476RG - For SD Card + -D PIN_SPI_MISO=200 ; PC2 on Nucleo L476RG - For SD Card + -D PIN_SPI_SCK=6 ; PB10 on Nucleo L476RG - For SD Card -I avionics/common/lib -I avionics/common/lib/RocketScheduler/include -I avionics/rockets/hollyburn/include From d4e43e921354a2a16fcf613e0124b25485453277 Mon Sep 17 00:00:00 2001 From: Edward Li Date: Tue, 6 Aug 2024 22:04:20 -0700 Subject: [PATCH 19/21] Got I2C sensors working on new board --- avionics/common/src/avionics.cpp | 2 -- avionics/envs/board/src/MS5xxx.cpp | 18 +++++++++--------- avionics/envs/board/src/env_config.cpp | 5 +++-- platformio.ini | 8 +++++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 9f580c27..c6b7341b 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -76,8 +76,6 @@ int main(void) { #endif Serial.println("Initializing..."); - PB10; - // Radio::initialize(); // LOG_INFO("Initialized radio"); Rocket rocket; diff --git a/avionics/envs/board/src/MS5xxx.cpp b/avionics/envs/board/src/MS5xxx.cpp index 2fa3718d..c7ac766d 100644 --- a/avionics/envs/board/src/MS5xxx.cpp +++ b/avionics/envs/board/src/MS5xxx.cpp @@ -47,8 +47,8 @@ uint8_t MS5xxx::connect() { void MS5xxx::ReadProm() { send_cmd(MS5xxx_CMD_RESET); delay(3); - - for(uint8_t i=0;i<8;i++) + + for(uint8_t i=0;i<8;i++) { C[i]=0x0000; send_cmd(MS5xxx_CMD_PROM_RD+2*i); @@ -60,7 +60,7 @@ void MS5xxx::ReadProm() { C[i] += c; _Wire->endTransmission(true); } - + } unsigned int MS5xxx::Calc_CRC4(unsigned char poly) @@ -117,7 +117,7 @@ unsigned long MS5xxx::read_adc(unsigned char aCMD) { unsigned long value=0; unsigned long c=0; - + send_cmd(MS5xxx_CMD_ADC_CONV+aCMD); // start DAQ and conversion of ADC data switch (aCMD & 0x0f) { @@ -141,13 +141,13 @@ unsigned long MS5xxx::read_adc(unsigned char aCMD) c = _Wire->read(); value += c; _Wire->endTransmission(true); - + return value; } void MS5xxx::Readout() { unsigned long D1=0, D2=0; - + double dT; double OFF; double SENS; @@ -161,7 +161,7 @@ void MS5xxx::Readout() { SENS=C[1]*pow(2,16)+dT*C[3]/pow(2,7); TEMP=(2000+(dT*C[6])/pow(2,23)); P=(((D1*SENS)/pow(2,21)-OFF)/pow(2,15)); - + // perform higher order corrections double T2=0., OFF2=0., SENS2=0.; if(TEMP<2000) { @@ -173,11 +173,11 @@ void MS5xxx::Readout() { SENS2+=8*(TEMP+1500)*(TEMP+1500); } } - + TEMP-=T2; OFF-=OFF2; SENS-=SENS2; - P=(((D1*SENS)/pow(2,21)-OFF)/pow(2,15)); + P=(((D1*SENS)/pow(2,21)-OFF)/pow(2,15)); } double MS5xxx::GetTemp() { diff --git a/avionics/envs/board/src/env_config.cpp b/avionics/envs/board/src/env_config.cpp index 99276dac..0dc43e72 100644 --- a/avionics/envs/board/src/env_config.cpp +++ b/avionics/envs/board/src/env_config.cpp @@ -1,7 +1,8 @@ #include "env_config.h" void env_initialize() { - Wire.setSCL(22); // PB6 - Wire.setSDA(23); // PB7 + // Should be handled by compiler flags now + // Wire.setSCL(10); // PB6 + // Wire.setSDA(21); // PB7 Wire.begin(); } diff --git a/platformio.ini b/platformio.ini index 53bf2e96..c8f49587 100644 --- a/platformio.ini +++ b/platformio.ini @@ -104,9 +104,11 @@ build_flags = -D RADIO_CONFIG_PACKET_SIM_ACTIVE=0 -D ENABLE_HWSERIAL5 -D EIGEN_NO_DEBUG ; for linear algrbra library - -D PIN_SPI_MOSI=201 ; PC3 on Nucleo L476RG - For SD Card - -D PIN_SPI_MISO=200 ; PC2 on Nucleo L476RG - For SD Card - -D PIN_SPI_SCK=6 ; PB10 on Nucleo L476RG - For SD Card + -D PIN_SPI_MOSI=201 ; PC3 on Nucleo L476RG - For SPI SD Card + -D PIN_SPI_MISO=200 ; PC2 on Nucleo L476RG - For SPI SD Card + -D PIN_SPI_SCK=6 ; PB10 on Nucleo L476RG - For SPI SD Card + -D PIN_WIRE_SDA=21 ; PB7 on Nucleo L476RG - For I2C Sensors + -D PIN_WIRE_SCL=10 ; PB6 on Nucleo L476RG - For I2C Sensors -I avionics/common/lib -I avionics/common/lib/RocketScheduler/include -I avionics/rockets/hollyburn/include From b7e7458aaee94c51dee2327397178351f1c3cc6d Mon Sep 17 00:00:00 2001 From: Edward Li Date: Tue, 6 Aug 2024 22:42:13 -0700 Subject: [PATCH 20/21] GPS Support! --- avionics/common/src/avionics.cpp | 4 +++- avionics/envs/board/lib/HAL/port_impl.cpp | 6 +++--- avionics/envs/board/src/sensors/GPS.cpp | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index c6b7341b..0bb025f2 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -76,6 +76,8 @@ int main(void) { #endif Serial.println("Initializing..."); + PA1; + // Radio::initialize(); // LOG_INFO("Initialized radio"); Rocket rocket; @@ -107,7 +109,7 @@ int main(void) { typedef Scheduler::Task Task; ReadEvalLog read_eval_logger(rocket); - Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(50)); + Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(5000)); registerTask(TaskID::ReadEvalLog, read_eval_log); // // Radio needs to be scheduled later; sensors need to be read first diff --git a/avionics/envs/board/lib/HAL/port_impl.cpp b/avionics/envs/board/lib/HAL/port_impl.cpp index c60f7134..4734e9ab 100644 --- a/avionics/envs/board/lib/HAL/port_impl.cpp +++ b/avionics/envs/board/lib/HAL/port_impl.cpp @@ -2,9 +2,9 @@ namespace Hal { -HardwareSerial CustomSerial1(10, 9); // PA_10, PA_9 -HardwareSerial CustomSerial2(3, 2); // PA_3, PA_2 -HardwareSerial CustomSerial3(47, 47); // PC_15 (unused) +HardwareSerial CustomSerial1(197, 196); // RX: PC0, TX: PC1 +HardwareSerial CustomSerial2(193, 192); // RX: PA1, TX: PA0 +HardwareSerial CustomSerial3(194, 194); // RX: PA4 (unused), TX: PA4 (unused) CustomSerial SerialInst::GPS{CustomSerial1}; CustomSerial SerialInst::Radio{CustomSerial2}; diff --git a/avionics/envs/board/src/sensors/GPS.cpp b/avionics/envs/board/src/sensors/GPS.cpp index e8f1cece..16ef3d56 100644 --- a/avionics/envs/board/src/sensors/GPS.cpp +++ b/avionics/envs/board/src/sensors/GPS.cpp @@ -43,11 +43,17 @@ GPS::GPS(Hal::CustomSerial &seri, float *const data) } void GPS::readData() { + Serial.println("1"); bool gpsSuccess = false; + Serial.println("2"); elapsedMillis timeout; + Serial.println("3"); while (serial_port_.available() && (timeout < GPS_TIMEOUT)) { + Serial.println("4"); char c = serial_port_.read(); + Serial.println("5"); if (gps.encode(c)) { + Serial.println("6"); gpsSuccess = true; break; } @@ -57,6 +63,14 @@ void GPS::readData() { status = SensorStatus::FAILURE; } +#ifdef TESTING + if (gpsSuccess) { + Serial.println("GPS SUCCESS"); + } else { + Serial.println("GPS FAIL"); + } +#endif + unsigned long fix_age; gps.f_get_position(data_, data_ + 1, &fix_age); data_[2] = gps.f_altitude(); From ec16483fd382c222384d644d5778bf3cf4027f6c Mon Sep 17 00:00:00 2001 From: Edward Li Date: Tue, 6 Aug 2024 23:29:00 -0700 Subject: [PATCH 21/21] Preliminary Radio Code --- avionics/common/include/tasks/main_tasks.hpp | 1 + avionics/common/src/avionics.cpp | 21 ++++++++++---------- avionics/envs/board/lib/HAL/port_impl.cpp | 2 +- avionics/envs/x86/lib/HAL/port_impl.cpp | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/avionics/common/include/tasks/main_tasks.hpp b/avionics/common/include/tasks/main_tasks.hpp index c5813390..969396e5 100644 --- a/avionics/common/include/tasks/main_tasks.hpp +++ b/avionics/common/include/tasks/main_tasks.hpp @@ -100,6 +100,7 @@ class RadioTxBulk { * @brief sends bulk sensor data */ void run() { + LOG_DEBUG("RadioTxBulk task started"); StateId state = rocket.state_machine.getState(); Radio::sendBulkSensor( Hal::tpoint_to_uint(rocket.sensors.last_poll_time()), diff --git a/avionics/common/src/avionics.cpp b/avionics/common/src/avionics.cpp index 0bb025f2..6d16d200 100644 --- a/avionics/common/src/avionics.cpp +++ b/avionics/common/src/avionics.cpp @@ -76,10 +76,8 @@ int main(void) { #endif Serial.println("Initializing..."); - PA1; - - // Radio::initialize(); - // LOG_INFO("Initialized radio"); + Radio::initialize(); + LOG_INFO("Initialized radio"); Rocket rocket; // Logically, these are all unrelated variables - but to allow the command // receiver to function, they need to be coalesced into one POD struct. @@ -108,17 +106,18 @@ int main(void) { /* Register all tasks */ typedef Scheduler::Task Task; + // Read sensors, evaluate state, log data, and send status ReadEvalLog read_eval_logger(rocket); - Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(5000)); + Task read_eval_log(ReadEvalLog::run, &read_eval_logger, Hal::ms(50)); registerTask(TaskID::ReadEvalLog, read_eval_log); // // Radio needs to be scheduled later; sensors need to be read first - // RadioTxBulk radio_txer(rocket); - // Task radio_tx(RadioTxBulk::run, &radio_txer, RadioTxBulk::freq); - // Scheduler::preregisterTask(static_cast(TaskID::RadioTxBulk), radio_tx, - // true, false); - // Scheduler::scheduleTask(Hal::now_ms() + Hal::ms(1), - // static_cast(TaskID::RadioTxBulk)); + RadioTxBulk radio_txer(rocket); + Task radio_tx(RadioTxBulk::run, &radio_txer, RadioTxBulk::freq); + Scheduler::preregisterTask(static_cast(TaskID::RadioTxBulk), radio_tx, + true, false); + Scheduler::scheduleTask(Hal::now_ms() + Hal::ms(1), + static_cast(TaskID::RadioTxBulk)); Task led_blink(LEDBlinker::toggle, nullptr, LEDBlinker::freq); registerTask(TaskID::LEDBlinker, led_blink); diff --git a/avionics/envs/board/lib/HAL/port_impl.cpp b/avionics/envs/board/lib/HAL/port_impl.cpp index 4734e9ab..ed141e68 100644 --- a/avionics/envs/board/lib/HAL/port_impl.cpp +++ b/avionics/envs/board/lib/HAL/port_impl.cpp @@ -3,7 +3,7 @@ namespace Hal { HardwareSerial CustomSerial1(197, 196); // RX: PC0, TX: PC1 -HardwareSerial CustomSerial2(193, 192); // RX: PA1, TX: PA0 +HardwareSerial CustomSerial2(192, 193); // RX: PA1, TX: PA0 HardwareSerial CustomSerial3(194, 194); // RX: PA4 (unused), TX: PA4 (unused) CustomSerial SerialInst::GPS{CustomSerial1}; diff --git a/avionics/envs/x86/lib/HAL/port_impl.cpp b/avionics/envs/x86/lib/HAL/port_impl.cpp index f2b9437a..c570017e 100644 --- a/avionics/envs/x86/lib/HAL/port_impl.cpp +++ b/avionics/envs/x86/lib/HAL/port_impl.cpp @@ -31,6 +31,6 @@ std::size_t CustomSerial::write(const uint8_t *const inbuf, std::size_t const si CustomSerial SerialInst::USB{StdIoController::DEV_NULL}; CustomSerial SerialInst::GPS{StdIoController::DEV_NULL}; -CustomSerial SerialInst::Radio{'R'}; +// CustomSerial SerialInst::Radio{'R'}; CustomSerial SerialInst::Camera{StdIoController::DEV_NULL}; } // namespace Hal