Skip to content
Snippets Groups Projects
Commit 7b510985 authored by Angelo Prete's avatar Angelo Prete
Browse files

[Parafoil] Removed altitude trigger

parent a36aae40
No related branches found
No related tags found
No related merge requests found
/* 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
/* 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
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment