pfuclt_aux.h
Go to the documentation of this file.
1 #ifndef PFUCLT_AUX_H
2 #define PFUCLT_AUX_H
3 
4 #include <ros/ros.h>
5 #include <vector>
6 #include <fstream>
7 #include <boost/ref.hpp>
8 #include <boost/accumulators/accumulators.hpp>
9 #include <boost/accumulators/statistics.hpp>
10 #include <boost/spirit/include/phoenix_core.hpp>
11 #include <boost/spirit/include/phoenix_operator.hpp>
12 
14 {
20 {
21  ASC,
23 };
24 
29 typedef struct landmark_s
30 {
31  int serial;
32  float x, y;
33 } Landmark;
34 
41 std::vector<Landmark> getLandmarks(const char* filename);
42 
48 template <typename T> T calc_stdDev(const std::vector<T>& vec)
49 {
50  using namespace boost::accumulators;
51 
52  accumulator_set<T, stats<tag::variance> > acc;
53  std::for_each(vec.begin(), vec.end(), boost::bind<void>(boost::ref(acc), _1));
54  return (T)sqrt(extract::variance(acc));
55 }
56 
66 template <typename T>
67 std::vector<unsigned int> order_index(std::vector<T> const& values,
68  const ORDER_TYPE order = DESC)
69 {
70  // from http://stackoverflow.com/a/10585614 and modified
71  // return sorted indices of vector values
72 
73  using namespace boost::phoenix;
74  using namespace boost::phoenix::arg_names;
75 
76  std::vector<unsigned int> indices(values.size());
77  int i = 0;
78  std::transform(values.begin(), values.end(), indices.begin(), ref(i)++);
79  if (order == DESC)
80  {
81  std::sort(indices.begin(), indices.end(),
82  ref(values)[arg1] > ref(values)[arg2]);
83  }
84  else // ASC
85  {
86  std::sort(indices.begin(), indices.end(),
87  ref(values)[arg1] < ref(values)[arg2]);
88  }
89 
90  return indices;
91 }
92 
103 template <typename T>
104 bool readParam(ros::NodeHandle& nh, const std::string name, T& variable)
105 {
106  std::ostringstream oss;
107  if (nh.getParam(name, variable))
108  {
109  oss << "Received parameter " << name << "=" << variable;
110  ROS_INFO("%s", oss.str().c_str());
111  return true;
112  }
113  else
114  ROS_ERROR("Failed to receive parameter %s", name.c_str());
115 
116  return false;
117 }
118 
119 /* @brief readParam (vectors) - reads and returns a parameter from the ROS
120  * parameter
121  * server
122  * @param nh - reference to the ROS nodehandle that will perform the parameter
123  * reading task
124  * @param name - the parameter's name
125  * @param variable - reference to the location where the parameter should be
126  * stored as type std::vector<T>
127  * @remark this function is overloaded from readParam for use with vectors
128  * @return
129  */
130 template <typename T>
131 bool readParam(ros::NodeHandle& nh, const std::string name,
132  std::vector<T>& variable)
133 {
134  std::ostringstream oss;
135  if (nh.getParam(name, variable))
136  {
137  oss << "Received parameter " << name << "=[ ";
138  for (typename std::vector<T>::iterator it = variable.begin();
139  it != variable.end(); ++it)
140  {
141  if (typeid(T) == typeid(bool))
142  oss << std::boolalpha << *it << " ";
143  else
144  oss << *it << " ";
145  }
146  oss << "]";
147 
148  ROS_INFO("%s", oss.str().c_str());
149  return true;
150  }
151  else {
152  ROS_ERROR("Failed to receive parameter %s", name.c_str());
153  return false;
154  }
155 }
156 
160 typedef struct timeEval_s
161 {
162  ros::Time rosPrev, rosNew;
163  ros::WallTime wallPrev, wallNew;
164  double diff;
165 
167  {
168  rosPrev = rosNew = ros::Time::now();
169  wallPrev = wallNew = ros::WallTime::now();
170  diff = 0.0;
171  }
172 
178  double updateTime(ros::Time t)
179  {
180  rosPrev = rosNew;
181  rosNew = t;
182 
183  diff = (rosNew-rosPrev).toNSec() * 1e-9;
184 
185  return diff;
186  }
187 
188  double updateTime(ros::WallTime t)
189  {
190  wallPrev = wallNew;
191  wallNew = t;
192 
193  diff = (wallNew-wallPrev).toNSec() * 1e-9;
194 
195  return diff;
196  }
197 
198 }TimeEval;
199 
200 // end of namespace pfuclt_omni_dataset
201 }
202 
203 #endif // PFUCLT_AUX_H
bool readParam(ros::NodeHandle &nh, const std::string name, T &variable)
readParam - reads and returns a parameter from the ROS parameter server
Definition: pfuclt_aux.h:104
double updateTime(ros::WallTime t)
Definition: pfuclt_aux.h:188
std::vector< unsigned int > order_index(std::vector< T > const &values, const ORDER_TYPE order=DESC)
order_index - Generates a vector of indexes ordered according to another vector
Definition: pfuclt_aux.h:67
T calc_stdDev(const std::vector< T > &vec)
calc_stdDev - Calculates standard deviation from a vector of type T
Definition: pfuclt_aux.h:48
ORDER_TYPE
The ORDER_TYPE enum - use to define an ascending or descending ordering.
Definition: pfuclt_aux.h:19
struct pfuclt_omni_dataset::landmark_s Landmark
The Landmark struct - used to store a landmark, defined by its serial number, and its position {x...
std::vector< Landmark > getLandmarks(const char *filename)
getLandmarks - read landmark configuration from CSV file
Definition: pfuclt_aux.cpp:7
The timeEval_s struct - takes care of time difference evaluation through the ros::Time methods...
Definition: pfuclt_aux.h:160
struct pfuclt_omni_dataset::timeEval_s TimeEval
The timeEval_s struct - takes care of time difference evaluation through the ros::Time methods...
double updateTime(ros::Time t)
updateTime - adds the newest time available to the struct and returns the time difference ...
Definition: pfuclt_aux.h:178
The Landmark struct - used to store a landmark, defined by its serial number, and its position {x...
Definition: pfuclt_aux.h:29


pfuclt_omni_dataset
Author(s):
autogenerated on Tue Jul 4 2017 19:38:38