brake_test_executor_node_service_calls.h
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 
18 #ifndef BRAKE_TEST_EXECUTOR_NODE_SERVICE_CALLS_H
19 #define BRAKE_TEST_EXECUTOR_NODE_SERVICE_CALLS_H
20 
21 #include <ros/ros.h>
22 #include <std_srvs/Trigger.h>
23 
24 #include <prbt_hardware_support/BrakeTestErrorCodes.h>
25 #include <prbt_hardware_support/BrakeTest.h>
26 #include <prbt_hardware_support/SendBrakeTestResult.h>
27 
28 namespace prbt_hardware_support
29 {
30 
31 template<class T>
32 static void triggerServiceCall(T& client)
33 {
34  ROS_DEBUG_STREAM("Calling service: " << client.getService() << ")");
35  std_srvs::Trigger srv;
36  if ( !client.call(srv) )
37  {
38  ROS_WARN_STREAM("Calling service " << client.getService() << " failed.");
39  return;
40  }
41 
42  if (!srv.response.success)
43  {
44  ROS_WARN_STREAM("Execution of service " << client.getService()
45  << " failed with error message\n:"
46  << srv.response.message);
47  }
48 }
49 
50 template<class T>
51 static BrakeTest::Response executeBrakeTestCall(T& client)
52 {
53  ROS_DEBUG_STREAM("Calling service: " << client.getService() << ")");
54  BrakeTest srv;
55  if ( !client.call(srv) )
56  {
57  ROS_WARN_STREAM("Calling service " << client.getService() << " failed.");
58  BrakeTest::Response res;
59  res.success = false;
60  res.error_msg = "Failed to trigger brake test via service " + client.getService();
61  res.error_code.value = BrakeTestErrorCodes::TRIGGER_BRAKETEST_SERVICE_FAILURE;
62  return res;
63  }
64  return srv.response;
65 }
66 
67 template<class T>
68 static bool sendBrakeTestResultCall(T& client,
69  const bool brake_test_result)
70 {
71  ROS_DEBUG_STREAM("Calling service: " << client.getService());
72  SendBrakeTestResult srv;
73  srv.request.result = brake_test_result;
74  return client.call(srv);
75 }
76 
77 }
78 
79 #endif // BRAKE_TEST_EXECUTOR_NODE_SERVICE_CALLS_H
static bool sendBrakeTestResultCall(T &client, const bool brake_test_result)
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
static BrakeTest::Response executeBrakeTestCall(T &client)


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