JointFilter.h
Go to the documentation of this file.
1 /*
2  * JointFilter.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 JOINTFILTER_H_
33 #define JOINTFILTER_H_
34 
35 #include <pcl/point_types.h>
36 #include <unsupported/Eigen/MatrixFunctions>
37 #include <Eigen/Geometry>
38 #include <lgsm/Lgsm>
39 #include <boost/shared_ptr.hpp>
40 #include <boost/unordered_map.hpp>
41 
42 #include <ros/ros.h>
43 #include <geometry_msgs/Pose.h>
44 #include <geometry_msgs/Twist.h>
45 #include <geometry_msgs/PoseWithCovariance.h>
46 #include <tf/tf.h>
47 #include <tf/transform_datatypes.h>
50 
51 #include <visualization_msgs/MarkerArray.h>
52 
53 #include <wrappers/matrix/matrix_wrapper.h>
54 
55 #include "omip_msgs/RigidBodyTwistWithCovMsg.h"
57 
58 #include "geometry_msgs/PoseWithCovarianceStamped.h"
59 
60 #define JOINT_AXIS_MARKER_RADIUS 0.01
61 #define JOINT_AXIS_AND_VARIABLE_MARKER_RADIUS 0.02
62 #define JOINT_VALUE_TEXT_SIZE 0.1
63 
64 //#define PUBLISH_PREDICTED_POSE_AS_PWC 1
65 
66 namespace omip
67 {
68 
69 typedef int long JointCombinedFilterId;
70 
72 {
77 };
78 
81 
83 {
84 public:
85 
89  JointFilter();
90 
94  virtual ~JointFilter();
95 
102  JointFilterPtr clone() const
103  {
104  return (JointFilterPtr(doClone()));
105  }
106 
110  JointFilter(const JointFilter &joint);
111 
112  virtual void initialize();
113 
118  virtual void predictState(double time_interval_ns){}
119 
127  virtual void predictMeasurement(){}
128 
134  virtual void correctState(){}
135 
141  virtual void setMeasurement(joint_measurement_t acquired_measurement, const double& measurement_timestamp_ns);
142 
143  virtual void setInitialMeasurement(const joint_measurement_t &initial_measurement,
144  const Eigen::Twistd& rrb_pose_at_srb_birth_in_sf,
145  const Eigen::Twistd& srb_pose_at_srb_birth_in_sf);
146 
152  virtual Eigen::Twistd getPredictedMeasurement() const;
153 
160 
162 
167  virtual geometry_msgs::TwistWithCovariance getPredictedSRBPoseWithCovInSensorFrame() = 0;
168 
175  virtual geometry_msgs::TwistWithCovariance getPredictedSRBDeltaPoseWithCovInSensorFrame() =0;
176 
183  virtual geometry_msgs::TwistWithCovariance getPredictedSRBVelocityWithCovInSensorFrame() =0;
184 
190  virtual void setNormalizingTerm(double normalizing_term);
191 
198  virtual void setModelPriorProbability(double model_prior_probability);
199 
206  virtual double getModelPriorProbability() const;
207 
213  virtual double getLikelihoodOfLastMeasurements() const;
214 
220  virtual void setLikelihoodOfLastMeasurements(double likelihood);
221 
227  virtual double getUnnormalizedProbabilityOfJointFilter() const;
228 
235  virtual double getProbabilityOfJointFilter() const;
236 
242  virtual JointFilterType getJointFilterType() const = 0;
243 
249  virtual std::string getJointFilterTypeStr() const = 0;
250 
254  virtual std::vector<visualization_msgs::Marker> getJointMarkersInRRBFrame() const = 0;
255 
256  virtual Eigen::Vector3d getJointPositionInRRBFrame() const;
257 
258  virtual Eigen::Vector3d getJointOrientationRPYInRRBFrame() const;
259 
260  virtual Eigen::Vector3d getJointOrientationUnitaryVector() const;
261 
267  virtual JointCombinedFilterId getJointId() const;
268 
269  virtual void setJointId(JointCombinedFilterId joint_id);
270 
271  virtual double getOrientationPhiInRRBFrame() const;
272 
273  virtual double getOrientationThetaInRRBFrame() const;
274 
275  virtual double getCovarianceOrientationPhiPhiInRRBFrame() const;
276 
277  virtual double getCovarianceOrientationThetaThetaInRRBFrame() const;
278 
279  virtual double getCovarianceOrientationPhiThetaInRRBFrame() const;
280 
281  virtual void setLoopPeriodNS(double loop_period_ns);
282 
283  virtual double getLoopPeriodNS() const;
284 
285  virtual int getNumSamplesForLikelihoodEstimation() const;
286 
287  virtual void setNumSamplesForLikelihoodEstimation(int likelihood_sample_num);
288 
289  virtual double getNormalizingTerm();
290 
291  virtual void setCovariancePrior(double prior_cov_vel);
292 
293  virtual void setCovarianceAdditiveSystemNoisePhi(double sigma_sys_noise_phi);
294 
295  virtual void setCovarianceAdditiveSystemNoiseTheta(double sigma_sys_noise_theta);
296 
297  virtual void setCovarianceAdditiveSystemNoisePx(double sigma_sys_noise_px);
298 
299  virtual void setCovarianceAdditiveSystemNoisePy(double sigma_sys_noise_py);
300 
301  virtual void setCovarianceAdditiveSystemNoisePz(double sigma_sys_noise_pz);
302 
303  virtual void setCovarianceAdditiveSystemNoiseJointState(double sigma_sys_noise_pv);
304 
305  virtual void setCovarianceAdditiveSystemNoiseJointVelocity(double sigma_sys_noise_pvd);
306 
307  virtual void setCovarianceMeasurementNoise(double sigma_meas_noise);
308 
314  virtual double getJointState() const;
315 
321  virtual double getJointVelocity() const;
322 
323 protected:
324 
330  void _initVariables(JointCombinedFilterId joint_id);
331 
332  JointCombinedFilterId _joint_id;
333 
334  // Number of past measurements to use to estimate the likelihood of the current belief for the joint parameters
336 
337  //Using the Bayes Rule, the probability of a model given the data is the likelihood of the data given the model,
338  //times the (prior) probability of the model, divided by the probability of the data:
339  //p(Model|Data) = p(Data|Model) x p(Model) / p(Data)
340  //p(Data) is just a regularization term. We can ignore it and say that p(Model|Data) is proportional to... At the end, we can renormalize with the assumption that
341  //SUM_all_models( p(Model|Data) ) = 1
342  //p(Model) is the prior probability of a certain model. We usually assume an uniform distribution, so that p(Model) = 1/(NumDifferentModels), but we can set them differently,
343  //checking that SUM_all_models(p(Model)) = 1
344  //Finally, the probability of a model is proportional to the likelihood of the data given that model
345 
350 
352 
353  // Position of the joint axis
354  Eigen::Vector3d _joint_position;
355  // Uncertainty about the position of the joint axis
357 
358  // Orientation of the joint axis in spherical coordinates (phi,theta). Radius is always one (unitary vector is a point on the unit sphere)
361  // Equivalent joint orientation as unitary vector
362  Eigen::Vector3d _joint_orientation;
363  // Uncertainty about the orientation of the joint axis
365 
366  // Joint state (variable)
367  double _joint_state;
368  // Uncertainty about the joint state
370 
371  // Memory of all joint states so far
372  std::vector<double> _joint_states_all;
373 
374  // Joint velocity (variable)
376  // Uncertainty about the joint velocity
378 
379  // Not used!
380  // Joint velocity (variable)
382  // Uncertainty about the joint velocity
384 
385  Eigen::Vector3d _rrb_centroid_in_sf;
386  Eigen::Vector3d _srb_centroid_in_sf;
387 
388  // System noise
399 
400  // "A Twist does not have an absolutely fixed reference frame: you use it to represent the velocity of one frame with respect to another frame,
401  // expressed with respect to still another THIRD frame"
402  // Twists need to define:
403  // - Tracking frame: the frame that is tracked. In our case is the second rigid body rb2
404  // - Observation frame: the frame from which the motion is observed (do you see the car from the street or from a moving train?). In our case is the frame of
405  // the reference rigid body rrb
406  // - Reference frame: the reference frame in which to EXPRESS the twist. Usually is the same as the observation frame. In our case is the frame of the reference rigid body rrb
407  // - Reference point: the reference point with which to express the twist. Usually is the origin of the tracking frame. In our case is the origin of the second rigid body rb2
408  // - Reference point frame: the frame in which the reference point is expressed. Usually is the tracking frame. In our case is the frame of the second rigid body rb2
409  // All these twists should use the frame of the reference rigid body as:
410  // - Observation frame AND
411  // - Reference frame
412  // However, they are provided using as the sensor frame as:
413  // - Observation frame AND
414  // - Reference frame
415 
416  // Twists relative to the sensor frame
417  Eigen::Twistd _rrb_current_pose_in_sf;
419  Eigen::Matrix<double, 6, 6> _rrb_pose_cov_in_sf;
420  Eigen::Twistd _rrb_current_vel_in_sf;
421  Eigen::Matrix<double, 6, 6> _rrb_vel_cov_in_sf;
422 
423  Eigen::Twistd _srb_current_pose_in_sf;
424  Eigen::Matrix<double, 6, 6> _srb_pose_cov_in_sf;
425  Eigen::Twistd _srb_current_vel_in_sf;
426 
427  // Twists relative to the reference rigid body frame (rrbf)
429  Eigen::Matrix<double, 6, 6> _srb_initial_pose_cov_in_rrbf;
431  Eigen::Matrix<double, 6, 6> _srb_current_pose_cov_in_rrbf;
432 
437  Eigen::Matrix<double, 6, 6> _current_delta_pose_cov_in_rrbf;
440  std::vector<Eigen::Twistd> _delta_poses_in_rrbf;
441 
442  virtual JointFilter* doClone() const = 0;
443 
445 
446 #ifdef PUBLISH_PREDICTED_POSE_AS_PWC
447  // This is used to visualize the predictions based on the joint hypothesis
448  ros::NodeHandle _predicted_next_pose_nh;
449  ros::Publisher _predicted_next_pose_publisher;
450 #endif
451 
453 
455 
456  int _rrb_id;
457 
458  // To have a memory of the turns in the revolute joint
462 };
463 
464 }
465 
466 #endif /* JOINTFILTER_H_ */
virtual void setCovarianceAdditiveSystemNoiseJointState(double sigma_sys_noise_pv)
Eigen::Twistd _previous_delta_pose_in_rrbf
Definition: JointFilter.h:438
JointFilterPtr clone() const
Creates a new Joint object with the same values as this one and passes its reference.
Definition: JointFilter.h:102
virtual ~JointFilter()
Destructor.
virtual void setCovariancePrior(double prior_cov_vel)
Eigen::Twistd _rrb_current_pose_in_sf
Definition: JointFilter.h:417
Eigen::Twistd _srb_current_pose_in_sf
Definition: JointFilter.h:423
std::pair< omip_msgs::RigidBodyPoseAndVelMsg, omip_msgs::RigidBodyPoseAndVelMsg > joint_measurement_t
double _sigma_sys_noise_px
Definition: JointFilter.h:392
bool _from_inverted_to_non_inverted
Definition: JointFilter.h:460
virtual void setCovarianceAdditiveSystemNoisePhi(double sigma_sys_noise_phi)
Eigen::Twistd _predicted_delta_pose_in_rrbf
Definition: JointFilter.h:439
virtual void estimateUnnormalizedModelProbability()
Definition: JointFilter.h:161
Eigen::Matrix3d _uncertainty_joint_position
Definition: JointFilter.h:356
virtual double getJointState() const
Return the joint state. Useful for plotting and testing purposes (monitoring action) ...
Eigen::Matrix< double, 6, 6 > _rrb_vel_cov_in_sf
Definition: JointFilter.h:421
Eigen::Matrix< double, 6, 6 > _current_delta_pose_cov_in_rrbf
Definition: JointFilter.h:437
virtual double getOrientationThetaInRRBFrame() const
virtual Eigen::Vector3d getJointOrientationRPYInRRBFrame() const
virtual void initialize()
JointFilterType
Definition: JointFilter.h:71
double _sigma_sys_noise_py
Definition: JointFilter.h:393
double _joint_orientation_phi
Definition: JointFilter.h:359
double _uncertainty_joint_velocity
Definition: JointFilter.h:377
Eigen::Twistd _srb_current_pose_in_rrbf
Definition: JointFilter.h:430
Eigen::Twistd _srb_initial_pose_in_rrbf
Definition: JointFilter.h:428
virtual double getJointVelocity() const
Return the joint velocity. Useful for plotting and testing purposes (monitoring action) ...
virtual void estimateMeasurementHistoryLikelihood()
Estimate the error of the last joint parameters by testing them against the full observed trajectory ...
Definition: JointFilter.h:159
std::vector< double > _joint_states_all
Definition: JointFilter.h:372
virtual void setCovarianceAdditiveSystemNoiseTheta(double sigma_sys_noise_theta)
virtual void setCovarianceAdditiveSystemNoisePz(double sigma_sys_noise_pz)
virtual JointFilter * doClone() const =0
Eigen::Matrix< double, 6, 6 > _rrb_pose_cov_in_sf
Definition: JointFilter.h:419
bool _externally_set_likelihood
Definition: JointFilter.h:347
virtual void predictMeasurement()
Generate a prediction about the pose-twist of the second rigid body (SRB) using the frame of the refe...
Definition: JointFilter.h:127
virtual geometry_msgs::TwistWithCovariance getPredictedSRBDeltaPoseWithCovInSensorFrame()=0
Generate a prediction about the change in pose of the second rigid body (SRB) and its covariance usin...
virtual Eigen::Vector3d getJointOrientationUnitaryVector() const
virtual double getLoopPeriodNS() const
Eigen::Twistd _rrb_current_vel_in_sf
Definition: JointFilter.h:420
Eigen::Twistd _srb_previous_pose_in_rrbf
Definition: JointFilter.h:433
virtual JointFilterType getJointFilterType() const =0
Get the joint type as one of the possible JointFilterTypes.
Eigen::Vector3d _rrb_centroid_in_sf
Definition: JointFilter.h:385
virtual void setInitialMeasurement(const joint_measurement_t &initial_measurement, const Eigen::Twistd &rrb_pose_at_srb_birth_in_sf, const Eigen::Twistd &srb_pose_at_srb_birth_in_sf)
Definition: JointFilter.cpp:24
double _model_prior_probability
Definition: JointFilter.h:348
virtual double getLikelihoodOfLastMeasurements() const
Return the estimated error of the last joint parameters by testing them against the full observed tra...
bool _from_non_inverted_to_inverted
Definition: JointFilter.h:461
virtual void setCovarianceAdditiveSystemNoisePy(double sigma_sys_noise_py)
double _joint_acceleration
Definition: JointFilter.h:381
virtual void setCovarianceAdditiveSystemNoisePx(double sigma_sys_noise_px)
double _measurement_timestamp_ns
Definition: JointFilter.h:454
virtual double getUnnormalizedProbabilityOfJointFilter() const
Return the unnormalized joint filter probability as p(Data|Model) x p(Model)
Eigen::Twistd _srb_predicted_pose_in_rrbf
Definition: JointFilter.h:434
virtual double getNormalizingTerm()
Eigen::Matrix2d _uncertainty_joint_orientation_phitheta
Definition: JointFilter.h:364
virtual Eigen::Twistd getPredictedMeasurement() const
Get the predicted pose-twist of the second rigid body (SRB) using the frame of the reference rigid bo...
double _uncertainty_joint_state
Definition: JointFilter.h:369
virtual double getModelPriorProbability() const
Get the prior probability of this type of model/joint. We could use this in the feature if the robot ...
virtual std::vector< visualization_msgs::Marker > getJointMarkersInRRBFrame() const =0
Eigen::Twistd _srb_current_vel_in_sf
Definition: JointFilter.h:425
virtual void setLoopPeriodNS(double loop_period_ns)
virtual void correctState()
Correct the state of the filter (the joint parameters) based on the difference between the predicted ...
Definition: JointFilter.h:134
virtual void setCovarianceAdditiveSystemNoiseJointVelocity(double sigma_sys_noise_pvd)
Eigen::Matrix< double, 6, 6 > _srb_pose_cov_in_sf
Definition: JointFilter.h:424
Eigen::Vector3d _joint_orientation
Definition: JointFilter.h:362
double _normalizing_term
Definition: JointFilter.h:349
bool _inverted_delta_srb_pose_in_rrbf
Definition: JointFilter.h:459
virtual Eigen::Vector3d getJointPositionInRRBFrame() const
virtual void setNumSamplesForLikelihoodEstimation(int likelihood_sample_num)
Eigen::Matrix< double, 6, 6 > _srb_current_pose_cov_in_rrbf
Definition: JointFilter.h:431
double _measurements_likelihood
Definition: JointFilter.h:346
virtual double getCovarianceOrientationPhiPhiInRRBFrame() const
double _unnormalized_model_probability
Definition: JointFilter.h:351
virtual int getNumSamplesForLikelihoodEstimation() const
tf::TransformBroadcaster _tf_pub
Definition: JointFilter.h:452
double _uncertainty_joint_acceleration
Definition: JointFilter.h:383
Eigen::Vector3d _joint_position
Definition: JointFilter.h:354
virtual double getCovarianceOrientationThetaThetaInRRBFrame() const
double _joint_orientation_theta
Definition: JointFilter.h:360
int long JointCombinedFilterId
Definition: JointFilter.h:69
virtual geometry_msgs::TwistWithCovariance getPredictedSRBVelocityWithCovInSensorFrame()=0
Generate a prediction about the velocity of the second rigid body (SRB) and its covariance using the ...
JointFilter()
Constructor.
Definition: JointFilter.cpp:9
Eigen::Twistd _current_delta_pose_in_rrbf
Definition: JointFilter.h:436
virtual void setLikelihoodOfLastMeasurements(double likelihood)
Set the estimated error of the last joint parameters (only useful for the disconnected joint because ...
virtual double getCovarianceOrientationPhiThetaInRRBFrame() const
Eigen::Twistd _rrb_previous_pose_in_sf
Definition: JointFilter.h:418
JointCombinedFilterId _joint_id
Definition: JointFilter.h:332
double _sigma_sys_noise_theta
Definition: JointFilter.h:391
virtual void predictState(double time_interval_ns)
Predict the next state.
Definition: JointFilter.h:118
double _sigma_sys_noise_jvd
Definition: JointFilter.h:396
virtual geometry_msgs::TwistWithCovariance getPredictedSRBPoseWithCovInSensorFrame()=0
Generate a prediction about the pose-twist of the second rigid body (SRB) and its covariance using th...
std::vector< Eigen::Twistd > _delta_poses_in_rrbf
Definition: JointFilter.h:440
boost::shared_ptr< JointFilter > JointFilterPtr
Definition: JointFilter.h:79
Eigen::Matrix< double, 6, 6 > _srb_initial_pose_cov_in_rrbf
Definition: JointFilter.h:429
virtual JointCombinedFilterId getJointId() const
Get the unique Id that identifies this joint.
virtual void setNormalizingTerm(double normalizing_term)
Set the normalizing term from the combined filter as the sum of all unnormalized probabilities.
virtual std::string getJointFilterTypeStr() const =0
Get the joint type as a string (printing purposes)
virtual void setMeasurement(joint_measurement_t acquired_measurement, const double &measurement_timestamp_ns)
Set the latest acquired measurement.
double _sigma_sys_noise_jv
Definition: JointFilter.h:395
virtual void setModelPriorProbability(double model_prior_probability)
Set the prior probability of this type of model/joint. We could use this in the feature if the robot ...
virtual void setJointId(JointCombinedFilterId joint_id)
double _joint_velocity
Definition: JointFilter.h:375
Eigen::Vector3d _srb_centroid_in_sf
Definition: JointFilter.h:386
double _sigma_sys_noise_phi
Definition: JointFilter.h:390
Eigen::Twistd _srb_previous_predicted_pose_in_rrbf
Definition: JointFilter.h:435
double _loop_period_ns
Definition: JointFilter.h:444
void _initVariables(JointCombinedFilterId joint_id)
Initialize all variables of the filter.
virtual double getOrientationPhiInRRBFrame() const
double _sigma_sys_noise_pz
Definition: JointFilter.h:394
virtual void setCovarianceMeasurementNoise(double sigma_meas_noise)
double _sigma_meas_noise
Definition: JointFilter.h:397
virtual double getProbabilityOfJointFilter() const
Return the normalized joint filter probability as p(Model|Data) = p(Data|Model) x p(Model) / p(Data) ...


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