Performs service calls for Stop1 and the respective reversal, that is enabling the manipulator. Incoming updates of the RUN_PERMITTED state are handled asynchronously. More...
#include <stop1_executor.h>
Public Member Functions | |
Stop1Executor (const TServiceCallFunc &hold_func, const TServiceCallFunc &unhold_func, const TServiceCallFunc &recover_func, const TServiceCallFunc &halt_func) | |
Create required service clients and state machine; start worker-thread and state machine. More... | |
void | updateRunPermitted (const bool run_permitted) |
This is called everytime an updated run_permitted value is obtained. More... | |
bool | updateRunPermittedCallback (std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res) |
virtual | ~Stop1Executor () |
Stop state machine and terminate worker-thread. More... | |
Protected Member Functions | |
void | stopStateMachine () |
Stop the state machine. More... | |
Private Member Functions | |
void | workerThreadFun () |
This is executed in the worker-thread and allows asynchronous handling of run_permitted updates. More... | |
Private Attributes | |
std::mutex | sm_mutex_ |
std::unique_ptr< RunPermittedStateMachine > | state_machine_ |
State machine. More... | |
std::atomic_bool | terminate_ { false } |
Flag indicating if the worker-thread should terminate. More... | |
std::condition_variable | worker_cv_ |
Condition variable for notifying a waiting worker-thread. More... | |
std::thread | worker_thread_ |
Worker-thread. More... | |
Performs service calls for Stop1 and the respective reversal, that is enabling the manipulator. Incoming updates of the RUN_PERMITTED state are handled asynchronously.
In order to handle the asynchrony of events, a state machine is used to represent the current state. The state machine manages a task queue for the currently required service call.
General behaviour:
Definition at line 60 of file stop1_executor.h.
prbt_hardware_support::Stop1Executor::Stop1Executor | ( | const TServiceCallFunc & | hold_func, |
const TServiceCallFunc & | unhold_func, | ||
const TServiceCallFunc & | recover_func, | ||
const TServiceCallFunc & | halt_func | ||
) |
Create required service clients and state machine; start worker-thread and state machine.
Definition at line 22 of file stop1_executor.cpp.
|
virtual |
Stop state machine and terminate worker-thread.
Definition at line 33 of file stop1_executor.cpp.
|
inlineprotected |
Stop the state machine.
Definition at line 131 of file stop1_executor.h.
void prbt_hardware_support::Stop1Executor::updateRunPermitted | ( | const bool | run_permitted | ) |
This is called everytime an updated run_permitted value is obtained.
Process run_permitted_updated event and notify worker-thread in case it is waiting for new required tasks.
run_permitted | The updated run_permitted value. |
Definition at line 48 of file stop1_executor.cpp.
bool prbt_hardware_support::Stop1Executor::updateRunPermittedCallback | ( | std_srvs::SetBool::Request & | req, |
std_srvs::SetBool::Response & | res | ||
) |
Definition at line 58 of file stop1_executor.cpp.
|
private |
This is executed in the worker-thread and allows asynchronous handling of run_permitted updates.
Wait for notification if the task queue of the state machine is empty. Once a task is present, execute it and signal its completion.
Definition at line 65 of file stop1_executor.cpp.
|
private |
Mutex for protecting access to the state machine, needs to be owned when triggering an event of the state machine
Definition at line 122 of file stop1_executor.h.
|
private |
State machine.
Definition at line 115 of file stop1_executor.h.
|
private |
Flag indicating if the worker-thread should terminate.
Definition at line 118 of file stop1_executor.h.
|
private |
Condition variable for notifying a waiting worker-thread.
Definition at line 125 of file stop1_executor.h.
|
private |
Worker-thread.
Definition at line 128 of file stop1_executor.h.