From 3e3346ff59faf1c758b1e7802692978ab81bd28b Mon Sep 17 00:00:00 2001 From: MaxMccullough Date: Sun, 19 Nov 2023 13:34:42 -0800 Subject: [PATCH 01/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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