fsrobo_r_robot_service_interface.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * FSRobo-R Package BSDL
3 * ---------
4 * Copyright (C) 2019 FUJISOFT. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors
14 * may be used to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *********************************************************************/
29 #include <sstream>
30 
31 namespace fsrobo_r_driver
32 {
33 namespace robot_service_interface
34 {
35 
37 {
38 }
39 
41 {
42 }
43 
44 bool FSRoboRRobotServiceInterface::init(std::string default_ip, int default_port)
45 {
46  std::string ip;
47  int port;
48 
49  // override IP/port with ROS params, if available
50  ros::param::param<std::string>("robot_ip_address", ip, default_ip);
51  ros::param::param<int>("~port", port, default_port);
52 
53  // check for valid parameter values
54  if (ip.empty())
55  {
56  ROS_ERROR("No valid robot IP address found. Please set ROS 'robot_ip_address' param");
57  return false;
58  }
59  if (port <= 0)
60  {
61  ROS_ERROR("No valid robot IP port found. Please set ROS '~port' param");
62  return false;
63  }
64 
65  char* ip_addr = strdup(ip.c_str()); // connection.init() requires "char*", not "const char*"
66  ROS_INFO("IO Interface connecting to IP address: '%s:%d'", ip_addr, port);
67  default_tcp_connection_.init(ip_addr, port);
68  free(ip_addr);
69 
70 
72 }
73 
75 {
76  this->connection_ = connection;
78 
79  io_ctrl_.init(connection);
81 
82  robot_configurator_.init(connection);
86 
87  return true;
88 }
89 
90 bool FSRoboRRobotServiceInterface::setIOCB(fsrobo_r_msgs::SetIO::Request &req, fsrobo_r_msgs::SetIO::Response &res)
91 {
92  ROS_WARN("SetIO!");
93 
95 
96  std::stringstream ss;
97  std::vector<industrial::shared_types::shared_int> data;
98  for (int x : req.data)
99  {
100  data.push_back(x);
101  ss << x;
102  ss << " ";
103  }
104  ROS_WARN("%s", ss.str().c_str());
105 
106  bool result = io_ctrl_.setIO(req.fun, req.address, data);
107 
108  res.success = result;
109 
110  if (!result)
111  {
112  ROS_ERROR("Writing IO element %d failed", req.address);
113  return false;
114  }
115 
116  return true;
117 }
118 
119 bool FSRoboRRobotServiceInterface::setPostureCB(fsrobo_r_msgs::SetPosture::Request &req, fsrobo_r_msgs::SetPosture::Response &res)
120 {
121  ROS_WARN("SetPosture!");
122 
123  bool exec_result;
124 
125  bool send_result = robot_configurator_.setPosture(req.posture, exec_result);
126 
127  bool result = send_result && exec_result;
128 
129  if (!result)
130  {
131  ROS_ERROR("Setting Posture failed");
132  return false;
133  }
134 
135  return true;
136 }
137 
138 bool FSRoboRRobotServiceInterface::getPostureCB(fsrobo_r_msgs::GetPosture::Request &req, fsrobo_r_msgs::GetPosture::Response &res)
139 {
140  ROS_WARN("GetPosture!");
141 
142  bool exec_result;
144 
145  bool send_result = robot_configurator_.getPosture(posture, exec_result);
146 
147  res.posture = posture;
148  bool result = send_result && exec_result;
149 
150  if (!result)
151  {
152  ROS_ERROR("Getting posture failed");
153  return false;
154  }
155 
156  return true;
157 }
158 
159 bool FSRoboRRobotServiceInterface::setToolOffsetCB(fsrobo_r_msgs::SetToolOffset::Request &req, fsrobo_r_msgs::SetToolOffset::Response &res)
160 {
161  ROS_WARN("SetToolOffset!");
162 
163  bool exec_result;
164 
165  bool send_result = robot_configurator_.setToolOffset(req.origin.x, req.origin.y, req.origin.z, req.rotation.z, req.rotation.y, req.rotation.x, exec_result);
166 
167  bool result = send_result && exec_result;
168 
169  if (!result)
170  {
171  ROS_ERROR("Setting tool offset failed");
172  return false;
173  }
174 
175  return true;
176 }
177 
178 } // fsrobo_r_driver
179 } // robot_service_interface
180 
bool setIO(industrial::shared_types::shared_int fun, industrial::shared_types::shared_int, std::vector< industrial::shared_types::shared_int > &data)
Writes to a single IO point on the controller.
Definition: io_control.cpp:58
bool getPostureCB(fsrobo_r_msgs::GetPosture::Request &req, fsrobo_r_msgs::GetPosture::Response &res)
Callback function registered to ROS get_posture service. Transform message into SimpleMessage objects...
bool init(char *buff, int port_num)
bool getPosture(industrial::shared_types::shared_int &posture, bool &result)
Get posture on the controller.
bool setIOCB(fsrobo_r_msgs::SetIO::Request &req, fsrobo_r_msgs::SetIO::Response &res)
Callback function registered to ROS set_io service. Transform message into SimpleMessage objects and ...
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool setPostureCB(fsrobo_r_msgs::SetPosture::Request &req, fsrobo_r_msgs::SetPosture::Response &res)
Callback function registered to ROS set_posture service. Transform message into SimpleMessage objects...
#define ROS_WARN(...)
bool setToolOffset(industrial::shared_types::shared_real x, industrial::shared_types::shared_real y, industrial::shared_types::shared_real z, industrial::shared_types::shared_real rz, industrial::shared_types::shared_real ry, industrial::shared_types::shared_real rx, bool &result)
Set tool offset on the controller.
#define ROS_INFO(...)
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool setPosture(industrial::shared_types::shared_int posture, bool &result)
Set posture on the controller.
virtual bool init(std::string default_ip="", int default_port=StandardSocketPorts::IO)
Initialize robot connection using default method.
bool init(SmplMsgConnection *connection)
Definition: io_control.cpp:52
#define ROS_ERROR(...)
bool setToolOffsetCB(fsrobo_r_msgs::SetToolOffset::Request &req, fsrobo_r_msgs::SetToolOffset::Response &res)
Callback function registered to ROS set_tool_offset service. Transform message into SimpleMessage obj...


fsrobo_r_driver
Author(s): F-ROSROBO
autogenerated on Sun Feb 9 2020 03:58:29