WPILibC++ 2023.4.3-108-ge5452e3
SplineHelper.h
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <utility>
8#include <vector>
9
10#include <wpi/SymbolExports.h>
11#include <wpi/array.h>
12
15
16namespace frc {
17/**
18 * Helper class that is used to generate cubic and quintic splines from user
19 * provided waypoints.
20 */
22 public:
23 /**
24 * Returns 2 cubic control vectors from a set of exterior waypoints and
25 * interior translations.
26 *
27 * @param start The starting pose.
28 * @param interiorWaypoints The interior waypoints.
29 * @param end The ending pose.
30 * @return 2 cubic control vectors.
31 */
34 const Pose2d& start, const std::vector<Translation2d>& interiorWaypoints,
35 const Pose2d& end);
36
37 /**
38 * Returns quintic splines from a set of waypoints.
39 *
40 * @param waypoints The waypoints
41 * @return List of quintic splines.
42 */
43 static std::vector<QuinticHermiteSpline> QuinticSplinesFromWaypoints(
44 const std::vector<Pose2d>& waypoints);
45
46 /**
47 * Returns a set of cubic splines corresponding to the provided control
48 * vectors. The user is free to set the direction of the start and end
49 * point. The directions for the middle waypoints are determined
50 * automatically to ensure continuous curvature throughout the path.
51 *
52 * The derivation for the algorithm used can be found here:
53 * <https://www.uio.no/studier/emner/matnat/ifi/nedlagte-emner/INF-MAT4350/h08/undervisningsmateriale/chap7alecture.pdf>
54 *
55 * @param start The starting control vector.
56 * @param waypoints The middle waypoints. This can be left blank if you
57 * only wish to create a path with two waypoints.
58 * @param end The ending control vector.
59 *
60 * @return A vector of cubic hermite splines that interpolate through the
61 * provided waypoints.
62 */
63 static std::vector<CubicHermiteSpline> CubicSplinesFromControlVectors(
64 const Spline<3>::ControlVector& start,
65 std::vector<Translation2d> waypoints,
67
68 /**
69 * Returns a set of quintic splines corresponding to the provided control
70 * vectors. The user is free to set the direction of all waypoints. Continuous
71 * curvature is guaranteed throughout the path.
72 *
73 * @param controlVectors The control vectors.
74 * @return A vector of quintic hermite splines that interpolate through the
75 * provided waypoints.
76 */
77 static std::vector<QuinticHermiteSpline> QuinticSplinesFromControlVectors(
78 const std::vector<Spline<5>::ControlVector>& controlVectors);
79
80 private:
81 static Spline<3>::ControlVector CubicControlVector(double scalar,
82 const Pose2d& point) {
83 return {{point.X().value(), scalar * point.Rotation().Cos()},
84 {point.Y().value(), scalar * point.Rotation().Sin()}};
85 }
86
87 static Spline<5>::ControlVector QuinticControlVector(double scalar,
88 const Pose2d& point) {
89 return {{point.X().value(), scalar * point.Rotation().Cos(), 0.0},
90 {point.Y().value(), scalar * point.Rotation().Sin(), 0.0}};
91 }
92
93 /**
94 * Thomas algorithm for solving tridiagonal systems Af = d.
95 *
96 * @param a the values of A above the diagonal
97 * @param b the values of A on the diagonal
98 * @param c the values of A below the diagonal
99 * @param d the vector on the rhs
100 * @param solutionVector the unknown (solution) vector, modified in-place
101 */
102 static void ThomasAlgorithm(const std::vector<double>& a,
103 const std::vector<double>& b,
104 const std::vector<double>& c,
105 const std::vector<double>& d,
106 std::vector<double>* solutionVector);
107};
108} // namespace frc
#define WPILIB_DLLEXPORT
Definition: SymbolExports.h:36
Represents a 2D pose containing translational and rotational elements.
Definition: Pose2d.h:25
constexpr const Rotation2d & Rotation() const
Returns the underlying rotation.
Definition: Pose2d.h:105
constexpr units::meter_t Y() const
Returns the Y component of the pose's translation.
Definition: Pose2d.h:98
constexpr units::meter_t X() const
Returns the X component of the pose's translation.
Definition: Pose2d.h:91
constexpr double Cos() const
Returns the cosine of the rotation.
Definition: Rotation2d.h:152
constexpr double Sin() const
Returns the sine of the rotation.
Definition: Rotation2d.h:159
Helper class that is used to generate cubic and quintic splines from user provided waypoints.
Definition: SplineHelper.h:21
static std::vector< CubicHermiteSpline > CubicSplinesFromControlVectors(const Spline< 3 >::ControlVector &start, std::vector< Translation2d > waypoints, const Spline< 3 >::ControlVector &end)
Returns a set of cubic splines corresponding to the provided control vectors.
static std::vector< QuinticHermiteSpline > QuinticSplinesFromControlVectors(const std::vector< Spline< 5 >::ControlVector > &controlVectors)
Returns a set of quintic splines corresponding to the provided control vectors.
static wpi::array< Spline< 3 >::ControlVector, 2 > CubicControlVectorsFromWaypoints(const Pose2d &start, const std::vector< Translation2d > &interiorWaypoints, const Pose2d &end)
Returns 2 cubic control vectors from a set of exterior waypoints and interior translations.
static std::vector< QuinticHermiteSpline > QuinticSplinesFromWaypoints(const std::vector< Pose2d > &waypoints)
Returns quintic splines from a set of waypoints.
Represents a two-dimensional parametric spline that interpolates between two points.
Definition: Spline.h:25
This class is a wrapper around std::array that does compile time size checking.
Definition: array.h:26
static EIGEN_DEPRECATED const end_t end
Definition: IndexedViewHelper.h:181
Definition: AprilTagPoseEstimator.h:15
class WPILIB_DLLEXPORT Pose2d
Definition: Transform2d.h:13
static constexpr const velocity::meters_per_second_t c(299792458.0)
Speed of light in vacuum.
unit< std::ratio< 1 >, units::category::scalar_unit > scalar
Definition: base.h:2521
b
Definition: data.h:44