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 
34 
38 
40 {
41 namespace robot_state_interface
42 {
43 
45 {
46  this->connection_ = NULL;
49 }
50 
51 bool RobotStateInterface::init(std::string default_ip, int default_port)
52 {
53  std::string ip;
54  int port;
55 
56  // override IP/port with ROS params, if available
57  ros::param::param<std::string>("robot_ip_address", ip, default_ip);
58  ros::param::param<int>("~port", port, default_port);
59 
60  // check for valid parameter values
61  if (ip.empty())
62  {
63  ROS_ERROR("No valid robot IP address found. Please set ROS 'robot_ip_address' param");
64  return false;
65  }
66  if (port <= 0)
67  {
68  ROS_ERROR("No valid robot IP port found. Please set ROS '~port' param");
69  return false;
70  }
71 
72  char* ip_addr = strdup(ip.c_str()); // connection.init() requires "char*", not "const char*"
73  ROS_INFO("Robot state connecting to IP address: '%s:%d'", ip_addr, port);
74  default_tcp_connection_.init(ip_addr, port);
75  free(ip_addr);
76 
78 }
79 
81 {
82  std::vector<std::string> joint_names;
83  if (!getJointNames("controller_joint_names", "robot_description", joint_names))
84  {
85  ROS_ERROR("Failed to initialize joint_names. Aborting");
86  return false;
87  }
88 
89  return init(connection, joint_names);
90 }
91 
92 bool RobotStateInterface::init(SmplMsgConnection* connection, std::vector<std::string>& joint_names)
93 {
94  this->joint_names_ = joint_names;
95  this->connection_ = connection;
97 
98  // initialize message-manager
100  return false;
101 
102  // initialize default handlers
104  return false;
106 
108  return false;
110 
111  return true;
112 }
113 
115 {
116  manager_.spin();
117 }
118 
119 } // robot_state_interface
120 } // industrial_robot_client
industrial_robot_client::robot_state_interface::RobotStateInterface::default_tcp_connection_
TcpClient default_tcp_connection_
Definition: robot_state_interface.h:153
industrial_robot_client::robot_state_interface::RobotStateInterface::default_robot_status_handler_
RobotStatusRelayHandler default_robot_status_handler_
Definition: robot_state_interface.h:155
industrial_robot_client::robot_state_interface::RobotStateInterface::add_handler
void add_handler(MessageHandler *handler, bool allow_replace=true)
Add a new handler.
Definition: robot_state_interface.h:147
industrial_robot_client::robot_state_interface::RobotStateInterface::manager_
MessageManager manager_
Definition: robot_state_interface.h:158
robot_state_interface.h
industrial_utils::param::getJointNames
bool getJointNames(const std::string joint_list_param, const std::string urdf_param, std::vector< std::string > &joint_names)
industrial_robot_client::robot_state_interface::RobotStateInterface::RobotStateInterface
RobotStateInterface()
Default constructor.
Definition: robot_state_interface.cpp:44
industrial_robot_client::robot_state_interface::RobotStateInterface::init
bool init(std::string default_ip="", int default_port=StandardSocketPorts::STATE)
Initialize robot connection using default method.
Definition: robot_state_interface.cpp:51
param_utils.h
industrial::message_manager::MessageManager::spin
void spin()
industrial::simple_socket::StandardSocketPorts
ROS_ERROR
#define ROS_ERROR(...)
industrial::tcp_client::TcpClient::init
bool init(char *buff, int port_num)
industrial_robot_client::robot_status_relay_handler::RobotStatusRelayHandler::init
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection)
Class initializer.
Definition: robot_status_relay_handler.cpp:47
industrial::smpl_msg_connection::SmplMsgConnection
industrial::smpl_msg_connection::SmplMsgConnection::makeConnect
virtual bool makeConnect()=0
industrial::message_manager::MessageManager::init
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection)
industrial_robot_client::robot_state_interface::RobotStateInterface::joint_names_
std::vector< std::string > joint_names_
Definition: robot_state_interface.h:159
industrial_robot_client
Definition: joint_relay_handler.h:46
industrial_robot_client::robot_state_interface::RobotStateInterface::default_joint_handler_
JointRelayHandler default_joint_handler_
Definition: robot_state_interface.h:154
industrial_robot_client::robot_state_interface::RobotStateInterface::connection_
SmplMsgConnection * connection_
Definition: robot_state_interface.h:157
industrial_robot_client::robot_state_interface::RobotStateInterface::run
void run()
Begin processing messages and publishing topics.
Definition: robot_state_interface.cpp:114
ROS_INFO
#define ROS_INFO(...)
industrial_robot_client::joint_relay_handler::JointRelayHandler::init
bool init(industrial::smpl_msg_connection::SmplMsgConnection *connection, std::vector< std::string > &joint_names)
Class initializer.
Definition: joint_relay_handler.cpp:46


industrial_robot_client
Author(s): Jeremy Zoss
autogenerated on Wed Mar 2 2022 00:24:59