RecursiveEstimatorNodeInterface.h
Go to the documentation of this file.
1 /*
2  * RecursiveEstimatorNodeInterface.h
3  *
4  * Author: roberto
5  *
6  * This is a modified implementation of the method for online estimation of kinematic structures described in our paper
7  * "Online Interactive Perception of Articulated Objects with Multi-Level Recursive Estimation Based on Task-Specific Priors"
8  * (Martín-Martín and Brock, 2014).
9  * This implementation can be used to reproduce the results of the paper and to be applied to new research.
10  * The implementation allows also to be extended to perceive different information/models or to use additional sources of information.
11  * A detail explanation of the method and the system can be found in our paper.
12  *
13  * If you are using this implementation in your research, please consider citing our work:
14  *
15 @inproceedings{martinmartin_ip_iros_2014,
16 Title = {Online Interactive Perception of Articulated Objects with Multi-Level Recursive Estimation Based on Task-Specific Priors},
17 Author = {Roberto {Mart\'in-Mart\'in} and Oliver Brock},
18 Booktitle = {Proceedings of the IEEE/RSJ International Conference on Intelligent Robots and Systems},
19 Pages = {2494-2501},
20 Year = {2014},
21 Location = {Chicago, Illinois, USA},
22 Note = {http://www.robotics.tu-berlin.de/fileadmin/fg170/Publikationen_pdf/martinmartin_ip_iros_2014.pdf},
23 Url = {http://www.robotics.tu-berlin.de/fileadmin/fg170/Publikationen_pdf/martinmartin_ip_iros_2014.pdf},
24 Projectname = {Interactive Perception}
25 }
26  * If you have questions or suggestions, contact us:
27  * roberto.martinmartin@tu-berlin.de
28  *
29  * Enjoy!
30  */
31 
32 #ifndef RECURSIVE_ESTIMATOR_NODE_INTERFACE_H_
33 #define RECURSIVE_ESTIMATOR_NODE_INTERFACE_H_
34 
35 #include <vector>
36 #include <boost/thread.hpp>
37 #include <ros/ros.h>
38 #include <ros/callback_queue.h>
39 #include <ros/node_handle.h>
40 #include <std_msgs/Empty.h>
41 
42 namespace omip
43 {
44 
51 template <class MeasurementTypeROS, class StateTypeROS, class RecursiveEstimatorFilterClass>
53 {
54 public:
55 
61  RecursiveEstimatorNodeInterface(int num_external_state_predictors) :
62  _re_filter(NULL),
63  _num_external_state_predictors(num_external_state_predictors),
64  _active(true)
65 
66  {
67  // We create a separate node handle with its own callback queue to process the measurement (only 1 type of measurement?)
70 
71  // We want to process the predictions about the state as soon as they arrive
72  // Therefore, we create a separate node handle with separate callback queues for each external state predictor
75  for(int num_external_state_predictors_idx = 0; num_external_state_predictors_idx < this->_num_external_state_predictors; num_external_state_predictors_idx++)
76  {
77  this->_state_prediction_queues.at(num_external_state_predictors_idx) = new ros::CallbackQueue(true);
78  this->_state_prediction_node_handles.at(num_external_state_predictors_idx).setCallbackQueue((this->_state_prediction_queues.at(num_external_state_predictors_idx)));
79  }
80 
83 
84  // All nodes subscribe to the "shutdown" signal
86  }
87 
93  {
94  if(this->_re_filter)
95  {
96  delete this->_re_filter;
97  this->_re_filter = NULL;
98  }
99  }
100 
105  virtual void run()
106  {
107  // For each predictor of states...
108  for(int idx = 0; idx < this->_num_external_state_predictors; idx++)
109  {
110  // ... we create a thread that spins on the callback queue of the predictor
111  this->_state_predictor_listener_threads.push_back(new boost::thread(boost::bind(&RecursiveEstimatorNodeInterface::spinStatePredictorQueue, this, idx)));
112  }
113  // Spin here the queue of the measurements
114  while (ros::ok() && this->_active)
115  {
116  //ros::getGlobalCallbackQueue()->callAvailable(ros::WallDuration(0.1));
118  }
119  }
120 
126  virtual void spinStatePredictorQueue(int state_prediction_queue_idx)
127  {
128  while (ros::ok() && this->_active)
129  {
130  this->_state_prediction_queues.at(state_prediction_queue_idx)->callAvailable(ros::WallDuration(0.01));
131  }
132  }
133 
139  virtual void measurementCallback(const boost::shared_ptr<MeasurementTypeROS const> & measurement) = 0;
140 
146  virtual void statePredictionCallback(const boost::shared_ptr<StateTypeROS const> & predicted_next_state) = 0;
147 
153  virtual void quitCallback(const std_msgs::EmptyConstPtr &msg)
154  {
155  ROS_INFO_STREAM("RecursiveEstimatorNode stopping!");
156  _active = false;
157  }
158 
162  template<class T>
163  bool getROSParameter(std::string param_name, T & param_container)
164  {
165  if (!(this->_measurements_node_handle.getParam(param_name, param_container)))
166  {
167  ROS_ERROR("The parameter %s can not be found.", param_name.c_str());
168  throw(std::string("The parameter can not be found. Parameter name: ") + param_name);
169  return false;
170  }
171  else
172  return true;
173  }
174 
178  template<class T>
179  bool getROSParameter(std::string param_name, T & param_container, const T & default_value)
180  {
181  if (!(this->_measurements_node_handle.getParam(param_name, param_container)))
182  {
183  ROS_WARN_STREAM("The parameter " << param_name <<" can not be found. Using the default value " << default_value );
184  param_container = default_value;
185  return false;
186  }
187  else
188  return true;
189  }
190 
191 protected:
192 
197  virtual void _publishState() const = 0;
198 
203  virtual void _publishPredictedMeasurement() const = 0;
204 
205 
206  RecursiveEstimatorFilterClass* _re_filter;
207 
208  std::string _namespace;
209 
210  // We create a separate thread to listen to a separate queue where the state predictions from higher level will arrive
211  // Right now the hierarchy that I developed uses only one prediction from higher levels, but nobody knows how it will evolve ;)
213  std::vector<ros::NodeHandle> _state_prediction_node_handles;
214  std::vector<ros::CallbackQueue*> _state_prediction_queues;
215  std::vector<boost::thread*> _state_predictor_listener_threads;
216 
217  // We have only one subscriber for state predictions (how to create several of them?)
224 
225  // I have to set the measurement queue to be the global queue so that the dynamic reconfigure works
226  // That is done in the constructor
229 
230  // These 2 times contain the time of the previous and current measurement that are processed
234 
235  bool _active;
236 };
237 }
238 
239 #endif /* RECURSIVE_ESTIMATOR_NODE_INTERFACE_H_ */
std::vector< ros::CallbackQueue * > _state_prediction_queues
virtual void quitCallback(const std_msgs::EmptyConstPtr &msg)
Callback to exit the node.
Time & fromNSec(uint64_t t)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
std::vector< boost::thread * > _state_predictor_listener_threads
This class defines an INTERFACE that all recursive estimator NODES need to implement It uses ROS TODO...
virtual void spinStatePredictorQueue(int state_prediction_queue_idx)
Spins one queue of predictors.
ROSCPP_DECL CallbackQueue * getGlobalCallbackQueue()
bool getROSParameter(std::string param_name, T &param_container)
virtual void measurementCallback(const boost::shared_ptr< MeasurementTypeROS const > &measurement)=0
Callback for the state predictions.
virtual void run()
Creates a thread per state predictor that listens to their predictions, and this thread will listen t...
bool getROSParameter(std::string param_name, T &param_container, const T &default_value)
void setCallbackQueue(CallbackQueueInterface *queue)
ROSCPP_DECL bool ok()
virtual void _publishPredictedMeasurement() const =0
Publish the prediction about the next measurement by this RE level.
virtual void statePredictionCallback(const boost::shared_ptr< StateTypeROS const > &predicted_next_state)=0
Callback for the state predictions.
#define ROS_WARN_STREAM(args)
std::vector< ros::NodeHandle > _state_prediction_node_handles
Definition: Feature.h:40
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
RecursiveEstimatorNodeInterface(int num_external_state_predictors)
Constructor.
#define ROS_ERROR(...)
virtual void _publishState() const =0
Publish the current state of this RE level.


omip_common
Author(s): Roberto Martín-Martín
autogenerated on Mon Jun 10 2019 14:06:05