33template <std::same_as<
double>... Ts>
34constexpr Eigen::Matrix<double,
sizeof...(Ts),
sizeof...(Ts)>
CostMatrix(
36 Eigen::Matrix<double,
sizeof...(Ts),
sizeof...(Ts)> result;
38 for (
int row = 0; row < result.rows(); ++row) {
39 for (
int col = 0; col < result.cols(); ++col) {
41 result(row, col) = 0.0;
47 [&](
int i,
double tolerance) {
48 if (tolerance == std::numeric_limits<double>::infinity()) {
51 result(i, i) = 1.0 / (tolerance * tolerance);
74 const std::array<double, N>& costs) {
75 Eigen::Matrix<double, N, N> result;
77 for (
int row = 0; row < result.rows(); ++row) {
78 for (
int col = 0; col < result.cols(); ++col) {
80 if (costs[row] == std::numeric_limits<double>::infinity()) {
81 result(row, col) = 0.0;
83 result(row, col) = 1.0 / (costs[row] * costs[row]);
86 result(row, col) = 0.0;
108 const std::span<const double> costs);
121template <std::same_as<
double>... Ts>
124 Eigen::Matrix<double,
sizeof...(Ts),
sizeof...(Ts)> result;
126 for (
int row = 0; row < result.rows(); ++row) {
127 for (
int col = 0; col < result.cols(); ++col) {
129 result(row, col) = 0.0;
135 [&](
int i,
double stdDev) { result(i, i) = stdDev * stdDev; },
154 const std::array<double, N>& stdDevs) {
155 Eigen::Matrix<double, N, N> result;
157 for (
int row = 0; row < result.rows(); ++row) {
158 for (
int col = 0; col < result.cols(); ++col) {
160 result(row, col) = stdDevs[row] * stdDevs[row];
162 result(row, col) = 0.0;
183 const std::span<const double> stdDevs);
196 const Eigen::Vector<double, Inputs>& u,
double maxMagnitude) {
197 return u * std::min(1.0, maxMagnitude / u.template lpNorm<Eigen::Infinity>());
202 double maxMagnitude);
#define WPILIB_DLLEXPORT
Definition SymbolExports.hpp:36
Definition LinearSystem.hpp:20
constexpr Eigen::Matrix< double, sizeof...(Ts), sizeof...(Ts)> CovarianceMatrix(Ts... stdDevs)
Creates a covariance matrix from the given vector for use with Kalman filters.
Definition StateSpaceUtil.hpp:122
template WPILIB_DLLEXPORT Eigen::VectorXd DesaturateInputVector< Eigen::Dynamic >(const Eigen::VectorXd &u, double maxMagnitude)
constexpr Eigen::Matrix< double, sizeof...(Ts), sizeof...(Ts)> CostMatrix(Ts... tolerances)
Creates a cost matrix from the given vector for use with LQR.
Definition StateSpaceUtil.hpp:34
Eigen::Vector< double, Inputs > DesaturateInputVector(const Eigen::Vector< double, Inputs > &u, double maxMagnitude)
Renormalize all inputs if any exceeds the maximum magnitude.
Definition StateSpaceUtil.hpp:195
constexpr void for_each(F &&f, Ts &&... elems)
Calls f(i, elem) for each element of elems where i is the index of the element in elems and elem is t...
Definition Algorithm.hpp:29