Apollo 10.0
自动驾驶开放平台
smoother.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 <string>
24
28
29namespace apollo {
30namespace planning {
31
35
36bool Smoother::IsCloseStop(const common::VehicleState& vehicle_state,
37 const MainStop& main_stop) {
38 if (!main_stop.has_stop_point()) {
39 ADEBUG << "not close for main stop:" << main_stop.DebugString();
40 return false;
41 }
42 Vec2d current_car_pos(vehicle_state.x(), vehicle_state.y());
43 Vec2d stop_pos(main_stop.stop_point().x(), main_stop.stop_point().y());
44 auto stop_distance = stop_pos.DistanceTo(current_car_pos);
45 if (stop_distance > FLAGS_smoother_stop_distance) {
46 ADEBUG << "distance between ADC position and stop position:"
47 << stop_distance;
48 return false;
49 }
50 return true;
51}
52
53// TODO(all): extend more smooth policies into different objects
54// when more use cases happens later.
56 const FrameHistory* frame_history, const Frame* current_frame,
57 ADCTrajectory* const current_trajectory_pb) {
58 if (frame_history == nullptr) {
59 const std::string msg = "frame history is null.";
60 AERROR << msg;
61 return Status(ErrorCode::PLANNING_ERROR, msg);
62 }
63 if (current_frame == nullptr) {
64 const std::string msg = "frame is null.";
65 AERROR << msg;
66 return Status(ErrorCode::PLANNING_ERROR, msg);
67 }
68 if (current_trajectory_pb == nullptr) {
69 const std::string msg = "current trajectory pb is null";
70 AERROR << msg;
71 return Status(ErrorCode::PLANNING_ERROR, msg);
72 }
73 const auto& main_decision = current_trajectory_pb->decision().main_decision();
74 if (!main_decision.has_stop()) {
75 // skip for current planning is not stop.
76 ADEBUG << "skip smoothing for current planning is not stop";
77 return Status::OK();
78 }
79
80 const auto& vehicle_state = current_frame->vehicle_state();
81 const double max_adc_stop_speed = common::VehicleConfigHelper::Instance()
82 ->GetConfig()
83 .vehicle_param()
84 .max_abs_speed_when_stopped();
85 if (vehicle_state.linear_velocity() > max_adc_stop_speed) {
86 ADEBUG << "vehicle speed:" << vehicle_state.linear_velocity()
87 << " skip smoothing for non-stop scenario";
88 return Status::OK();
89 }
90
91 if (!IsCloseStop(vehicle_state, main_decision.stop())) {
92 ADEBUG << "vehicle state:" << vehicle_state.DebugString()
93 << " skip smoothing for ADC is not close to stop point";
94 return Status::OK();
95 }
96
97 auto previous_frame = frame_history->Latest();
98 if (previous_frame == nullptr) {
99 const std::string msg = "previous frame is null";
100 AWARN << msg;
101 return Status(ErrorCode::PLANNING_ERROR, msg);
102 }
103 const auto& previous_planning =
104 previous_frame->current_frame_planned_trajectory();
105 auto header = current_trajectory_pb->header();
106 *current_trajectory_pb = previous_planning;
107 current_trajectory_pb->mutable_header()->CopyFrom(header);
108 auto smoother_debug = current_trajectory_pb->mutable_debug()
109 ->mutable_planning_data()
110 ->mutable_smoother();
111 smoother_debug->set_is_smoothed(true);
112 smoother_debug->set_type(
114 return Status::OK();
115}
116
117} // namespace planning
118} // namespace apollo
A general class to denote the return status of an API call.
Definition status.h:43
static Status OK()
generate a success status.
Definition status.h:60
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
std::string DebugString() const
Returns a human-readable string representing this object
Definition vec2d.cc:125
Frame holds all data for one planning cycle.
Definition frame.h:62
const common::VehicleState & vehicle_state() const
Definition frame.cc:83
apollo::common::Status Smooth(const FrameHistory *frame_history, const Frame *current_frame, ADCTrajectory *const current_trajectory_pb)
Definition smoother.cc:55
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
#define AWARN
Definition log.h:43
class register implement
Definition arena_queue.h:37
optional apollo::common::Header header
optional apollo::planning::DecisionResult decision
Defines the Vec2d class.