25void VehicleModel::RearCenteredKinematicBicycleModel(
26 const VehicleModelConfig& vehicle_model_config,
27 const double predicted_time_horizon,
const VehicleState& cur_vehicle_state,
28 VehicleState* predicted_vehicle_state) {
32 CHECK_GT(predicted_time_horizon, 0.0);
33 double dt = vehicle_model_config.rc_kinematic_bicycle_model().dt();
34 double cur_x = cur_vehicle_state.x();
35 double cur_y = cur_vehicle_state.y();
36 double cur_z = cur_vehicle_state.z();
37 double cur_phi = cur_vehicle_state.heading();
38 double cur_v = cur_vehicle_state.linear_velocity();
39 double cur_a = cur_vehicle_state.linear_acceleration();
40 double next_x = cur_x;
41 double next_y = cur_y;
42 double next_phi = cur_phi;
43 double next_v = cur_v;
44 if (dt >= predicted_time_horizon) {
45 dt = predicted_time_horizon;
48 double countdown_time = predicted_time_horizon;
49 bool finish_flag =
false;
50 static constexpr double kepsilon = 1e-8;
51 while (countdown_time > kepsilon && !finish_flag) {
53 if (countdown_time < kepsilon) {
54 dt = countdown_time + dt;
57 double intermidiate_phi =
58 cur_phi + 0.5 * dt * cur_v * cur_vehicle_state.kappa();
60 cur_phi + dt * (cur_v + 0.5 * dt * cur_a) * cur_vehicle_state.kappa();
62 cur_x + dt * (cur_v + 0.5 * dt * cur_a) * std::cos(intermidiate_phi);
64 cur_y + dt * (cur_v + 0.5 * dt * cur_a) * std::sin(intermidiate_phi);
66 next_v = cur_v + dt * cur_a;
73 predicted_vehicle_state->set_x(next_x);
74 predicted_vehicle_state->set_y(next_y);
75 predicted_vehicle_state->set_z(cur_z);
76 predicted_vehicle_state->set_heading(next_phi);
77 predicted_vehicle_state->set_kappa(cur_vehicle_state.kappa());
78 predicted_vehicle_state->set_linear_velocity(next_v);
79 predicted_vehicle_state->set_linear_acceleration(
80 cur_vehicle_state.linear_acceleration());
88 &vehicle_model_config))
89 <<
"Failed to load vehicle model config file "
90 << FLAGS_vehicle_model_config_filename;
100 RearCenteredKinematicBicycleModel(vehicle_model_config,
101 predicted_time_horizon, cur_vehicle_state,
102 &predicted_vehicle_state);
105 return predicted_vehicle_state;
static VehicleState Predict(const double predicted_time_horizon, const VehicleState &cur_vehicle_state)
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
@ REAR_CENTERED_KINEMATIC_BICYCLE_MODEL
@ COM_CENTERED_DYNAMIC_BICYCLE_MODEL
optional ModelType model_type