feature_finder_loader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Michael Ferguson
3  * Copyright (C) 2015 Fetch Robotics Inc.
4  * Copyright (C) 2013-2014 Unbounded Robotics Inc.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 // Author: Michael Ferguson
20 
21 #ifndef ROBOT_CALIBRATION_FEATURE_FINDER_LOADER_H
22 #define ROBOT_CALIBRATION_FEATURE_FINDER_LOADER_H
23 
24 #include <map>
25 #include <boost/shared_ptr.hpp>
26 
27 #include <ros/ros.h>
28 #include <pluginlib/class_loader.h>
30 
31 namespace robot_calibration
32 {
33 
35 typedef std::map<std::string, FeatureFinderPtr > FeatureFinderMap;
36 
41 {
42 public:
44  plugin_loader_("robot_calibration", "robot_calibration::FeatureFinder")
45  {
46  }
47 
49  FeatureFinderMap& features)
50  {
51  // Empty the mapping
52  features.clear();
53 
54  // Construct finders to detect relevant features
55  XmlRpc::XmlRpcValue finder_params;
56  if (!nh.getParam("features", finder_params))
57  {
58  ROS_FATAL("Parameter 'features' is not set!");
59  return false;
60  }
61 
62  // Should be a struct (mapping name -> config)
63  if (finder_params.getType() != XmlRpc::XmlRpcValue::TypeStruct)
64  {
65  ROS_FATAL("Parameter 'features' should be a struct.");
66  return false;
67  }
68 
69  // Load each finder
70  ROS_INFO("Loading %d feature finders.", (int)finder_params.size());
71  for (XmlRpc::XmlRpcValue::iterator it = finder_params.begin();
72  it != finder_params.end();
73  it++)
74  {
75  // Get name(space) of this finder
76  std::string name = static_cast<std::string>(it->first);
77  ros::NodeHandle finder_handle(nh, "features/"+name);
78 
79  // Get finder type
80  std::string type;
81  if (!finder_handle.getParam("type", type))
82  {
83  ROS_FATAL("Feature finder %s has no type defined", name.c_str());
84  return false;
85  }
86 
87  // Load correct finder
88  FeatureFinderPtr finder;
89  ROS_INFO(" New %s: %s", type.c_str(), name.c_str());
90  finder = plugin_loader_.createInstance(type);
91  if (finder && finder->init(name, finder_handle))
92  features[name] = finder;
93  }
94 
95  return true;
96  }
97 private:
99 };
100 
101 } // namespace robot_calibration
102 
103 #endif // ROBOT_CALIBRATION_FEATURE_FINDER_LOADER_H
#define ROS_FATAL(...)
std::map< std::string, FeatureFinderPtr > FeatureFinderMap
ValueStruct::iterator iterator
int size() const
Load feature finders, based on param server config.
Type const & getType() const
#define ROS_INFO(...)
bool load(ros::NodeHandle &nh, FeatureFinderMap &features)
Calibration code lives under this namespace.
pluginlib::ClassLoader< robot_calibration::FeatureFinder > plugin_loader_
bool getParam(const std::string &key, std::string &s) const
boost::shared_ptr< FeatureFinder > FeatureFinderPtr


robot_calibration
Author(s): Michael Ferguson
autogenerated on Tue Nov 3 2020 17:30:30