mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Replace .to<double>() and .template to<double>() with .value() (#3667)
It's a less verbose way to do the same thing.
This commit is contained in:
@@ -46,7 +46,7 @@ class Robot : public frc::TimedRobot {
|
||||
// distance per pulse = (distance per revolution) / (pulses per revolution)
|
||||
// = (Pi * D) / ppr
|
||||
static constexpr double kArmEncoderDistPerPulse =
|
||||
2.0 * wpi::numbers::pi * kElevatorDrumRadius.to<double>() / 4096.0;
|
||||
2.0 * wpi::numbers::pi * kElevatorDrumRadius.value() / 4096.0;
|
||||
|
||||
// This gearbox represents a gearbox containing 4 Vex 775pro motors.
|
||||
frc::DCMotor m_elevatorGearbox = frc::DCMotor::Vex775Pro(4);
|
||||
@@ -73,7 +73,7 @@ class Robot : public frc::TimedRobot {
|
||||
m_mech2d.GetRoot("Elevator Root", 10, 0);
|
||||
frc::MechanismLigament2d* m_elevatorMech2d =
|
||||
m_elevatorRoot->Append<frc::MechanismLigament2d>(
|
||||
"Elevator", units::inch_t(m_elevatorSim.GetPosition()).to<double>(),
|
||||
"Elevator", units::inch_t(m_elevatorSim.GetPosition()).value(),
|
||||
90_deg);
|
||||
|
||||
public:
|
||||
@@ -95,21 +95,21 @@ class Robot : public frc::TimedRobot {
|
||||
|
||||
// Finally, we set our simulated encoder's readings and simulated battery
|
||||
// voltage
|
||||
m_encoderSim.SetDistance(m_elevatorSim.GetPosition().to<double>());
|
||||
m_encoderSim.SetDistance(m_elevatorSim.GetPosition().value());
|
||||
// SimBattery estimates loaded battery voltages
|
||||
frc::sim::RoboRioSim::SetVInVoltage(
|
||||
frc::sim::BatterySim::Calculate({m_elevatorSim.GetCurrentDraw()}));
|
||||
|
||||
// Update the Elevator length based on the simulated elevator height
|
||||
m_elevatorMech2d->SetLength(
|
||||
units::inch_t(m_elevatorSim.GetPosition()).to<double>());
|
||||
units::inch_t(m_elevatorSim.GetPosition()).value());
|
||||
}
|
||||
|
||||
void TeleopPeriodic() override {
|
||||
if (m_joystick.GetTrigger()) {
|
||||
// Here, we run PID control like normal, with a constant setpoint of 30in.
|
||||
double pidOutput = m_controller.Calculate(
|
||||
m_encoder.GetDistance(), units::meter_t(30_in).to<double>());
|
||||
double pidOutput = m_controller.Calculate(m_encoder.GetDistance(),
|
||||
units::meter_t(30_in).value());
|
||||
m_motor.SetVoltage(units::volt_t(pidOutput));
|
||||
} else {
|
||||
// Otherwise, we disable the motor.
|
||||
|
||||
Reference in New Issue
Block a user