mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Catch incorrect parameters to state-space models earlier (#3680)
This allows giving more descriptive exceptions than if they are thrown later in KalmanFilter, for example. Fixes #3678.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Eigen/Core"
|
||||
#include "frc/StateSpaceUtil.h"
|
||||
@@ -32,11 +33,33 @@ class LinearSystem {
|
||||
* @param B Input matrix.
|
||||
* @param C Output matrix.
|
||||
* @param D Feedthrough matrix.
|
||||
* @throws std::domain_error if any matrix element isn't finite.
|
||||
*/
|
||||
LinearSystem(const Eigen::Matrix<double, States, States>& A,
|
||||
const Eigen::Matrix<double, States, Inputs>& B,
|
||||
const Eigen::Matrix<double, Outputs, States>& C,
|
||||
const Eigen::Matrix<double, Outputs, Inputs>& D) {
|
||||
if (!A.allFinite()) {
|
||||
throw std::domain_error(
|
||||
"Elements of A aren't finite. This is usually due to model "
|
||||
"implementation errors.");
|
||||
}
|
||||
if (!B.allFinite()) {
|
||||
throw std::domain_error(
|
||||
"Elements of B aren't finite. This is usually due to model "
|
||||
"implementation errors.");
|
||||
}
|
||||
if (!C.allFinite()) {
|
||||
throw std::domain_error(
|
||||
"Elements of C aren't finite. This is usually due to model "
|
||||
"implementation errors.");
|
||||
}
|
||||
if (!D.allFinite()) {
|
||||
throw std::domain_error(
|
||||
"Elements of D aren't finite. This is usually due to model "
|
||||
"implementation errors.");
|
||||
}
|
||||
|
||||
m_A = A;
|
||||
m_B = B;
|
||||
m_C = C;
|
||||
|
||||
Reference in New Issue
Block a user