robot_state_interface.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Southwest Research Institute
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Southwest Research Institute, nor the names
16  * of its contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
35 #include <map>
36 #include <string>
37 #include <vector>
38 
42 
44 {
45 namespace robot_state_interface
46 {
47 
49 {
50  this->connection_ = NULL;
52  this->add_handler(&default_joint_feedback_handler_);
53  this->add_handler(&default_joint_feedback_ex_handler_);
55 }
56 
57 bool RobotStateInterface::init(std::string default_ip, int default_port, bool version_0)
58 {
59  std::string ip;
60  int port;
61 
62  // override IP/port with ROS params, if available
63  ros::param::param<std::string>("robot_ip_address", ip, default_ip);
64  ros::param::param<int>("~port", port, default_port);
65  // check for valid parameter values
66  if (ip.empty())
67  {
68  ROS_ERROR("No valid robot IP address found. Please set ROS 'robot_ip_address' param");
69  return false;
70  }
71  if (port <= 0)
72  {
73  ROS_ERROR("No valid robot TCP port found. Please set ROS '~port' param");
74  return false;
75  }
76 
77  char* ip_addr = strdup(ip.c_str()); // connection.init() requires "char*", not "const char*"
78  ROS_INFO("Robot state connecting to IP address: '%s:%d'", ip_addr, port);
79  default_tcp_connection_.init(ip_addr, port);
80  free(ip_addr);
81 
83 }
84 
86 {
87  std::map<int, RobotGroup> robot_groups;
88  if (getJointGroups("topic_list", robot_groups))
89  {
90  this->version_0_ = false;
91  return init(connection, robot_groups);
92  }
93  else
94  {
95  this->version_0_ = true;
96  std::vector<std::string> joint_names;
97  if (!getJointNames("controller_joint_names", "robot_description", joint_names))
98  {
99  ROS_WARN("Unable to read 'controller_joint_names' param. Using standard 6-DOF joint names.");
100  }
101  return init(connection, joint_names);
102  }
103  return false;
104 }
105 
106 bool RobotStateInterface::init(SmplMsgConnection* connection, std::map<int, RobotGroup> robot_groups)
107 {
108  ROS_INFO_STREAM(" Initializing robot state " << robot_groups.size() << " groups");
109  this->robot_groups_ = robot_groups;
110  this->connection_ = connection;
111 
112  // initialize message-manager
113  if (!manager_.init(connection_))
114  {
115  ROS_ERROR("Failed to initialize message manager");
116  return false;
117  }
118 
119  // initialize default handlers
120  if (!default_joint_handler_.init(connection_, robot_groups_))
121  {
122  ROS_ERROR("Failed to initialialze joint handler");
123  return false;
124  }
126 
127  if (!default_joint_feedback_handler_.init(connection_, robot_groups_))
128  {
129  ROS_ERROR("Failed to initialize joint feedback handler");
130  return false;
131  }
132  this->add_handler(&default_joint_feedback_handler_);
133 
134  if (!default_joint_feedback_ex_handler_.init(connection_, robot_groups_))
135  {
136  ROS_ERROR("Failed to initialize joint(extended) feedback handler");
137  return false;
138  }
139  this->add_handler(&default_joint_feedback_ex_handler_);
140 
142  {
143  ROS_ERROR("Failed to initialize robot status handler");
144  return false;
145  }
147 
149 
150  ROS_INFO("Successfully initialized robot state interface");
151  return true;
152 }
153 
154 bool RobotStateInterface::init(SmplMsgConnection* connection, std::vector<std::string>& joint_names)
155 {
156  this->joint_names_ = joint_names;
157  this->connection_ = connection;
159 
160  // initialize message-manager
161  if (!manager_.init(connection_))
162  return false;
163 
164  // initialize default handlers
166  return false;
168 
169  if (!default_joint_feedback_handler_.init(connection_, joint_names_))
170  return false;
171  this->add_handler(&default_joint_feedback_handler_);
172 
174  return false;
176 
177  return true;
178 }
179 
181 {
182  manager_.spin();
183 }
184 
185 } // namespace robot_state_interface
186 } // namespace industrial_robot_client
bool init(std::string default_ip="", int default_port=StandardSocketPorts::STATE)
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection, std::vector< std::string > &joint_names)
bool init(char *buff, int port_num)
bool getJointNames(const std::string joint_list_param, const std::string urdf_param, std::vector< std::string > &joint_names)
bool getJointGroups(const std::string topic_param, std::map< int, RobotGroup > &robot_groups)
Parses multi-group joints from topic_param.
virtual bool init(SmplMsgConnection *connection, std::vector< std::string > &joint_names)
Class initializer.
#define ROS_WARN(...)
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection)
#define ROS_INFO(...)
void add_handler(MessageHandler *handler, bool allow_replace=true)
virtual bool init(SmplMsgConnection *connection, std::vector< std::string > &joint_names)
Class initializer.
#define ROS_INFO_STREAM(args)
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection)
#define ROS_ERROR(...)


motoman_driver
Author(s): Jeremy Zoss (Southwest Research Institute), Ted Miller (MotoROS) (Yaskawa Motoman), Eric Marcil (MotoROS) (Yaskawa Motoman)
autogenerated on Sat May 8 2021 02:27:44