brake_test_executor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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 
19 
20 namespace prbt_hardware_support
21 {
22 
24  ControllerHoldFunc&& controller_hold_func,
25  TriggerBrakeTestFunc&& trigger_brake_test_func,
26  ControllerUnholdFunc&& unhold_func,
27  BrakeTestResultFunc&& brake_test_result_func)
28  : detect_robot_motion_func_(detect_robot_motion_func)
29  , hold_controller_func_(controller_hold_func)
30  , execute_brake_test_func_(trigger_brake_test_func)
31  , unhold_controller_func_(unhold_func)
32  , brake_test_result_func_(brake_test_result_func)
33 {
35  {
36  throw BrakeTestExecutorException("Function to detect robot motion missing");
37  }
38 
40  {
41  throw BrakeTestExecutorException("Function to hold controller missing");
42  }
43 
45  {
46  throw BrakeTestExecutorException("Function to trigger brake test on robot missing");
47  }
48 
50  {
51  throw BrakeTestExecutorException("Function to unhold controller missing");
52  }
53 
55  {
56  throw BrakeTestExecutorException("Function to send brake test result to FS controller missing");
57  }
58 }
59 
60 bool BrakeTestExecutor::executeBrakeTest(BrakeTest::Request& /*req*/,
61  BrakeTest::Response& res)
62 {
64  {
65  res.success = false;
66  res.error_msg = "Robot is moving, cannot perform brake test";
67  res.error_code.value = BrakeTestErrorCodes::ROBOT_MOTION_DETECTED;
68  return true;
69  }
70 
71  ROS_INFO_STREAM("Enter hold for braketest. Do not unhold the controller!");
72 
74 
76  ROS_INFO("Brake test result: %i", res.success);
77  if (!res.success)
78  {
79  ROS_INFO("Brake test error code: %i", res.error_code.value);
80  if (!res.error_msg.empty())
81  {
82  ROS_INFO_STREAM("Brake test error msg: " << res.error_msg);
83  }
84  }
85 
87 
88  if(!brake_test_result_func_(res.success))
89  {
90  res.success = false;
91  res.error_msg = "Failed to send brake test result";
92  res.error_code.value = BrakeTestErrorCodes::FAILURE;
93  }
94 
95  return true;
96 }
97 
98 } // namespace prbt_hardware_support
std::function< void()> ControllerHoldFunc
std::function< BrakeTest::Response()> TriggerBrakeTestFunc
std::function< bool(const bool)> BrakeTestResultFunc
bool executeBrakeTest(BrakeTest::Request &req, BrakeTest::Response &response)
#define ROS_INFO(...)
std::function< bool()> DetectRobotMotionFunc
#define ROS_INFO_STREAM(args)
std::function< void()> ControllerUnholdFunc
BrakeTestExecutor(DetectRobotMotionFunc &&detect_robot_motion_func, ControllerHoldFunc &&controller_hold_func, TriggerBrakeTestFunc &&trigger_brake_test_func, ControllerUnholdFunc &&unhold_func, BrakeTestResultFunc &&brake_test_result_fun)


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