mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Clean up physics simulation class APIs (#2763)
This commit is contained in:
committed by
GitHub
parent
8f3e5794b3
commit
061432147d
@@ -15,27 +15,31 @@ using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
FlywheelSim::FlywheelSim(const LinearSystem<1, 1, 1>& plant,
|
||||
const DCMotor& gearbox, double gearing, bool addNoise,
|
||||
const DCMotor& gearbox, double gearing,
|
||||
const std::array<double, 1>& measurementStdDevs)
|
||||
: LinearSystemSim<1, 1, 1>(plant, addNoise, measurementStdDevs),
|
||||
m_motor(gearbox),
|
||||
: LinearSystemSim<1, 1, 1>(plant, measurementStdDevs),
|
||||
m_gearbox(gearbox),
|
||||
m_gearing(gearing) {}
|
||||
|
||||
FlywheelSim::FlywheelSim(const DCMotor& gearbox, double gearing,
|
||||
units::kilogram_square_meter_t moi, bool addNoise,
|
||||
units::kilogram_square_meter_t moi,
|
||||
const std::array<double, 1>& measurementStdDevs)
|
||||
: FlywheelSim(LinearSystemId::FlywheelSystem(gearbox, moi, gearing),
|
||||
gearbox, gearing, addNoise, measurementStdDevs) {}
|
||||
gearbox, gearing, measurementStdDevs) {}
|
||||
|
||||
units::radians_per_second_t FlywheelSim::GetAngularVelocity() const {
|
||||
return units::radians_per_second_t{Y(0)};
|
||||
return units::radians_per_second_t{GetOutput(0)};
|
||||
}
|
||||
|
||||
units::ampere_t FlywheelSim::GetCurrentDraw() const {
|
||||
// I = V / R - omega / (Kv * R)
|
||||
// Reductions are greater than 1, so a reduction of 10:1 would mean the motor
|
||||
// is spinning 10x faster than the output.
|
||||
return m_motor.Current(GetAngularVelocity() * m_gearing,
|
||||
units::volt_t{m_u(0)}) *
|
||||
return m_gearbox.Current(GetAngularVelocity() * m_gearing,
|
||||
units::volt_t{m_u(0)}) *
|
||||
wpi::sgn(m_u(0));
|
||||
}
|
||||
|
||||
void FlywheelSim::SetInputVoltage(units::volt_t voltage) {
|
||||
SetInput(frc::MakeMatrix<1, 1>(voltage.to<double>()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user