Apollo 11.0
自动驾驶开放平台
speed_limit.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2017 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
25#include "cyber/common/log.h"
26
27namespace apollo {
28namespace planning {
29
30void SpeedLimit::AppendSpeedLimit(const double s, const double v) {
31 if (!speed_limit_points_.empty()) {
32 DCHECK_GE(s, speed_limit_points_.back().first);
33 }
34 speed_limit_points_.emplace_back(s, v);
35}
36
37const std::vector<std::pair<double, double>>& SpeedLimit::speed_limit_points()
38 const {
39 return speed_limit_points_;
40}
41
42double SpeedLimit::GetSpeedLimitByS(const double s) const {
43 CHECK_GE(speed_limit_points_.size(), 2U);
44 DCHECK_GE(s, speed_limit_points_.front().first);
45
46 auto compare_s = [](const std::pair<double, double>& point, const double s) {
47 return point.first < s;
48 };
49
50 auto it_lower = std::lower_bound(speed_limit_points_.begin(),
51 speed_limit_points_.end(), s, compare_s);
52
53 if (it_lower == speed_limit_points_.end()) {
54 return (it_lower - 1)->second;
55 }
56 return it_lower->second;
57}
58
59void SpeedLimit::Clear() { speed_limit_points_.clear(); }
60
61} // namespace planning
62} // namespace apollo
const std::vector< std::pair< double, double > > & speed_limit_points() const
void AppendSpeedLimit(const double s, const double v)
double GetSpeedLimitByS(const double s) const
Planning module main class.
class register implement
Definition arena_queue.h:37