46 Eigen::Displacementd T_rrbf_srbf_t_next = predicted_delta * T_rrbf_srbf_t0;
53 double p_one_meas_given_model_params = 0;
54 double p_all_meas_given_model_params = 0;
56 double sigma_translation = 0.05;
57 double sigma_rotation = 0.2;
59 double accumulated_error = 0.;
61 double frame_counter = 0.;
69 double delta_idx_samples = (double)std::max(1., (
double)trajectory_length/(double)this->_likelihood_sample_num);
71 size_t current_idx = 0;
74 for (
size_t sample_idx = 0; sample_idx < amount_samples; sample_idx++)
76 current_idx = boost::math::round(sample_idx*delta_idx_samples);
77 Eigen::Displacementd rb2_last_delta_relative_displ = this->
_delta_poses_in_rrbf.at(current_idx).exp(1e-12);
78 Eigen::Vector3d rb2_last_delta_relative_translation = rb2_last_delta_relative_displ.getTranslation();
79 Eigen::Quaterniond rb2_last_delta_relative_rotation = Eigen::Quaterniond(rb2_last_delta_relative_displ.qw(),
80 rb2_last_delta_relative_displ.qx(),
81 rb2_last_delta_relative_displ.qy(),
82 rb2_last_delta_relative_displ.qz());
84 Eigen::Vector3d rigid_joint_translation = Eigen::Vector3d(0.,0.,0.);
85 Eigen::Displacementd rb2_last_delta_relative_displ_rigid_hyp = Eigen::Twistd(0.,
88 rigid_joint_translation.x(),
89 rigid_joint_translation.y(),
90 rigid_joint_translation.z()).
exp(1e-12);
91 Eigen::Vector3d rb2_last_delta_relative_translation_rigid_hyp = rb2_last_delta_relative_displ_rigid_hyp.getTranslation();
92 Eigen::Quaterniond rb2_last_delta_relative_rotation_rigid_hyp = Eigen::Quaterniond(rb2_last_delta_relative_displ_rigid_hyp.qw(),
93 rb2_last_delta_relative_displ_rigid_hyp.qx(),
94 rb2_last_delta_relative_displ_rigid_hyp.qy(),
95 rb2_last_delta_relative_displ_rigid_hyp.qz());
98 double translation_error = (rb2_last_delta_relative_translation - rb2_last_delta_relative_translation_rigid_hyp).norm();
105 Eigen::Quaterniond rotation_error = rb2_last_delta_relative_rotation.inverse() * rb2_last_delta_relative_rotation_rigid_hyp;
106 double rotation_error_angle = Eigen::Displacementd(0., 0., 0., rotation_error.w(),rotation_error.x(), rotation_error.y(),rotation_error.z()).
log(1e-12).norm();
114 accumulated_error += translation_error + fabs(rotation_error_angle);
116 p_one_meas_given_model_params = (1.0/(sigma_translation*
sqrt(2.0*M_PI)))*
exp((-1.0/2.0)*
pow(translation_error/sigma_translation, 2)) *
117 (1.0/(sigma_rotation*
sqrt(2.0*M_PI)))*
exp((-1.0/2.0)*
pow(rotation_error_angle/sigma_rotation, 2));
119 p_all_meas_given_model_params += (p_one_meas_given_model_params/(double)amount_samples);
136 Eigen::Twistd delta_srb_in_sf = delta_rrb_in_sf;
138 geometry_msgs::TwistWithCovariance hypothesis;
140 hypothesis.twist.linear.x = delta_srb_in_sf.vx();
141 hypothesis.twist.linear.y = delta_srb_in_sf.vy();
142 hypothesis.twist.linear.z = delta_srb_in_sf.vz();
143 hypothesis.twist.angular.x = delta_srb_in_sf.rx();
144 hypothesis.twist.angular.y = delta_srb_in_sf.ry();
145 hypothesis.twist.angular.z = delta_srb_in_sf.rz();
147 for (
unsigned int i = 0; i < 6; i++)
149 for (
unsigned int j = 0; j < 6; j++)
162 Eigen::Twistd delta_srb_in_sf = delta_rrb_in_sf;
164 geometry_msgs::TwistWithCovariance hypothesis;
166 hypothesis.twist.linear.x = delta_srb_in_sf.vx();
167 hypothesis.twist.linear.y = delta_srb_in_sf.vy();
168 hypothesis.twist.linear.z = delta_srb_in_sf.vz();
169 hypothesis.twist.angular.x = delta_srb_in_sf.rx();
170 hypothesis.twist.angular.y = delta_srb_in_sf.ry();
171 hypothesis.twist.angular.z = delta_srb_in_sf.rz();
173 for (
unsigned int i = 0; i < 6; i++)
175 for (
unsigned int j = 0; j < 6; j++)
190 Eigen::Displacementd T_sf_rrbf_next = rrb_next_pose_in_sf.exp(1e-12);
193 Eigen::Displacementd T_sf_srbf_next = T_rrbf_srbf_next*T_sf_rrbf_next;
195 Eigen::Twistd srb_next_pose_in_sf = T_sf_srbf_next.log(1e-12);
197 geometry_msgs::TwistWithCovariance hypothesis;
199 hypothesis.twist.linear.x = srb_next_pose_in_sf.vx();
200 hypothesis.twist.linear.y = srb_next_pose_in_sf.vy();
201 hypothesis.twist.linear.z = srb_next_pose_in_sf.vz();
202 hypothesis.twist.angular.x = srb_next_pose_in_sf.rx();
203 hypothesis.twist.angular.y = srb_next_pose_in_sf.ry();
204 hypothesis.twist.angular.z = srb_next_pose_in_sf.rz();
207 for (
unsigned int i = 0; i < 6; i++)
209 for (
unsigned int j = 0; j < 6; j++)
211 hypothesis.covariance[6 * i + j] = new_pose_covariance(i, j);
215 #ifdef PUBLISH_PREDICTED_POSE_AS_PWC 217 geometry_msgs::PoseWithCovarianceStamped pose_with_cov_stamped;
219 pose_with_cov_stamped.header.frame_id =
"camera_rgb_optical_frame";
221 Eigen::Displacementd displ_from_twist = srb_next_pose_in_sf.exp(1e-12);
222 pose_with_cov_stamped.pose.pose.position.x = displ_from_twist.x();
223 pose_with_cov_stamped.pose.pose.position.y = displ_from_twist.y();
224 pose_with_cov_stamped.pose.pose.position.z = displ_from_twist.z();
225 pose_with_cov_stamped.pose.pose.orientation.x = displ_from_twist.qx();
226 pose_with_cov_stamped.pose.pose.orientation.y = displ_from_twist.qy();
227 pose_with_cov_stamped.pose.pose.orientation.z = displ_from_twist.qz();
228 pose_with_cov_stamped.pose.pose.orientation.w = displ_from_twist.qw();
230 for (
unsigned int i = 0; i < 6; i++)
231 for (
unsigned int j = 0; j < 6; j++)
232 pose_with_cov_stamped.pose.covariance[6 * i + j] = hypothesis.covariance[6 * i + j];
233 _predicted_next_pose_publisher.publish(pose_with_cov_stamped);
241 std::vector<visualization_msgs::Marker> rigid_markers;
243 visualization_msgs::Marker connection_marker;
244 connection_marker.ns =
"kinematic_structure";
245 connection_marker.action = visualization_msgs::Marker::ADD;
246 connection_marker.type = visualization_msgs::Marker::ARROW;
247 connection_marker.id = 3 * this->
_joint_id;
248 connection_marker.scale.x = 0.02f;
249 connection_marker.scale.y = 0.f;
250 connection_marker.scale.z = 0.f;
251 connection_marker.color.r = 0.f;
252 connection_marker.color.g = 0.f;
253 connection_marker.color.b = 1.f;
254 connection_marker.color.a = 1.f;
257 Eigen::Affine3d current_ref_pose;
258 current_ref_pose.matrix() = current_ref_pose_displ.toHomogeneousMatrix();
259 Eigen::Vector3d second_centroid_relative_to_ref_body = current_ref_pose.inverse() * this->
_srb_centroid_in_sf;
260 geometry_msgs::Point pt1;
261 pt1.x = second_centroid_relative_to_ref_body.x();
262 pt1.y = second_centroid_relative_to_ref_body.y();
263 pt1.z = second_centroid_relative_to_ref_body.z();
264 connection_marker.points.push_back(pt1);
267 Eigen::Vector3d first_centroid_relative_to_ref_body = current_ref_pose.inverse() * this->
_rrb_centroid_in_sf;
268 geometry_msgs::Point pt2;
269 pt2.x = first_centroid_relative_to_ref_body.x();
270 pt2.y = first_centroid_relative_to_ref_body.y();
271 pt2.z = first_centroid_relative_to_ref_body.z();
272 connection_marker.points.push_back(pt2);
274 rigid_markers.push_back(connection_marker);
277 visualization_msgs::Marker empty_marker;
278 empty_marker.pose.position.x = 0.;
279 empty_marker.pose.position.y = 0.;
280 empty_marker.pose.position.z = 0.;
281 empty_marker.header.frame_id =
"camera_rgb_optical_frame";
282 empty_marker.type = visualization_msgs::Marker::SPHERE;
283 empty_marker.action = visualization_msgs::Marker::DELETE;
284 empty_marker.scale.x = 0.0001;
285 empty_marker.scale.y = 0.0001;
286 empty_marker.scale.z = 0.0001;
287 empty_marker.color.a = 0.3;
288 empty_marker.color.r = 0.0;
289 empty_marker.color.g = 0.0;
290 empty_marker.color.b = 1.0;
291 empty_marker.ns =
"kinematic_structure";
292 empty_marker.id = 3 * this->
_joint_id + 1;
294 rigid_markers.push_back(empty_marker);
296 empty_marker.id = 3 * this->
_joint_id + 2;
297 rigid_markers.push_back(empty_marker);
299 empty_marker.ns =
"kinematic_structure_uncertainty";
302 rigid_markers.push_back(empty_marker);
304 empty_marker.id = 3* this->
_joint_id + 1;
306 rigid_markers.push_back(empty_marker);
308 empty_marker.id = 3* this->
_joint_id + 2;
310 rigid_markers.push_back(empty_marker);
312 return rigid_markers;
322 return std::string(
"RigidJointFilter");
virtual void estimateUnnormalizedModelProbability()
virtual void initialize()
virtual void setMaxTranslationRigid(double max_trans)
Eigen::Twistd _rrb_current_pose_in_sf
Eigen::Twistd _predicted_delta_pose_in_rrbf
virtual JointFilterType getJointFilterType() const
INLINE Rall1d< T, V, S > log(const Rall1d< T, V, S > &arg)
virtual geometry_msgs::TwistWithCovariance getPredictedSRBDeltaPoseWithCovInSensorFrame()
Generate a prediction about the change in pose of the second rigid body (SRB) and its covariance usin...
Eigen::Matrix< double, 6, 6 > _rrb_vel_cov_in_sf
virtual void estimateMeasurementHistoryLikelihood()
virtual void initialize()
Eigen::Twistd _srb_initial_pose_in_rrbf
virtual void setMaxRotationRigid(double max_rot)
int _likelihood_sample_num
virtual ~RigidJointFilter()
Eigen::Matrix< double, 6, 6 > _rrb_pose_cov_in_sf
Eigen::Twistd _rrb_current_vel_in_sf
Eigen::Vector3d _rrb_centroid_in_sf
double _model_prior_probability
virtual void predictMeasurement()
Eigen::Twistd _srb_predicted_pose_in_rrbf
double _motion_memory_prior
virtual geometry_msgs::TwistWithCovariance getPredictedSRBPoseWithCovInSensorFrame()
double _measurements_likelihood
double _unnormalized_model_probability
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
virtual std::string getJointFilterTypeStr() const
virtual std::vector< visualization_msgs::Marker > getJointMarkersInRRBFrame() const
virtual geometry_msgs::TwistWithCovariance getPredictedSRBVelocityWithCovInSensorFrame()
Generate a prediction about the velocity of the second rigid body (SRB) and its covariance using the ...
INLINE Rall1d< T, V, S > exp(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
JointCombinedFilterId _joint_id
std::vector< Eigen::Twistd > _delta_poses_in_rrbf
double _rig_max_translation
Eigen::Vector3d _srb_centroid_in_sf