Apollo  6.0
Open source self driving car software
prediction_util.h
Go to the documentation of this file.
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
13  *implied. See the License for the specific language governing
14  *permissions and limitations under the License.
15  *****************************************************************************/
16 
17 #pragma once
18 
19 #include <limits>
20 #include <utility>
21 #include <vector>
22 
23 #include "Eigen/Dense"
24 #include "modules/common/proto/pnc_point.pb.h"
26 
27 namespace apollo {
28 namespace prediction {
29 namespace math_util {
37 double Normalize(const double value, const double mean, const double std);
38 
44 double Relu(const double value);
45 
51 std::vector<double> Softmax(const std::vector<double>& value,
52  bool use_exp = true);
53 
60 int SolveQuadraticEquation(const std::vector<double>& coefficients,
61  std::pair<double, double>* roots);
62 
69 double EvaluateQuinticPolynomial(const std::array<double, 6>& coeffs,
70  const double t, const uint32_t order,
71  const double end_t, const double end_v);
72 
79 double EvaluateQuarticPolynomial(const std::array<double, 5>& coeffs,
80  const double t, const uint32_t order,
81  const double end_t, const double end_v);
82 
92  const std::array<double, 4>& coefs, const double t, const uint32_t order,
93  const double end_t = std::numeric_limits<double>::infinity(),
94  const double end_v = 0.0);
95 
96 template <std::size_t N>
97 std::array<double, 2 * N - 2> ComputePolynomial(
98  const std::array<double, N - 1>& start_state,
99  const std::array<double, N - 1>& end_state, const double param);
100 
101 template <>
102 inline std::array<double, 4> ComputePolynomial<3>(
103  const std::array<double, 2>& start_state,
104  const std::array<double, 2>& end_state, const double param) {
105  std::array<double, 4> coefs;
106  coefs[0] = start_state[0];
107  coefs[1] = start_state[1];
108 
109  auto m0 = end_state[0] - start_state[0] - start_state[1] * param;
110  auto m1 = end_state[1] - start_state[1];
111 
112  auto param_p3 = param * param * param;
113  coefs[3] = (m1 * param - 2.0 * m0) / param_p3;
114 
115  coefs[2] = (m1 - 3.0 * coefs[3] * param * param) / param * 0.5;
116  return coefs;
117 }
118 
119 double GetSByConstantAcceleration(const double v0, const double acceleration,
120  const double t);
121 
122 } // namespace math_util
123 
124 namespace predictor_util {
131 void TranslatePoint(const double translate_x, const double translate_y,
132  common::TrajectoryPoint* point);
133 
145  Eigen::Matrix<double, 6, 1>* state,
146  const Eigen::Matrix<double, 6, 6>& transition, double theta,
147  const double start_time, const std::size_t num, const double period,
148  std::vector<common::TrajectoryPoint>* points);
149 
158 double AdjustSpeedByCurvature(const double speed, const double curvature);
159 
160 } // namespace predictor_util
161 } // namespace prediction
162 } // namespace apollo
double EvaluateCubicPolynomial(const std::array< double, 4 > &coefs, const double t, const uint32_t order, const double end_t=std::numeric_limits< double >::infinity(), const double end_v=0.0)
Evaluate cubic polynomial.
double Normalize(const double value, const double mean, const double std)
Normalize the value by specified mean and standard deviation.
std::array< double, 2 *N - 2 > ComputePolynomial(const std::array< double, N - 1 > &start_state, const std::array< double, N - 1 > &end_state, const double param)
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::array< double, 4 > ComputePolynomial< 3 >(const std::array< double, 2 > &start_state, const std::array< double, 2 > &end_state, const double param)
Definition: prediction_util.h:102
Definition: future.h:29
void GenerateFreeMoveTrajectoryPoints(Eigen::Matrix< double, 6, 1 > *state, const Eigen::Matrix< double, 6, 6 > &transition, double theta, const double start_time, const std::size_t num, const double period, std::vector< common::TrajectoryPoint > *points)
Generate a set of free move trajectory points.
int SolveQuadraticEquation(const std::vector< double > &coefficients, std::pair< double, double > *roots)
Solve quadratic equation.
std::vector< double > Softmax(const std::vector< double > &value, bool use_exp=true)
Softmax function used in neural networks as an activation function.
double EvaluateQuarticPolynomial(const std::array< double, 5 > &coeffs, const double t, const uint32_t order, const double end_t, const double end_v)
Evaluate quartic polynomial.
double EvaluateQuinticPolynomial(const std::array< double, 6 > &coeffs, const double t, const uint32_t order, const double end_t, const double end_v)
Evaluate quintic polynomial.
double Relu(const double value)
RELU function used in neural networks as an activation function.
double GetSByConstantAcceleration(const double v0, const double acceleration, const double t)
void TranslatePoint(const double translate_x, const double translate_y, common::TrajectoryPoint *point)
Translate a point.
apollo::cyber::base::std value
double AdjustSpeedByCurvature(const double speed, const double curvature)
Adjust a speed value according to a curvature. If the input speed is okay on the input curvature...