WPILibC++ 2023.4.3-108-ge5452e3
DARE.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 <wpi/SymbolExports.h>
8
9#include "Eigen/Core"
10
11namespace frc {
12
13/**
14 *
15 * Computes the unique stabilizing solution X to the discrete-time algebraic
16 * Riccati equation:
17 *
18 * AᵀXA − X − AᵀXB(BᵀXB + R)⁻¹BᵀXA + Q = 0
19 *
20 * @param A The system matrix.
21 * @param B The input matrix.
22 * @param Q The state cost matrix.
23 * @param R The input cost matrix.
24 * @throws std::invalid_argument if number of inputs is greater than number of
25 * states.
26 * @throws std::invalid_argument if Q isn't symmetric positive semidefinite.
27 * @throws std::invalid_argument if R isn't symmetric positive definite.
28 * @throws std::invalid_argument if the (A, B) pair isn't stabilizable.
29 * @throws std::invalid_argument if the (A, C) pair where Q = CᵀC isn't
30 * detectable.
31 */
33Eigen::MatrixXd DARE(const Eigen::Ref<const Eigen::MatrixXd>& A,
37
38/**
39Computes the unique stabilizing solution X to the discrete-time algebraic
40Riccati equation:
41
42 AᵀXA − X − (AᵀXB + N)(BᵀXB + R)⁻¹(BᵀXA + Nᵀ) + Q = 0
43
44This overload of the DARE is useful for finding the control law uₖ that
45minimizes the following cost function subject to xₖ₊₁ = Axₖ + Buₖ.
46
47@verbatim
48 ∞ [xₖ]ᵀ[Q N][xₖ]
49J = Σ [uₖ] [Nᵀ R][uₖ] ΔT
50 k=0
51@endverbatim
52
53This is a more general form of the following. The linear-quadratic regulator
54is the feedback control law uₖ that minimizes the following cost function
55subject to xₖ₊₁ = Axₖ + Buₖ:
56
57@verbatim
58
59J = Σ (xₖᵀQxₖ + uₖᵀRuₖ) ΔT
60 k=0
61@endverbatim
62
63This can be refactored as:
64
65@verbatim
66 ∞ [xₖ]ᵀ[Q 0][xₖ]
67J = Σ [uₖ] [0 R][uₖ] ΔT
68 k=0
69@endverbatim
70
71@param A The system matrix.
72@param B The input matrix.
73@param Q The state cost matrix.
74@param R The input cost matrix.
75@param N The state-input cross cost matrix.
76@throws std::invalid_argument if number of inputs is greater than number of
77 states.
78@throws std::invalid_argument if Q − NR⁻¹Nᵀ isn't symmetric positive
79 semidefinite.
80@throws std::invalid_argument if R isn't symmetric positive definite.
81@throws std::invalid_argument if the (A, B) pair isn't stabilizable.
82@throws std::invalid_argument if the (A, C) pair where Q = CᵀC isn't detectable.
83*/
85Eigen::MatrixXd DARE(const Eigen::Ref<const Eigen::MatrixXd>& A,
90
91} // namespace frc
#define WPILIB_DLLEXPORT
Definition: SymbolExports.h:36
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:283
Definition: AprilTagPoseEstimator.h:15
WPILIB_DLLEXPORT Eigen::MatrixXd DARE(const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::MatrixXd > &B, const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::MatrixXd > &R)
Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation:
static constexpr const unit_t< compound_unit< energy::joules, inverse< temperature::kelvin >, inverse< substance::moles > > > R(8.3144598)
Gas constant.