sr_arm_finder.cpp
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Shadow Robot Company Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
17 /*
18 * File: sf_arm_finder.cpp
19 * Author: Andriy Petlovanyy <andriy@shadowrobot.com>
20 * @brief see README.md
21 */
22 
25 #include "urdf_parser/urdf_parser.h"
26 #include "urdf_model/model.h"
27 #include "urdf_model/joint.h"
28 #include <boost/foreach.hpp>
29 #include <boost/algorithm/string/predicate.hpp>
30 #include <map>
31 #include <set>
32 #include <utility>
33 #include <vector>
34 #include <string>
35 
36 namespace shadow_robot
37 {
39 {
40  if (ros::param::has("arm"))
41  {
42  ros::param::get("arm/mapping", arm_config_.mapping_);
43  ros::param::get("arm/joint_prefix", arm_config_.joint_prefix_);
44 
45  if (ros::param::has("robot_description"))
46  {
47  const std::vector<std::string> default_hand_joints_vector = SrHandFinder::get_default_joints();
48  const std::set<std::string> hand_default_joints(default_hand_joints_vector.begin(),
49  default_hand_joints_vector.end());
50  std::string robot_description;
51  ros::param::get("robot_description", robot_description);
52  const urdf::ModelInterfaceSharedPtr hand_urdf = urdf::parseURDF(robot_description);
53 
54  std::pair<std::string, urdf::JointSharedPtr> joint;
55  BOOST_FOREACH(joint, hand_urdf->joints_)
56  {
57  const std::string joint_name = joint.first;
58  if ((urdf::Joint::FIXED != joint.second->type) &&
59  (hand_default_joints.end() == hand_default_joints.find(joint_name)))
60  {
61  bool found_suffix = false;
62  BOOST_FOREACH(std::string default_joint_name, hand_default_joints)
63  {
64  if (boost::ends_with(joint_name, default_joint_name))
65  {
66  found_suffix = true;
67  break;
68  }
69  }
70 
71  if (!found_suffix)
72  {
73  std::pair<std::string, std::string> hand;
74  BOOST_FOREACH(hand, arm_config_.mapping_)
75  {
76  const std::string hand_serial = hand.first;
77  const std::string hand_id = hand.second;
78 
79  if ((arm_config_.joint_prefix_.count(hand_serial) > 0) &&
80  boost::starts_with(joint_name, arm_config_.joint_prefix_[hand_serial]))
81  {
82  joints_[hand_id].push_back(joint_name);
83  }
84  }
85  }
86  }
87  }
88  }
89  else
90  {
91  ROS_WARN_STREAM("No robot_description found on parameter server. Assuming that there is no arm.");
92  }
93  }
94  else
95  {
96  ROS_ERROR_STREAM("No arm is detected");
97  }
98 }
99 
101 {
102  return arm_config_;
103 }
104 
105 std::map<std::string, std::vector<std::string> > SrArmFinder::get_joints()
106 {
107  return joints_;
108 }
109 
110 } /* namespace shadow_robot */
std::map< std::string, std::string > joint_prefix_
static const std::vector< std::string > get_default_joints()
ROSCPP_DECL bool get(const std::string &key, std::string &s)
ROSCPP_DECL bool has(const std::string &key)
#define ROS_WARN_STREAM(args)
std::map< std::string, std::string > mapping_
std::map< std::string, std::vector< std::string > > joints_
#define ROS_ERROR_STREAM(args)
std::map< std::string, std::vector< std::string > > get_joints()


sr_utilities
Author(s): Ugo Cupcic
autogenerated on Mon Feb 28 2022 23:52:19