18 #include <gtest/gtest.h> 20 #include <Eigen/Dense> 26 #define EPS_JACOBI 1e-4 // [-] 27 #define EPS_PERTURB 1e-7 // [-] 28 #define SAMPLES 1e6 // [-] 29 #define OPERATING_REGION_X 20.0 // [m] 30 #define OPERATING_REGION_Y 20.0 // [m] 31 #define OPERATING_REGION_THETA 2 * M_PI // [rad] 32 #define OPERATING_REGION_KAPPA 2.0 // [1/m] 33 #define OPERATING_REGION_DELTA_S 0.4 // [m] 34 #define OPERATING_REGION_SIGMA 2.0 // [1/m^2] 35 #define random(lower, upper) (rand() * (upper - lower) / RAND_MAX + lower) 36 #define random_boolean() rand() % 2 67 double sigma(control.
sigma);
72 &state_next.
y, &state_next.
theta, &state_next.
kappa);
87 pify(state.
theta + state.
kappa * d * integration_step + 0.5 * sigma * d * integration_step * integration_step);
88 state_next.
kappa = state.
kappa + sigma * integration_step;
100 for (
int i = 0; i < F_x.cols(); ++i)
104 state_perturb.
x = state.
x + perturb(0, i);
105 state_perturb.
y = state.
y + perturb(1, i);
106 state_perturb.
theta = state.
theta + perturb(2, i);
110 F_x(0, i) = (f_x_perturb.
x - f_x.
x) / perturb(i, i);
111 F_x(1, i) = (f_x_perturb.
y - f_x.
y) / perturb(i, i);
112 F_x(2, i) = (f_x_perturb.
theta - f_x.
theta) / perturb(i, i);
123 for (
int i = 0; i < F_u.cols(); ++i)
129 double integration_step_perturb = fabs(control_perturb.
delta_s);
132 state_perturb.
x = state.
x;
133 state_perturb.
y = state.
y;
135 state_perturb.
kappa = state.
kappa + perturb(1, i);
137 State f_u_perturb =
integrate_ODE(state_perturb, control_perturb, integration_step_perturb);
138 F_u(0, i) = (f_u_perturb.
x - f_u.
x) / perturb(i, i);
139 F_u(1, i) = (f_u_perturb.
y - f_u.
y) / perturb(i, i);
140 F_u(2, i) = (f_u_perturb.
theta - f_u.
theta) / perturb(i, i);
148 for (
int i = 0; i <
SAMPLES; i++)
155 double integration_step = fabs(control.
delta_s);
161 for (
int i = 0; i < F_x_ana.rows(); ++i)
163 for (
int j = 0; j < F_x_ana.cols(); ++j)
165 EXPECT_LE(fabs(F_x_ana(i, j) - F_x_num(i, j)),
EPS_JACOBI);
174 for (
int i = 0; i <
SAMPLES; i++)
181 double integration_step = fabs(control.
delta_s);
187 for (
int i = 0; i < F_u_ana.rows(); ++i)
189 for (
int j = 0; j < F_u_ana.cols(); ++j)
191 EXPECT_LE(fabs(F_u_ana(i, j) - F_u_num(i, j)),
EPS_JACOBI);
197 int main(
int argc,
char **argv)
199 testing::InitGoogleTest(&argc, argv);
200 return RUN_ALL_TESTS();
Eigen::Matrix< double, 3, 3 > Matrix3d
double get_epsilon()
Return value of epsilon.
#define OPERATING_REGION_Y
double sgn(double x)
Return sign of a number.
Eigen::Matrix< double, 2, 2 > Matrix2d
double delta_s
Signed arc length of a segment.
int main(int argc, char **argv)
Eigen::Matrix< double, 3, 3 > Matrix3d
Eigen::Matrix< double, 3, 2 > Matrix32d
Matrix3d get_num_motion_jacobi_x(const State &state, const Control &control, double integration_step)
void end_of_circular_arc(double x_i, double y_i, double theta_i, double kappa, double direction, double length, double *x_f, double *y_f, double *theta_f)
Computation of the end point on a circular arc x_i, y_i, theta_i: initial configuration kappa: curvat...
void end_of_straight_line(double x_i, double y_i, double theta, double direction, double length, double *x_f, double *y_f)
Computation of the end point on a straight line x_i, y_i: initial configuration theta: angle of strai...
Description of a path segment with its corresponding control inputs.
double pify(double alpha)
Conversion of arbitrary angle given in [rad] to [-pi, pi[.
void end_of_clothoid(double x_i, double y_i, double theta_i, double kappa_i, double sigma, double direction, double length, double *x_f, double *y_f, double *theta_f, double *kappa_f)
Computation of the end point on a clothoid x_i, y_i, theta_i, kappa_i: initial configuration sigma: s...
double x
Position in x of the robot.
#define OPERATING_REGION_DELTA_S
Matrix32d get_num_motion_jacobi_u(const State &state, const Control &control, double integration_step)
Control get_random_control()
#define OPERATING_REGION_X
#define random(lower, upper)
Description of a kinematic car's state.
#define OPERATING_REGION_THETA
State integrate_ODE(const State &state, const Control &control, double integration_step)
Eigen::Matrix< double, 2, 2 > Matrix2d
double sigma
Sharpness (derivative of curvature with respect to arc length) of a segment.
#define OPERATING_REGION_SIGMA
double kappa
Curvature at position (x,y)
#define OPERATING_REGION_KAPPA
double y
Position in y of the robot.
Eigen::Matrix< double, 3, 2 > Matrix32d
double theta
Orientation of the robot.
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.