stop1_executor.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Pilz GmbH & Co. KG
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13 
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef STOP1_EXECUTOR_H
19 #define STOP1_EXECUTOR_H
20 
21 #include <atomic>
22 #include <condition_variable>
23 #include <mutex>
24 #include <string>
25 #include <thread>
26 
27 #include <ros/ros.h>
28 #include <ros/service_client.h>
29 #include <std_srvs/Trigger.h>
30 #include <std_srvs/SetBool.h>
31 
34 
35 namespace prbt_hardware_support
36 {
37 
62 {
63 public:
69  Stop1Executor(const TServiceCallFunc& hold_func,
70  const TServiceCallFunc& unhold_func,
71  const TServiceCallFunc& recover_func,
72  const TServiceCallFunc& halt_func);
73 
77  virtual ~Stop1Executor();
78 
90  void updateRunPermitted(const bool run_permitted);
91  bool updateRunPermittedCallback(std_srvs::SetBool::Request &req,
92  std_srvs::SetBool::Response &res);
93 
94 protected:
100  void stopStateMachine();
101 
102 private:
103 
116  void workerThreadFun();
117 
118 private:
120  std::unique_ptr<RunPermittedStateMachine> state_machine_;
121 
123  std::atomic_bool terminate_{false};
124 
127  std::mutex sm_mutex_;
128 
130  std::condition_variable worker_cv_;
131 
133  std::thread worker_thread_;
134 
135 };
136 
138 {
139  ROS_DEBUG("Stop state machine");
140  state_machine_->stop();
141 }
142 
143 } // namespace prbt_hardware_support
144 
145 #endif // STOP1_EXECUTOR_H
bool updateRunPermittedCallback(std_srvs::SetBool::Request &req, std_srvs::SetBool::Response &res)
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.
std::atomic_bool terminate_
Flag indicating if the worker-thread should terminate.
std::condition_variable worker_cv_
Condition variable for notifying a waiting worker-thread.
void updateRunPermitted(const bool run_permitted)
This is called everytime an updated run_permitted value is obtained.
std::thread worker_thread_
Worker-thread.
void stopStateMachine()
Stop the state machine.
void workerThreadFun()
This is executed in the worker-thread and allows asynchronous handling of run_permitted updates...
Performs service calls for Stop1 and the respective reversal, that is enabling the manipulator...
std::function< bool()> TServiceCallFunc
std::unique_ptr< RunPermittedStateMachine > state_machine_
State machine.
#define ROS_DEBUG(...)
virtual ~Stop1Executor()
Stop state machine and terminate worker-thread.


prbt_hardware_support
Author(s):
autogenerated on Tue Feb 2 2021 03:50:17