motoman_utils.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2014, Southwest Research Institute
5  * Author: Shaun Edwards
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  * * Neither the name of the Southwest Research Institute, nor the names
18  * of its contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
35 #include "ros/ros.h"
36 #include <map>
37 #include <string>
38 #include <vector>
39 
41 {
42 namespace motoman_utils
43 {
44 
45 bool getJointGroups(const std::string topic_param, std::map<int, RobotGroup> & robot_groups)
46 {
47  if (ros::param::has(topic_param))
48  {
49  XmlRpc::XmlRpcValue topics_list_rpc;
50  ros::param::get(topic_param, topics_list_rpc);
51 
52 
53  std::vector<XmlRpc::XmlRpcValue> topics_list;
54 
55  ROS_INFO_STREAM("Loading topic list");
56  ROS_INFO_STREAM("Found " << topics_list_rpc.size() << " topics");
57 
58  for (int i = 0; i < topics_list_rpc.size(); i++)
59  {
60  XmlRpc::XmlRpcValue state_value;
61  state_value = topics_list_rpc[i];
62  ROS_INFO_STREAM("Topic(state_value): " << state_value);
63  topics_list.push_back(state_value);
64  }
65 
66 
67  for (size_t i = 0; i < topics_list.size(); i++)
68  {
69  ROS_INFO_STREAM("Loading group: " << topics_list[i]);
70  RobotGroup rg;
71  std::vector<std::string> rg_joint_names;
72 
73  XmlRpc::XmlRpcValue joints;
74 
75  joints = topics_list[i]["joints"];
76  for (int jt = 0; jt < joints.size(); jt++)
77  {
78  rg_joint_names.push_back(static_cast<std::string>(joints[jt]));
79  }
80 
81  XmlRpc::XmlRpcValue group_number;
82 
83 
84  group_number = topics_list[i]["group"];
85  int group_number_int = static_cast<int>(group_number);
86 
88  std::string name_string;
89 
90  name = topics_list[i]["name"];
91  name_string = static_cast<std::string>(name);
92 
94  std::string ns_string;
95 
96  ns = topics_list[i]["ns"];
97 
98  ns_string = static_cast<std::string>(ns);
99 
100  ROS_DEBUG_STREAM("Setting group: ");
101  ROS_DEBUG_STREAM(" group number: " << group_number);
102  ROS_DEBUG_STREAM(" group number(int): " << group_number_int);
103  ROS_DEBUG_STREAM(" joints_names(size): " << rg_joint_names.size());
104  ROS_DEBUG_STREAM(" name: " << name_string);
105  ROS_DEBUG_STREAM(" ns: " << ns_string);
106  rg.set_group_id(group_number_int);
107  rg.set_joint_names(rg_joint_names);
108  rg.set_name(name_string);
109  rg.set_ns(ns_string);
110 
111  robot_groups[group_number] = rg;
112  }
113 
114  ROS_INFO_STREAM("Loaded " << robot_groups.size() << " groups");
115  return true;
116  }
117  else
118  {
119  ROS_ERROR_STREAM("Failed to find " << topic_param << " parameter");
120  return false;
121  }
122 }
123 
124 } // namespace motoman_utils
125 } // namespace industrial_robot_client
126 
void set_group_id(int gid)
Definition: robot_group.h:75
bool getJointGroups(const std::string topic_param, std::map< int, RobotGroup > &robot_groups)
Parses multi-group joints from topic_param.
int size() const
void set_name(std::string name)
Definition: robot_group.h:65
ROSCPP_DECL bool get(const std::string &key, std::string &s)
void set_joint_names(std::vector< std::string > jnames)
Definition: robot_group.h:81
ROSCPP_DECL bool has(const std::string &key)
#define ROS_DEBUG_STREAM(args)
#define ROS_INFO_STREAM(args)
void set_ns(std::string ns)
Definition: robot_group.h:70
#define ROS_ERROR_STREAM(args)


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