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

@@ -93,7 +93,7 @@ double AnalogEncoder::GetDistancePerRotation() const {
}
double AnalogEncoder::GetDistance() const {
return Get().to<double>() * GetDistancePerRotation();
return Get().value() * GetDistancePerRotation();
}
void AnalogEncoder::Reset() {

View File

@@ -282,7 +282,7 @@ units::second_t Counter::GetPeriod() const {
void Counter::SetMaxPeriod(units::second_t maxPeriod) {
int32_t status = 0;
HAL_SetCounterMaxPeriod(m_counter, maxPeriod.to<double>(), &status);
HAL_SetCounterMaxPeriod(m_counter, maxPeriod.value(), &status);
FRC_CheckErrorStatus(status, "{}", "SetMaxPeriod");
}

View File

@@ -42,7 +42,7 @@ void DMA::SetPause(bool pause) {
void DMA::SetTimedTrigger(units::second_t seconds) {
int32_t status = 0;
HAL_SetDMATimedTrigger(dmaHandle, seconds.to<double>(), &status);
HAL_SetDMATimedTrigger(dmaHandle, seconds.value(), &status);
FRC_CheckErrorStatus(status, "{}", "SetTimedTrigger");
}

View File

@@ -112,7 +112,7 @@ double DutyCycleEncoder::GetDistancePerRotation() const {
}
double DutyCycleEncoder::GetDistance() const {
return Get().to<double>() * GetDistancePerRotation();
return Get().value() * GetDistancePerRotation();
}
int DutyCycleEncoder::GetFrequency() const {

View File

@@ -87,7 +87,7 @@ units::second_t Encoder::GetPeriod() const {
void Encoder::SetMaxPeriod(units::second_t maxPeriod) {
int32_t status = 0;
HAL_SetEncoderMaxPeriod(m_encoder, maxPeriod.to<double>(), &status);
HAL_SetEncoderMaxPeriod(m_encoder, maxPeriod.value(), &status);
FRC_CheckErrorStatus(status, "{}", "SetMaxPeriod");
}

View File

@@ -200,6 +200,5 @@ void IterativeRobotBase::LoopFunc() {
}
void IterativeRobotBase::PrintLoopOverrunMessage() {
FRC_ReportError(err::Error, "Loop time of {:.6f}s overrun",
m_period.to<double>());
FRC_ReportError(err::Error, "Loop time of {:.6f}s overrun", m_period.value());
}

View File

@@ -168,7 +168,7 @@ units::volt_t RobotController::GetBrownoutVoltage() {
void RobotController::SetBrownoutVoltage(units::volt_t brownoutVoltage) {
int32_t status = 0;
HAL_SetBrownoutVoltage(brownoutVoltage.to<double>(), &status);
HAL_SetBrownoutVoltage(brownoutVoltage.value(), &status);
FRC_CheckErrorStatus(status, "{}", "SetBrownoutVoltage");
}

View File

@@ -274,7 +274,7 @@ void SPI::SetAutoTransmitData(wpi::span<const uint8_t> dataToSend,
void SPI::StartAutoRate(units::second_t period) {
int32_t status = 0;
HAL_StartSPIAutoRate(m_port, period.to<double>(), &status);
HAL_StartSPIAutoRate(m_port, period.value(), &status);
FRC_CheckErrorStatus(status, "Port {}", m_port);
}
@@ -307,7 +307,7 @@ int SPI::ReadAutoReceivedData(uint32_t* buffer, int numToRead,
units::second_t timeout) {
int32_t status = 0;
int32_t val = HAL_ReadSPIAutoReceivedData(m_port, buffer, numToRead,
timeout.to<double>(), &status);
timeout.value(), &status);
FRC_CheckErrorStatus(status, "Port {}", m_port);
return val;
}

View File

@@ -124,7 +124,7 @@ int SerialPort::Write(std::string_view buffer) {
void SerialPort::SetTimeout(units::second_t timeout) {
int32_t status = 0;
HAL_SetSerialTimeout(m_portHandle, timeout.to<double>(), &status);
HAL_SetSerialTimeout(m_portHandle, timeout.value(), &status);
FRC_CheckErrorStatus(status, "{}", "SetTimeout");
}

View File

@@ -64,8 +64,8 @@ inline SynchronousInterrupt::WaitResult operator|(
SynchronousInterrupt::WaitResult SynchronousInterrupt::WaitForInterrupt(
units::second_t timeout, bool ignorePrevious) {
int32_t status = 0;
auto result = HAL_WaitForInterrupt(m_handle, timeout.to<double>(),
ignorePrevious, &status);
auto result =
HAL_WaitForInterrupt(m_handle, timeout.value(), ignorePrevious, &status);
auto rising =
((result & 0xFF) != 0) ? WaitResult::kRisingEdge : WaitResult::kTimeout;

View File

@@ -13,8 +13,7 @@
namespace frc {
void Wait(units::second_t seconds) {
std::this_thread::sleep_for(
std::chrono::duration<double>(seconds.to<double>()));
std::this_thread::sleep_for(std::chrono::duration<double>(seconds.value()));
}
units::second_t GetTime() {

View File

@@ -162,7 +162,7 @@ void Ultrasonic::SetEnabled(bool enable) {
void Ultrasonic::InitSendable(wpi::SendableBuilder& builder) {
builder.SetSmartDashboardType("Ultrasonic");
builder.AddDoubleProperty(
"Value", [=] { return units::inch_t{GetRange()}.to<double>(); }, nullptr);
"Value", [=] { return units::inch_t{GetRange()}.value(); }, nullptr);
}
void Ultrasonic::Initialize() {

View File

@@ -80,7 +80,7 @@ void Watchdog::Impl::UpdateAlarm() {
} else {
HAL_UpdateNotifierAlarm(
notifier,
static_cast<uint64_t>(m_watchdogs.top()->m_expirationTime.to<double>() *
static_cast<uint64_t>(m_watchdogs.top()->m_expirationTime.value() *
1e6),
&status);
}
@@ -114,7 +114,7 @@ void Watchdog::Impl::Main() {
watchdog->m_lastTimeoutPrintTime = now;
if (!watchdog->m_suppressTimeoutMessage) {
FRC_ReportError(warn::Warning, "Watchdog not fed within {:.6f}s",
watchdog->m_timeout.to<double>());
watchdog->m_timeout.value());
}
}

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());
}

View File

@@ -87,9 +87,9 @@ void FieldObject2d::UpdateEntry(bool setDefault) {
wpi::SmallVector<double, 9> arr;
for (auto&& pose : m_poses) {
auto& translation = pose.Translation();
arr.push_back(translation.X().to<double>());
arr.push_back(translation.Y().to<double>());
arr.push_back(pose.Rotation().Degrees().to<double>());
arr.push_back(translation.X().value());
arr.push_back(translation.Y().value());
arr.push_back(pose.Rotation().Degrees().value());
}
if (setDefault) {
m_entry.SetDefaultDoubleArray(arr);
@@ -104,13 +104,13 @@ void FieldObject2d::UpdateEntry(bool setDefault) {
for (auto&& pose : m_poses) {
auto& translation = pose.Translation();
wpi::support::endian::write64be(
p, wpi::DoubleToBits(translation.X().to<double>()));
p, wpi::DoubleToBits(translation.X().value()));
p += 8;
wpi::support::endian::write64be(
p, wpi::DoubleToBits(translation.Y().to<double>()));
p, wpi::DoubleToBits(translation.Y().value()));
p += 8;
wpi::support::endian::write64be(
p, wpi::DoubleToBits(pose.Rotation().Degrees().to<double>()));
p, wpi::DoubleToBits(pose.Rotation().Degrees().value()));
p += 8;
}
if (setDefault) {

View File

@@ -14,7 +14,7 @@ MechanismLigament2d::MechanismLigament2d(std::string_view name, double length,
const frc::Color8Bit& color)
: MechanismObject2d(name),
m_length{length},
m_angle{angle.to<double>()},
m_angle{angle.value()},
m_weight{lineWeight} {
SetColor(color);
}
@@ -40,7 +40,7 @@ void MechanismLigament2d::SetColor(const Color8Bit& color) {
void MechanismLigament2d::SetAngle(units::degree_t angle) {
std::scoped_lock lock(m_mutex);
m_angle = angle.to<double>();
m_angle = angle.value();
Flush();
}