forked from SS47816/frenet_optimal_planner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspline.h
executable file
·99 lines (82 loc) · 2.04 KB
/
spline.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/** spline.h
*
* Copyright (C) 2022 Shuo SUN & Advanced Robotics Center, National University of Singapore
*
* Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0
*
* Defination of 1D & 2D Splines
*/
#ifndef SPLINE_H_
#define SPLINE_H_
#include <vector>
#include "Eigen/Dense"
#include "frenet.h"
#include "math_utils.h"
namespace fop
{
class Spline
{
public:
// Constructors
Spline(){};
Spline(const std::vector<double>& x, const std::vector<double>& y);
// Destructor
virtual ~Spline(){};
// Coefficients
std::vector<double> a_;
std::vector<long double> b_;
std::vector<long double> c_;
std::vector<long double> d_;
std::vector<double> w_;
std::vector<double> x_;
std::vector<double> y_;
int num_x_;
// Calculate point y
double calculatePoint(double t);
// Calculate point dy
double calculateFirstDerivative(double t);
// Calculate point ddy
double calculateSecondDerivative(double t);
private:
// Construct matrix A
Eigen::MatrixXd calculateMatrixA(std::vector<double> h);
// Construct matrix B
Eigen::MatrixXd calculateMatrixB(std::vector<double> h);
// find the nearest last point
int searchIndex(double x);
};
class Spline2D
{
public:
// Constructors
Spline2D(){};
Spline2D(const Lane& ref_wps);
// Destructor
virtual ~Spline2D(){};
// Data type for returned results
struct ResultType
{
std::vector<double> rx;
std::vector<double> ry;
std::vector<double> ryaw;
std::vector<double> rk;
std::vector<double> s;
};
// Lists of point coordinates
std::vector<double> s_;
Spline sx_;
Spline sy_;
// Calculate point (x,y) coordinates
VehicleState calculatePosition(double s);
// Calculate curvature at the point
double calculateCurvature(double s);
// Calculate yaw at the point
double calculateYaw(double s);
// Construct the spline
ResultType calculateSplineCourse(const Lane& ref_wps, double ds);
private:
// Calculate a list of s
std::vector<double> calculate_s(const Lane& ref_wps);
};
} // namespace fop
#endif // SPLINE_H_