mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-08-06 09:37:34 +00:00
Added thread rework, and cleaned up Tacos startup
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#include <sta/tacos/manager.hpp>
|
||||
#include <sta/tacos/statemachine.hpp>
|
||||
#include <tasks/dummy.hpp>
|
||||
#include <gpio.h>
|
||||
#include <sta/devices/stm32/gpio_pin.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -22,17 +24,47 @@ namespace sta
|
||||
{
|
||||
void onStatemachineInit()
|
||||
{
|
||||
STA_DEBUG_PRINTLN("Starting statemachine task!");
|
||||
Statemachine::instance()->setStateFunction([](uint16_t state) -> uint16_t {
|
||||
// ###### Implement your state transition function here! ######
|
||||
|
||||
/**
|
||||
* This function should return some state within 0 and STA_TACOS_NUM_STATES (specified in the config.hpp).
|
||||
* Return the same state as given as the argument for no state transition. Make sure, that this function is not
|
||||
* computationally expensive.
|
||||
*/
|
||||
|
||||
return state;
|
||||
});
|
||||
|
||||
Statemachine::instance()->setTimerFunction([](uint16_t state, uint16_t lastState, uint32_t event) {
|
||||
// ###### Set the failsafe and lockout timers here ######
|
||||
|
||||
/**
|
||||
* This function is called after a state transition from lastState to state. Event corresponds to EventFlag enum in the Statemachine
|
||||
* and encode how the state change happened.
|
||||
*
|
||||
* Setting a timer here is fully optional and depends on your system's specifications.
|
||||
*/
|
||||
|
||||
uint32_t someFailsafeMillis = 42;
|
||||
uint16_t someNextState = STA_TACOS_INITIAL_STATE;
|
||||
uint32_t someLockoutMillis = 21;
|
||||
|
||||
// Start the failsafe timer to force a state transition to someNextState after someFailsafeMillis milliseconds.
|
||||
Statemachine::instance()->setFailsafeTimer(someFailsafeMillis, someNextState);
|
||||
|
||||
// Start the lockout timer to block a state transition for the first someLockoutMillis milliseconds.
|
||||
Statemachine::instance()->setLockoutTimer(someLockoutMillis);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void onManagerInit()
|
||||
{
|
||||
STA_DEBUG_PRINTLN("Starting manager task!");
|
||||
// ###### Register different threads for different states here. ######
|
||||
|
||||
Manager::instance()->registerThread(std::make_shared<demo::DummyTask>("0"), {0});
|
||||
Manager::instance()->registerThread(std::make_shared<demo::DummyTask>("1"), {1});
|
||||
Manager::instance()->registerThread(std::make_shared<demo::DummyTask>("2"), {2});
|
||||
Manager::instance()->registerThread(std::make_shared<demo::DummyTask>("3"), {3});
|
||||
// The dummy task runs for state 0.
|
||||
Manager::instance()->registerThread(std::make_shared<demo::DummyTask>("Dummy"), {0});
|
||||
}
|
||||
} // namespace tacos
|
||||
} // namespace sta
|
||||
|
@@ -29,8 +29,8 @@ namespace demo
|
||||
void DummyTask::func()
|
||||
{
|
||||
STA_DEBUG_PRINTLN(this->getName());
|
||||
// STA_DEBUG_PRINT("Executing ");
|
||||
// STA_DEBUG_PRINTLN(this->getName());
|
||||
|
||||
osDelay(1000);
|
||||
}
|
||||
} // namespace demo
|
||||
|
||||
|
Reference in New Issue
Block a user