2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2020-07-24 08:34:30 -07:00
|
|
|
|
2020-08-07 09:38:13 -07:00
|
|
|
package edu.wpi.first.math;
|
2020-07-24 08:34:30 -07:00
|
|
|
|
2020-12-29 22:45:16 -08:00
|
|
|
import org.ejml.simple.SimpleMatrix;
|
2020-08-07 09:38:13 -07:00
|
|
|
|
2020-07-24 08:34:30 -07:00
|
|
|
public final class Drake {
|
2020-12-29 22:45:16 -08:00
|
|
|
private Drake() {}
|
2020-07-24 08:34:30 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Solves the discrete alegebraic Riccati equation.
|
|
|
|
|
*
|
|
|
|
|
* @param A System matrix.
|
|
|
|
|
* @param B Input matrix.
|
|
|
|
|
* @param Q State cost matrix.
|
|
|
|
|
* @param R Input cost matrix.
|
|
|
|
|
* @return Solution of DARE.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings({"LocalVariableName", "ParameterName"})
|
|
|
|
|
public static SimpleMatrix discreteAlgebraicRiccatiEquation(
|
2020-12-29 22:45:16 -08:00
|
|
|
SimpleMatrix A, SimpleMatrix B, SimpleMatrix Q, SimpleMatrix R) {
|
2020-07-24 08:34:30 -07:00
|
|
|
var S = new SimpleMatrix(A.numRows(), A.numCols());
|
2020-12-29 22:45:16 -08:00
|
|
|
WPIMathJNI.discreteAlgebraicRiccatiEquation(
|
|
|
|
|
A.getDDRM().getData(),
|
|
|
|
|
B.getDDRM().getData(),
|
|
|
|
|
Q.getDDRM().getData(),
|
|
|
|
|
R.getDDRM().getData(),
|
|
|
|
|
A.numCols(),
|
|
|
|
|
B.numCols(),
|
|
|
|
|
S.getDDRM().getData());
|
2020-07-24 08:34:30 -07:00
|
|
|
return S;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Solves the discrete alegebraic Riccati equation.
|
|
|
|
|
*
|
|
|
|
|
* @param A System matrix.
|
|
|
|
|
* @param B Input matrix.
|
|
|
|
|
* @param Q State cost matrix.
|
|
|
|
|
* @param R Input cost matrix.
|
|
|
|
|
* @return Solution of DARE.
|
|
|
|
|
*/
|
2020-08-14 23:40:33 -07:00
|
|
|
@SuppressWarnings({"ParameterName", "MethodTypeParameterName"})
|
2020-12-29 22:45:16 -08:00
|
|
|
public static <States extends Num, Inputs extends Num>
|
|
|
|
|
Matrix<States, States> discreteAlgebraicRiccatiEquation(
|
|
|
|
|
Matrix<States, States> A,
|
|
|
|
|
Matrix<States, Inputs> B,
|
|
|
|
|
Matrix<States, States> Q,
|
|
|
|
|
Matrix<Inputs, Inputs> R) {
|
|
|
|
|
return new Matrix<>(
|
|
|
|
|
discreteAlgebraicRiccatiEquation(
|
|
|
|
|
A.getStorage(), B.getStorage(), Q.getStorage(), R.getStorage()));
|
2020-07-24 08:34:30 -07:00
|
|
|
}
|
|
|
|
|
}
|