diff --git a/wpilibc/src/main/native/cpp/Ultrasonic.cpp b/wpilibc/src/main/native/cpp/Ultrasonic.cpp index 6e9704ea09..2f9d6f873b 100644 --- a/wpilibc/src/main/native/cpp/Ultrasonic.cpp +++ b/wpilibc/src/main/native/cpp/Ultrasonic.cpp @@ -137,23 +137,17 @@ void Ultrasonic::SetAutomaticMode(bool enabling) { } } -double Ultrasonic::GetRangeInches() const { +units::meter_t Ultrasonic::GetRange() const { if (IsRangeValid()) { if (m_simRange) { - return m_simRange.Get(); + return units::meter_t{m_simRange.Get()}; } - return units::inch_t{m_counter.GetPeriod() * kSpeedOfSound / 2.0} - .to(); + return m_counter.GetPeriod() * kSpeedOfSound / 2.0; } else { - return 0; + return 0_m; } } -double Ultrasonic::GetRangeMM() const { - return units::millimeter_t{m_counter.GetPeriod() * kSpeedOfSound / 2.0} - .to(); -} - bool Ultrasonic::IsEnabled() const { return m_enabled; } @@ -165,7 +159,7 @@ void Ultrasonic::SetEnabled(bool enable) { void Ultrasonic::InitSendable(SendableBuilder& builder) { builder.SetSmartDashboardType("Ultrasonic"); builder.AddDoubleProperty( - "Value", [=]() { return GetRangeInches(); }, nullptr); + "Value", [=] { return units::inch_t{GetRange()}.to(); }, nullptr); } void Ultrasonic::Initialize() { diff --git a/wpilibc/src/main/native/include/frc/Ultrasonic.h b/wpilibc/src/main/native/include/frc/Ultrasonic.h index 88c5b811d1..25624bf850 100644 --- a/wpilibc/src/main/native/include/frc/Ultrasonic.h +++ b/wpilibc/src/main/native/include/frc/Ultrasonic.h @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -123,22 +124,13 @@ class Ultrasonic : public Sendable, public SendableHelper { static void SetAutomaticMode(bool enabling); /** - * Get the range in inches from the ultrasonic sensor. + * Get the range from the ultrasonic sensor. * - * @return Range in inches of the target returned from the ultrasonic sensor. - * If there is no valid value yet, i.e. at least one measurement - * hasn't completed, then return 0. + * @return Range of the target returned from the ultrasonic sensor. If there + * is no valid value yet, i.e. at least one measurement hasn't + * completed, then return 0. */ - double GetRangeInches() const; - - /** - * Get the range in millimeters from the ultrasonic sensor. - * - * @return Range in millimeters of the target returned by the ultrasonic - * sensor. If there is no valid value yet, i.e. at least one - * measurement hasn't completed, then return 0. - */ - double GetRangeMM() const; + units::meter_t GetRange() const; bool IsEnabled() const;