TACOS/include/sta/README.md

96 lines
2.8 KiB
Markdown

# TACOS.hpp
The TACOS API is defined in the tacos.hpp, in normal use cases you should only need to include this file.
## Functions
```cpp
uint16_t getState()
```
Retrieves the current state of the TACOS state machine.
---
```cpp
void requestState(uint32_t from, uint32_t to, uint32_t lockout = 0, bool publish = true)
```
Requests a state transition. Invalid state transitions will be dismissed. First come, first serve. Can be blocked by the lockout timer.
- **Parameters**:
- `from`: The starting state for the transition.
- `to`: The target state to transition to.
- `lockout`: (Optional) A timer to block further transitions.
- `publish`: (Optional) Whether to publish the state transition to the CAN bus.
```cpp
void forceState(uint32_t from, uint32_t to, uint32_t lockout = 0, bool publish = true)
```
Forces a state transition. Will be ignored if already in the given state. Triggers instantly. Ignores the lockout timer.
- **Parameters**:
- `from`: The starting state for the transition.
- `to`: The target state to transition to.
- `lockout`: (Optional) A timer to block further transitions.
- `publish`: (Optional) Whether to publish the state transition to the CAN bus.
---
```cpp
void setStateTimed(uint32_t from, uint32_t to, uint32_t millis, uint32_t lockout = 0, bool publish = false)
```
Requests a state transition after a specified time. Equivalent to calling `requestState` after a specified time.
- **Parameters**:
- `from`: The starting state.
- `to`: The target state.
- `millis`: The wait time in milliseconds before requesting the transition.
- `lockout`: (Optional) A timer for blocking subsequent transitions.
> [!IMPORTANT]
> If there is already a timed transition scheduled, calling `setStateTimed` will overwrite this request.
---
```cpp
template<typename T, typename ... Args> std::shared_ptr<T> addThread(std::set<uint16_t> states, Args ... args)
```
Registers a new thread to be run by TACOS.
- **Template Parameters**:
- `T`: The class type of the thread, which should inherit from `TacosThread`.
- **Parameters**:
- `states`: A set of states in which the thread should be active.
- `args`: The constructor arguments for the thread class.
---
### CAN Bus Functions (Conditional)
The following functions are available only if `STA_TACOS_CAN_BUS_ENABLED` is defined:
```cpp
bool queueCanBusMsg(CanSysMsg & msg, uint32_t timeout)
```
Queues a message to be sent over the CAN bus.
- **Parameters**:
- `msg`: The message to be sent.
- `timeout`: The maximum time to wait for sending the message.
---
```cpp
bool publishState(uint32_t from, uint32_t to, uint32_t timeout = 0)
```
Publishes a state transition message to the CAN bus.
- **Parameters**:
- `from`: The starting state for the transition.
- `to`: The target state.
- `timeout`: (Optional) A timeout for CAN communication.