[wpilib] LinearSystemSim.setState: calculate new output state (#7799)

Establishes the invariant that the state and measurement always match up, even immediately after construction.
This commit is contained in:
HarryXChen
2025-02-19 01:49:28 -05:00
committed by GitHub
parent bd2211119f
commit c898853b4d
6 changed files with 80 additions and 21 deletions

View File

@@ -21,3 +21,12 @@ TEST(SingleJointedArmTest, Disabled) {
// The arm should swing down.
EXPECT_NEAR(sim.GetAngle().value(), -std::numbers::pi / 2, 0.01);
}
TEST(SingleJointedArmTest, InitialState) {
constexpr auto startingAngle = 45_deg;
frc::sim::SingleJointedArmSim sim(frc::DCMotor::KrakenX60(2), 125, 3_kg_sq_m,
30_in, 0_deg, 90_deg, true, startingAngle);
EXPECT_EQ(startingAngle, sim.GetAngle());
EXPECT_DOUBLE_EQ(0, sim.GetVelocity().value());
}