mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-10 16:45:59 +00:00
feat(state-via-can): state transitions via can are forced to resync state across devices
This commit is contained in:
parent
e03f624c5b
commit
d75bce6691
@ -42,10 +42,11 @@ namespace sta
|
|||||||
* @param from The start we want to transition from.
|
* @param from The start we want to transition from.
|
||||||
* @param to The state we want to transition to.
|
* @param to The state we want to transition to.
|
||||||
* @param lockout An optional timer blocking state transition for a given time.
|
* @param lockout An optional timer blocking state transition for a given time.
|
||||||
|
* @param force If true, the state transition will be executed regardless of the current state.
|
||||||
*
|
*
|
||||||
* @ingroup tacos_api
|
* @ingroup tacos_api
|
||||||
*/
|
*/
|
||||||
void setState(uint32_t from, uint32_t to, uint32_t lockout = 0);
|
void setState(uint32_t from, uint32_t to, uint32_t lockout = 0, bool force = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Request a state transition after a given time has passed. Invalid state transitions will be dismissed.
|
* @brief Request a state transition after a given time has passed. Invalid state transitions will be dismissed.
|
||||||
|
@ -162,8 +162,9 @@ namespace sta
|
|||||||
* @param from The state which we want to leave. This is used to filter out obsolete transitions.
|
* @param from The state which we want to leave. This is used to filter out obsolete transitions.
|
||||||
* @param to The state to transition to.
|
* @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 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.
|
||||||
*/
|
*/
|
||||||
void requestStateTransition(uint32_t from, uint32_t to, uint32_t lockout = 0);
|
void requestStateTransition(uint32_t from, uint32_t to, uint32_t lockout = 0, bool force = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Request a state transition after a given time has passed.
|
* @brief Request a state transition after a given time has passed.
|
||||||
|
@ -155,8 +155,8 @@ namespace sta {
|
|||||||
|
|
||||||
STA_ASSERT(header.payloadLength == 2);
|
STA_ASSERT(header.payloadLength == 2);
|
||||||
|
|
||||||
// First byte of payload is the origin state, second byte is the destination state
|
// First byte of payload is the origin state, second byte is the destination state. Transition is forced
|
||||||
tacos::setState(payload[0], payload[1]);
|
tacos::setState(payload[0], payload[1], 0, true);
|
||||||
}
|
}
|
||||||
} // namespace tacos
|
} // namespace tacos
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
@ -64,7 +64,7 @@ namespace sta
|
|||||||
return currentState_;
|
return currentState_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Statemachine::requestStateTransition(uint32_t from, uint32_t to, uint32_t lockout /* = 0 */)
|
void Statemachine::requestStateTransition(uint32_t from, uint32_t to, uint32_t lockout /* = 0 */, bool force /* = 0 */)
|
||||||
{
|
{
|
||||||
StateTransition transition;
|
StateTransition transition;
|
||||||
transition.from = from;
|
transition.from = from;
|
||||||
@ -72,9 +72,28 @@ namespace sta
|
|||||||
transition.event = EventFlags::NORMAL;
|
transition.event = EventFlags::NORMAL;
|
||||||
transition.lockout = lockout;
|
transition.lockout = lockout;
|
||||||
|
|
||||||
// Try to add a state transition request to the queue. Don't wait if another
|
if (force){
|
||||||
// thread is already requesting a state change.
|
// Perform the transition and notify the threads. The event flags are set
|
||||||
queue_.put(transition, 0);
|
// here in order to allow threads to react immediately.
|
||||||
|
currentState_ = transition.to;
|
||||||
|
Statemachine::stateChangeEvent.set(transition.event);
|
||||||
|
Statemachine::stateChangeEvent.clear(EventFlags::ALL);
|
||||||
|
|
||||||
|
if (failsafeTimer_.isRunning())
|
||||||
|
{
|
||||||
|
failsafeTimer_.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the lockout timer if requested.
|
||||||
|
if (transition.lockout != 0)
|
||||||
|
{
|
||||||
|
setLockoutTimer(transition.lockout);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// Try to add a state transition request to the queue. Don't wait if another
|
||||||
|
// thread is already requesting a state change.
|
||||||
|
queue_.put(transition, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Statemachine::requestTimedStateTransition(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout /* = 0 */)
|
void Statemachine::requestTimedStateTransition(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout /* = 0 */)
|
||||||
|
@ -16,9 +16,9 @@ namespace sta
|
|||||||
return Statemachine::instance()->getCurrentState();
|
return Statemachine::instance()->getCurrentState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setState(uint32_t from, uint32_t to, uint32_t lockout /* = 0 */)
|
void setState(uint32_t from, uint32_t to, uint32_t lockout /* = 0 */, bool force /* = false */)
|
||||||
{
|
{
|
||||||
Statemachine::instance()->requestStateTransition(from, to, lockout);
|
Statemachine::instance()->requestStateTransition(from, to, lockout, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setStateTimed(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout /* = 0 */)
|
void setStateTimed(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout /* = 0 */)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user