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:
Tyler Veness
2021-10-25 08:58:12 -07:00
committed by GitHub
parent 6bc1db44bc
commit 181723e573
134 changed files with 782 additions and 826 deletions

View File

@@ -16,9 +16,9 @@ ADXRS450_GyroSim::ADXRS450_GyroSim(const frc::ADXRS450_Gyro& gyro) {
}
void ADXRS450_GyroSim::SetAngle(units::degree_t angle) {
m_simAngle.Set(angle.to<double>());
m_simAngle.Set(angle.value());
}
void ADXRS450_GyroSim::SetRate(units::degrees_per_second_t rate) {
m_simRate.Set(rate.to<double>());
m_simRate.Set(rate.value());
}

View File

@@ -19,7 +19,7 @@ void AnalogEncoderSim::SetPosition(frc::Rotation2d angle) {
}
void AnalogEncoderSim::SetTurns(units::turn_t turns) {
m_positionSim.Set(turns.to<double>());
m_positionSim.Set(turns.value());
}
units::turn_t AnalogEncoderSim::GetTurns() {

View File

@@ -49,7 +49,7 @@ Eigen::Vector<double, 2> DifferentialDrivetrainSim::ClampInput(
void DifferentialDrivetrainSim::SetInputs(units::volt_t leftVoltage,
units::volt_t rightVoltage) {
m_u << leftVoltage.to<double>(), rightVoltage.to<double>();
m_u << leftVoltage.value(), rightVoltage.value();
m_u = ClampInput(m_u);
}
@@ -93,10 +93,10 @@ Pose2d DifferentialDrivetrainSim::GetPose() const {
units::ampere_t DifferentialDrivetrainSim::GetLeftCurrentDraw() const {
auto loadIleft =
m_motor.Current(units::radians_per_second_t(m_x(State::kLeftVelocity) *
m_currentGearing /
m_wheelRadius.to<double>()),
units::volt_t(m_u(0))) *
m_motor.Current(
units::radians_per_second_t(m_x(State::kLeftVelocity) *
m_currentGearing / m_wheelRadius.value()),
units::volt_t(m_u(0))) *
wpi::sgn(m_u(0));
return loadIleft;
@@ -104,10 +104,10 @@ units::ampere_t DifferentialDrivetrainSim::GetLeftCurrentDraw() const {
units::ampere_t DifferentialDrivetrainSim::GetRightCurrentDraw() const {
auto loadIRight =
m_motor.Current(units::radians_per_second_t(m_x(State::kRightVelocity) *
m_currentGearing /
m_wheelRadius.to<double>()),
units::volt_t(m_u(1))) *
m_motor.Current(
units::radians_per_second_t(m_x(State::kRightVelocity) *
m_currentGearing / m_wheelRadius.value()),
units::volt_t(m_u(1))) *
wpi::sgn(m_u(1));
return loadIRight;
@@ -122,9 +122,9 @@ void DifferentialDrivetrainSim::SetState(
}
void DifferentialDrivetrainSim::SetPose(const frc::Pose2d& pose) {
m_x(State::kX) = pose.X().to<double>();
m_x(State::kY) = pose.Y().to<double>();
m_x(State::kHeading) = pose.Rotation().Radians().to<double>();
m_x(State::kX) = pose.X().value();
m_x(State::kY) = pose.Y().value();
m_x(State::kHeading) = pose.Rotation().Radians().value();
m_x(State::kLeftPosition) = 0;
m_x(State::kRightPosition) = 0;
}
@@ -154,7 +154,7 @@ Eigen::Vector<double, 7> DifferentialDrivetrainSim::Dynamics(
xdot(1) = v * std::sin(x(State::kHeading));
xdot(2) =
((x(State::kRightVelocity) - x(State::kLeftVelocity)) / (2.0 * m_rb))
.to<double>();
.value();
xdot.block<4, 1>(3, 0) = A * x.block<4, 1>(3, 0) + B * u;
return xdot;
}

View File

@@ -17,7 +17,7 @@ DutyCycleEncoderSim::DutyCycleEncoderSim(const frc::DutyCycleEncoder& encoder) {
}
void DutyCycleEncoderSim::Set(units::turn_t turns) {
m_simPosition.Set(turns.to<double>());
m_simPosition.Set(turns.value());
}
void DutyCycleEncoderSim::SetDistance(double distance) {

View File

@@ -78,7 +78,7 @@ units::ampere_t ElevatorSim::GetCurrentDraw() const {
}
void ElevatorSim::SetInputVoltage(units::volt_t voltage) {
SetInput(Eigen::Vector<double, 1>{voltage.to<double>()});
SetInput(Eigen::Vector<double, 1>{voltage.value()});
}
Eigen::Vector<double, 2> ElevatorSim::UpdateX(
@@ -93,10 +93,10 @@ Eigen::Vector<double, 2> ElevatorSim::UpdateX(
currentXhat, u, dt);
// Check for collision after updating x-hat.
if (WouldHitLowerLimit(units::meter_t(updatedXhat(0)))) {
return Eigen::Vector<double, 2>{m_minHeight.to<double>(), 0.0};
return Eigen::Vector<double, 2>{m_minHeight.value(), 0.0};
}
if (WouldHitUpperLimit(units::meter_t(updatedXhat(0)))) {
return Eigen::Vector<double, 2>{m_maxHeight.to<double>(), 0.0};
return Eigen::Vector<double, 2>{m_maxHeight.value(), 0.0};
}
return updatedXhat;
}

View File

@@ -38,5 +38,5 @@ units::ampere_t FlywheelSim::GetCurrentDraw() const {
}
void FlywheelSim::SetInputVoltage(units::volt_t voltage) {
SetInput(Eigen::Vector<double, 1>{voltage.to<double>()});
SetInput(Eigen::Vector<double, 1>{voltage.value()});
}

View File

@@ -43,7 +43,7 @@ units::volt_t RoboRioSim::GetVInVoltage() {
}
void RoboRioSim::SetVInVoltage(units::volt_t vInVoltage) {
HALSIM_SetRoboRioVInVoltage(vInVoltage.to<double>());
HALSIM_SetRoboRioVInVoltage(vInVoltage.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterVInCurrentCallback(
@@ -60,7 +60,7 @@ units::ampere_t RoboRioSim::GetVInCurrent() {
}
void RoboRioSim::SetVInCurrent(units::ampere_t vInCurrent) {
HALSIM_SetRoboRioVInCurrent(vInCurrent.to<double>());
HALSIM_SetRoboRioVInCurrent(vInCurrent.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserVoltage6VCallback(
@@ -77,7 +77,7 @@ units::volt_t RoboRioSim::GetUserVoltage6V() {
}
void RoboRioSim::SetUserVoltage6V(units::volt_t userVoltage6V) {
HALSIM_SetRoboRioUserVoltage6V(userVoltage6V.to<double>());
HALSIM_SetRoboRioUserVoltage6V(userVoltage6V.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserCurrent6VCallback(
@@ -94,7 +94,7 @@ units::ampere_t RoboRioSim::GetUserCurrent6V() {
}
void RoboRioSim::SetUserCurrent6V(units::ampere_t userCurrent6V) {
HALSIM_SetRoboRioUserCurrent6V(userCurrent6V.to<double>());
HALSIM_SetRoboRioUserCurrent6V(userCurrent6V.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive6VCallback(
@@ -128,7 +128,7 @@ units::volt_t RoboRioSim::GetUserVoltage5V() {
}
void RoboRioSim::SetUserVoltage5V(units::volt_t userVoltage5V) {
HALSIM_SetRoboRioUserVoltage5V(userVoltage5V.to<double>());
HALSIM_SetRoboRioUserVoltage5V(userVoltage5V.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserCurrent5VCallback(
@@ -145,7 +145,7 @@ units::ampere_t RoboRioSim::GetUserCurrent5V() {
}
void RoboRioSim::SetUserCurrent5V(units::ampere_t userCurrent5V) {
HALSIM_SetRoboRioUserCurrent5V(userCurrent5V.to<double>());
HALSIM_SetRoboRioUserCurrent5V(userCurrent5V.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive5VCallback(
@@ -179,7 +179,7 @@ units::volt_t RoboRioSim::GetUserVoltage3V3() {
}
void RoboRioSim::SetUserVoltage3V3(units::volt_t userVoltage3V3) {
HALSIM_SetRoboRioUserVoltage3V3(userVoltage3V3.to<double>());
HALSIM_SetRoboRioUserVoltage3V3(userVoltage3V3.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserCurrent3V3Callback(
@@ -196,7 +196,7 @@ units::ampere_t RoboRioSim::GetUserCurrent3V3() {
}
void RoboRioSim::SetUserCurrent3V3(units::ampere_t userCurrent3V3) {
HALSIM_SetRoboRioUserCurrent3V3(userCurrent3V3.to<double>());
HALSIM_SetRoboRioUserCurrent3V3(userCurrent3V3.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterUserActive3V3Callback(
@@ -281,7 +281,7 @@ units::volt_t RoboRioSim::GetBrownoutVoltage() {
}
void RoboRioSim::SetBrownoutVoltage(units::volt_t vInVoltage) {
HALSIM_SetRoboRioBrownoutVoltage(vInVoltage.to<double>());
HALSIM_SetRoboRioBrownoutVoltage(vInVoltage.value());
}
void RoboRioSim::ResetData() {

View File

@@ -41,11 +41,11 @@ bool IsTimingPaused() {
}
void StepTiming(units::second_t delta) {
HALSIM_StepTiming(static_cast<uint64_t>(delta.to<double>() * 1e6));
HALSIM_StepTiming(static_cast<uint64_t>(delta.value() * 1e6));
}
void StepTimingAsync(units::second_t delta) {
HALSIM_StepTimingAsync(static_cast<uint64_t>(delta.to<double>() * 1e6));
HALSIM_StepTimingAsync(static_cast<uint64_t>(delta.value() * 1e6));
}
} // namespace frc::sim

View File

@@ -72,7 +72,7 @@ units::ampere_t SingleJointedArmSim::GetCurrentDraw() const {
}
void SingleJointedArmSim::SetInputVoltage(units::volt_t voltage) {
SetInput(Eigen::Vector<double, 1>{voltage.to<double>()});
SetInput(Eigen::Vector<double, 1>{voltage.value()});
}
Eigen::Vector<double, 2> SingleJointedArmSim::UpdateX(
@@ -96,7 +96,7 @@ Eigen::Vector<double, 2> SingleJointedArmSim::UpdateX(
xdot += Eigen::Vector<double, 2>{
0.0, (m_mass * m_r * -9.8 * 3.0 / (m_mass * m_r * m_r) *
std::cos(x(0)))
.template to<double>()};
.value()};
}
return xdot;
},
@@ -104,9 +104,9 @@ Eigen::Vector<double, 2> SingleJointedArmSim::UpdateX(
// Check for collisions.
if (WouldHitLowerLimit(units::radian_t(updatedXhat(0)))) {
return Eigen::Vector<double, 2>{m_minAngle.to<double>(), 0.0};
return Eigen::Vector<double, 2>{m_minAngle.value(), 0.0};
} else if (WouldHitUpperLimit(units::radian_t(updatedXhat(0)))) {
return Eigen::Vector<double, 2>{m_maxAngle.to<double>(), 0.0};
return Eigen::Vector<double, 2>{m_maxAngle.value(), 0.0};
}
return updatedXhat;
}

View File

@@ -20,5 +20,5 @@ void UltrasonicSim::SetRangeValid(bool isValid) {
}
void UltrasonicSim::SetRange(units::meter_t range) {
m_simRange.Set(range.to<double>());
m_simRange.Set(range.value());
}