Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Use cubic spline for initial guess #148

Closed
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
be4d354
add wpi files
bruingineer Apr 8, 2024
914314f
remove json. fix gcem include
bruingineer Apr 8, 2024
0cf5274
added spline initial guess
bruingineer Apr 8, 2024
4328fcf
Update OptimalTrajectoryGenerator.cpp
bruingineer Apr 8, 2024
4cf778e
account for control intervals
bruingineer Apr 8, 2024
4b31685
Update TrajoptUtil.inc
bruingineer Apr 8, 2024
b949f00
Merge branch 'main' into better-initial-guess-wpi-v2
bruingineer Apr 8, 2024
e18109b
spline init guess and rust bind
bruingineer Apr 9, 2024
210698e
debug prints
bruingineer Apr 9, 2024
588d51b
Update TrajoptUtil.inc
bruingineer Apr 9, 2024
fff8dd1
delete unused wpi
bruingineer Apr 9, 2024
40f1c2b
remove old spline init guess
bruingineer Apr 9, 2024
146ee68
Update EigenCore.h
bruingineer Apr 9, 2024
b7fcb9b
fix fn signatures
bruingineer Apr 9, 2024
0806543
add debug rotation
bruingineer Apr 9, 2024
982294b
wrap angle and push back theta
bruingineer Apr 9, 2024
b2dd682
remove prints, rename initialguess
bruingineer Apr 9, 2024
523069a
removing more files
bruingineer Apr 9, 2024
a513309
rename calc init guess (linear / spline)
bruingineer Apr 9, 2024
adc36f2
switch end spline heading
bruingineer Apr 9, 2024
dfd6524
Use FetchContent with allwpilib to avoid copy-paste
calcmogul Apr 9, 2024
5c782c4
Fix wpiformat warnings
calcmogul Apr 9, 2024
be0eb9c
Merge pull request #1 from calcmogul/use-fetchcontent-with-allwpilib
bruingineer Apr 10, 2024
3ee7027
Remove protobuf from WPILib
calcmogul Apr 11, 2024
eee055b
Install Eigen when using CasADi backend
calcmogul Apr 11, 2024
c55b37b
Fix wpimath linkage
calcmogul Apr 11, 2024
f03ab25
Rewrite WPILib patching script in Python
calcmogul Apr 11, 2024
1285978
Run wpiformat
calcmogul Apr 11, 2024
6e27e18
Enable check for git apply subprocess
calcmogul Apr 11, 2024
9c6f7cf
Remove more protobuf files
calcmogul Apr 11, 2024
a1560e1
Remove find_dependency(Protobuf) from wpiutil-config.cmake.in
calcmogul Apr 11, 2024
66a944f
Fix Linux example build
calcmogul Apr 11, 2024
ac2de27
Update TrajoptUtil.inc
bruingineer Apr 11, 2024
39d0e8e
rust api to return holonomic initial guess
bruingineer Apr 15, 2024
6a311f6
Update swerve.rs
bruingineer Apr 16, 2024
3e0c67e
init guess kinematics not implemented
bruingineer Apr 16, 2024
b8e51a8
add spline1d
bruingineer Apr 16, 2024
fb02f42
add pose holonomic spline
bruingineer Apr 16, 2024
0c98a92
Update CubicHermitePoseSplineHolonomic.h
bruingineer Apr 16, 2024
b0eb5c9
fix GenerateSplineInitialGuess arguments
bruingineer Apr 17, 2024
17a359d
Merge branch 'better-initial-guess-wpi-v2' into work-in-progress-init…
bruingineer Apr 17, 2024
b12c1cb
Run wpiformat
calcmogul Apr 17, 2024
b3599bd
Increase build timeout
calcmogul Apr 17, 2024
a91dbd6
added trajectory parameterize. WIP
bruingineer Apr 18, 2024
cae4649
Update SwervePathBuilder.cpp
bruingineer Apr 19, 2024
94e2a88
sample trajectory with current given control intervals
bruingineer Apr 20, 2024
c528786
use trajectory init guess
bruingineer Apr 20, 2024
01983bd
finding access error...
bruingineer Apr 20, 2024
3831abb
add debug prints
bruingineer Apr 20, 2024
daf4551
total time on rust
bruingineer Apr 20, 2024
d303669
fix indexing errors
bruingineer Apr 20, 2024
bf08e90
troubleshoot spline heading
bruingineer Apr 20, 2024
43a39e7
Update CubicHermitePoseSplineHolonomic.h
bruingineer Apr 20, 2024
ed7cedc
updated parameterizer to use the updated getpoint
bruingineer Apr 20, 2024
b42c034
comment prints
bruingineer Apr 20, 2024
1189d37
typo, move dt calc
bruingineer Apr 21, 2024
feac53b
print iterations, up iteration count
bruingineer Apr 21, 2024
14b9c5e
fix end control vector
bruingineer Apr 21, 2024
00d6b2e
print fmt
bruingineer Apr 21, 2024
e30c680
print idx
bruingineer Apr 21, 2024
a7ce083
fix indexing for guess waypoints
bruingineer Apr 21, 2024
4676022
remove comments and prints
bruingineer Apr 21, 2024
cf17781
add dt per sgmt
bruingineer Apr 21, 2024
1e17f21
same dt for all path
bruingineer Apr 21, 2024
29619e9
Merge branch 'better-initial-guess-wpi-v2' into wip-no-prints
bruingineer Apr 21, 2024
3e72c2c
run wpiformat
bruingineer Apr 21, 2024
acd0923
move dt to whole sgmt
bruingineer Apr 21, 2024
908826b
Merge branch 'main' into work-in-progress-init-guess
bruingineer Apr 21, 2024
fbc04b6
Merge branch 'main' into better-initial-guess-wpi-v2
bruingineer Apr 21, 2024
76448d1
Merge branch 'work-in-progress-init-guess' into better-initial-guess-…
bruingineer Apr 21, 2024
c63d6bb
wpiformat
bruingineer Apr 21, 2024
54a6db5
uncomment swerve.rs
bruingineer Apr 21, 2024
83c097f
dt doesn't work with init guess points
bruingineer Apr 21, 2024
d506ac7
prints and state indexing
bruingineer Apr 21, 2024
0fa599d
fix whole sgmt points count
bruingineer Apr 22, 2024
4ff9ed7
wpiformat
bruingineer Apr 22, 2024
1089b77
wpiformat
bruingineer Apr 22, 2024
49b78ec
fix another init guess point index issue
bruingineer Apr 22, 2024
42fdbbe
add prints
bruingineer Apr 23, 2024
8e3ed0c
wrap headings of sampled init guess
bruingineer Apr 23, 2024
b6dc225
delete comments
bruingineer Apr 23, 2024
187028c
remove comments
bruingineer Apr 23, 2024
211a3c7
remove unused fn
bruingineer Apr 23, 2024
96b4bbb
Update swerve.rs
bruingineer Apr 23, 2024
2db063e
Fix compiler warnings
calcmogul Apr 24, 2024
6b84ccd
Run cargo fmt
calcmogul Apr 24, 2024
05e6f29
Suppress unknown pragma warnings on MinGW
calcmogul Apr 24, 2024
e00b275
Fix clang-tidy warnings
calcmogul Apr 24, 2024
0bfd0f8
Ignore unknown pragmas in wpiutil
calcmogul Apr 24, 2024
f76508e
Make wpiutil emscripten backtrace a no-op
calcmogul Apr 24, 2024
2b46242
Merge branch 'main' into better-initial-guess-wpi-v2
calcmogul Apr 24, 2024
f88645e
Fix -Wno-unknown-pragmas guard
calcmogul Apr 24, 2024
864c151
Don't compress debug info with MinGW
calcmogul Apr 24, 2024
451f098
Try to fix debug info compression
calcmogul Apr 24, 2024
d815307
Try to remove -gz=zlib option
calcmogul Apr 24, 2024
9c460af
Remove -gz=none option
calcmogul Apr 24, 2024
3baae3b
Run wpiformat
calcmogul Apr 24, 2024
4c4b7ee
add kinematics to init guess
bruingineer Apr 24, 2024
ca204dc
link wpiutil to rust
bruingineer Apr 24, 2024
413dbe9
switch wpiutil order in build.rs
bruingineer Apr 24, 2024
74febce
fix init guess index sampling. make poseSpline hold a cubic instead o…
bruingineer Apr 25, 2024
30b5d5d
Run wpiformat
calcmogul Apr 25, 2024
a04bb57
Merge branch 'main' into better-initial-guess-wpi-v2
bruingineer Apr 25, 2024
c5b793a
inc iterations, move print dt addition
bruingineer Apr 25, 2024
a996bbd
Update SwervePathBuilder.cpp
bruingineer Apr 25, 2024
b66b2d6
Update SwervePathBuilder.cpp
bruingineer Apr 25, 2024
d0b3016
traj per sgmt
bruingineer Apr 27, 2024
e2fa1db
Merge branch 'send-new-control-intervals-to-choreo' into apply-constr…
bruingineer Apr 27, 2024
ebdddd6
Update SwervePathBuilder.cpp
bruingineer Apr 27, 2024
bcb0f8b
Update SwervePathBuilder.cpp
bruingineer Apr 27, 2024
b720e85
super messy wip
bruingineer Apr 29, 2024
3617b5b
refactor init guess spline fn
bruingineer May 7, 2024
8c53512
refactor updates
bruingineer May 9, 2024
b3633f2
refactor spline util
bruingineer May 9, 2024
3ab68e8
update swerve path builder
bruingineer May 9, 2024
0cdf62f
Merge branch 'main' into send-new-control-intervals-to-choreo
bruingineer May 9, 2024
7d96aed
Merge branch 'main' into send-new-control-intervals-to-choreo
bruingineer May 9, 2024
e8cbfb9
remove includes
bruingineer May 9, 2024
f6a50fb
Update SwervePathBuilder.cpp
bruingineer May 9, 2024
410c78e
wpiformat
bruingineer May 9, 2024
c0bcc3a
wpiformat
bruingineer May 9, 2024
963c2bd
Update SwervePathBuilder.cpp
bruingineer May 9, 2024
8d1da90
fix typo
bruingineer May 17, 2024
cf1121c
restore set int count on rust
bruingineer May 17, 2024
bb490fc
build.rs add wpimath and wpiutil
bruingineer May 17, 2024
a2c7bf5
Update SwervePathBuilder.cpp
bruingineer May 17, 2024
a633371
trajectories between all points
bruingineer May 17, 2024
1d0cd69
fix comments and prints
bruingineer May 20, 2024
2d584b5
working
bruingineer May 21, 2024
1297553
Merge branch 'main' into send-new-control-intervals-to-choreo
bruingineer May 21, 2024
b139657
Merge branch 'main' into better-initial-guess-wpi-v2
bruingineer May 21, 2024
58ef24e
Merge branch 'better-initial-guess-wpi-v2' into send-new-control-inte…
bruingineer May 21, 2024
2764b1b
Merge branch 'main' into better-initial-guess-wpi-v2
bruingineer Jun 20, 2024
f72b955
Update SwervePathBuilder.cpp
bruingineer Jun 20, 2024
2efed95
Increase CI timeouts
calcmogul Jun 20, 2024
729b74b
Increase native build CI timeout more
calcmogul Jun 20, 2024
d400e38
Merge branch 'main' into better-initial-guess-wpi-v2
calcmogul Jun 20, 2024
b25a904
Remove casadi if statement
calcmogul Jun 20, 2024
c2e2e35
Disable psabi warning
calcmogul Jun 20, 2024
83879b5
Disable psabi warning in wpimath build
calcmogul Jun 20, 2024
a6274f0
Set number of jobs to 4
calcmogul Jun 20, 2024
4974655
Merge branch 'main' into better-initial-guess-wpi-v2
calcmogul Jun 21, 2024
748dd18
Reduce build timeout
calcmogul Jun 21, 2024
8c58da8
Upgrade WPIMath
calcmogul Jun 21, 2024
f8ce53e
Add comment about WPIMath revision
calcmogul Jun 21, 2024
a0e32a0
Remove find_dependency(Protobuf) line from wpiutil
calcmogul Jun 21, 2024
40325b8
Remove more protobuf stuff
calcmogul Jun 21, 2024
1f059fb
Merge branch 'main' into better-initial-guess-wpi-v2
calcmogul Jun 21, 2024
b0fd9e7
Clean up includes
calcmogul Jun 21, 2024
5878e5d
Merge branch 'main' into better-initial-guess-wpi-v2
calcmogul Jun 21, 2024
c5bdff7
Merge branch 'main' into better-initial-guess-wpi-v2
bruingineer Jun 25, 2024
2cdb72a
Initial Guess Point to Pose2d. Constraint members const public
bruingineer Jun 25, 2024
f97a6aa
building, spline guess needs to be fixed
bruingineer Jun 25, 2024
e4e2901
Merge branch 'main' into better-initial-guess-wpi-v2
calcmogul Jun 25, 2024
74efa9b
Run wpiformat
calcmogul Jun 25, 2024
fefe591
Fix Doxygen warnings
calcmogul Jun 25, 2024
ff86e74
Fix Linux compilation errors
calcmogul Jun 25, 2024
bbed620
Merge branch 'main' into better-initial-guess-wpi-v2
calcmogul Jun 25, 2024
6d717da
Cleanup
calcmogul Jun 25, 2024
f8598cf
fix sample index
bruingineer Jun 25, 2024
adb2f53
format
bruingineer Jun 25, 2024
9b24db4
Merge branch 'main' into better-initial-guess-wpi-v2
bruingineer Jun 29, 2024
e94f7f4
clean up
bruingineer Jun 29, 2024
5fb02f0
move spline guess to util
bruingineer Jun 29, 2024
8366504
WIP refactor spline guess
bruingineer Jun 29, 2024
b9be9ab
fix control interval return ref
bruingineer Jun 29, 2024
1c2f6e1
spline refactor
bruingineer Jul 1, 2024
1b297c6
Update GenerateSplineInitialGuess.hpp
bruingineer Jul 1, 2024
d9b5c6f
size_t in for loop
bruingineer Jul 1, 2024
6736b33
Update GenerateSplineInitialGuess.hpp
bruingineer Jul 1, 2024
cb5efb6
initialize all fields in swervesolution
bruingineer Jul 1, 2024
7b9e6e9
Merge branch 'main' into better-initial-guess-wpi-v2
calcmogul Jul 2, 2024
6a4130a
Fix #include sorting
calcmogul Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 23 additions & 0 deletions include/frc/EigenCore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#pragma once

#include <Eigen/Core>

namespace frc {

template <int Size>
using Vectord = Eigen::Vector<double, Size>;

template <int Rows, int Cols,
int Options = Eigen::AutoAlign |
((Rows == 1 && Cols != 1) ? Eigen::RowMajor
: (Cols == 1 && Rows != 1)
? Eigen::ColMajor
: EIGEN_DEFAULT_MATRIX_STORAGE_ORDER_OPTION),
int MaxRows = Rows, int MaxCols = Cols>
using Matrixd = Eigen::Matrix<double, Rows, Cols, Options, MaxRows, MaxCols>;

} // namespace frc
172 changes: 172 additions & 0 deletions include/frc/MathUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#pragma once

#include <numbers>
#include <type_traits>

#include "trajopt/SymbolExports.h"

#include "units/angle.h"
#include "units/base.h"
#include "units/math.h"

namespace frc {

/**
* Returns 0.0 if the given value is within the specified range around zero. The
* remaining range between the deadband and the maximum magnitude is scaled from
* 0.0 to the maximum magnitude.
*
* @param value Value to clip.
* @param deadband Range around zero.
* @param maxMagnitude The maximum magnitude of the input (defaults to 1). Can
* be infinite.
* @return The value after the deadband is applied.
*/
template <typename T>
requires std::is_arithmetic_v<T> || units::traits::is_unit_t_v<T>
T ApplyDeadband(T value, T deadband, T maxMagnitude = T{1.0}) {
T magnitude;
if constexpr (std::is_arithmetic_v<T>) {
magnitude = std::abs(value);
} else {
magnitude = units::math::abs(value);
}

if (magnitude > deadband) {
if (maxMagnitude / deadband > 1.0E12) {
// If max magnitude is sufficiently large, the implementation encounters
// roundoff error. Implementing the limiting behavior directly avoids
// the problem.
return value > T{0.0} ? value - deadband : value + deadband;
}
if (value > T{0.0}) {
// Map deadband to 0 and map max to max.
//
// y - y₁ = m(x - x₁)
// y - y₁ = (y₂ - y₁)/(x₂ - x₁) (x - x₁)
// y = (y₂ - y₁)/(x₂ - x₁) (x - x₁) + y₁
//
// (x₁, y₁) = (deadband, 0) and (x₂, y₂) = (max, max).
// x₁ = deadband
// y₁ = 0
// x₂ = max
// y₂ = max
//
// y = (max - 0)/(max - deadband) (x - deadband) + 0
// y = max/(max - deadband) (x - deadband)
// y = max (x - deadband)/(max - deadband)
return maxMagnitude * (value - deadband) / (maxMagnitude - deadband);
} else {
// Map -deadband to 0 and map -max to -max.
//
// y - y₁ = m(x - x₁)
// y - y₁ = (y₂ - y₁)/(x₂ - x₁) (x - x₁)
// y = (y₂ - y₁)/(x₂ - x₁) (x - x₁) + y₁
//
// (x₁, y₁) = (-deadband, 0) and (x₂, y₂) = (-max, -max).
// x₁ = -deadband
// y₁ = 0
// x₂ = -max
// y₂ = -max
//
// y = (-max - 0)/(-max + deadband) (x + deadband) + 0
// y = max/(max - deadband) (x + deadband)
// y = max (x + deadband)/(max - deadband)
return maxMagnitude * (value + deadband) / (maxMagnitude - deadband);
}
} else {
return T{0.0};
}
}

/**
* Returns modulus of input.
*
* @param input Input value to wrap.
* @param minimumInput The minimum value expected from the input.
* @param maximumInput The maximum value expected from the input.
*/
template <typename T>
constexpr T InputModulus(T input, T minimumInput, T maximumInput) {
T modulus = maximumInput - minimumInput;

// Wrap input if it's above the maximum input
int numMax = (input - minimumInput) / modulus;
input -= numMax * modulus;

// Wrap input if it's below the minimum input
int numMin = (input - maximumInput) / modulus;
input -= numMin * modulus;

return input;
}

/**
* Checks if the given value matches an expected value within a certain
* tolerance.
*
* @param expected The expected value
* @param actual The actual value
* @param tolerance The allowed difference between the actual and the expected
* value
* @return Whether or not the actual value is within the allowed tolerance
*/
template <typename T>
requires std::is_arithmetic_v<T> || units::traits::is_unit_t_v<T>
constexpr bool IsNear(T expected, T actual, T tolerance) {
if constexpr (std::is_arithmetic_v<T>) {
return std::abs(expected - actual) < tolerance;
} else {
return units::math::abs(expected - actual) < tolerance;
}
}

/**
* Checks if the given value matches an expected value within a certain
* tolerance. Supports continuous input for cases like absolute encoders.
*
* Continuous input means that the min and max value are considered to be the
* same point, and tolerances can be checked across them. A common example
* would be for absolute encoders: calling isNear(2, 359, 5, 0, 360) returns
* true because 359 is 1 away from 360 (which is treated as the same as 0) and
* 2 is 2 away from 0, adding up to an error of 3 degrees, which is within the
* given tolerance of 5.
*
* @param expected The expected value
* @param actual The actual value
* @param tolerance The allowed difference between the actual and the expected
* value
* @param min Smallest value before wrapping around to the largest value
* @param max Largest value before wrapping around to the smallest value
* @return Whether or not the actual value is within the allowed tolerance
*/
template <typename T>
requires std::is_arithmetic_v<T> || units::traits::is_unit_t_v<T>
constexpr bool IsNear(T expected, T actual, T tolerance, T min, T max) {
T errorBound = (max - min) / 2.0;
T error = frc::InputModulus<T>(expected - actual, -errorBound, errorBound);

if constexpr (std::is_arithmetic_v<T>) {
return std::abs(error) < tolerance;
} else {
return units::math::abs(error) < tolerance;
}
}

/**
* Wraps an angle to the range -pi to pi radians (-180 to 180 degrees).
*
* @param angle Angle to wrap.
*/
TRAJOPT_DLLEXPORT
constexpr units::radian_t AngleModulus(units::radian_t angle) {
return InputModulus<units::radian_t>(angle,
units::radian_t{-std::numbers::pi},
units::radian_t{std::numbers::pi});
}

} // namespace frc
100 changes: 100 additions & 0 deletions include/frc/array.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#pragma once

#include <array>
#include <concepts>
#include <cstddef>
#include <tuple>
#include <utility>

namespace wpi {

struct empty_array_t {};
constexpr empty_array_t empty_array;

/**
* This class is a wrapper around std::array that does compile time size
* checking.
*
* std::array's implicit constructor can result in uninitialized elements if the
* number of arguments doesn't match the std::array size.
*/
template <typename T, size_t N>
class array : public std::array<T, N> {
public:
constexpr explicit array(empty_array_t) {}

template <std::convertible_to<T>... Ts>
requires(1 + sizeof...(Ts) == N)
constexpr array(T arg, Ts&&... args) // NOLINT
: std::array<T, N>{std::forward<T>(arg), std::forward<Ts>(args)...} {}

constexpr array(const array<T, N>&) = default;
constexpr array& operator=(const array<T, N>&) = default;
constexpr array(array<T, N>&&) = default;
constexpr array& operator=(array<T, N>&&) = default;

constexpr array(const std::array<T, N>& rhs) { // NOLINT
*static_cast<std::array<T, N>*>(this) = rhs;
}

constexpr array& operator=(const std::array<T, N>& rhs) {
*static_cast<std::array<T, N>*>(this) = rhs;
return *this;
}

constexpr array(std::array<T, N>&& rhs) { // NOLINT
*static_cast<std::array<T, N>*>(this) = rhs;
}

constexpr array& operator=(std::array<T, N>&& rhs) {
*static_cast<std::array<T, N>*>(this) = rhs;
return *this;
}
};

template <typename T, std::convertible_to<T>... Ts>
array(T, Ts...) -> array<T, 1 + sizeof...(Ts)>;

} // namespace wpi

template <size_t I, typename T, size_t N>
requires(I < N)
constexpr T& get(wpi::array<T, N>& arr) noexcept {
return std::get<I>(static_cast<std::array<T, N>>(arr));
}

template <size_t I, typename T, size_t N>
requires(I < N)
constexpr T&& get(wpi::array<T, N>&& arr) noexcept {
return std::move(std::get<I>(arr));
}

template <size_t I, typename T, size_t N>
requires(I < N)
constexpr const T& get(const wpi::array<T, N>& arr) noexcept {
return std::get<I>(static_cast<std::array<T, N>>(arr));
}

template <size_t I, typename T, size_t N>
requires(I < N)
constexpr const T&& get(const wpi::array<T, N>&& arr) noexcept {
return std::move(std::get<I>(arr));
}

// Enables structured bindings
namespace std { // NOLINT
// Partial specialization for wpi::array
template <typename T, size_t N>
struct tuple_size<wpi::array<T, N>> : public integral_constant<size_t, N> {};

// Partial specialization for wpi::array
template <size_t I, typename T, size_t N>
requires(I < N)
struct tuple_element<I, wpi::array<T, N>> {
using type = T;
};
} // namespace std
Loading
Loading