sr_hand_finder.cpp
Go to the documentation of this file.
1 /*
2 * File: sf_hand_finder.cpp
3 * Author: Vahid Aminzadeh <vahid@shadowrobot.com>
4 * Copyright 2015 Shadow Robot Company Ltd.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @brief see README.md
20 */
21 
23 #include "urdf_parser/urdf_parser.h"
24 #include "urdf_model/model.h"
25 #include "urdf_model/joint.h"
26 #include <ros/package.h>
27 #include <boost/assign/list_of.hpp>
28 #include <boost/foreach.hpp>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/algorithm/string/predicate.hpp>
31 #include <utility>
32 #include <map>
33 #include <set>
34 #include <vector>
35 #include <string>
36 #include <iostream>
37 
38 using boost::assign::list_of;
39 using urdf::ModelInterface;
40 using urdf::Joint;
41 
42 namespace shadow_robot
43 {
44 const std::vector<std::string> SrHandFinder::joint_names_ = list_of("FFJ1")("FFJ2")("FFJ3")("FFJ4")("MFJ1")("MFJ2")(
45  "MFJ3")("MFJ4")("RFJ1")("RFJ2")("RFJ3")("RFJ4")("LFJ1")("LFJ2")("LFJ3")("LFJ4")("LFJ5")("THJ1")("THJ2")(
46  "THJ3")("THJ4")("THJ5")("WRJ1")("WRJ2");
47 
48 const std::vector<std::string> SrHandFinder::get_default_joints()
49 {
51 }
52 
54 {
55  return hand_config_;
56 }
57 
59 {
60  if (ros::param::has("hand"))
61  {
62  std::map<std::string, std::string> mapping_map;
63  ros::param::get("hand/mapping", hand_config_.mapping_);
64  ros::param::get("hand/joint_prefix", hand_config_.joint_prefix_);
65 
66  std::pair<std::string, std::string> pair;
67  BOOST_FOREACH(pair, hand_config_.mapping_)
68  {
69  // hand empty mapping
70  if (pair.second.empty())
71  {
72  hand_config_.mapping_[pair.first] = pair.first;
73  ROS_INFO_STREAM("detected hands are \n" << "hand serial:" << pair.first << " hand_id:"
74  << pair.second << " , replaced internally by: " << pair.first);
75  }
76  else
77  ROS_INFO_STREAM("detected hands are \n" << "hand serial:" << pair.first << " hand_id:" << pair.second);
78  }
79 
83  }
84  else
85  {
86  ROS_ERROR_STREAM("No hand found");
87  }
88 }
89 
91 {
92  std::pair<std::string, std::string> hand;
93  if (ros::param::has("robot_description"))
94  {
95  std::set<std::string> hand_joints;
96 
97  BOOST_FOREACH(hand, hand_config_.joint_prefix_)
98  {
99  BOOST_FOREACH(std::string default_joint_name, joint_names_)
100  {
101  hand_joints.insert(hand.second + default_joint_name);
102  }
103  }
104  std::string robot_description;
105  ros::param::get("robot_description", robot_description);
106  const boost::shared_ptr<ModelInterface> hand_urdf = urdf::parseURDF(robot_description);
107  BOOST_FOREACH(hand, hand_config_.joint_prefix_)
108  {
109  std::set<std::string> joints_tmp;
110  std::pair<std::string, boost::shared_ptr<Joint> > joint;
111  BOOST_FOREACH(joint, hand_urdf->joints_)
112  {
113  if (Joint::FIXED != joint.second->type)
114  {
115  const std::string joint_name = joint.first;
116  bool found_prefix = false;
117  std::pair<std::string, std::string> hand_prefix;
118  BOOST_FOREACH(hand_prefix, hand_config_.joint_prefix_)
119  {
120  if (boost::starts_with(joint_name, hand_prefix.second))
121  {
122  found_prefix = true;
123  }
124  }
125 
126  if (!found_prefix)
127  {
128  ROS_DEBUG_STREAM("Joint " + joint_name + "has invalid prefix");
129  }
130  else if (0 == joint_name.find(hand.second))
131  {
132  joints_tmp.insert(joint_name);
133  }
134  }
135  }
136 
137  std::set_intersection(joints_tmp.begin(), joints_tmp.end(), hand_joints.begin(), hand_joints.end(),
138  std::back_inserter(joints_[hand_config_.mapping_[hand.first]]));
139  }
140  }
141  else
142  {
143  ROS_WARN_STREAM("No robot_description found on parameter server. Joint names are loaded for 5 finger hand");
144  BOOST_FOREACH(hand, hand_config_.mapping_)
145  {
146  const std::string hand_mapping = hand.second;
147  BOOST_FOREACH(std::string default_joint_name, joint_names_)
148  {
149  joints_[hand_mapping].push_back(hand_config_.joint_prefix_[hand.first] + default_joint_name);
150  }
151  }
152  }
153 }
154 
156 {
157  std::string ethercat_path = ros::package::getPath("sr_ethercat_hand_config");
158  for (std::map<std::string, std::string>::const_iterator mapping_iter = hand_config_.mapping_.begin();
159  mapping_iter != hand_config_.mapping_.end(); ++mapping_iter)
160  {
161  calibration_path_[mapping_iter->second] = ethercat_path + "/calibrations/"
162  + mapping_iter->second + "/" + "calibration.yaml";
163  }
164 }
165 
167 {
168  std::string ethercat_path = ros::package::getPath("sr_ethercat_hand_config");
169  for (std::map<std::string, std::string>::const_iterator mapping_iter = hand_config_.mapping_.begin();
170  mapping_iter != hand_config_.mapping_.end(); ++mapping_iter)
171  {
172  hand_controller_tuning_.friction_compensation_[mapping_iter->second] =
173  ethercat_path + "/controls/" + "friction_compensation.yaml";
174  hand_controller_tuning_.motor_control_[mapping_iter->second] =
175  ethercat_path + "/controls/motors/" + mapping_iter->second + "/motor_board_effort_controllers.yaml";
176  std::string host_path(ethercat_path + "/controls/host/" + mapping_iter->second + "/");
177  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
178  host_path + "sr_edc_calibration_controllers.yaml");
179  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
180  host_path + "sr_edc_joint_velocity_controllers_PWM.yaml");
181  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
182  host_path + "sr_edc_effort_controllers_PWM.yaml");
183  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
184  host_path + "sr_edc_joint_velocity_controllers.yaml");
185  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
186  host_path + "sr_edc_effort_controllers.yaml");
187 
188  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
189  host_path + "sr_edc_mixed_position_velocity_joint_controllers_PWM.yaml");
190  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
191  host_path + "sr_edc_joint_position_controllers_PWM.yaml");
192  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
193  host_path + "sr_edc_mixed_position_velocity_joint_controllers.yaml");
194  hand_controller_tuning_.host_control_[mapping_iter->second].push_back(
195  host_path + "sr_edc_joint_position_controllers.yaml");
196  }
197 }
198 
199 std::map<std::string, std::vector<std::string> > SrHandFinder::get_joints()
200 {
201  return joints_;
202 }
203 
204 std::map<std::string, std::string> SrHandFinder::get_calibration_path()
205 {
206  return calibration_path_;
207 }
208 
210 {
212 }
213 } /* namespace shadow_robot */
HandControllerTuning get_hand_controller_tuning()
std::map< std::string, std::string > mapping_
std::map< std::string, std::vector< std::string > > host_control_
static const std::vector< std::string > get_default_joints()
HandControllerTuning hand_controller_tuning_
ROSCPP_DECL bool get(const std::string &key, std::string &s)
static const std::vector< std::string > joint_names_
ROSCPP_DECL bool has(const std::string &key)
std::map< std::string, std::string > get_calibration_path()
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
std::map< std::string, std::vector< std::string > > get_joints()
ROSLIB_DECL std::string getPath(const std::string &package_name)
std::map< std::string, std::string > motor_control_
#define ROS_INFO_STREAM(args)
std::map< std::string, std::string > friction_compensation_
#define ROS_ERROR_STREAM(args)
std::map< std::string, std::string > calibration_path_
std::map< std::string, std::string > joint_prefix_
std::map< std::string, std::vector< std::string > > joints_


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:49