diff --git a/src/Parafoil/AltitudeTrigger/LandingFlare.h b/src/Parafoil/AltitudeTrigger/LandingFlare.h new file mode 100644 index 0000000000000000000000000000000000000000..c0134119f667d56b4e2739132b504a2bba731e33 --- /dev/null +++ b/src/Parafoil/AltitudeTrigger/LandingFlare.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2025 Skyward Experimental Rocketry + * Author: Davide Basso + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#pragma once + +#include "AltitudeTrigger.h" + +namespace Parafoil +{ + +class BoardScheduler; +class NASController; + +class LandingFlare : public Boardcore::InjectableWithDeps< + Boardcore::InjectableBase<AltitudeTrigger>, + BoardScheduler, NASController> +{ +public: + LandingFlare() + : Super({ + .threshold = Config::Wing::LandingFlare::ALTITUDE, + .confidence = Config::Wing::LandingFlare::CONFIDENCE, + .updateRate = Config::Wing::LandingFlare::UPDATE_RATE, + }) {}; +}; + +} // namespace Parafoil diff --git a/src/Parafoil/Configs/WingConfig.h b/src/Parafoil/Configs/WingConfig.h index 89e440403e8c762a2895e6b1c6ea63f62678d5ab..2b918f5dfa74c62366d8d71abf73b4b8b4c13da9 100644 --- a/src/Parafoil/Configs/WingConfig.h +++ b/src/Parafoil/Configs/WingConfig.h @@ -146,10 +146,10 @@ constexpr auto ENABLED = false; constexpr auto ENABLED = true; #endif -constexpr auto FLARE_ALTITUDE = 15_m; -constexpr auto CONFIDENCE = 10; // [samples] -constexpr auto UPDATE_RATE = 10_hz; -constexpr auto FLARE_DURATION = 5_s; +constexpr auto ALTITUDE = 15_m; +constexpr auto CONFIDENCE = 10; // [samples] +constexpr auto UPDATE_RATE = 10_hz; +constexpr auto DURATION = 5_s; } // namespace LandingFlare } // namespace Wing diff --git a/src/Parafoil/StateMachines/WingController/WingController.cpp b/src/Parafoil/StateMachines/WingController/WingController.cpp index b63eebcb5723c3534a29763b1ba4597c6c30a794..cc6f805ce79e97101fe2d110c0fbc986137412ca 100644 --- a/src/Parafoil/StateMachines/WingController/WingController.cpp +++ b/src/Parafoil/StateMachines/WingController/WingController.cpp @@ -21,6 +21,7 @@ */ #include "WingController.h" +#include <Parafoil/AltitudeTrigger/LandingFlare.h> #include <Parafoil/BoardScheduler.h> #include <Parafoil/Configs/ActuatorsConfig.h> #include <Parafoil/Configs/WESConfig.h> @@ -214,6 +215,10 @@ State WingController::FlyingControlledDescent(const Boardcore::Event& event) updateState(WingControllerState::FLYING_CONTROLLED_DESCENT); startAlgorithm(); + + // Enable the landing flare altitude trigger + getModule<LandingFlare>()->enable(); + return HANDLED; } case EV_EMPTY: @@ -231,8 +236,7 @@ State WingController::FlyingControlledDescent(const Boardcore::Event& event) flareTimeoutEventId = EventBroker::getInstance().postDelayed( DPL_FLARE_STOP, TOPIC_FLIGHT, - Millisecond{Config::Wing::LandingFlare::FLARE_DURATION} - .value()); + Millisecond{Config::Wing::LandingFlare::DURATION}.value()); return HANDLED; } @@ -251,6 +255,7 @@ State WingController::FlyingControlledDescent(const Boardcore::Event& event) getModule<WindEstimation>()->stopAlgorithm(); getModule<WindEstimation>()->stopCalibration(); + getModule<LandingFlare>()->disable(); return HANDLED; } diff --git a/src/Parafoil/StateMachines/WingController/WingController.h b/src/Parafoil/StateMachines/WingController/WingController.h index 4edeb0245ae5257a814fb271573e17d8ebf17328..71094ec6138b01a0c45e61a32d8c05816534ab6e 100644 --- a/src/Parafoil/StateMachines/WingController/WingController.h +++ b/src/Parafoil/StateMachines/WingController/WingController.h @@ -66,6 +66,7 @@ class NASController; class FlightStatsRecorder; class WindEstimation; class Sensors; +class LandingFlare; /** * State machine that manages the wings of the Parafoil. @@ -82,9 +83,9 @@ class Sensors; */ class WingController : public Boardcore::HSM<WingController>, - public Boardcore::InjectableWithDeps<BoardScheduler, Actuators, - NASController, FlightStatsRecorder, - WindEstimation, Sensors> + public Boardcore::InjectableWithDeps< + BoardScheduler, Actuators, NASController, FlightStatsRecorder, + WindEstimation, Sensors, LandingFlare> { public: /** diff --git a/src/Parafoil/parafoil-entry.cpp b/src/Parafoil/parafoil-entry.cpp index 034e23310f3bbf648bc1a39b1d8c93cb25a49b77..2a68f7e849b22e61c8c9228e91bed82af292adc6 100644 --- a/src/Parafoil/parafoil-entry.cpp +++ b/src/Parafoil/parafoil-entry.cpp @@ -21,7 +21,7 @@ */ #include <Parafoil/Actuators/Actuators.h> -#include <Parafoil/AltitudeTrigger/AltitudeTrigger.h> +#include <Parafoil/AltitudeTrigger/LandingFlare.h> #include <Parafoil/BoardScheduler.h> #include <Parafoil/Buses.h> #include <Parafoil/FlightStatsRecorder/FlightStatsRecorder.h> @@ -121,17 +121,9 @@ int main() auto radio = new Radio(); initResult &= depman.insert(radio); - // Landing flare activation - namespace LandingFlareConfig = Config::Wing::LandingFlare; - AltitudeTriggerConfig landingFlareConfig = { - .threshold = LandingFlareConfig::FLARE_ALTITUDE, - .confidence = LandingFlareConfig::CONFIDENCE, - .updateRate = LandingFlareConfig::UPDATE_RATE, - }; - auto landingFlare = new AltitudeTrigger(landingFlareConfig); - initResult &= depman.insert(landingFlare); - // Flight algorithms + auto landingFlare = new LandingFlare(); + initResult &= depman.insert(landingFlare); auto wingController = new WingController(); initResult &= depman.insert(wingController); auto windEstimation = new WindEstimation();