Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
prbt_hardware_support::Stop1Executor Class Reference

Performs service calls for Stop1 and the respective reversal, that is enabling the manipulator. Incoming updates of the STO state are handled asynchronously. More...

#include <stop1_executor.h>

Inheritance diagram for prbt_hardware_support::Stop1Executor:
Inheritance graph
[legend]

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 updateSto (const bool sto)
 This is called everytime an updated sto value is obtained. More...
 
bool updateStoCallback (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 sto updates. More...
 

Private Attributes

std::mutex sm_mutex_
 
std::unique_ptr< StoStateMachinestate_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...
 

Detailed Description

Performs service calls for Stop1 and the respective reversal, that is enabling the manipulator. Incoming updates of the STO 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:

Note
Unhold the controller is skipped if STO changes during recover. This avoids the superfluous execution of a hold trajectory, which would result in an overlong stopping time.
If a service call fails, the execution is always continued in order to make a Stop1 or a recover-retry possible.
Remarks
this class is templated for easier mocking. However for usability it can be used by AdapterSto

Definition at line 61 of file stop1_executor.h.

Constructor & Destructor Documentation

◆ Stop1Executor()

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 23 of file stop1_executor.cpp.

◆ ~Stop1Executor()

prbt_hardware_support::Stop1Executor::~Stop1Executor ( )
virtual

Stop state machine and terminate worker-thread.

Definition at line 36 of file stop1_executor.cpp.

Member Function Documentation

◆ stopStateMachine()

void prbt_hardware_support::Stop1Executor::stopStateMachine ( )
inlineprotected

Stop the state machine.

Note
The access modifier protected allows this method to be used in tests.

Definition at line 137 of file stop1_executor.h.

◆ updateSto()

void prbt_hardware_support::Stop1Executor::updateSto ( const bool  sto)

This is called everytime an updated sto value is obtained.

Process sto_updated event and notify worker-thread in case it is waiting for new required tasks.

Note
Access to the state machine is protected for thread-safety.
Parameters
stoThe updated sto value.

Definition at line 51 of file stop1_executor.cpp.

◆ updateStoCallback()

bool prbt_hardware_support::Stop1Executor::updateStoCallback ( std_srvs::SetBool::Request &  req,
std_srvs::SetBool::Response &  res 
)

Definition at line 61 of file stop1_executor.cpp.

◆ workerThreadFun()

void prbt_hardware_support::Stop1Executor::workerThreadFun ( )
private

This is executed in the worker-thread and allows asynchronous handling of sto 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.

Note
Access to the state machine is protected for thread-safety. It is assumed that task execution does not access the state machine, whereas the completion signalling does.

Definition at line 69 of file stop1_executor.cpp.

Member Data Documentation

◆ sm_mutex_

std::mutex prbt_hardware_support::Stop1Executor::sm_mutex_
private

Mutex for protecting access to the state machine, needs to be owned when triggering an event of the state machine

Definition at line 127 of file stop1_executor.h.

◆ state_machine_

std::unique_ptr<StoStateMachine> prbt_hardware_support::Stop1Executor::state_machine_
private

State machine.

Definition at line 120 of file stop1_executor.h.

◆ terminate_

std::atomic_bool prbt_hardware_support::Stop1Executor::terminate_ {false}
private

Flag indicating if the worker-thread should terminate.

Definition at line 123 of file stop1_executor.h.

◆ worker_cv_

std::condition_variable prbt_hardware_support::Stop1Executor::worker_cv_
private

Condition variable for notifying a waiting worker-thread.

Definition at line 130 of file stop1_executor.h.

◆ worker_thread_

std::thread prbt_hardware_support::Stop1Executor::worker_thread_
private

Worker-thread.

Definition at line 133 of file stop1_executor.h.


The documentation for this class was generated from the following files:


prbt_hardware_support
Author(s):
autogenerated on Tue Feb 25 2020 03:19:31