mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-08-06 01:37:33 +00:00
refactor: merged manger task into statemachine task
This commit is contained in:
@@ -69,6 +69,9 @@
|
||||
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -134,11 +137,15 @@ namespace sta
|
||||
public:
|
||||
/**
|
||||
* @brief The global event signaling a state change.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
static RtosEvent stateChangeEvent;
|
||||
|
||||
/**
|
||||
* @brief Getter function for the singleton instance.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
static Statemachine* instance()
|
||||
{
|
||||
@@ -146,7 +153,7 @@ namespace sta
|
||||
|
||||
if (!_instance)
|
||||
{
|
||||
// Create the manager singleton instance.
|
||||
// Create the statemachine singleton instance.
|
||||
Statemachine::_instance = new Statemachine();
|
||||
}
|
||||
|
||||
@@ -155,6 +162,8 @@ namespace sta
|
||||
|
||||
/**
|
||||
* @brief Returns the statemachine's current state.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
uint16_t getCurrentState() const;
|
||||
|
||||
@@ -165,6 +174,8 @@ namespace sta
|
||||
* @param to The state to transition to.
|
||||
* @param lockout The minimum number of milliseconds we expect to stay in this state. This is used to block premature transitions.
|
||||
* @param force If true, the state transition will be executed regardless of the current state.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
void requestStateTransition(uint32_t from, uint32_t to, uint32_t lockout = 0, bool force = false, bool publish = true);
|
||||
|
||||
@@ -175,9 +186,27 @@ namespace sta
|
||||
* @param to The state to transition to.
|
||||
* @param millis the number of milliseconds to wait before triggering the transition.
|
||||
* @param lockout The minimum number of milliseconds we expect to stay in this state. This is used to block premature transitions.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
void requestTimedStateTransition(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout = 0, bool publish = true);
|
||||
|
||||
/**
|
||||
* @brief Register a thread to be managed by the statemachine.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
void registerThread(std::shared_ptr<TacosThread> thread, std::set<uint16_t> states);
|
||||
|
||||
/**
|
||||
* @brief Get the Active Threads object
|
||||
*
|
||||
* @return std::vector<std::shared_ptr<TacosThread>>
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
std::vector<std::shared_ptr<TacosThread>> getActiveThreads();
|
||||
|
||||
void init() override;
|
||||
void func() override;
|
||||
|
||||
@@ -208,9 +237,32 @@ namespace sta
|
||||
* @brief Starts the lockoutTimer for the desired duration.
|
||||
*
|
||||
* @param millis The duration of the timer in milliseconds.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
void setLockoutTimer(uint32_t millis);
|
||||
|
||||
/**
|
||||
* @brief Forces only threads of current state to run.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
void updateThreads();
|
||||
|
||||
/**
|
||||
* @brief Starts all threads which should be running in the given state. Does nothing if the state is already running.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
void startThreads(uint16_t state);
|
||||
|
||||
/**
|
||||
* @brief Stops all threads which should not be running in the given state.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
void stopThreads(uint16_t state);
|
||||
|
||||
private:
|
||||
uint16_t currentState_;
|
||||
|
||||
@@ -218,6 +270,13 @@ namespace sta
|
||||
RtosTimer failsafeTimer_;
|
||||
|
||||
RtosQueue<StateTransition> queue_;
|
||||
|
||||
/**
|
||||
* @brief Pointers to all threads which are managed by the statemachine.
|
||||
*
|
||||
* @ingroup tacos_statemachine
|
||||
*/
|
||||
std::vector<std::shared_ptr<TacosThread>> threads_[STA_TACOS_NUM_STATES];
|
||||
};
|
||||
} // namespace tacos
|
||||
} // namespace sta
|
||||
|
Reference in New Issue
Block a user