Apollo  6.0
Open source self driving car software
spline_1d_constraint.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 implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
23 #pragma once
24 
25 #include <algorithm>
26 #include <vector>
27 
28 #include "Eigen/Core"
31 
32 namespace apollo {
33 namespace planning {
34 
36  public:
37  explicit Spline1dConstraint(const Spline1d& pss);
38  Spline1dConstraint(const std::vector<double>& x_knots, const uint32_t order);
39 
40  // direct methods
41  bool AddInequalityConstraint(const Eigen::MatrixXd& constraint_matrix,
42  const Eigen::MatrixXd& constraint_boundary);
43  bool AddEqualityConstraint(const Eigen::MatrixXd& constraint_matrix,
44  const Eigen::MatrixXd& constraint_boundary);
45 
46  // preset method
52  bool AddBoundary(const std::vector<double>& x_coord,
53  const std::vector<double>& lower_bound,
54  const std::vector<double>& upper_bound);
55 
56  bool AddDerivativeBoundary(const std::vector<double>& x_coord,
57  const std::vector<double>& lower_bound,
58  const std::vector<double>& upper_bound);
59 
60  bool AddSecondDerivativeBoundary(const std::vector<double>& x_coord,
61  const std::vector<double>& lower_bound,
62  const std::vector<double>& upper_bound);
63 
64  bool AddThirdDerivativeBoundary(const std::vector<double>& x_coord,
65  const std::vector<double>& lower_bound,
66  const std::vector<double>& upper_bound);
67 
73  bool AddPointConstraint(const double x, const double fx);
74  bool AddPointDerivativeConstraint(const double x, const double dfx);
75  bool AddPointSecondDerivativeConstraint(const double x, const double ddfx);
76  bool AddPointThirdDerivativeConstraint(const double x, const double dddfx);
77 
78  bool AddPointConstraintInRange(const double x, const double fx,
79  const double range);
80  bool AddPointDerivativeConstraintInRange(const double x, const double dfx,
81  const double range);
83  const double ddfx,
84  const double range);
85  bool AddPointThirdDerivativeConstraintInRange(const double x,
86  const double dddfx,
87  const double range);
88  // guarantee up to values are joint
89  bool AddSmoothConstraint();
90 
91  // guarantee up to derivative are joint
93 
94  // guarantee up to second order derivative are joint
96 
97  // guarantee up to third order derivative are joint
99 
104  bool AddMonotoneInequalityConstraint(const std::vector<double>& x_coord);
105 
106  // default inequality constraint at knots
108 
113  const AffineConstraint& equality_constraint() const;
114 
115  private:
116  uint32_t FindIndex(const double x) const;
117 
118  bool FilterConstraints(const std::vector<double>& x_coord,
119  const std::vector<double>& lower_bound,
120  const std::vector<double>& upper_bound,
121  std::vector<double>* const filtered_lower_bound_x,
122  std::vector<double>* const filtered_lower_bound,
123  std::vector<double>* const filtered_upper_bound_x,
124  std::vector<double>* const filtered_upper_bound);
125  void GeneratePowerX(const double x, const uint32_t order,
126  std::vector<double>* const power_x) const;
127 
128  using AddConstraintInRangeFunc =
129  std::function<bool(const std::vector<double>&, const std::vector<double>&,
130  const std::vector<double>&)>;
131  bool AddConstraintInRange(AddConstraintInRangeFunc func, const double x,
132  const double val, const double range);
133 
134  private:
135  AffineConstraint inequality_constraint_;
136  AffineConstraint equality_constraint_;
137  std::vector<double> x_knots_;
138  uint32_t spline_order_;
139 };
140 
141 } // namespace planning
142 } // namespace apollo
bool AddPointSecondDerivativeConstraint(const double x, const double ddfx)
void(* func)(void *)
Definition: routine_context.h:41
bool AddSecondDerivativeBoundary(const std::vector< double > &x_coord, const std::vector< double > &lower_bound, const std::vector< double > &upper_bound)
const AffineConstraint & equality_constraint() const
bool AddEqualityConstraint(const Eigen::MatrixXd &constraint_matrix, const Eigen::MatrixXd &constraint_boundary)
bool AddBoundary(const std::vector< double > &x_coord, const std::vector< double > &lower_bound, const std::vector< double > &upper_bound)
: inequality boundary constraints if no boundary, do specify either by std::infinity or let vector...
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool AddDerivativeBoundary(const std::vector< double > &x_coord, const std::vector< double > &lower_bound, const std::vector< double > &upper_bound)
bool AddPointThirdDerivativeConstraint(const double x, const double dddfx)
Planning module main class. It processes GPS and IMU as input, to generate planning info...
bool AddInequalityConstraint(const Eigen::MatrixXd &constraint_matrix, const Eigen::MatrixXd &constraint_boundary)
bool AddPointConstraintInRange(const double x, const double fx, const double range)
Spline1dConstraint(const Spline1d &pss)
bool AddThirdDerivativeBoundary(const std::vector< double > &x_coord, const std::vector< double > &lower_bound, const std::vector< double > &upper_bound)
bool AddPointConstraint(const double x, const double fx)
: equality constraint to guarantee joint smoothness boundary equality constriant constraint on fx...
bool AddPointDerivativeConstraint(const double x, const double dfx)
bool AddPointThirdDerivativeConstraintInRange(const double x, const double dddfx, const double range)
Definition: affine_constraint.h:29
const AffineConstraint & inequality_constraint() const
: output interface inequality constraint
Definition: spline_1d.h:40
bool AddMonotoneInequalityConstraint(const std::vector< double > &x_coord)
: Add monotone constraint inequality, guarantee the monotone city at evaluated point. customized monotone inequality constraint at x_coord
Definition: spline_1d_constraint.h:35
: piecewise smoothing spline class
bool AddPointSecondDerivativeConstraintInRange(const double x, const double ddfx, const double range)
bool AddPointDerivativeConstraintInRange(const double x, const double dfx, const double range)