mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[wpimath] Reorganize LinearSystem factories (#8468)
This commit is contained in:
@@ -11,10 +11,10 @@
|
||||
#include "wpi/math/controller/LinearQuadraticRegulator.hpp"
|
||||
#include "wpi/math/estimator/KalmanFilter.hpp"
|
||||
#include "wpi/math/linalg/EigenCore.hpp"
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
#include "wpi/math/system/LinearSystem.hpp"
|
||||
#include "wpi/math/system/LinearSystemLoop.hpp"
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
#include "wpi/units/time.hpp"
|
||||
|
||||
namespace wpi::math {
|
||||
@@ -36,7 +36,8 @@ class StateSpaceTest : public testing::Test {
|
||||
// Gear ratio
|
||||
constexpr double G = 40.0 / 40.0;
|
||||
|
||||
return wpi::math::LinearSystemId::ElevatorSystem(motors, m, r, G).Slice(0);
|
||||
return wpi::math::Models::ElevatorFromPhysicalConstants(motors, m, r, G)
|
||||
.Slice(0);
|
||||
}();
|
||||
LinearQuadraticRegulator<2, 1> controller{plant, {0.02, 0.4}, {12.0}, kDt};
|
||||
KalmanFilter<2, 1, 1> observer{plant, {0.05, 1.0}, {0.0001}, kDt};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
#include "wpi/units/math.hpp"
|
||||
|
||||
namespace wpi::math {
|
||||
@@ -19,8 +19,8 @@ TEST(DifferentialDriveAccelerationLimiterTest, LowLimits) {
|
||||
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
auto plant = LinearSystemId::IdentifyDrivetrainSystem(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
auto plant = Models::DifferentialDriveFromSysId(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
|
||||
DifferentialDriveAccelerationLimiter accelLimiter{plant, trackwidth, maxA,
|
||||
maxAlpha};
|
||||
@@ -111,8 +111,8 @@ TEST(DifferentialDriveAccelerationLimiterTest, HighLimits) {
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
|
||||
auto plant = LinearSystemId::IdentifyDrivetrainSystem(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
auto plant = Models::DifferentialDriveFromSysId(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
|
||||
// Limits are so high, they don't get hit, so states of constrained and
|
||||
// unconstrained systems should match
|
||||
@@ -181,8 +181,8 @@ TEST(DifferentialDriveAccelerationLimiterTest, SeparateMinMaxLowLimits) {
|
||||
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
auto plant = LinearSystemId::IdentifyDrivetrainSystem(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
auto plant = Models::DifferentialDriveFromSysId(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
|
||||
DifferentialDriveAccelerationLimiter accelLimiter{plant, trackwidth, minA,
|
||||
maxA, maxAlpha};
|
||||
@@ -240,8 +240,8 @@ TEST(DifferentialDriveAccelerationLimiterTest, SeparateMinMaxLowLimits) {
|
||||
TEST(DifferentialDriveAccelerationLimiterTest, MinAccelGreaterThanMaxAccel) {
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
auto plant = LinearSystemId::IdentifyDrivetrainSystem(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
auto plant = Models::DifferentialDriveFromSysId(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
EXPECT_NO_THROW({
|
||||
DifferentialDriveAccelerationLimiter accelLimiter(plant, 1_m, 1_mps_sq,
|
||||
1_rad_per_s_sq);
|
||||
|
||||
@@ -4,13 +4,10 @@
|
||||
|
||||
#include "wpi/math/controller/DifferentialDriveFeedforward.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/controller/LinearPlantInversionFeedforward.hpp"
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
#include "wpi/units/acceleration.hpp"
|
||||
#include "wpi/units/length.hpp"
|
||||
#include "wpi/units/time.hpp"
|
||||
@@ -26,7 +23,7 @@ TEST(DifferentialDriveFeedforwardTest, CalculateWithTrackwidth) {
|
||||
wpi::math::DifferentialDriveFeedforward differentialDriveFeedforward{
|
||||
kVLinear, kALinear, kVAngular, kAAngular, trackwidth};
|
||||
wpi::math::LinearSystem<2, 2, 2> plant =
|
||||
wpi::math::LinearSystemId::IdentifyDrivetrainSystem(
|
||||
wpi::math::Models::DifferentialDriveFromSysId(
|
||||
kVLinear, kALinear, kVAngular, kAAngular, trackwidth);
|
||||
for (auto currentLeftVelocity = -4_mps; currentLeftVelocity <= 4_mps;
|
||||
currentLeftVelocity += 2_mps) {
|
||||
@@ -60,8 +57,8 @@ TEST(DifferentialDriveFeedforwardTest, CalculateWithoutTrackwidth) {
|
||||
wpi::math::DifferentialDriveFeedforward differentialDriveFeedforward{
|
||||
kVLinear, kALinear, kVAngular, kAAngular};
|
||||
wpi::math::LinearSystem<2, 2, 2> plant =
|
||||
wpi::math::LinearSystemId::IdentifyDrivetrainSystem(kVLinear, kALinear,
|
||||
kVAngular, kAAngular);
|
||||
wpi::math::Models::DifferentialDriveFromSysId(kVLinear, kALinear,
|
||||
kVAngular, kAAngular);
|
||||
for (auto currentLeftVelocity = -4_mps; currentLeftVelocity <= 4_mps;
|
||||
currentLeftVelocity += 2_mps) {
|
||||
for (auto currentRightVelocity = -4_mps; currentRightVelocity <= 4_mps;
|
||||
|
||||
@@ -4,15 +4,13 @@
|
||||
|
||||
#include "wpi/math/controller/ElevatorFeedforward.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/controller/LinearPlantInversionFeedforward.hpp"
|
||||
#include "wpi/math/linalg/EigenCore.hpp"
|
||||
#include "wpi/units/acceleration.hpp"
|
||||
#include "wpi/units/length.hpp"
|
||||
#include "wpi/units/time.hpp"
|
||||
#include "wpi/units/velocity.hpp"
|
||||
|
||||
static constexpr auto Ks = 0.5_V;
|
||||
static constexpr auto Kv = 1.5_V * 1_s / 1_m;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
|
||||
namespace wpi::math {
|
||||
|
||||
@@ -15,8 +15,8 @@ TEST(ImplicitModelFollowerTest, SameModel) {
|
||||
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
auto plant = LinearSystemId::IdentifyDrivetrainSystem(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
auto plant = Models::DifferentialDriveFromSysId(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
|
||||
ImplicitModelFollower<2, 2> imf{plant, plant};
|
||||
|
||||
@@ -60,12 +60,12 @@ TEST(ImplicitModelFollowerTest, SlowerRefModel) {
|
||||
using Kv_t = decltype(1_V / 1_mps);
|
||||
using Ka_t = decltype(1_V / 1_mps_sq);
|
||||
|
||||
auto plant = LinearSystemId::IdentifyDrivetrainSystem(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
auto plant = Models::DifferentialDriveFromSysId(Kv_t{1.0}, Ka_t{1.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
|
||||
// Linear acceleration is slower, but angular acceleration is the same
|
||||
auto plantRef = LinearSystemId::IdentifyDrivetrainSystem(
|
||||
Kv_t{1.0}, Ka_t{2.0}, Kv_t{1.0}, Ka_t{1.0});
|
||||
auto plantRef = Models::DifferentialDriveFromSysId(Kv_t{1.0}, Ka_t{2.0},
|
||||
Kv_t{1.0}, Ka_t{1.0});
|
||||
|
||||
ImplicitModelFollower<2, 2> imf{plant, plantRef};
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
#include "wpi/math/system/NumericalIntegration.hpp"
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/trajectory/TrajectoryGenerator.hpp"
|
||||
#include "wpi/math/util/MathUtil.hpp"
|
||||
#include "wpi/units/math.hpp"
|
||||
@@ -46,7 +46,7 @@ static constexpr auto kLinearV = 3.02_V / 1_mps;
|
||||
static constexpr auto kLinearA = 0.642_V / 1_mps_sq;
|
||||
static constexpr auto kAngularV = 1.382_V / 1_mps;
|
||||
static constexpr auto kAngularA = 0.08495_V / 1_mps_sq;
|
||||
static auto plant = wpi::math::LinearSystemId::IdentifyDrivetrainSystem(
|
||||
static auto plant = wpi::math::Models::DifferentialDriveFromSysId(
|
||||
kLinearV, kLinearA, kAngularV, kAngularA);
|
||||
static constexpr auto kTrackwidth = 0.9_m;
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "wpi/math/controller/LinearPlantInversionFeedforward.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/linalg/EigenCore.hpp"
|
||||
|
||||
@@ -4,14 +4,12 @@
|
||||
|
||||
#include "wpi/math/controller/LinearQuadraticRegulator.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/linalg/EigenCore.hpp"
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
#include "wpi/math/system/LinearSystem.hpp"
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
#include "wpi/units/time.hpp"
|
||||
|
||||
namespace wpi::math {
|
||||
@@ -29,7 +27,8 @@ TEST(LinearQuadraticRegulatorTest, ElevatorGains) {
|
||||
// Gear ratio
|
||||
constexpr double G = 40.0 / 40.0;
|
||||
|
||||
return wpi::math::LinearSystemId::ElevatorSystem(motors, m, r, G).Slice(0);
|
||||
return wpi::math::Models::ElevatorFromPhysicalConstants(motors, m, r, G)
|
||||
.Slice(0);
|
||||
}();
|
||||
Matrixd<1, 2> K =
|
||||
LinearQuadraticRegulator<2, 1>{plant, {0.02, 0.4}, {12.0}, 5_ms}.K();
|
||||
@@ -51,7 +50,7 @@ TEST(LinearQuadraticRegulatorTest, ArmGains) {
|
||||
// Gear ratio
|
||||
constexpr double G = 100.0;
|
||||
|
||||
return wpi::math::LinearSystemId::SingleJointedArmSystem(
|
||||
return wpi::math::Models::SingleJointedArmFromPhysicalConstants(
|
||||
motors, 1.0 / 3.0 * m * r * r, G)
|
||||
.Slice(0);
|
||||
}();
|
||||
@@ -77,7 +76,8 @@ TEST(LinearQuadraticRegulatorTest, FourMotorElevator) {
|
||||
// Gear ratio
|
||||
constexpr double G = 14.67;
|
||||
|
||||
return wpi::math::LinearSystemId::ElevatorSystem(motors, m, r, G).Slice(0);
|
||||
return wpi::math::Models::ElevatorFromPhysicalConstants(motors, m, r, G)
|
||||
.Slice(0);
|
||||
}();
|
||||
Matrixd<1, 2> K =
|
||||
LinearQuadraticRegulator<2, 1>{plant, {0.1, 0.2}, {12.0}, 20_ms}.K();
|
||||
@@ -179,7 +179,8 @@ TEST(LinearQuadraticRegulatorTest, LatencyCompensate) {
|
||||
// Gear ratio
|
||||
constexpr double G = 14.67;
|
||||
|
||||
return wpi::math::LinearSystemId::ElevatorSystem(motors, m, r, G).Slice(0);
|
||||
return wpi::math::Models::ElevatorFromPhysicalConstants(motors, m, r, G)
|
||||
.Slice(0);
|
||||
}();
|
||||
LinearQuadraticRegulator<2, 1> controller{plant, {0.1, 0.2}, {12.0}, 20_ms};
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "wpi/math/controller/SimpleMotorFeedforward.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/controller/LinearPlantInversionFeedforward.hpp"
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "wpi/math/geometry/Rotation2d.hpp"
|
||||
#include "wpi/math/kinematics/DifferentialDriveKinematics.hpp"
|
||||
#include "wpi/math/trajectory/TrajectoryGenerator.hpp"
|
||||
#include "wpi/math/util/StateSpaceUtil.hpp"
|
||||
#include "wpi/units/angle.hpp"
|
||||
#include "wpi/units/length.hpp"
|
||||
#include "wpi/units/time.hpp"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "wpi/math/geometry/Rotation2d.hpp"
|
||||
#include "wpi/math/kinematics/DifferentialDriveKinematics.hpp"
|
||||
#include "wpi/math/trajectory/TrajectoryGenerator.hpp"
|
||||
#include "wpi/math/util/StateSpaceUtil.hpp"
|
||||
#include "wpi/units/angle.hpp"
|
||||
#include "wpi/units/length.hpp"
|
||||
#include "wpi/units/time.hpp"
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
|
||||
#include "wpi/math/linalg/EigenCore.hpp"
|
||||
#include "wpi/math/random/Normal.hpp"
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
#include "wpi/math/system/NumericalJacobian.hpp"
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/math/trajectory/TrajectoryGenerator.hpp"
|
||||
#include "wpi/units/moment_of_inertia.hpp"
|
||||
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
#include <Eigen/Core>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
#include "wpi/units/moment_of_inertia.hpp"
|
||||
#include "wpi/units/time.hpp"
|
||||
|
||||
TEST(KalmanFilterTest, Flywheel) {
|
||||
auto motor = wpi::math::DCMotor::NEO();
|
||||
auto flywheel =
|
||||
wpi::math::LinearSystemId::FlywheelSystem(motor, 1_kg_sq_m, 1.0);
|
||||
wpi::math::Models::FlywheelFromPhysicalConstants(motor, 1_kg_sq_m, 1.0);
|
||||
wpi::math::KalmanFilter<1, 1, 1> kf{flywheel, {1}, {1}, 5_ms};
|
||||
}
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
#include "wpi/math/estimator/AngleStatistics.hpp"
|
||||
#include "wpi/math/linalg/EigenCore.hpp"
|
||||
#include "wpi/math/random/Normal.hpp"
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
#include "wpi/math/system/Discretization.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
#include "wpi/math/system/NumericalIntegration.hpp"
|
||||
#include "wpi/math/system/NumericalJacobian.hpp"
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/trajectory/TrajectoryGenerator.hpp"
|
||||
#include "wpi/units/moment_of_inertia.hpp"
|
||||
|
||||
@@ -183,9 +183,8 @@ TEST(MerweUKFTest, DriveConvergence) {
|
||||
|
||||
TEST(MerweUKFTest, LinearUKF) {
|
||||
constexpr wpi::units::second_t dt = 20_ms;
|
||||
auto plant =
|
||||
wpi::math::LinearSystemId::IdentifyVelocitySystem<wpi::units::meters>(
|
||||
0.02_V / 1_mps, 0.006_V / 1_mps_sq);
|
||||
auto plant = wpi::math::Models::FlywheelFromSysId(0.02_V / 1_rad_per_s,
|
||||
0.006_V / 1_rad_per_s_sq);
|
||||
wpi::math::MerweUKF<1, 1, 1> observer{
|
||||
[&](const wpi::math::Vectord<1>& x, const wpi::math::Vectord<1>& u) {
|
||||
return plant.A() * x + plant.B() * u;
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
#include "wpi/math/estimator/AngleStatistics.hpp"
|
||||
#include "wpi/math/linalg/EigenCore.hpp"
|
||||
#include "wpi/math/random/Normal.hpp"
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
#include "wpi/math/system/Discretization.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
#include "wpi/math/system/NumericalIntegration.hpp"
|
||||
#include "wpi/math/system/NumericalJacobian.hpp"
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/trajectory/TrajectoryGenerator.hpp"
|
||||
#include "wpi/units/moment_of_inertia.hpp"
|
||||
|
||||
@@ -183,9 +183,8 @@ TEST(S3UKFTest, DriveConvergence) {
|
||||
|
||||
TEST(S3UKFTest, LinearUKF) {
|
||||
constexpr wpi::units::second_t dt = 20_ms;
|
||||
auto plant =
|
||||
wpi::math::LinearSystemId::IdentifyVelocitySystem<wpi::units::meters>(
|
||||
0.02_V / 1_mps, 0.006_V / 1_mps_sq);
|
||||
auto plant = wpi::math::Models::FlywheelFromSysId(0.02_V / 1_rad_per_s,
|
||||
0.006_V / 1_rad_per_s_sq);
|
||||
wpi::math::S3UKF<1, 1, 1> observer{
|
||||
[&](const wpi::math::Vectord<1>& x, const wpi::math::Vectord<1>& u) {
|
||||
return plant.A() * x + plant.B() * u;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include "wpi/math/kinematics/SwerveDriveKinematics.hpp"
|
||||
#include "wpi/math/trajectory/TrajectoryGenerator.hpp"
|
||||
#include "wpi/util/print.hpp"
|
||||
#include "wpi/util/timestamp.h"
|
||||
|
||||
void testFollowTrajectory(
|
||||
const wpi::math::SwerveDriveKinematics<4>& kinematics,
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "wpi/math/kinematics/SwerveDriveKinematics.hpp"
|
||||
#include "wpi/math/trajectory/TrajectoryGenerator.hpp"
|
||||
#include "wpi/util/print.hpp"
|
||||
#include "wpi/util/timestamp.h"
|
||||
|
||||
void testFollowTrajectory(
|
||||
const wpi::math::SwerveDriveKinematics<4>& kinematics,
|
||||
|
||||
@@ -2,22 +2,54 @@
|
||||
// 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.
|
||||
|
||||
#include "wpi/math/system/plant/LinearSystemId.hpp"
|
||||
#include "wpi/math/system/Models.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
#include "wpi/math/system/LinearSystem.hpp"
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/units/length.hpp"
|
||||
#include "wpi/units/mass.hpp"
|
||||
|
||||
TEST(LinearSystemIDTest, IdentifyDrivetrainVelocitySystem) {
|
||||
TEST(ModelsTest, FlywheelFromPhysicalConstants) {
|
||||
#if __GNUC__ <= 11
|
||||
auto model = wpi::math::LinearSystemId::DrivetrainVelocitySystem(
|
||||
auto model = wpi::math::Models::FlywheelFromPhysicalConstants(
|
||||
wpi::math::DCMotor::NEO(2), 0.00032_kg_sq_m, 1.0);
|
||||
#else
|
||||
constexpr auto model = wpi::math::Models::FlywheelFromPhysicalConstants(
|
||||
wpi::math::DCMotor::NEO(2), 0.00032_kg_sq_m, 1.0);
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(model.A().isApprox(wpi::math::Matrixd<1, 1>{-26.87032}, 0.001));
|
||||
ASSERT_TRUE(model.B().isApprox(wpi::math::Matrixd<1, 1>{1354.166667}, 0.001));
|
||||
ASSERT_TRUE(model.C().isApprox(wpi::math::Matrixd<1, 1>{1.0}, 0.001));
|
||||
ASSERT_TRUE(model.D().isApprox(wpi::math::Matrixd<1, 1>{0.0}, 0.001));
|
||||
}
|
||||
|
||||
TEST(ModelsTest, FlywheelFromSysId) {
|
||||
constexpr double kv = 1.0;
|
||||
constexpr double ka = 0.5;
|
||||
|
||||
#if __GNUC__ <= 11
|
||||
auto model = wpi::math::Models::FlywheelFromSysId(kv * 1_V / 1_rad_per_s,
|
||||
ka * 1_V / 1_rad_per_s_sq);
|
||||
#else
|
||||
constexpr auto model = wpi::math::Models::FlywheelFromSysId(
|
||||
kv * 1_V / 1_rad_per_s, ka * 1_V / 1_rad_per_s_sq);
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(model.A().isApprox(wpi::math::Matrixd<1, 1>{-kv / ka}, 0.001));
|
||||
ASSERT_TRUE(model.B().isApprox(wpi::math::Matrixd<1, 1>{1.0 / ka}, 0.001));
|
||||
}
|
||||
|
||||
TEST(ModelsTest, DifferentialDriveFromPhysicalConstants) {
|
||||
#if __GNUC__ <= 11
|
||||
auto model = wpi::math::Models::DifferentialDriveFromPhysicalConstants(
|
||||
wpi::math::DCMotor::NEO(4), 70_kg, 0.05_m, 0.4_m, 6.0_kg_sq_m, 6.0);
|
||||
#else
|
||||
constexpr auto model = wpi::math::LinearSystemId::DrivetrainVelocitySystem(
|
||||
wpi::math::DCMotor::NEO(4), 70_kg, 0.05_m, 0.4_m, 6.0_kg_sq_m, 6.0);
|
||||
constexpr auto model =
|
||||
wpi::math::Models::DifferentialDriveFromPhysicalConstants(
|
||||
wpi::math::DCMotor::NEO(4), 70_kg, 0.05_m, 0.4_m, 6.0_kg_sq_m, 6.0);
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(model.A().isApprox(
|
||||
@@ -31,8 +63,8 @@ TEST(LinearSystemIDTest, IdentifyDrivetrainVelocitySystem) {
|
||||
wpi::math::Matrixd<2, 2>{{0.0, 0.0}, {0.0, 0.0}}, 0.001));
|
||||
}
|
||||
|
||||
TEST(LinearSystemIDTest, ElevatorSystem) {
|
||||
auto model = wpi::math::LinearSystemId::ElevatorSystem(
|
||||
TEST(ModelsTest, ElevatorFromPhysicalConstants) {
|
||||
auto model = wpi::math::Models::ElevatorFromPhysicalConstants(
|
||||
wpi::math::DCMotor::NEO(2), 5_kg, 0.05_m, 12)
|
||||
.Slice(0);
|
||||
ASSERT_TRUE(model.A().isApprox(
|
||||
@@ -42,53 +74,16 @@ TEST(LinearSystemIDTest, ElevatorSystem) {
|
||||
ASSERT_TRUE(model.D().isApprox(wpi::math::Matrixd<1, 1>{0.0}, 0.001));
|
||||
}
|
||||
|
||||
TEST(LinearSystemIDTest, FlywheelSystem) {
|
||||
#if __GNUC__ <= 11
|
||||
auto model = wpi::math::LinearSystemId::FlywheelSystem(
|
||||
wpi::math::DCMotor::NEO(2), 0.00032_kg_sq_m, 1.0);
|
||||
#else
|
||||
constexpr auto model = wpi::math::LinearSystemId::FlywheelSystem(
|
||||
wpi::math::DCMotor::NEO(2), 0.00032_kg_sq_m, 1.0);
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(model.A().isApprox(wpi::math::Matrixd<1, 1>{-26.87032}, 0.001));
|
||||
ASSERT_TRUE(model.B().isApprox(wpi::math::Matrixd<1, 1>{1354.166667}, 0.001));
|
||||
ASSERT_TRUE(model.C().isApprox(wpi::math::Matrixd<1, 1>{1.0}, 0.001));
|
||||
ASSERT_TRUE(model.D().isApprox(wpi::math::Matrixd<1, 1>{0.0}, 0.001));
|
||||
}
|
||||
|
||||
TEST(LinearSystemIDTest, DCMotorSystem) {
|
||||
#if __GNUC__ <= 11
|
||||
auto model = wpi::math::LinearSystemId::DCMotorSystem(
|
||||
wpi::math::DCMotor::NEO(2), 0.00032_kg_sq_m, 1.0);
|
||||
#else
|
||||
constexpr auto model = wpi::math::LinearSystemId::DCMotorSystem(
|
||||
wpi::math::DCMotor::NEO(2), 0.00032_kg_sq_m, 1.0);
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(model.A().isApprox(
|
||||
wpi::math::Matrixd<2, 2>{{0, 1}, {0, -26.87032}}, 0.001));
|
||||
ASSERT_TRUE(
|
||||
model.B().isApprox(wpi::math::Matrixd<2, 1>{0, 1354.166667}, 0.001));
|
||||
ASSERT_TRUE(model.C().isApprox(
|
||||
wpi::math::Matrixd<2, 2>{{1.0, 0.0}, {0.0, 1.0}}, 0.001));
|
||||
ASSERT_TRUE(model.D().isApprox(wpi::math::Matrixd<2, 1>{0.0, 0.0}, 0.001));
|
||||
}
|
||||
|
||||
TEST(LinearSystemIDTest, IdentifyPositionSystem) {
|
||||
// By controls engineering in frc,
|
||||
// x-dot = [0 1 | 0 -kv/ka] x = [0 | 1/ka] u
|
||||
TEST(ModelsTest, ElevatorFromSysId) {
|
||||
constexpr double kv = 1.0;
|
||||
constexpr double ka = 0.5;
|
||||
|
||||
#if __GNUC__ <= 11
|
||||
auto model =
|
||||
wpi::math::LinearSystemId::IdentifyPositionSystem<wpi::units::meter>(
|
||||
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
|
||||
auto model = wpi::math::Models::ElevatorFromSysId(kv * 1_V / 1_mps,
|
||||
ka * 1_V / 1_mps_sq);
|
||||
#else
|
||||
constexpr auto model =
|
||||
wpi::math::LinearSystemId::IdentifyPositionSystem<wpi::units::meter>(
|
||||
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
|
||||
constexpr auto model = wpi::math::Models::ElevatorFromSysId(
|
||||
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(model.A().isApprox(
|
||||
@@ -97,23 +92,20 @@ TEST(LinearSystemIDTest, IdentifyPositionSystem) {
|
||||
model.B().isApprox(wpi::math::Matrixd<2, 1>{0.0, 1.0 / ka}, 0.001));
|
||||
}
|
||||
|
||||
TEST(LinearSystemIDTest, IdentifyVelocitySystem) {
|
||||
// By controls engineering in frc,
|
||||
// V = kv * velocity + ka * acceleration
|
||||
// x-dot = -kv/ka * v + 1/ka \cdot V
|
||||
TEST(ModelsTest, SingleJointedArmFromSysId) {
|
||||
constexpr double kv = 1.0;
|
||||
constexpr double ka = 0.5;
|
||||
|
||||
#if __GNUC__ <= 11
|
||||
auto model =
|
||||
wpi::math::LinearSystemId::IdentifyVelocitySystem<wpi::units::meter>(
|
||||
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
|
||||
auto model = wpi::math::Models::SingleJointedArmFromSysId(
|
||||
kv * 1_V / 1_rad_per_s, ka * 1_V / 1_rad_per_s_sq);
|
||||
#else
|
||||
constexpr auto model =
|
||||
wpi::math::LinearSystemId::IdentifyVelocitySystem<wpi::units::meter>(
|
||||
kv * 1_V / 1_mps, ka * 1_V / 1_mps_sq);
|
||||
constexpr auto model = wpi::math::Models::SingleJointedArmFromSysId(
|
||||
kv * 1_V / 1_rad_per_s, ka * 1_V / 1_rad_per_s_sq);
|
||||
#endif
|
||||
|
||||
ASSERT_TRUE(model.A().isApprox(wpi::math::Matrixd<1, 1>{-kv / ka}, 0.001));
|
||||
ASSERT_TRUE(model.B().isApprox(wpi::math::Matrixd<1, 1>{1.0 / ka}, 0.001));
|
||||
ASSERT_TRUE(model.A().isApprox(
|
||||
wpi::math::Matrixd<2, 2>{{0.0, 1.0}, {0.0, -kv / ka}}, 0.001));
|
||||
ASSERT_TRUE(
|
||||
model.B().isApprox(wpi::math::Matrixd<2, 1>{0.0, 1.0 / ka}, 0.001));
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
#include "wpi/util/SmallVector.hpp"
|
||||
|
||||
using namespace wpi::math;
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/math/system/plant/DCMotor.hpp"
|
||||
#include "wpi/math/system/DCMotor.hpp"
|
||||
|
||||
using namespace wpi::math;
|
||||
|
||||
Reference in New Issue
Block a user