parameters.cpp
Go to the documentation of this file.
1 //=================================================================================================
2 // Copyright (c) 2013, Johannes Meyer, TU Darmstadt
3 // All rights reserved.
4 
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of the Flight Systems and Automatic Control group,
13 // TU Darmstadt, nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without
15 // specific prior written permission.
16 
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //=================================================================================================
28 
29 #include "parameters.h"
30 #include <set>
31 
32 #include <ros/node_handle.h>
33 #include <ros/console.h>
34 
35 #include <hector_nav_msgs/GetDistanceToObstacle.h>
36 #include <hector_nav_msgs/GetNormal.h>
37 
38 namespace hector_object_tracker {
39 
40 std::map<std::string, bool> _project_objects;
41 std::map<std::string, bool> _with_orientation;
42 std::map<std::string, double> _default_distance;
43 std::map<std::string, double> _distance_variance;
44 std::map<std::string, double> _angle_variance;
45 std::map<std::string, double> _min_height;
46 std::map<std::string, double> _max_height;
47 std::map<std::string, double> _pending_support;
48 std::map<std::string, double> _pending_time;
49 std::map<std::string, double> _active_support;
50 std::map<std::string, double> _active_time;
51 std::map<std::string, double> _inactive_support;
52 std::map<std::string, double> _inactive_time;
53 std::map<std::string, double> _min_distance_between_objects;
54 std::map<std::string, std_msgs::ColorRGBA> _marker_color;
55 std::map<std::string, ros::ServiceClientPtr> _distance_to_obstacle_service;
56 std::map<std::string, ros::ServiceClientPtr> _get_normal_service;
57 std::map<std::string, ServiceClientsWithProperties> _percept_verification_services;
58 std::map<std::string, ServiceClientsWithProperties> _object_verification_services;
59 
60 namespace Parameters {
61 
62  void load(const std::string &class_id /* = std::string() */)
63  {
64  static std::set<std::string> _per_class_parameters_loaded;
65 
66  if (_per_class_parameters_loaded.count(class_id)) return;
67  ros::NodeHandle priv_nh("~");
68 
69  std::string prefix = class_id + "/";
70  if (prefix == "/") prefix.clear();
71 
72  if (priv_nh.hasParam(prefix + "project_objects"))
73  priv_nh.getParam(prefix + "project_objects", _project_objects[class_id]);
74  if (priv_nh.hasParam(prefix + "with_orientation"))
75  priv_nh.getParam(prefix + "with_orientation", _with_orientation[class_id]);
76  if (priv_nh.hasParam(prefix + "default_distance"))
77  priv_nh.getParam(prefix + "default_distance", _default_distance[class_id]);
78  if (priv_nh.hasParam(prefix + "distance_variance"))
79  priv_nh.getParam(prefix + "distance_variance", _distance_variance[class_id]);
80  if (priv_nh.hasParam(prefix + "angle_variance"))
81  priv_nh.getParam(prefix + "angle_variance", _angle_variance[class_id]);
82  if (priv_nh.hasParam(prefix + "min_height"))
83  priv_nh.getParam(prefix + "min_height", _min_height[class_id]);
84  if (priv_nh.hasParam(prefix + "max_height"))
85  priv_nh.getParam(prefix + "max_height", _max_height[class_id]);
86  if (priv_nh.hasParam(prefix + "pending_support"))
87  priv_nh.getParam(prefix + "pending_support", _pending_support[class_id]);
88  if (priv_nh.hasParam(prefix + "pending_time"))
89  priv_nh.getParam(prefix + "pending_time", _pending_time[class_id]);
90  if (priv_nh.hasParam(prefix + "active_support"))
91  priv_nh.getParam(prefix + "active_support", _active_support[class_id]);
92  if (priv_nh.hasParam(prefix + "active_time"))
93  priv_nh.getParam(prefix + "active_time", _active_time[class_id]);
94  if (priv_nh.hasParam(prefix + "inactive_support"))
95  priv_nh.getParam(prefix + "inactive_support", _inactive_support[class_id]);
96  if (priv_nh.hasParam(prefix + "inactive_time"))
97  priv_nh.getParam(prefix + "inactive_time", _inactive_time[class_id]);
98  if (priv_nh.hasParam(prefix + "min_distance_between_objects"))
99  priv_nh.getParam(prefix + "min_distance_between_objects", _min_distance_between_objects[class_id]);
100 
101  if (priv_nh.hasParam(prefix + "marker_color")) {
102  XmlRpc::XmlRpcValue color;
103  priv_nh.getParam(prefix + "marker_color", color);
104  if (color.getType() == XmlRpc::XmlRpcValue::TypeArray && color.size() >= 3) {
105  _marker_color[class_id].r = (double) color[0];
106  _marker_color[class_id].g = (double) color[1];
107  _marker_color[class_id].b = (double) color[2];
108  if (color.size() > 3)
109  _marker_color[class_id].a = (double) color[3];
110  else
111  _marker_color[class_id].a = 1.0;
112  } else {
113  ROS_ERROR_STREAM("Illegal value for param marker_color: " << color << ". Must be an array of size 3 or 4.");
114  }
115  }
116 
117  std::string distance_to_obstacle_service;
118  if (priv_nh.hasParam(prefix + "distance_to_obstacle_service")) {
119  priv_nh.getParam(prefix + "distance_to_obstacle_service", distance_to_obstacle_service);
120  } else if (class_id.empty()) {
121  distance_to_obstacle_service = "get_distance_to_obstacle";
122  }
123 
124  if (!distance_to_obstacle_service.empty()) {
125  _distance_to_obstacle_service[class_id].reset(new ros::ServiceClient(ros::NodeHandle().serviceClient<hector_nav_msgs::GetDistanceToObstacle>(distance_to_obstacle_service)));
126  bool project_objects = _project_objects.count(class_id) ? _project_objects.at(class_id) : _project_objects.at(std::string());
127  if (project_objects && !_distance_to_obstacle_service[class_id]->waitForExistence(ros::Duration(5.0))) {
128  ROS_WARN_STREAM("project_objects is true, but GetDistanceToObstacle service is not (yet) available" << (!class_id.empty() ? "for class " + class_id : ""));
129  }
130  }
131 
132  if (priv_nh.hasParam(prefix + "get_normal_service")) {
133  std::string get_normal_service;
134  priv_nh.getParam(prefix + "get_normal_service", get_normal_service);
135  _get_normal_service[class_id].reset(new ros::ServiceClient(ros::NodeHandle().serviceClient<hector_nav_msgs::GetNormal>(get_normal_service)));
136  }
137 
138  _per_class_parameters_loaded.insert(class_id);
139  }
140 
141 } // namespace Parameters
142 } // namespace hector_object_tracker
std::map< std::string, double > _inactive_support
Definition: parameters.cpp:51
std::map< std::string, double > _pending_support
Definition: parameters.cpp:47
std::map< std::string, ros::ServiceClientPtr > _distance_to_obstacle_service
Definition: parameters.cpp:55
std::map< std::string, double > _inactive_time
Definition: parameters.cpp:52
std::map< std::string, double > _min_height
Definition: parameters.cpp:45
std::map< std::string, double > _active_time
Definition: parameters.cpp:50
std::map< std::string, double > _pending_time
Definition: parameters.cpp:48
int size() const
std::map< std::string, double > _min_distance_between_objects
Definition: parameters.cpp:53
std::map< std::string, ros::ServiceClientPtr > _get_normal_service
Definition: parameters.cpp:56
std::map< std::string, std_msgs::ColorRGBA > _marker_color
Definition: parameters.cpp:54
std::map< std::string, bool > _with_orientation
Definition: parameters.cpp:41
std::map< std::string, double > _max_height
Definition: parameters.cpp:46
Type const & getType() const
void load(const std::string &class_id)
Definition: parameters.cpp:62
std::map< std::string, bool > _project_objects
Definition: parameters.cpp:40
std::map< std::string, double > _default_distance
Definition: parameters.cpp:42
std::map< std::string, ServiceClientsWithProperties > _percept_verification_services
Definition: parameters.cpp:57
std::map< std::string, double > _active_support
Definition: parameters.cpp:49
std::map< std::string, double > _angle_variance
Definition: parameters.cpp:44
#define ROS_WARN_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
std::map< std::string, double > _distance_variance
Definition: parameters.cpp:43
bool hasParam(const std::string &key) const
#define ROS_ERROR_STREAM(args)
std::map< std::string, ServiceClientsWithProperties > _object_verification_services
Definition: parameters.cpp:58


hector_object_tracker
Author(s): Johannes Meyer
autogenerated on Mon Jun 10 2019 13:35:13