Apollo 11.0
自动驾驶开放平台
interpolation_plus_1d.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 *****************************************************************************/
17
18#include <algorithm>
19
20#include "cyber/common/log.h"
21
22namespace apollo {
23namespace control {
24
26 const double& value,
27 const google::protobuf::RepeatedField<double>& input_vector,
28 const google::protobuf::RepeatedField<double>& output_vector) {
29 int input_size = input_vector.size();
30 int output_size = output_vector.size();
31
32 ADEBUG << "input_size is " << input_size << ", output_size is " << output_size;
33 if (input_size < 1 || output_size < 1) {
34 AERROR << "1d interpolation: vector size is 0";
35 return 1.0;
36 } else if (input_size != output_size) {
37 AERROR << "1d interpolation: vector size is wrong"
38 << ", input_size: " << input_size << ", output_size: " << output_size;
39 return 1.0;
40 }
41
42 if (value <= input_vector.Get(0)) {
43 ADEBUG << "return the output_vector.Get(0)";
44 return output_vector.Get(0);
45 } else if (value >= input_vector.Get(input_size - 1)) {
46 ADEBUG << "return the output_vector.Get(input_size - 1)";
47 return output_vector.Get(input_size - 1);
48 }
49
50 for (int i = 1; i < input_size; ++i) {
51 if (value >= input_vector.Get(i - 1) && value < input_vector.Get(i)) {
52 ADEBUG << "return the interpolation_1d";
53 return output_vector.Get(i - 1)
54 + (output_vector.Get(i) - output_vector.Get(i - 1)) * (value - input_vector.Get(i - 1))
55 / (input_vector.Get(i) - input_vector.Get(i - 1));
56 }
57 }
58
59 AERROR << "1d interpolation: something is wrong";
60 return 1.0;
61}
62
63} // namespace control
64} // namespace apollo
static double interpolation_1d(const double &value, const google::protobuf::RepeatedField< double > &input_vector, const google::protobuf::RepeatedField< double > &output_vector)
#define ADEBUG
Definition log.h:41
#define AERROR
Definition log.h:44
class register implement
Definition arena_queue.h:37