/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. *****************************************************************************/ /** * @file **/ #include "modules/planning/common/reference_line_info.h" #include "modules/planning/proto/sl_boundary.pb.h" namespace apollo { namespace planning { uint32_t ReferenceLineInfo::s_reference_line_id_ = 0; ReferenceLineInfo::ReferenceLineInfo(const ReferenceLine& reference_line) : reference_line_(reference_line) { id_ = std::to_string(s_reference_line_id_); ++s_reference_line_id_; } const std::string& ReferenceLineInfo::Id() const { return id_; } bool ReferenceLineInfo::AddObstacle(const Obstacle* obstacle) { auto path_obstacle = CreatePathObstacle(obstacle); if (!path_obstacle) { AERROR << "Failed to create path obstacle for " << obstacle->Id(); return false; } if (!path_decision_.AddPathObstacle(std::move(path_obstacle))) { AERROR << "Failed to add path_obstacle " << obstacle->Id(); return false; } return true; } bool ReferenceLineInfo::AddObstacles( const std::vector& obstacles) { for (const auto* obstacle : obstacles) { if (!AddObstacle(obstacle)) { AERROR << "Failed to add obstacle " << obstacle->Id(); return false; } } return true; } std::unique_ptr ReferenceLineInfo::CreatePathObstacle( const Obstacle* obstacle) { auto path_obstacle = std::unique_ptr(new PathObstacle(obstacle)); if (!InitPerceptionSLBoundary(path_obstacle.get())) { AERROR << "Failed to create perception sl boundary for obstacle " << obstacle->Id(); return nullptr; } return path_obstacle; } bool ReferenceLineInfo::InitPerceptionSLBoundary(PathObstacle* path_obstacle) { double start_s(std::numeric_limits::max()); double end_s(std::numeric_limits::lowest()); double start_l(std::numeric_limits::max()); double end_l(std::numeric_limits::lowest()); std::vector corners; path_obstacle->Obstacle()->PerceptionBoundingBox().GetAllCorners(&corners); for (const auto& point : corners) { common::SLPoint sl_point; if (!reference_line_.get_point_in_frenet_frame(point, &sl_point)) { AERROR << "failed to get projection for point: " << point.DebugString() << " on reference line."; return false; } start_s = std::fmin(start_s, sl_point.s()); end_s = std::fmax(end_s, sl_point.s()); start_l = std::fmin(start_l, sl_point.l()); end_l = std::fmax(end_l, sl_point.l()); } SLBoundary perception_sl_boundary; perception_sl_boundary.set_start_s(start_s); perception_sl_boundary.set_end_s(end_s); perception_sl_boundary.set_start_l(start_l); perception_sl_boundary.set_end_l(end_l); path_obstacle->SetPerceptionSLBoundary(perception_sl_boundary); return true; } } // namespace planning } // namespace apollo