mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Merge branch 'main' into 2022
This commit is contained in:
@@ -104,6 +104,9 @@ class LinearFilter {
|
||||
* y[n] = (1 - gain) * x[n] + gain * y[n-1]<br>
|
||||
* where gain = e<sup>-dt / T</sup>, T is the time constant in seconds
|
||||
*
|
||||
* Note: T = 1 / (2 pi f) where f is the cutoff frequency in Hz, the frequency
|
||||
* above which the input starts to attenuate.
|
||||
*
|
||||
* This filter is stable for time constants greater than zero.
|
||||
*
|
||||
* @param timeConstant The discrete-time time constant in seconds.
|
||||
@@ -121,6 +124,9 @@ class LinearFilter {
|
||||
* y[n] = gain * x[n] + (-gain) * x[n-1] + gain * y[n-1]<br>
|
||||
* where gain = e<sup>-dt / T</sup>, T is the time constant in seconds
|
||||
*
|
||||
* Note: T = 1 / (2 pi f) where f is the cutoff frequency in Hz, the frequency
|
||||
* below which the input starts to attenuate.
|
||||
*
|
||||
* This filter is stable for time constants greater than zero.
|
||||
*
|
||||
* @param timeConstant The discrete-time time constant in seconds.
|
||||
|
||||
@@ -52,6 +52,27 @@ class CubicHermiteSpline : public Spline<3> {
|
||||
* @return The hermite basis matrix for cubic hermite spline interpolation.
|
||||
*/
|
||||
static Eigen::Matrix<double, 4, 4> MakeHermiteBasis() {
|
||||
// Given P(i), P'(i), P(i+1), P'(i+1), the control vectors, we want to find
|
||||
// the coefficients of the spline P(t) = a3 * t^3 + a2 * t^2 + a1 * t + a0.
|
||||
//
|
||||
// P(i) = P(0) = a0
|
||||
// P'(i) = P'(0) = a1
|
||||
// P(i+1) = P(1) = a3 + a2 + a1 + a0
|
||||
// P'(i+1) = P'(1) = 3 * a3 + 2 * a2 + a1
|
||||
//
|
||||
// [ P(i) ] = [ 0 0 0 1 ][ a3 ]
|
||||
// [ P'(i) ] = [ 0 0 1 0 ][ a2 ]
|
||||
// [ P(i+1) ] = [ 1 1 1 1 ][ a1 ]
|
||||
// [ P'(i+1) ] = [ 3 2 1 0 ][ a0 ]
|
||||
//
|
||||
// To solve for the coefficients, we can invert the 4x4 matrix and move it
|
||||
// to the other side of the equation.
|
||||
//
|
||||
// [ a3 ] = [ 2 1 -2 1 ][ P(i) ]
|
||||
// [ a2 ] = [ -3 -2 3 -1 ][ P'(i) ]
|
||||
// [ a1 ] = [ 0 1 0 0 ][ P(i+1) ]
|
||||
// [ a0 ] = [ 1 0 0 0 ][ P'(i+1) ]
|
||||
|
||||
// clang-format off
|
||||
static auto basis = (Eigen::Matrix<double, 4, 4>() <<
|
||||
+2.0, +1.0, -2.0, +1.0,
|
||||
|
||||
@@ -52,10 +52,38 @@ class QuinticHermiteSpline : public Spline<5> {
|
||||
* @return The hermite basis matrix for quintic hermite spline interpolation.
|
||||
*/
|
||||
static Eigen::Matrix<double, 6, 6> MakeHermiteBasis() {
|
||||
// Given P(i), P'(i), P''(i), P(i+1), P'(i+1), P''(i+1), the control
|
||||
// vectors, we want to find the coefficients of the spline
|
||||
// P(t) = a5 * t^5 + a4 * t^4 + a3 * t^3 + a2 * t^2 + a1 * t + a0.
|
||||
//
|
||||
// P(i) = P(0) = a0
|
||||
// P'(i) = P'(0) = a1
|
||||
// P''(i) = P''(0) = 2 * a2
|
||||
// P(i+1) = P(1) = a5 + a4 + a3 + a2 + a1 + a0
|
||||
// P'(i+1) = P'(1) = 5 * a5 + 4 * a4 + 3 * a3 + 2 * a2 + a1
|
||||
// P''(i+1) = P''(1) = 20 * a5 + 12 * a4 + 6 * a3 + 2 * a2
|
||||
//
|
||||
// [ P(i) ] = [ 0 0 0 0 0 1 ][ a5 ]
|
||||
// [ P'(i) ] = [ 0 0 0 0 1 0 ][ a4 ]
|
||||
// [ P''(i) ] = [ 0 0 0 2 0 0 ][ a3 ]
|
||||
// [ P(i+1) ] = [ 1 1 1 1 1 1 ][ a2 ]
|
||||
// [ P'(i+1) ] = [ 5 4 3 2 1 0 ][ a1 ]
|
||||
// [ P''(i+1) ] = [ 20 12 6 2 0 0 ][ a0 ]
|
||||
//
|
||||
// To solve for the coefficients, we can invert the 6x6 matrix and move it
|
||||
// to the other side of the equation.
|
||||
//
|
||||
// [ a5 ] = [ -6.0 -3.0 -0.5 6.0 -3.0 0.5 ][ P(i) ]
|
||||
// [ a4 ] = [ 15.0 8.0 1.5 -15.0 7.0 -1.0 ][ P'(i) ]
|
||||
// [ a3 ] = [ -10.0 -6.0 -1.5 10.0 -4.0 0.5 ][ P''(i) ]
|
||||
// [ a2 ] = [ 0.0 0.0 0.5 0.0 0.0 0.0 ][ P(i+1) ]
|
||||
// [ a1 ] = [ 0.0 1.0 0.0 0.0 0.0 0.0 ][ P'(i+1) ]
|
||||
// [ a0 ] = [ 1.0 0.0 0.0 0.0 0.0 0.0 ][ P''(i+1) ]
|
||||
|
||||
// clang-format off
|
||||
static const auto basis = (Eigen::Matrix<double, 6, 6>() <<
|
||||
-06.0, -03.0, -00.5, +06.0, -03.0, +00.5,
|
||||
+15.0, +08.0, +01.5, -15.0, +07.0, +01.0,
|
||||
+15.0, +08.0, +01.5, -15.0, +07.0, -01.0,
|
||||
-10.0, -06.0, -01.5, +10.0, -04.0, +00.5,
|
||||
+00.0, +00.0, +00.5, +00.0, +00.0, +00.0,
|
||||
+00.0, +01.0, +00.0, +00.0, +00.0, +00.0,
|
||||
|
||||
@@ -36,19 +36,19 @@ class TrajectoryUtil {
|
||||
static Trajectory FromPathweaverJson(const wpi::Twine& path);
|
||||
|
||||
/**
|
||||
* Deserializes a Trajectory from PathWeaver-style JSON.
|
||||
|
||||
* @param json the string containing the serialized JSON
|
||||
|
||||
* @return the trajectory represented by the JSON
|
||||
*/
|
||||
* Deserializes a Trajectory from PathWeaver-style JSON.
|
||||
*
|
||||
* @param json the string containing the serialized JSON
|
||||
*
|
||||
* @return the trajectory represented by the JSON
|
||||
*/
|
||||
static std::string SerializeTrajectory(const Trajectory& trajectory);
|
||||
|
||||
/**
|
||||
* Serializes a Trajectory to PathWeaver-style JSON.
|
||||
|
||||
*
|
||||
* @param trajectory the trajectory to export
|
||||
|
||||
*
|
||||
* @return the string containing the serialized JSON
|
||||
*/
|
||||
static Trajectory DeserializeTrajectory(wpi::StringRef json_str);
|
||||
|
||||
Reference in New Issue
Block a user