Apollo 10.0
自动驾驶开放平台
ego_info.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 "cyber/common/log.h"
25
26namespace apollo {
27namespace planning {
28
31
33 ego_vehicle_config_ = common::VehicleConfigHelper::GetConfig();
34}
35
37 const common::VehicleState& vehicle_state) {
38 set_start_point(start_point);
39 set_vehicle_state(vehicle_state);
40 CalculateEgoBox(vehicle_state);
41 return true;
42}
43
44void EgoInfo::CalculateEgoBox(const common::VehicleState& vehicle_state) {
45 const auto& param = ego_vehicle_config_.vehicle_param();
46 ADEBUG << "param: " << param.DebugString();
47
48 Vec2d vec_to_center(
49 (param.front_edge_to_center() - param.back_edge_to_center()) / 2.0,
50 (param.left_edge_to_center() - param.right_edge_to_center()) / 2.0);
51
52 Vec2d position(vehicle_state.x(), vehicle_state.y());
53 Vec2d center(position + vec_to_center.rotate(vehicle_state.heading()));
54
55 ego_box_ =
56 Box2d(center, vehicle_state.heading(), param.length(), param.width());
57}
58
60 start_point_.Clear();
61 vehicle_state_.Clear();
62 front_clear_distance_ = FLAGS_default_front_clear_distance;
63}
64
65// TODO(all): remove this function and "front_clear_distance" related.
66// It doesn't make sense when:
67// 1. the heading is not necessaries align with the road
68// 2. the road is not necessaries straight
70 const std::vector<const Obstacle*>& obstacles) {
71 Vec2d position(vehicle_state_.x(), vehicle_state_.y());
72
73 const auto& param = ego_vehicle_config_.vehicle_param();
74 Vec2d vec_to_center(
75 (param.front_edge_to_center() - param.back_edge_to_center()) / 2.0,
76 (param.left_edge_to_center() - param.right_edge_to_center()) / 2.0);
77
78 Vec2d center(position + vec_to_center.rotate(vehicle_state_.heading()));
79
80 Vec2d unit_vec_heading = Vec2d::CreateUnitVec2d(vehicle_state_.heading());
81
82 // Due to the error of ego heading, only short range distance is meaningful
83 static constexpr double kDistanceThreshold = 50.0;
84 static constexpr double buffer = 0.1; // in meters
85 const double impact_region_length =
86 param.length() + buffer + kDistanceThreshold;
87 Box2d ego_front_region(center + unit_vec_heading * kDistanceThreshold / 2.0,
88 vehicle_state_.heading(), impact_region_length,
89 param.width() + buffer);
90
91 for (const auto& obstacle : obstacles) {
92 if (obstacle->IsVirtual() ||
93 !ego_front_region.HasOverlap(obstacle->PerceptionBoundingBox())) {
94 continue;
95 }
96
97 double dist = ego_box_.center().DistanceTo(
98 obstacle->PerceptionBoundingBox().center()) -
99 ego_box_.diagonal() / 2.0;
100
101 if (front_clear_distance_ < 0.0 || dist < front_clear_distance_) {
102 front_clear_distance_ = dist;
103 }
104 }
105}
106
108 const ReferenceLineProvider* reference_line_provider) {
109 reference_line_provider->GetAdcWaypoint(&adc_waypoint_);
110 reference_line_provider->GetAdcDis2Destination(&distance_to_destination_);
111 AINFO << adc_waypoint_.DebugString();
112 AINFO << "distance_to_destination: " << distance_to_destination_;
113}
114} // namespace planning
115} // namespace apollo
static const VehicleConfig & GetConfig()
Get the current vehicle configuration.
Rectangular (undirected) bounding box in 2-D.
Definition box2d.h:52
double diagonal() const
Getter of the size of the diagonal of the box
Definition box2d.h:172
bool HasOverlap(const LineSegment2d &line_segment) const
Determines whether this box overlaps a given line segment
Definition box2d.cc:184
const Vec2d & center() const
Getter of the center of the box
Definition box2d.h:106
Implements a class of 2-dimensional vectors.
Definition vec2d.h:42
static Vec2d CreateUnitVec2d(const double angle)
Creates a unit-vector with a given angle to the positive x semi-axis
Definition vec2d.cc:29
Vec2d rotate(const double angle) const
rotate the vector by angle.
Definition vec2d.cc:65
double DistanceTo(const Vec2d &other) const
Returns the distance to the given vector
Definition vec2d.cc:47
bool Update(const common::TrajectoryPoint &start_point, const common::VehicleState &vehicle_state)
Definition ego_info.cc:36
common::VehicleState vehicle_state() const
Definition ego_info.h:51
void CalculateCurrentRouteInfo(const ReferenceLineProvider *reference_line_provider)
Definition ego_info.cc:107
void CalculateFrontObstacleClearDistance(const std::vector< const Obstacle * > &obstacles)
Definition ego_info.cc:69
common::TrajectoryPoint start_point() const
Definition ego_info.h:49
The class of ReferenceLineProvider.
bool GetAdcWaypoint(hdmap::LaneWaypoint *waypoint) const
Planning module main class.
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42
class register implement
Definition arena_queue.h:37
optional VehicleParam vehicle_param
std::string DebugString() const
Definition path.cc:68