modbus_adapter_run_permitted_node.cpp
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 #include <functional>
19 
20 #include <ros/ros.h>
21 
23 
28 #include <std_srvs/SetBool.h>
29 
30 using namespace prbt_hardware_support;
31 
32 static const std::string RUN_PERMITTED_SERVICE_NAME{ "run_permitted" };
33 
34 // LCOV_EXCL_START
35 static void sendRunPermittedUpdate(ros::ServiceClient& run_permitted_service, const bool run_permitted)
36 {
37  std_srvs::SetBool srv;
38  srv.request.data = run_permitted;
39  if (!run_permitted_service.call(srv))
40  {
41  ROS_ERROR_STREAM("RUN_PERMITTED service call failed");
42  }
43 
44  if (!srv.response.success)
45  {
46  ROS_ERROR_STREAM(srv.response.message);
47  }
48 }
49 
50 int main(int argc, char** argv)
51 {
52  ros::init(argc, argv, "modbus_adapter_run_permitted");
53  ros::NodeHandle nh;
54 
55  using std::placeholders::_1;
56 
57  ModbusApiSpec api_spec{ nh };
59  ros::ServiceClient run_permitted_service = nh.serviceClient<std_srvs::SetBool>(RUN_PERMITTED_SERVICE_NAME);
60  ModbusAdapterRunPermitted adapter_run_permitted(std::bind(sendRunPermittedUpdate, run_permitted_service, _1),
61  api_spec);
62  FilterPipeline filter_pipeline(nh,
63  std::bind(&ModbusAdapterRunPermitted::modbusMsgCallback, &adapter_run_permitted, _1));
64 
65  ros::spin();
66 
67  return EXIT_FAILURE;
68 }
69 // LCOV_EXCL_STOP
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
void modbusMsgCallback(const ModbusMsgInStampedConstPtr &msg_raw)
Called whenever a new modbus messages arrives.
static void sendRunPermittedUpdate(ros::ServiceClient &run_permitted_service, const bool run_permitted)
An abstraction of a series of filters which ensures that only Modbus messages with different timestam...
static const std::string RUN_PERMITTED_SERVICE_NAME
static void waitForService(const std::string service_name, const double retry_timeout=DEFAULT_RETRY_TIMEOUT, const double msg_output_period=DEFAULT_MSG_OUTPUT_PERIOD)
ROSCPP_DECL void spin()
Listens to the modbus_read topic and reacts to updated RUN_PERMITTED states.
int main(int argc, char **argv)
#define ROS_ERROR_STREAM(args)
Specifies the meaning of the holding registers.


prbt_hardware_support
Author(s):
autogenerated on Mon Feb 28 2022 23:14:34