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 RUN_PERMITTED 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 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< RunPermittedStateMachinestate_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 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:

Note
Unhold the controller is skipped if RUN_PERMITTED 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 60 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 22 of file stop1_executor.cpp.

◆ ~Stop1Executor()

prbt_hardware_support::Stop1Executor::~Stop1Executor ( )
virtual

Stop state machine and terminate worker-thread.

Definition at line 33 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 131 of file stop1_executor.h.

◆ updateRunPermitted()

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.

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

Definition at line 48 of file stop1_executor.cpp.

◆ updateRunPermittedCallback()

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.

◆ workerThreadFun()

void prbt_hardware_support::Stop1Executor::workerThreadFun ( )
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.

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 65 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 122 of file stop1_executor.h.

◆ state_machine_

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

State machine.

Definition at line 115 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 118 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 125 of file stop1_executor.h.

◆ worker_thread_

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

Worker-thread.

Definition at line 128 of file stop1_executor.h.


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


prbt_hardware_support
Author(s):
autogenerated on Thu Oct 22 2020 03:16:04