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 {
61 {
62 public:
68  Stop1Executor(const TServiceCallFunc& hold_func, const TServiceCallFunc& unhold_func,
69  const TServiceCallFunc& recover_func, const TServiceCallFunc& halt_func);
70 
74  virtual ~Stop1Executor();
75 
87  void updateRunPermitted(const bool run_permitted);
88  bool updateRunPermittedCallback(std_srvs::SetBool::Request& req, std_srvs::SetBool::Response& res);
89 
90 protected:
96  void stopStateMachine();
97 
98 private:
111  void workerThreadFun();
112 
113 private:
115  std::unique_ptr<RunPermittedStateMachine> state_machine_;
116 
118  std::atomic_bool terminate_{ false };
119 
122  std::mutex sm_mutex_;
123 
125  std::condition_variable worker_cv_;
126 
128  std::thread worker_thread_;
129 };
130 
132 {
133  ROS_DEBUG("Stop state machine");
134  state_machine_->stop();
135 }
136 
137 } // namespace prbt_hardware_support
138 
139 #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 Sun Oct 25 2020 03:13:00