Apollo 10.0
自动驾驶开放平台
vehicle_model.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2019 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include "cyber/common/file.h"
21
22namespace apollo {
23namespace common {
24
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) {
29 // Kinematic bicycle model centered at rear axis center by Euler forward
30 // discretization
31 // Assume constant control command and constant z axis position
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;
46 }
47
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) {
52 countdown_time -= dt;
53 if (countdown_time < kepsilon) {
54 dt = countdown_time + dt;
55 finish_flag = true;
56 }
57 double intermidiate_phi =
58 cur_phi + 0.5 * dt * cur_v * cur_vehicle_state.kappa();
59 next_phi =
60 cur_phi + dt * (cur_v + 0.5 * dt * cur_a) * cur_vehicle_state.kappa();
61 next_x =
62 cur_x + dt * (cur_v + 0.5 * dt * cur_a) * std::cos(intermidiate_phi);
63 next_y =
64 cur_y + dt * (cur_v + 0.5 * dt * cur_a) * std::sin(intermidiate_phi);
65
66 next_v = cur_v + dt * cur_a;
67 cur_x = next_x;
68 cur_y = next_y;
69 cur_phi = next_phi;
70 cur_v = next_v;
71 }
72
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());
81}
82
83VehicleState VehicleModel::Predict(const double predicted_time_horizon,
84 const VehicleState& cur_vehicle_state) {
85 VehicleModelConfig vehicle_model_config;
86
87 ACHECK(cyber::common::GetProtoFromFile(FLAGS_vehicle_model_config_filename,
88 &vehicle_model_config))
89 << "Failed to load vehicle model config file "
90 << FLAGS_vehicle_model_config_filename;
91
92 // Some models not supported for now
93 ACHECK(vehicle_model_config.model_type() !=
95 ACHECK(vehicle_model_config.model_type() != VehicleModelConfig::MLP_MODEL);
96
97 VehicleState predicted_vehicle_state;
98 if (vehicle_model_config.model_type() ==
100 RearCenteredKinematicBicycleModel(vehicle_model_config,
101 predicted_time_horizon, cur_vehicle_state,
102 &predicted_vehicle_state);
103 }
104
105 return predicted_vehicle_state;
106}
107
108} // namespace common
109} // namespace apollo
static VehicleState Predict(const double predicted_time_horizon, const VehicleState &cur_vehicle_state)
#define ACHECK(cond)
Definition log.h:80
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,...
Definition file.cc:132
class register implement
Definition arena_queue.h:37