MultiRBTrackerNode.cpp
Go to the documentation of this file.
1 #include <vector>
2 #include <stdio.h>
3 #include "geometry_msgs/PoseArray.h"
4 #include <geometry_msgs/PoseWithCovarianceStamped.h>
6 #include <rosbag/query.h>
7 #include <rosbag/view.h>
8 #include <sensor_msgs/Range.h>
9 
11 #include "rb_tracker/RBFilter.h"
12 
13 #include "omip_common/OMIPUtils.h"
14 
16 
17 #if ROS_VERSION_MINIMUM(1, 11, 1) // if current ros version is >= 1.11.1 (indigo)
18 #else
20 #endif
21 
22 #define LINES_OF_TERMINAL_RBT 20
23 
24 using namespace omip;
25 
26 #define MAX_DELAY_BETWEEN_FT_AND_ST 0.02
27 
30  _loop_period_ns(0.),
31  _ransac_iterations(-1),
32  _estimation_error_threshold(-1.),
33  _static_motion_threshold(-1.),
34  _new_rbm_error_threshold(-1.),
35  _max_error_to_reassign_feats(-1.),
36  _sensor_fps(0.0),
37  _processing_factor(0),
38  _supporting_features_threshold(-1),
39  _min_num_feats_for_new_rb(-1),
40  _min_num_frames_for_new_rb(-1),
41  _publishing_rbposes_with_cov(false),
42  _publishing_clustered_pc(true),
43  _publishing_tf(true),
44  _printing_rb_poses(true),
45  _shape_tracker_received(false)
46 {
47  this->_namespace = std::string("rb_tracker");
48 
49  this->ReadParameters();
50 
52 
53  // Setup the callback for the dynamic reconfigure
54  this->_dr_callback = boost::bind(&MultiRBTrackerNode::DynamicReconfigureCallback, this, _1, _2);
55  this->_dr_srv.setCallback(this->_dr_callback);
56 
57  // Setup the subscriber for the measurements from the lower RE level
59  // Setup the subscriber for state predictions from the higher RE level
60  this->_state_prediction_subscriber = this->_state_prediction_node_handles[0].subscribe(this->_namespace + "/predicted_measurement", 10,
62 
63  this->_meas_from_st_subscriber = this->_state_prediction_node_handles[0].subscribe("/shape_tracker/state", 10,
65 
66  // Setup the publisher for the predicted measurements. They are used as state predictions by the lower RE level
67  this->_measurement_prediction_publisher = this->_measurements_node_handle.advertise<ft_state_ros_t>("/feature_tracker/predicted_measurement", 1);
68  this->_state_publisher = this->_measurements_node_handle.advertise<omip_msgs::RigidBodyPosesAndVelsMsg>(this->_namespace + "/state", 1);
69 
70 
71  this->_state_publisher2 = this->_measurements_node_handle.advertise<omip_msgs::RigidBodyPosesAndVelsMsg>(this->_namespace + "/state_after_feat_correction", 1);
72 
73  // Additional published topics
74  this->_clustered_pc_publisher = this->_measurements_node_handle.advertise<sensor_msgs::PointCloud2>(this->_namespace + "/clustered_tracked_feats", 100);
75  this->_freefeats_pc_publisher = this->_measurements_node_handle.advertise<sensor_msgs::PointCloud2>(this->_namespace + "/free_feats", 100);
76 
77  this->_predictedfeats_pc_publisher = this->_measurements_node_handle.advertise<sensor_msgs::PointCloud2>(this->_namespace + "/predicted_feats", 100);
78  this->_atbirthfeats_pc_publisher = this->_measurements_node_handle.advertise<sensor_msgs::PointCloud2>(this->_namespace + "/atbirth_feats", 100);
79 
80 
81  // Initial constraint in the motion of the camera (initially constrained to no motion)
82  int max_num_rb = -1;
83  this->getROSParameter<int>(this->_namespace + std::string("/max_num_rb"), max_num_rb, max_num_rb);
84 
85  // Initial constraint in the motion of the camera (initially constrained to no motion)
86  int initial_cam_motion_constraint = 6;
87  this->getROSParameter<int>(this->_namespace + std::string("/cam_motion_constraint"), initial_cam_motion_constraint, initial_cam_motion_constraint);
88 
89  // Type of filter for the static environment (EKF based or ICP based)
90  int static_environment_tracker_type_int;
91  this->getROSParameter<int>(this->_namespace + std::string("/static_environment_type"), static_environment_tracker_type_int);
92  this->_static_environment_tracker_type = (static_environment_tracker_t)static_environment_tracker_type_int;
93 
94  double meas_depth_factor;
95  this->getROSParameter<double>(this->_namespace + std::string("/cov_meas_depth_factor"), meas_depth_factor);
96  double min_cov_meas_x;
97  this->getROSParameter<double>(this->_namespace + std::string("/min_cov_meas_x"), min_cov_meas_x);
98  double min_cov_meas_y;
99  this->getROSParameter<double>(this->_namespace + std::string("/min_cov_meas_y"), min_cov_meas_y);
100  double min_cov_meas_z;
101  this->getROSParameter<double>(this->_namespace + std::string("/min_cov_meas_z"), min_cov_meas_z);
102  double prior_cov_pose;
103  this->getROSParameter<double>(this->_namespace + std::string("/prior_cov_pose"), prior_cov_pose);
104  double prior_cov_vel;
105  this->getROSParameter<double>(this->_namespace + std::string("/prior_cov_vel"), prior_cov_vel);
106  double cov_sys_acc_tx;
107  this->getROSParameter<double>(this->_namespace + std::string("/cov_sys_acc_tx"), cov_sys_acc_tx);
108  double cov_sys_acc_ty;
109  this->getROSParameter<double>(this->_namespace + std::string("/cov_sys_acc_ty"), cov_sys_acc_ty);
110  double cov_sys_acc_tz;
111  this->getROSParameter<double>(this->_namespace + std::string("/cov_sys_acc_tz"), cov_sys_acc_tz);
112  double cov_sys_acc_rx;
113  this->getROSParameter<double>(this->_namespace + std::string("/cov_sys_acc_rx"), cov_sys_acc_rx);
114  double cov_sys_acc_ry;
115  this->getROSParameter<double>(this->_namespace + std::string("/cov_sys_acc_ry"), cov_sys_acc_ry);
116  double cov_sys_acc_rz;
117  this->getROSParameter<double>(this->_namespace + std::string("/cov_sys_acc_rz"), cov_sys_acc_rz);
118 
119  int min_num_points_in_segment;
120  this->getROSParameter<int>(this->_namespace + std::string("/min_num_points_in_segment"), min_num_points_in_segment);
121  double min_probabilistic_value;
122  this->getROSParameter<double>(this->_namespace + std::string("/min_probabilistic_value"), min_probabilistic_value);
123  double max_fitness_score;
124  this->getROSParameter<double>(this->_namespace + std::string("/max_fitness_score"), max_fitness_score);
125 
126  double min_amount_translation_for_new_rb;
127  this->getROSParameter<double>(this->_namespace + std::string("/min_amount_translation_for_new_rb"), min_amount_translation_for_new_rb);
128  double min_amount_rotation_for_new_rb;
129  this->getROSParameter<double>(this->_namespace + std::string("/min_amount_rotation_for_new_rb"), min_amount_rotation_for_new_rb);
130 
131  int min_num_supporting_feats_to_correct;
132  this->getROSParameter<int>(this->_namespace + std::string("/min_num_supporting_feats_to_correct"), min_num_supporting_feats_to_correct);
133 
134  ROS_INFO_STREAM_NAMED( "MultiRBTrackerNode.ReadParameters",
135  "MultiRBTrackerNode Parameters: " <<
136  "\n\tmax_num_rb: " << max_num_rb <<
137  "\n\tmeas_depth_factor: " << meas_depth_factor <<
138  "\n\tmin_cov_meas_x: " << min_cov_meas_x <<
139  "\n\tmin_cov_meas_y: " << min_cov_meas_y <<
140  "\n\tmin_cov_meas_z: " << min_cov_meas_z <<
141  "\n\tprior_cov_pose: " << prior_cov_pose <<
142  "\n\tprior_cov_vel: " << prior_cov_vel <<
143  "\n\tcov_sys_acc_tx: " << cov_sys_acc_tx <<
144  "\n\tcov_sys_acc_ty: " << cov_sys_acc_ty <<
145  "\n\tcov_sys_acc_tz: " << cov_sys_acc_tz <<
146  "\n\tcov_sys_acc_rx: " << cov_sys_acc_rx <<
147  "\n\tcov_sys_acc_ry: " << cov_sys_acc_ry <<
148  "\n\tcov_sys_acc_rz: " << cov_sys_acc_rz <<
149  "\n\tmin_num_points_in_segment: " << min_num_points_in_segment <<
150  "\n\tmin_probabilistic_value: " << min_probabilistic_value <<
151  "\n\tmax_fitness_score: " << max_fitness_score <<
152  "\n\tmin_amount_translation_for_new_rb: " << min_amount_translation_for_new_rb <<
153  "\n\tmin_amount_rotation_for_new_rb: " << min_amount_rotation_for_new_rb <<
154  "\n\tmin_num_supporting_feats_to_correct: " << min_num_supporting_feats_to_correct <<
155  "\n\tcam_motion_constraint: " << initial_cam_motion_constraint);
156 
157  // Create the RE filter
158  this->_re_filter = new MultiRBTracker(max_num_rb, this->_loop_period_ns,
159  this->_ransac_iterations,
167  initial_cam_motion_constraint,
168  this->_static_environment_tracker_type
169  );
170 
171  this->_re_filter->setMeasurementDepthFactor(meas_depth_factor);
172  this->_re_filter->setMinCovarianceMeasurementX(min_cov_meas_x);
173  this->_re_filter->setMinCovarianceMeasurementY(min_cov_meas_y);
174  this->_re_filter->setMinCovarianceMeasurementZ(min_cov_meas_z);
175  this->_re_filter->setPriorCovariancePose(prior_cov_pose);
176  this->_re_filter->setPriorCovarianceVelocity(prior_cov_vel);
177  this->_re_filter->setCovarianceSystemAccelerationTx(cov_sys_acc_tx);
178  this->_re_filter->setCovarianceSystemAccelerationTy(cov_sys_acc_ty);
179  this->_re_filter->setCovarianceSystemAccelerationTz(cov_sys_acc_tz);
180  this->_re_filter->setCovarianceSystemAccelerationRx(cov_sys_acc_rx);
181  this->_re_filter->setCovarianceSystemAccelerationRy(cov_sys_acc_ry);
182  this->_re_filter->setCovarianceSystemAccelerationRz(cov_sys_acc_rz);
183  this->_re_filter->setNumberOfTrackedFeatures(this->_num_tracked_feats);
184  this->_re_filter->setMinNumPointsInSegment(min_num_points_in_segment);
185  this->_re_filter->setMinProbabilisticValue(min_probabilistic_value);
186  this->_re_filter->setMaxFitnessScore(max_fitness_score);
187  this->_re_filter->setMinAmountTranslationForNewRB(min_amount_translation_for_new_rb);
188  this->_re_filter->setMinAmountRotationForNewRB(min_amount_rotation_for_new_rb);
189  this->_re_filter->setMinNumberOfSupportingFeaturesToCorrectPredictedState(min_num_supporting_feats_to_correct);
190 
191  this->_re_filter->Init();
192 }
193 
195 {
196 }
197 
198 void MultiRBTrackerNode::DynamicReconfigureCallback(rb_tracker::RBTrackerDynReconfConfig &config, uint32_t level)
199 {
200  // Set class variables to new values. They should match what is input at the dynamic reconfigure GUI.
201  this->_publishing_rbposes_with_cov = config.pub_rb_poses_with_cov;
202  this->_publishing_clustered_pc = config.pub_clustered_pc;
203  this->_publishing_tf = config.pub_tf;
204  this->_printing_rb_poses = config.print_rb_poses;
205  if(this->_re_filter)
206  {
207  this->_re_filter->setDynamicReconfigureValues(config);
208  }
209 }
210 
212 {
213  this->getROSParameter<int>(this->_namespace + std::string("/ransac_iterations"), this->_ransac_iterations);
214  this->getROSParameter<double>(this->_namespace + std::string("/estimation_error_threshold"), this->_estimation_error_threshold);
215  this->getROSParameter<double>(this->_namespace + std::string("/static_motion_threshold"), this->_static_motion_threshold);
216  this->getROSParameter<double>(this->_namespace + std::string("/new_rbm_error_threshold"), this->_new_rbm_error_threshold);
217  this->getROSParameter<double>(this->_namespace + std::string("/max_error_to_reassign_feats"), this->_max_error_to_reassign_feats);
218  this->getROSParameter<int>(this->_namespace + std::string("/supporting_features_threshold"), this->_supporting_features_threshold);
219  this->getROSParameter<int>(this->_namespace + std::string("/min_num_feats_for_new_rb"), this->_min_num_feats_for_new_rb);
220  this->getROSParameter<int>(this->_namespace + std::string("/min_num_frames_for_new_rb"), this->_min_num_frames_for_new_rb);
221 
222  this->getROSParameter<bool>(this->_namespace + std::string("/pub_rb_poses_with_cov"), this->_publishing_rbposes_with_cov, false);
223  this->getROSParameter<bool>(this->_namespace + std::string("/pub_clustered_pc"), this->_publishing_clustered_pc, true);
224  this->getROSParameter<bool>(this->_namespace + std::string("/pub_tf"), this->_publishing_tf, true);
225  this->getROSParameter<bool>(this->_namespace + std::string("/print_rb_poses"), this->_printing_rb_poses, true);
226 
227  this->getROSParameter<double>(std::string("/omip/sensor_fps"), this->_sensor_fps);
228  this->getROSParameter<int>(std::string("/omip/processing_factor"), this->_processing_factor);
229  this->_loop_period_ns = 1e9/(this->_sensor_fps/(double)this->_processing_factor);
230 
231  this->getROSParameter<int>(std::string("/feature_tracker/number_features"), this->_num_tracked_feats);
232 
233 
234  ROS_INFO_STREAM_NAMED( "MultiRBTrackerNode.ReadParameters",
235  "MultiRBTrackerNode Parameters: " << std::endl //
236  << "\tRANSAC iterations: " << this->_ransac_iterations << std::endl //
237  << "\tEstimation error threshold: " << this->_estimation_error_threshold<< std::endl //
238  << "\tStatic motion threshold: " << this->_static_motion_threshold << std::endl //
239  << "\tNew RB motion threshold: " << this->_new_rbm_error_threshold<< std::endl //
240  << "\tMax error to reassign features: " << this->_max_error_to_reassign_feats<< std::endl //
241  << "\tNumber of tracked features: " << this->_num_tracked_feats<< std::endl //
242  << "\tSupporting features threshold: " << this->_supporting_features_threshold<< std::endl //
243  << "\tMin num of feats for motion estimation: " << this->_min_num_feats_for_new_rb << std::endl //
244  << "\tMin age for creation: " << this->_min_num_frames_for_new_rb << std::endl //
245  << "\tMax framerate (factor): " << this->_sensor_fps << "(" << this->_processing_factor << ")" );
246 }
247 
249 {
250  this->_shape_tracker_meas = omip_msgs::ShapeTrackerStates(*shape_tracker_states);
251  this->_re_filter->processMeasurementFromShapeTracker(this->_shape_tracker_meas);
252 
253 
254 // ROS_WARN_STREAM( "Current time minus refinement time: " << (this->_current_measurement_time - shape_tracker_states->header.stamp).toSec() );
255 // //Check if the result includes a valid refinement and updates
256 // if((this->_current_measurement_time - shape_tracker_states->header.stamp).toSec() < MAX_DELAY_BETWEEN_FT_AND_ST)
257 // {
258 // ROS_WARN_STREAM("Received measurement from shape tracker");
259 // this->_shape_tracker_meas = omip_msgs::ShapeTrackerStates(*shape_tracker_states);
260 // this->_shape_tracker_received = true;
261 // }else{
262 // ROS_ERROR_STREAM("Received measurement from shape tracker but too late. Time of the refinement: "
263 // << shape_tracker_states->header.stamp << " Current time: " << this->_current_measurement_time);
264 // }
265 }
266 
268 {
269  ros::Time tinit = ros::Time::now();
270 
271  // Get the time of the measurement as reference time
272  this->_current_measurement_time = features_pc->header.stamp;
273 
274  // Convert point cloud of features to PCL pc
275  rbt_measurement_t features_pc_pcl = rbt_measurement_t(new FeatureCloudPCLwc());
276  pcl::fromROSMsg(*features_pc, *features_pc_pcl);
277 
278  this->_re_filter->setMeasurement(features_pc_pcl, (double)this->_current_measurement_time.toNSec());
279 
280  // Measure the time interval between the previous measurement and the current measurement
281  ros::Duration time_between_meas = this->_current_measurement_time - this->_previous_measurement_time;
282 
283  // The time interval between frames is the inverse of the max_framerate
284  double period_between_frames = 1.0/this->_sensor_fps;
285 
286  // The number of frames elapsed is the time elapsed divided by the period between frames
287  int frames_between_meas = round((time_between_meas.toSec())/period_between_frames);
288 
289  // Processing fps: ignore (this->_processing_factor - 1) frames and process one. This gives effectively the desired processing fps: _sensor_fps/_processing_factor
290  if( this->_previous_measurement_time.toSec() == 0.)
291  {
292  ROS_ERROR("First iteration. We predict after correct");
293  }else{
294  if( frames_between_meas != this->_processing_factor)
295  {
296  ROS_ERROR("Lost frames:%3d. Need to predict state and measurement again.", frames_between_meas - this->_processing_factor);
297 
298  // Predict next RE state
299  this->_re_filter->predictState((double)time_between_meas.toNSec());
300 
301  // If the received prediction from the higher level is for this time step we use it
302  if(abs((_last_predictions_kh.header.stamp - this->_current_measurement_time).toNSec()) < _loop_period_ns/2 )
303  {
304  ROS_ERROR_STREAM_NAMED("MultiRBTrackerNode.measurementCallback", "The prediction from higher level can be used to predict next measurement before correction");
305  this->_re_filter->addPredictedState(_last_predictions_kh, (double)_last_predictions_kh.header.stamp.toNSec());
306  }else{
307  ROS_ERROR_STREAM_NAMED("MultiRBTrackerNode.measurementCallback",
308  "The prediction from higher level can NOT be used to predict next measurement before correction. Delay: "
309  << (double)(this->_current_measurement_time - _last_predictions_kh.header.stamp).toNSec()/1e9);
310  }
311 
312  // Predict next measurement based on the predicted state
313  this->_re_filter->predictMeasurement();
314  }else{
315  ROS_INFO("Frames between measurements:%3d.", frames_between_meas);
316  }
317  }
318 
319  // In the first iteration we cannot correct the state because we have only one measurement
320  if(this->_previous_measurement_time.toSec() != 0.)
321  {
322  // Use the predicted measurement and the received measurement to correct the state
323  this->_re_filter->correctState();
324  }
325 
326  this->_re_filter->ReflectState();
327 
328  // Publish the obtained new state
329  this->_publishState();
330 
331  // Publish additional stuff
332  this->_PrintResults();
333  this->_PublishTF();
336 
337  ros::Duration loop_duration(0.02);
338  loop_duration.sleep();
339 
340  // Predict next RE state
341  this->_re_filter->predictState(this->_loop_period_ns);
342 
343  // If the received prediction from the higher level is for the next time step we use it
344  if(abs((_last_predictions_kh.header.stamp - (this->_current_measurement_time + ros::Duration(_loop_period_ns/1e9))).toNSec()) < _loop_period_ns/2 )
345  {
346  ROS_ERROR_STREAM_NAMED("MultiRBTrackerNode.measurementCallback", "The prediction from higher level can be used to predict next measurement after correction");
347  this->_re_filter->addPredictedState(_last_predictions_kh, (double)_last_predictions_kh.header.stamp.toNSec());
348  }else{
349  ROS_ERROR_STREAM_NAMED("MultiRBTrackerNode.measurementCallback",
350  "The prediction from higher level can NOT be used to predict next measurment after correction. Delay: "
351  << (double)((this->_current_measurement_time + ros::Duration(_loop_period_ns/1e9)) - _last_predictions_kh.header.stamp).toNSec()/1e9);
352  }
353 
354  // Predict next measurement based on the predicted state
355  this->_re_filter->predictMeasurement();
356 
358 
359  this->_previous_measurement_time = this->_current_measurement_time;
360 
361  ros::Time tend = ros::Time::now();
362  ROS_WARN_STREAM("Time between meas vision: " << time_between_meas.toSec()*1000 << " ms");
363  ROS_WARN_STREAM("Total meas processing time vision: " << (tend-tinit).toSec()*1000 << " ms");
364 }
365 
367 {
368  this->_last_predictions_kh = rbt_state_t(*predicted_rb_poses);
369 }
370 
372 {
373  rbt_state_t poses_and_vels_msg = this->_re_filter->getState();
374  poses_and_vels_msg.header.stamp = this->_current_measurement_time;
375 
376  poses_and_vels_msg.header.frame_id = "camera_rgb_optical_frame";
377  this->_state_publisher2.publish(poses_and_vels_msg);
378 
379  rbt_state_t poses_and_vels_msg_corrected = this->_re_filter->getState();
380  poses_and_vels_msg_corrected.header.stamp = this->_current_measurement_time;
381 
382  poses_and_vels_msg_corrected.header.frame_id = "camera_rgb_optical_frame";
383 
384  this->_state_publisher.publish(poses_and_vels_msg_corrected);
385 
386  this->_shape_tracker_received = false;
387 }
388 
390 {
391  FeatureCloudPCLwc::Ptr predicted_locations = this->_re_filter->getPredictedMeasurement();
392  predicted_locations->header.frame_id = "camera_rgb_optical_frame";
393 
394  sensor_msgs::PointCloud2 predicted_locations_ros;
395  pcl::toROSMsg(*predicted_locations, predicted_locations_ros);
396 
397  this->_measurement_prediction_publisher.publish(predicted_locations_ros);
398 }
399 
401 {
402  if(this->_printing_rb_poses)
403  {
404  // Get the poses (twists) of each RB
405  std::vector<Eigen::Matrix4d> tracked_bodies_motion = this->_re_filter->getPoses();
406 
407  Eigen::Twistd pose_in_ec;
408 
409  RB_id_t RB_id;
410  int num_supporting_feats = 0;
411  for (size_t poses_idx = 0; poses_idx < tracked_bodies_motion.size(); poses_idx++)
412  {
413  RB_id = this->_re_filter->getRBId(poses_idx);
414  num_supporting_feats = this->_re_filter->getNumberSupportingFeatures(poses_idx);
415 
416  TransformMatrix2Twist(tracked_bodies_motion[poses_idx], pose_in_ec);
417  ROS_INFO_NAMED( "MultiRBTrackerNode::_PublishRBPoses", "RB%2d: Supporting feats: %d, Pose (vx,vy,vz,rx,ry,rz): % 2.2f,% 2.2f,% 2.2f,% 2.2f,% 2.2f,% 2.2f",
418  (int)RB_id,
419  num_supporting_feats,
420  pose_in_ec.vx(),
421  pose_in_ec.vy(),
422  pose_in_ec.vz(),
423  pose_in_ec.rx(),
424  pose_in_ec.ry(),
425  pose_in_ec.rz());
426  }
427  }
428 }
429 
431 {
433  {
434  // Get the poses and covariances on the poses (pose with cov) of each RB
435  std::vector<geometry_msgs::PoseWithCovariancePtr> tracked_poses_with_cov = this->_re_filter->getPosesWithCovariance();
436 
437  RB_id_t RB_id;
438  for (size_t poses_idx = 0; poses_idx < tracked_poses_with_cov.size(); poses_idx++)
439  {
440  RB_id = this->_re_filter->getRBId(poses_idx);
441  std::ostringstream oss;
442  oss << "ip/rb" << RB_id;
443 
444  // Publish the pose with covariance of each RB with a different publisher and on a different topic name
445  if (this->_est_body_publishers.find(RB_id) == this->_est_body_publishers.end())
446  {
447  ros::Publisher* new_estimated_pose_publisher = new ros::Publisher(
448  this->_measurements_node_handle.advertise<geometry_msgs::PoseWithCovarianceStamped>(oss.str(), 100));
449  this->_est_body_publishers[RB_id] = new_estimated_pose_publisher;
450  }
451  geometry_msgs::PoseWithCovarianceStamped pose_with_cov_stamped;
452  pose_with_cov_stamped.header.stamp = this->_current_measurement_time;
453  pose_with_cov_stamped.header.frame_id = "camera_rgb_optical_frame";
454  pose_with_cov_stamped.pose = *(tracked_poses_with_cov[poses_idx]);
455  this->_est_body_publishers[this->_re_filter->getRBId(poses_idx)]->publish(pose_with_cov_stamped);
456  }
457  }
458 }
459 
461 {
462  static tf::TransformBroadcaster tf_br;
463 
464  if(this->_publishing_tf)
465  {
466  // Get the poses and covariances on the poses (pose with cov) of each RB
467  std::vector<geometry_msgs::PoseWithCovariancePtr> tracked_poses_with_cov = this->_re_filter->getPosesWithCovariance();
468  RB_id_t RB_id;
469  for (size_t poses_idx = 0; poses_idx < tracked_poses_with_cov.size(); poses_idx++)
470  {
471  RB_id = this->_re_filter->getRBId(poses_idx);
472  std::ostringstream oss;
473  oss << "ip/rb" << RB_id;
474 
475  // Publish the pose of the RBs on the TF tree
476  tf::Transform transform_auxiliar;
477  transform_auxiliar.setOrigin(tf::Vector3(tracked_poses_with_cov[poses_idx]->pose.position.x, tracked_poses_with_cov[poses_idx]->pose.position.y,
478  tracked_poses_with_cov[poses_idx]->pose.position.z));
479  transform_auxiliar.setRotation(tf::Quaternion(tracked_poses_with_cov.at(poses_idx)->pose.orientation.x,tracked_poses_with_cov.at(poses_idx)->pose.orientation.y,
480  tracked_poses_with_cov.at(poses_idx)->pose.orientation.z, tracked_poses_with_cov.at(poses_idx)->pose.orientation.w));
481 
482  tf_br.sendTransform(tf::StampedTransform(transform_auxiliar, this->_current_measurement_time, "camera_rgb_optical_frame",
483  RB_id == 0 ? "static_environment" : oss.str().c_str()));
484  }
485  }
486 }
487 
489 {
490  if(this->_publishing_clustered_pc)
491  {
492  FeatureCloudPCL clustered_pc = this->_re_filter->getLabelledSupportingFeatures();
493  clustered_pc.header.frame_id = "camera_rgb_optical_frame";
494  clustered_pc.header.stamp = pcl_conversions::toPCL(this->_current_measurement_time);
495 
496  sensor_msgs::PointCloud2 feature_set_ros;
497  pcl::toROSMsg(clustered_pc, feature_set_ros);
498  feature_set_ros.header.stamp = this->_current_measurement_time;
499  this->_clustered_pc_publisher.publish(feature_set_ros);
500 
501  FeatureCloudPCL freefeats_pc = this->_re_filter->getFreeFeatures();
502  freefeats_pc.header.frame_id = "camera_rgb_optical_frame";
503  freefeats_pc.header.stamp = pcl_conversions::toPCL(this->_current_measurement_time);
504 
505  sensor_msgs::PointCloud2 freefeats_pc_ros;
506  pcl::toROSMsg(freefeats_pc, freefeats_pc_ros);
507  this->_freefeats_pc_publisher.publish(freefeats_pc_ros);
508 
509  FeatureCloudPCL predictedfeats_pc = this->_re_filter->getPredictedFeatures();
510  predictedfeats_pc.header.frame_id = "camera_rgb_optical_frame";
511  predictedfeats_pc.header.stamp = pcl_conversions::toPCL(this->_current_measurement_time);
512 
513  sensor_msgs::PointCloud2 predictedfeats_pc_ros;
514  pcl::toROSMsg(predictedfeats_pc, predictedfeats_pc_ros);
515  this->_predictedfeats_pc_publisher.publish(predictedfeats_pc_ros);
516 
517  FeatureCloudPCL atbirthfeats_pc = this->_re_filter->getAtBirthFeatures();
518  atbirthfeats_pc.header.frame_id = "camera_rgb_optical_frame";
519  atbirthfeats_pc.header.stamp = pcl_conversions::toPCL(this->_current_measurement_time);
520 
521  sensor_msgs::PointCloud2 atbirthfeats_pc_ros;
522  pcl::toROSMsg(atbirthfeats_pc, atbirthfeats_pc_ros);
523  this->_atbirthfeats_pc_publisher.publish(atbirthfeats_pc_ros);
524  }
525 }
526 
527 int main(int argc, char** argv)
528 {
529  ros::init(argc, argv, "rb_tracker");
530  MultiRBTrackerNode rbtvn;
531  rbtvn.run();
532 
533  return (0);
534 }
virtual void _PublishPosesWithCovariance()
TFSIMD_FORCE_INLINE void setRotation(const Quaternion &q)
#define ROS_INFO_NAMED(name,...)
void publish(const boost::shared_ptr< M > &message) const
#define ROS_ERROR_STREAM_NAMED(name, args)
ros::Publisher _clustered_pc_publisher
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
virtual void _PublishClusteredFeatures()
Publish the tracked features clustered in RBs (the cluster id is written in the "label" field of the ...
void MeasurementFromShapeTrackerCallback(const boost::shared_ptr< omip_msgs::ShapeTrackerStates const > &shape_tracker_states)
ros::Publisher _atbirthfeats_pc_publisher
ros::Publisher _predictedfeats_pc_publisher
bool sleep() const
ros::Subscriber _meas_from_st_subscriber
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void TransformMatrix2Twist(const Eigen::Matrix4d &transformation_matrix, Eigen::Twistd &twist)
virtual void _publishState() const
Publish the current state of this RE level.
void fromROSMsg(const sensor_msgs::PointCloud2 &cloud, pcl::PointCloud< T > &pcl_cloud)
omip_msgs::RigidBodyPosesAndVelsMsg rbt_state_t
#define ROS_INFO_STREAM_NAMED(name, args)
std::map< RB_id_t, ros::Publisher * > _est_body_publishers
long int RB_id_t
Time & fromSec(double t)
sensor_msgs::PointCloud2 ft_state_ros_t
virtual void _PrintResults() const
Print the results of the RB tracker on the terminal.
dynamic_reconfigure::Server< rb_tracker::RBTrackerDynReconfConfig > _dr_srv
int main(int argc, char **argv)
dynamic_reconfigure::Server< rb_tracker::RBTrackerDynReconfConfig >::CallbackType _dr_callback
static_environment_tracker_t _static_environment_tracker_type
#define ROS_INFO(...)
int64_t toNSec() const
virtual void measurementCallback(const boost::shared_ptr< rbt_measurement_ros_t const > &features_pc)
Callback for the measurements for this RE level (3D features from the lower level, FT)
ros::Publisher _freefeats_pc_publisher
void sendTransform(const StampedTransform &transform)
uint64_t toNSec() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
#define ROS_WARN_STREAM(args)
pcl::PointCloud< FeaturePCL > FeatureCloudPCL
virtual void statePredictionCallback(const boost::shared_ptr< rbt_state_t const > &predicted_next_state)
Callback for the predictions about the state of this RE level coming from the higher level of the hie...
omip_msgs::ShapeTrackerStates _shape_tracker_meas
void toROSMsg(const sensor_msgs::PointCloud2 &cloud, sensor_msgs::Image &image)
static Time now()
pcl::PointCloud< FeaturePCLwc > FeatureCloudPCLwc
static_environment_tracker_t
FeatureCloudPCLwc::Ptr rbt_measurement_t
#define ROS_ERROR(...)
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
void toPCL(const ros::Time &stamp, pcl::uint64_t &pcl_stamp)
virtual void _publishPredictedMeasurement() const
Publish the prediction about the next measurement by this RE level.
void DynamicReconfigureCallback(rb_tracker::RBTrackerDynReconfConfig &config, uint32_t level)
Callback for the Dynamic Reconfigure parameters.


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