mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpimath] Fix drivetrain system identification (#3406)
The units for angular Kv and Ka were inconsistent with the derivation. A second factory function overload was added for angular units that uses a trackwidth to convert to the other form. Notice how section 15.2 of https://file.tavsys.net/control/controls-engineering-in-frc.pdf defines the angular feedforward as u = Kv,angular v instead of u = Kv,angular + omega. The units cancel for elements of A but not B, so just the B matrix was incorrect in our code. This breaks existing C++ code since the units are part of the function signature.
This commit is contained in:
@@ -98,8 +98,7 @@ class Drivetrain {
|
||||
frc::Field2d m_fieldSim;
|
||||
frc::LinearSystem<2, 2, 2> m_drivetrainSystem =
|
||||
frc::LinearSystemId::IdentifyDrivetrainSystem(
|
||||
1.98_V / 1_mps, 0.2_V / 1_mps_sq, 1.5_V / 1_rad_per_s,
|
||||
0.3_V / 1_rad_per_s_sq);
|
||||
1.98_V / 1_mps, 0.2_V / 1_mps_sq, 1.5_V / 1_mps, 0.3_V / 1_mps_sq);
|
||||
frc::sim::DifferentialDrivetrainSim m_drivetrainSimulator{
|
||||
m_drivetrainSystem, kTrackWidth, frc::DCMotor::CIM(2), 8, 2_in};
|
||||
};
|
||||
|
||||
@@ -52,11 +52,11 @@ constexpr double kEncoderDistancePerPulse =
|
||||
// Toolsuite provides a convenient tool for obtaining these values for your
|
||||
// robot.
|
||||
constexpr auto ks = 0.22_V;
|
||||
constexpr auto kv = 1.98 * 1_V * 1_s / 1_m;
|
||||
constexpr auto ka = 0.2 * 1_V * 1_s * 1_s / 1_m;
|
||||
constexpr auto kv = 1.98 * 1_V / 1_mps;
|
||||
constexpr auto ka = 0.2 * 1_V / 1_mps_sq;
|
||||
|
||||
constexpr auto kvAngular = 1.5 * 1_V * 1_s / 1_rad;
|
||||
constexpr auto kaAngular = 0.3 * 1_V * 1_s * 1_s / 1_rad;
|
||||
constexpr auto kvAngular = 1.5 * 1_V / 1_mps;
|
||||
constexpr auto kaAngular = 0.3 * 1_V / 1_mps_sq;
|
||||
|
||||
extern const frc::LinearSystem<2, 2, 2> kDrivetrainPlant;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user