From 7b5109851b8919f8f372f0b11557cc120af7ee59 Mon Sep 17 00:00:00 2001 From: Angelo Prete <angelo.prete@skywarder.eu> Date: Thu, 9 May 2024 08:47:38 +0200 Subject: [PATCH] [Parafoil] Removed altitude trigger --- .../Main/AltitudeTrigger/AltitudeTrigger.cpp | 101 ------------------ .../Main/AltitudeTrigger/AltitudeTrigger.h | 81 -------------- src/entrypoints/Main/main-entry.cpp | 15 --- 3 files changed, 197 deletions(-) delete mode 100644 src/boards/Main/AltitudeTrigger/AltitudeTrigger.cpp delete mode 100644 src/boards/Main/AltitudeTrigger/AltitudeTrigger.h diff --git a/src/boards/Main/AltitudeTrigger/AltitudeTrigger.cpp b/src/boards/Main/AltitudeTrigger/AltitudeTrigger.cpp deleted file mode 100644 index f2fce72bd..000000000 --- a/src/boards/Main/AltitudeTrigger/AltitudeTrigger.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Authors: Matteo Pignataro, Federico Mandelli - * - * 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. - */ - -#include "AltitudeTrigger.h" - -#include <Main/BoardScheduler.h> -#include <Main/Configs/WingConfig.h> -#include <Main/StateMachines/NASController/NASController.h> -#include <common/Events.h> -#include <events/EventBroker.h> - -using namespace Boardcore; -using namespace Common; - -namespace Main -{ - -AltitudeTrigger::AltitudeTrigger(TaskScheduler *sched) - : running(false), confidence(0), - deploymentAltitude(WingConfig::ALTITUDE_TRIGGER_DEPLOYMENT_ALTITUDE), - scheduler(sched) -{ -} - -bool AltitudeTrigger::start() -{ - return (scheduler->addTask(std::bind(&AltitudeTrigger::update, this), - WingConfig::ALTITUDE_TRIGGER_PERIOD) != 0); -} - -void AltitudeTrigger::enable() -{ - miosix::Lock<miosix::FastMutex> l(mutex); - confidence = 0; - running = true; -} - -void AltitudeTrigger::setDeploymentAltitude(float altitude) -{ - miosix::Lock<miosix::FastMutex> l(mutex); - deploymentAltitude = altitude; -} - -void AltitudeTrigger::disable() -{ - miosix::Lock<miosix::FastMutex> l(mutex); - running = false; -} - -bool AltitudeTrigger::isActive() -{ - miosix::Lock<miosix::FastMutex> l(mutex); - return running; -} - -void AltitudeTrigger::update() -{ - miosix::Lock<miosix::FastMutex> l(mutex); - if (running) - { - // We multiply by -1 to have a positive height - float height = - -ModuleManager::getInstance().get<NASController>()->getNasState().d; - - if (height < WingConfig::ALTITUDE_TRIGGER_DEPLOYMENT_ALTITUDE) - { - confidence++; - } - else - { - confidence = 0; - } - if (confidence >= WingConfig ::ALTITUDE_TRIGGER_CONFIDENCE) - { - confidence = 0; - EventBroker::getInstance().post(ALTITUDE_TRIGGER_ALTITUDE_REACHED, - TOPIC_FLIGHT); - running = false; - } - } -} -} // namespace Main diff --git a/src/boards/Main/AltitudeTrigger/AltitudeTrigger.h b/src/boards/Main/AltitudeTrigger/AltitudeTrigger.h deleted file mode 100644 index 0c4e22aba..000000000 --- a/src/boards/Main/AltitudeTrigger/AltitudeTrigger.h +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright (c) 2023 Skyward Experimental Rocketry - * Author: Matteo Pignataro - * - * 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 <Main/BoardScheduler.h> - -#include <atomic> -#include <utils/ModuleManager/ModuleManager.hpp> - -namespace Main -{ - -class AltitudeTrigger : public Boardcore::Module -{ -public: - explicit AltitudeTrigger(Boardcore::TaskScheduler *sched); - - /** - * @brief Adds the update() task to the task scheduler. - */ - bool start(); - - /** - * @brief Enable the AltitudeTrigger. - */ - void enable(); - - /** - * @brief Disable the AltitudeTrigger. - */ - void disable(); - - /** - * @return The status of the AltitudeTrigger - */ - bool isActive(); - - /** - * @return Set the altitude of the AltitudeTrigger - */ - void setDeploymentAltitude(float altitude); - -private: - // Update method that posts a FLIGHT_WING_ALT_PASSED when the correct - // altitude is reached - void update(); - - bool running; - - // Number of times that the algorithm detects to be below the fixed - // altitude - int confidence; - - float deploymentAltitude; - - miosix::FastMutex mutex; - - Boardcore::TaskScheduler *scheduler = nullptr; -}; - -} // namespace Main diff --git a/src/entrypoints/Main/main-entry.cpp b/src/entrypoints/Main/main-entry.cpp index c1ece383a..57276b3e3 100644 --- a/src/entrypoints/Main/main-entry.cpp +++ b/src/entrypoints/Main/main-entry.cpp @@ -20,7 +20,6 @@ * THE SOFTWARE. */ -#include <Main/AltitudeTrigger/AltitudeTrigger.h> #include <Main/BoardScheduler.h> #include <Main/Buses.h> #include <Main/Configs/WingConfig.h> @@ -71,8 +70,6 @@ int main() // Other critical components (Max - 2) Radio* radio = new Radio(scheduler->getScheduler(miosix::PRIORITY_MAX - 2)); - AltitudeTrigger* altTrigger = - new AltitudeTrigger(scheduler->getScheduler(miosix::PRIORITY_MAX - 2)); // Components without a scheduler TMRepository* tmRepo = new TMRepository(); @@ -122,12 +119,6 @@ int main() LOG_ERR(logger, "Error inserting the TMRepository module"); } - if (!modules.insert<AltitudeTrigger>(altTrigger)) - { - initResult = false; - LOG_ERR(logger, "Error inserting the Altitude Trigger module"); - } - if (!modules.insert<PinHandler>(pinHandler)) { initResult = false; @@ -175,12 +166,6 @@ int main() LOG_ERR(logger, "Error starting the Radio module"); } - if (!modules.get<AltitudeTrigger>()->start()) - { - initResult = false; - LOG_ERR(logger, "Error starting the AltitudeTrigger module"); - } - if (!modules.get<PinHandler>()->start()) { initResult = false; -- GitLab