Apollo 11.0
自动驾驶开放平台
speed_profile_generator.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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
22
23#include <algorithm>
24#include <utility>
25
26#include "cyber/common/log.h"
30
31namespace apollo {
32namespace planning {
33
35
37 double last_point_t = 0.0;
38 double last_point_s = 0.0;
39 if (!speed_data->empty()) {
40 last_point_t = speed_data->back().t();
41 last_point_s = speed_data->back().s();
42 }
43 if (last_point_t >= FLAGS_fallback_total_time) {
44 return;
45 }
46 for (double t = last_point_t + FLAGS_fallback_time_unit;
47 t < FLAGS_fallback_total_time; t += FLAGS_fallback_time_unit) {
48 speed_data->AppendSpeedPoint(last_point_s, t, 0.0, 0.0, 0.0);
49 }
50}
51
53 const double distance, const double max_speed) {
54 static constexpr double kConstDeceleration = -0.8; // (~3sec to fully stop)
55 static constexpr double kProceedingSpeed = 2.23; // (5mph proceeding speed)
56 const double proceeding_speed = std::fmin(max_speed, kProceedingSpeed);
57 const double distance_to_start_deceleration =
58 proceeding_speed * proceeding_speed / kConstDeceleration / 2;
59 bool is_const_deceleration_mode = distance < distance_to_start_deceleration;
60
61 double a = kConstDeceleration;
62 double t = 0.0;
63 double s = 0.0;
64 double v = proceeding_speed;
65
66 static constexpr double kDeltaT = 0.1;
67
68 SpeedData speed_data;
69 while (s < distance && v > 0) {
70 if (is_const_deceleration_mode) {
71 speed_data.AppendSpeedPoint(s, t, v, a, 0.0);
72 t += kDeltaT;
73 double v_new = std::max(0.0, v + a * t);
74 s += kDeltaT * (v + v_new) / 2;
75 v = v_new;
76 } else {
77 speed_data.AppendSpeedPoint(s, t, v, 0.0, 0.0);
78 t += kDeltaT;
79 s += kDeltaT * v;
80 if (distance - s < distance_to_start_deceleration)
81 is_const_deceleration_mode = true;
82 }
83 }
84
85 return speed_data;
86}
87
88} // namespace planning
89} // namespace apollo
void AppendSpeedPoint(const double s, const double time, const double v, const double a, const double da)
Definition speed_data.cc:48
static void FillEnoughSpeedPoints(SpeedData *const speed_data)
static SpeedData GenerateFixedDistanceCreepProfile(const double distance, const double max_speed)
Planning module main class.
class register implement
Definition arena_queue.h:37