mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Add mechanism specific SetState overloads to physics sims (#5534)
This commit is contained in:
@@ -24,6 +24,11 @@ DCMotorSim::DCMotorSim(const DCMotor& gearbox, double gearing,
|
||||
: DCMotorSim(LinearSystemId::DCMotorSystem(gearbox, moi, gearing), gearbox,
|
||||
gearing, measurementStdDevs) {}
|
||||
|
||||
void DCMotorSim::SetState(units::radian_t angularPosition,
|
||||
units::radians_per_second_t angularVelocity) {
|
||||
SetState(Vectord<2>{angularPosition, angularVelocity});
|
||||
}
|
||||
|
||||
units::radian_t DCMotorSim::GetAngularPosition() const {
|
||||
return units::radian_t{GetOutput(0)};
|
||||
}
|
||||
|
||||
@@ -25,8 +25,7 @@ ElevatorSim::ElevatorSim(const LinearSystem<2, 1, 1>& plant,
|
||||
m_maxHeight(maxHeight),
|
||||
m_gearing(gearing),
|
||||
m_simulateGravity(simulateGravity) {
|
||||
SetState(
|
||||
frc::Vectord<2>{std::clamp(startingHeight, minHeight, maxHeight), 0.0});
|
||||
SetState(startingHeight, 0_mps);
|
||||
}
|
||||
|
||||
ElevatorSim::ElevatorSim(const DCMotor& gearbox, double gearing,
|
||||
@@ -40,6 +39,12 @@ ElevatorSim::ElevatorSim(const DCMotor& gearbox, double gearing,
|
||||
gearbox, gearing, drumRadius, minHeight, maxHeight,
|
||||
simulateGravity, startingHeight, measurementStdDevs) {}
|
||||
|
||||
void ElevatorSim::SetState(units::meter_t position,
|
||||
units::meters_per_second_t velocity) {
|
||||
SetState(
|
||||
Vectord<2>{std::clamp(position, m_minHeight, m_maxHeight), velocity});
|
||||
}
|
||||
|
||||
bool ElevatorSim::WouldHitLowerLimit(units::meter_t elevatorHeight) const {
|
||||
return elevatorHeight <= m_minHeight;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ FlywheelSim::FlywheelSim(const DCMotor& gearbox, double gearing,
|
||||
: FlywheelSim(LinearSystemId::FlywheelSystem(gearbox, moi, gearing),
|
||||
gearbox, gearing, measurementStdDevs) {}
|
||||
|
||||
void FlywheelSim::SetState(units::radians_per_second_t velocity) {
|
||||
LinearSystemSim::SetState(Vectord<1>{velocity.value()});
|
||||
}
|
||||
|
||||
units::radians_per_second_t FlywheelSim::GetAngularVelocity() const {
|
||||
return units::radians_per_second_t{GetOutput(0)};
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ SingleJointedArmSim::SingleJointedArmSim(
|
||||
m_gearbox(gearbox),
|
||||
m_gearing(gearing),
|
||||
m_simulateGravity(simulateGravity) {
|
||||
SetState(frc::Vectord<2>{startingAngle, 0.0});
|
||||
SetState(startingAngle, 0_rad_per_s);
|
||||
}
|
||||
|
||||
SingleJointedArmSim::SingleJointedArmSim(
|
||||
@@ -42,6 +42,11 @@ SingleJointedArmSim::SingleJointedArmSim(
|
||||
gearbox, gearing, armLength, minAngle, maxAngle, simulateGravity,
|
||||
startingAngle, measurementStdDevs) {}
|
||||
|
||||
void SingleJointedArmSim::SetState(units::radian_t angle,
|
||||
units::radians_per_second_t velocity) {
|
||||
SetState(Vectord<2>{std::clamp(angle, m_minAngle, m_maxAngle), velocity});
|
||||
}
|
||||
|
||||
bool SingleJointedArmSim::WouldHitLowerLimit(units::radian_t armAngle) const {
|
||||
return armAngle <= m_minAngle;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user