2020-07-24 08:34:30 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) 2019-2020 FIRST. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2020-08-07 09:38:13 -07:00
|
|
|
package edu.wpi.first.math;
|
2020-07-24 08:34:30 -07:00
|
|
|
|
|
|
|
|
import org.ejml.simple.SimpleMatrix;
|
|
|
|
|
|
2020-08-07 09:38:13 -07:00
|
|
|
import edu.wpi.first.wpiutil.math.Matrix;
|
|
|
|
|
|
2020-07-24 08:34:30 -07:00
|
|
|
public final class Drake {
|
|
|
|
|
private Drake() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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(
|
|
|
|
|
SimpleMatrix A,
|
|
|
|
|
SimpleMatrix B,
|
|
|
|
|
SimpleMatrix Q,
|
|
|
|
|
SimpleMatrix R) {
|
|
|
|
|
var S = new SimpleMatrix(A.numRows(), A.numCols());
|
2020-08-07 09:38:13 -07:00
|
|
|
WPIMathJNI.discreteAlgebraicRiccatiEquation(A.getDDRM().getData(), B.getDDRM().getData(),
|
2020-07-24 08:34:30 -07:00
|
|
|
Q.getDDRM().getData(), R.getDDRM().getData(), A.numCols(), B.numCols(),
|
|
|
|
|
S.getDDRM().getData());
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
@SuppressWarnings("ParameterName")
|
|
|
|
|
public static SimpleMatrix discreteAlgebraicRiccatiEquation(
|
|
|
|
|
Matrix A,
|
|
|
|
|
Matrix B,
|
|
|
|
|
Matrix Q,
|
|
|
|
|
Matrix R) {
|
|
|
|
|
return discreteAlgebraicRiccatiEquation(A.getStorage(), B.getStorage(), Q.getStorage(),
|
|
|
|
|
R.getStorage());
|
|
|
|
|
}
|
|
|
|
|
}
|