feature_finder.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Fetch Robotics Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 // Author: Michael Ferguson
00018 
00019 #include <robot_calibration/capture/feature_finder.h>
00020 #include <robot_calibration/capture/led_finder.h>
00021 #include <robot_calibration/capture/checkerboard_finder.h>
00022 #include <robot_calibration/capture/ground_plane_finder.h>
00023 #include <robot_calibration/capture/plane_finder.h>
00024 
00025 namespace robot_calibration
00026 {
00027 
00028 bool loadFeatureFinders(ros::NodeHandle& nh,
00029                         FeatureFinderMap& features)
00030 {
00031   // Empty the mapping
00032   features.clear();
00033 
00034   // Construct finders to detect relevant features
00035   XmlRpc::XmlRpcValue finder_params;
00036   if (!nh.getParam("features", finder_params))
00037   {
00038     ROS_FATAL("Parameter 'features' is not set!");
00039     return false;
00040   }
00041 
00042   // Should be a struct (mapping name -> config)
00043   if (finder_params.getType() != XmlRpc::XmlRpcValue::TypeStruct)
00044   {
00045     ROS_FATAL("Parameter 'features' should be a struct.");
00046     return false;
00047   }
00048 
00049   ROS_INFO("Loading %d feature finders.", (int)finder_params.size());
00050 
00051   // Load each finder
00052   for (XmlRpc::XmlRpcValue::iterator it = finder_params.begin();
00053        it != finder_params.end();
00054        it++)
00055   {
00056     // Get name(space) of this finder
00057     std::string name = static_cast<std::string>(it->first);
00058     ros::NodeHandle finder_handle(nh, "features/"+name);
00059 
00060     // Get finder type
00061     std::string type;
00062     if (!finder_handle.getParam("type", type))
00063     {
00064       ROS_FATAL("Feature finder %s has no type defined", name.c_str());
00065       return false;
00066     }
00067 
00068     // Load correct finder
00069     // TODO: this will probably be plugin-based in the future
00070     FeatureFinderPtr finder;
00071     if (type == "robot_calibration/LedFinder")
00072     {
00073       ROS_INFO("  New robot_calibration/LedFinder: %s", name.c_str());
00074       finder.reset(new robot_calibration::LedFinder(finder_handle));
00075     }
00076     else if (type == "robot_calibration/GroundPlaneFinder")
00077     {
00078       ROS_INFO("  New robot_calibration/GroundPlaneFinder: %s", name.c_str());
00079       finder.reset(new robot_calibration::GroundPlaneFinder(finder_handle));
00080     }
00081     else if (type == "robot_calibration/CheckerboardFinder")
00082     {
00083       ROS_INFO("  New robot_calibration/CheckerboardFinder: %s", name.c_str());
00084       finder.reset(new robot_calibration::CheckerboardFinder(finder_handle));
00085     }
00086     else if (type == "robot_calibration/PlaneFinder")
00087     {
00088       ROS_INFO("  New robot_calibration/PlaneFinder: %s", name.c_str());
00089       finder.reset(new robot_calibration::PlaneFinder(finder_handle));
00090     }
00091     else
00092     {
00093       ROS_FATAL("Unknown finder: %s", type.c_str());
00094       return false;
00095     }
00096 
00097     features[name] = finder;
00098   }
00099 
00100   return true;
00101 }
00102 
00103 }  // namespace robot_calibration


robot_calibration
Author(s): Michael Ferguson
autogenerated on Thu Jun 6 2019 21:54:10