28 I_ = Matrix3d::Identity();
42 for (
int i = 0, n = covariance_eigen.rows(); i < n; ++i)
44 for (
int j = 0, m = covariance_eigen.cols(); j < m; ++j)
46 covariance_eigen(i, j) = covariance[(i << 2) + j];
49 return covariance_eigen;
54 for (
int i = 0, n = covariance_eigen.rows(); i < n; ++i)
56 for (
int j = 0, m = covariance_eigen.cols(); j < m; ++j)
58 covariance[(i << 2) + j] = covariance_eigen(i, j);
70 double sgn_sigma =
sgn(control.
sigma);
71 double abs_sigma = fabs(control.
sigma);
72 double sqrt_sigma_inv = 1 /
sqrt(abs_sigma);
74 double k2 =
SQRT_PI_INV * sqrt_sigma_inv * (abs_sigma * integration_step + sgn_sigma * state.
kappa);
76 double k4 = k1 + d * sgn_sigma *
HALF_PI * k2 * k2;
77 double k5 = k1 + d * sgn_sigma *
HALF_PI * k3 * k3;
78 double cos_k1 =
cos(k1);
79 double sin_k1 =
sin(k1);
80 double cos_k4 =
cos(k4);
81 double sin_k4 =
sin(k4);
82 double cos_k5 =
cos(k5);
83 double sin_k5 =
sin(k5);
88 fresnel(k2, fresnel_s_k2, fresnel_c_k2);
89 fresnel(k3, fresnel_s_k3, fresnel_c_k3);
95 F_x(0, 2) =
SQRT_PI * sqrt_sigma_inv *
96 (-d * sin_k1 * (fresnel_c_k2 - fresnel_c_k3) - sgn_sigma * cos_k1 * (fresnel_s_k2 - fresnel_s_k3));
97 F_x(1, 2) =
SQRT_PI * sqrt_sigma_inv *
98 (d * cos_k1 * (fresnel_c_k2 - fresnel_c_k3) - sgn_sigma * sin_k1 * (fresnel_s_k2 - fresnel_s_k3));
104 F_u(2, 0) = state.
kappa + control.
sigma * integration_step;
107 (sgn_sigma * sin_k1 * (fresnel_c_k2 - fresnel_c_k3) + d * cos_k1 * (fresnel_s_k2 - fresnel_s_k3)) /
109 d * (cos_k4 - cos_k5) / control.
sigma;
111 (-sgn_sigma * cos_k1 * (fresnel_c_k2 - fresnel_c_k3) + d * sin_k1 * (fresnel_s_k2 - fresnel_s_k3)) /
113 d * (sin_k4 - sin_k5) / control.
sigma;
114 F_u(2, 1) = d * integration_step;
122 double k9 = state.
theta + d * integration_step * state.
kappa;
123 double cos_k9 =
cos(k9);
124 double sin_k9 =
sin(k9);
130 F_x(0, 2) = (-cos_th + cos_k9) / state.
kappa;
131 F_x(1, 2) = (-sin_th + sin_k9) / state.
kappa;
137 F_u(2, 0) = state.
kappa;
139 F_u(0, 1) = (sin_th - sin_k9) / (state.
kappa * state.
kappa) + d * integration_step * cos_k9 / state.
kappa;
140 F_u(1, 1) = (-cos_th + cos_k9) / (state.
kappa * state.
kappa) + d * integration_step * sin_k9 / state.
kappa;
141 F_u(2, 1) = d * integration_step;
152 F_x(0, 2) = -d * integration_step * sin_th;
153 F_x(1, 2) = d * integration_step * cos_th;
159 F_u(2, 0) = state.
kappa;
161 F_u(2, 1) = d * integration_step;
202 double cos_angle =
cos(angle);
203 double sin_angle =
sin(angle);
205 R(1, 0) = -sin_angle;
223 Matrix3d Sigma_pred = F_x * Sigma * F_x.transpose() + F_u * Q * F_u.transpose();
228 Matrix3d F_K = F_x - F_u * K * R_1I;
229 Matrix3d Lambda_pred = F_K * Lambda * F_K.transpose();
244 Matrix3d Sigma_xz = Sigma_pred * H_x.transpose();
245 Matrix3d Sigma_z = H_x * Sigma_xz + R;
246 Matrix3d L = Sigma_xz * Sigma_z.inverse();
250 Matrix3d Sigma_corr = I_LH_x * Sigma_pred * I_LH_x.transpose() + L * R * L.transpose();
253 Matrix3d Lambda_corr = Lambda_pred + L * Sigma_xz.transpose();
double k1
Weight on longitudinal error.
double get_epsilon()
Return value of epsilon.
void set_parameters(const Motion_Noise &motion_noise, const Measurement_Noise &measurement_noise, const Controller &_controller)
Sets the parameters required by the EKF.
double sgn(double x)
Return sign of a number.
double std_y
Standard deviation of localization in y.
Eigen::Matrix< double, 2, 3 > Matrix23d
double delta_s
Signed arc length of a segment.
double Lambda[16]
Covariance of the state estimate due to the absence of measurements.
Matrix3d get_observation_jacobi() const
Computes the Jacobian of the observation equations with respect to the state.
void eigen_to_covariance(const Matrix3d &covariance_eigen, double covariance[16]) const
Converts a covariance given by an Eigen matrix to a double array.
Matrix2d get_motion_covariance(const State &state, const Control &control, double integration_step) const
Returns the motion covariance in control space.
Controller controller_
Feedback controller.
Eigen::Matrix< double, 3, 3 > Matrix3d
double std_x
Standard deviation of localization in x.
Eigen::Matrix< double, 3, 2 > Matrix32d
double k2
Weight on lateral error.
Matrix3d covariance_to_eigen(const double covariance[16]) const
Converts a covariance given by a double array to an Eigen matrix.
void fresnel(double s, double &S_f, double &C_f)
Fresnel integrals: S_f = int_0_s(sin(pi/2 u*u)du), C_f = int_0_s(cos(pi/2 u*u)du) approximated with C...
Motion_Noise motion_noise_
Motion noise.
Parameters of the motion noise model according to the book: Probabilistic Robotics, S. Thrun and others, MIT Press, 2006, p. 127-128 and p.204-206.
Description of a path segment with its corresponding control inputs.
void update(const State_With_Covariance &state_pred, State_With_Covariance &state_corr) const
Predicts the covariances.
State state
Expected state of the robot.
double covariance[16]
Covariance of the state given by Sigma + Lambda: (x_x x_y x_theta x_kappa y_x y_y y_theta y_kappa the...
Description of a kinematic car's state with covariance.
Parameters of the measurement noise.
double k3
Weight on heading error.
Parameters of the feedback controller.
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
Matrix3d get_observation_covariance() const
Returns the observation covariance.
double alpha1
Variance in longitudinal direction: alpha1*delta_s*delta_s + alpha2*kappa*kappa.
Description of a kinematic car's state.
Eigen::Matrix< double, 2, 2 > Matrix2d
double sigma
Sharpness (derivative of curvature with respect to arc length) of a segment.
double std_theta
Standard deviation of localization in theta.
Matrix23d get_controller_gain(const Control &control) const
Returns the gain of the controller.
double Sigma[16]
Covariance of the state estimation due to motion and measurement noise.
Matrix3d get_rotation_matrix(double angle) const
Returns the rotation matrix from a global frame to a local frame.
double alpha3
Variance in lateral direction: alpha3*delta_s*delta_s + alpha4*kappa*kappa.
double kappa
Curvature at position (x,y)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
Matrix3d I_
Identity matrix.
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
double theta
Orientation of the robot.
Measurement_Noise measurement_noise_
Measurement noise.
void predict(const State_With_Covariance &state, const Control &control, double integration_step, State_With_Covariance &state_pred) const
Predicts the covariances based on the paper: Rapidly-exploring random belief trees for motion plannin...
void get_motion_jacobi(const State &state, const Control &control, double integration_step, Matrix3d &F_x, Matrix32d &F_u) const
Computes the Jacobians of the motion equations with respect to the state and control.