modbus_adapter_sto_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 STO_SERVICE_NAME{"safe_torque_off"};
33 
34 // LCOV_EXCL_START
35 static void sendStoUpdate(ros::ServiceClient& sto_service, const bool sto)
36 {
37  std_srvs::SetBool srv;
38  srv.request.data = sto;
39  if (!sto_service.call(srv))
40  {
41  ROS_ERROR_STREAM("STO service call failed");
42  }
43 
44  if (!srv.response.success)
45  {
46  ROS_ERROR_STREAM(srv.response.message);
47  }
48 }
49 
50 
51 int main(int argc, char **argv)
52 {
53  ros::init(argc, argv, "modbus_adapter_sto");
54  ros::NodeHandle nh;
55 
56  using std::placeholders::_1;
57 
58  ModbusApiSpec api_spec{nh};
60  ros::ServiceClient sto_service = nh.serviceClient<std_srvs::SetBool>(STO_SERVICE_NAME);
61  ModbusAdapterSto adapter_sto(std::bind(sendStoUpdate, sto_service, _1), api_spec);
62  FilterPipeline filter_pipeline( nh, std::bind(&ModbusAdapterSto::modbusMsgCallback, &adapter_sto, _1) );
63 
64  ros::spin();
65 
66  return EXIT_FAILURE;
67 }
68 // LCOV_EXCL_STOP
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
int main(int argc, char **argv)
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.
An abstraction of a series of filters which ensures that only Modbus messages with different timestam...
static void waitForService(const std::string service_name, const double retry_timeout=DEFAULT_RETRY_TIMEOUT, const double msg_output_period=DEFAULT_MSG_OUTPUT_PERIOD)
static void sendStoUpdate(ros::ServiceClient &sto_service, const bool sto)
ROSCPP_DECL void spin()
Listens to the modbus_read topic and reacts to updated STO states.
static const std::string STO_SERVICE_NAME
#define ROS_ERROR_STREAM(args)
Specifies the meaning of the holding registers.


prbt_hardware_support
Author(s):
autogenerated on Thu Mar 19 2020 03:13:27