mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[wpimath] Remove unit suffixes from variable names (#7529)
* Move units into API docs instead because suffixes make user code verbose and hard to read * Rename trackWidth to trackwidth * Make ultrasonic classes use meters instead of a mix of m, cm, mm, ft, and inches
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <hal/UsageReporting.h>
|
||||
#include <units/length.h>
|
||||
#include <wpi/sendable/SendableBuilder.h>
|
||||
#include <wpi/sendable/SendableRegistry.h>
|
||||
|
||||
@@ -15,29 +16,30 @@
|
||||
using namespace frc;
|
||||
|
||||
SharpIR SharpIR::GP2Y0A02YK0F(int channel) {
|
||||
return SharpIR(channel, 62.28, -1.092, 20, 150.0);
|
||||
return SharpIR(channel, 62.28, -1.092, 20_cm, 150_cm);
|
||||
}
|
||||
|
||||
SharpIR SharpIR::GP2Y0A21YK0F(int channel) {
|
||||
return SharpIR(channel, 26.449, -1.226, 10.0, 80.0);
|
||||
return SharpIR(channel, 26.449, -1.226, 10_cm, 80_cm);
|
||||
}
|
||||
|
||||
SharpIR SharpIR::GP2Y0A41SK0F(int channel) {
|
||||
return SharpIR(channel, 12.354, -1.07, 4.0, 30.0);
|
||||
return SharpIR(channel, 12.354, -1.07, 4_cm, 30_cm);
|
||||
}
|
||||
|
||||
SharpIR SharpIR::GP2Y0A51SK0F(int channel) {
|
||||
return SharpIR(channel, 5.2819, -1.161, 2.0, 15.0);
|
||||
return SharpIR(channel, 5.2819, -1.161, 2_cm, 15_cm);
|
||||
}
|
||||
|
||||
SharpIR::SharpIR(int channel, double a, double b, double minCM, double maxCM)
|
||||
: m_sensor(channel), m_A(a), m_B(b), m_minCM(minCM), m_maxCM(maxCM) {
|
||||
SharpIR::SharpIR(int channel, double a, double b, units::meter_t min,
|
||||
units::meter_t max)
|
||||
: m_sensor(channel), m_A(a), m_B(b), m_min(min), m_max(max) {
|
||||
HAL_ReportUsage("IO", channel, "SharpIR");
|
||||
wpi::SendableRegistry::Add(this, "SharpIR", channel);
|
||||
|
||||
m_simDevice = hal::SimDevice("SharpIR", m_sensor.GetChannel());
|
||||
if (m_simDevice) {
|
||||
m_simRange = m_simDevice.CreateDouble("Range (cm)", false, 0.0);
|
||||
m_simRange = m_simDevice.CreateDouble("Range (m)", false, 0.0);
|
||||
m_sensor.SetSimDevice(m_simDevice);
|
||||
}
|
||||
}
|
||||
@@ -46,19 +48,16 @@ int SharpIR::GetChannel() const {
|
||||
return m_sensor.GetChannel();
|
||||
}
|
||||
|
||||
units::centimeter_t SharpIR::GetRange() const {
|
||||
double distance;
|
||||
|
||||
units::meter_t SharpIR::GetRange() const {
|
||||
if (m_simRange) {
|
||||
distance = m_simRange.Get();
|
||||
return std::clamp(units::meter_t{m_simRange.Get()}, m_min, m_max);
|
||||
} else {
|
||||
// Don't allow zero/negative values
|
||||
auto v = std::max(m_sensor.GetVoltage(), 0.00001);
|
||||
distance = m_A * std::pow(v, m_B);
|
||||
}
|
||||
|
||||
// Always constrain output
|
||||
return units::centimeter_t{std::max(std::min(distance, m_maxCM), m_minCM)};
|
||||
return std::clamp(units::meter_t{m_A * std::pow(v, m_B) * 1e-2}, m_min,
|
||||
m_max);
|
||||
}
|
||||
}
|
||||
|
||||
void SharpIR::InitSendable(wpi::SendableBuilder& builder) {
|
||||
|
||||
@@ -18,11 +18,11 @@ using namespace frc;
|
||||
using namespace frc::sim;
|
||||
|
||||
DifferentialDrivetrainSim::DifferentialDrivetrainSim(
|
||||
LinearSystem<2, 2, 2> plant, units::meter_t trackWidth, DCMotor driveMotor,
|
||||
LinearSystem<2, 2, 2> plant, units::meter_t trackwidth, DCMotor driveMotor,
|
||||
double gearRatio, units::meter_t wheelRadius,
|
||||
const std::array<double, 7>& measurementStdDevs)
|
||||
: m_plant(std::move(plant)),
|
||||
m_rb(trackWidth / 2.0),
|
||||
m_rb(trackwidth / 2.0),
|
||||
m_wheelRadius(wheelRadius),
|
||||
m_motor(driveMotor),
|
||||
m_originalGearing(gearRatio),
|
||||
@@ -36,11 +36,11 @@ DifferentialDrivetrainSim::DifferentialDrivetrainSim(
|
||||
DifferentialDrivetrainSim::DifferentialDrivetrainSim(
|
||||
frc::DCMotor driveMotor, double gearing, units::kilogram_square_meter_t J,
|
||||
units::kilogram_t mass, units::meter_t wheelRadius,
|
||||
units::meter_t trackWidth, const std::array<double, 7>& measurementStdDevs)
|
||||
units::meter_t trackwidth, const std::array<double, 7>& measurementStdDevs)
|
||||
: DifferentialDrivetrainSim(
|
||||
frc::LinearSystemId::DrivetrainVelocitySystem(
|
||||
driveMotor, mass, wheelRadius, trackWidth / 2.0, J, gearing),
|
||||
trackWidth, driveMotor, gearing, wheelRadius, measurementStdDevs) {}
|
||||
driveMotor, mass, wheelRadius, trackwidth / 2.0, J, gearing),
|
||||
trackwidth, driveMotor, gearing, wheelRadius, measurementStdDevs) {}
|
||||
|
||||
Eigen::Vector2d DifferentialDrivetrainSim::ClampInput(
|
||||
const Eigen::Vector2d& u) {
|
||||
|
||||
@@ -16,9 +16,9 @@ SharpIRSim::SharpIRSim(const SharpIR& sharpIR)
|
||||
|
||||
SharpIRSim::SharpIRSim(int channel) {
|
||||
frc::sim::SimDeviceSim deviceSim{"SharpIR", channel};
|
||||
m_simRange = deviceSim.GetDouble("Range (cm)");
|
||||
m_simRange = deviceSim.GetDouble("Range (m)");
|
||||
}
|
||||
|
||||
void SharpIRSim::SetRange(units::centimeter_t rng) {
|
||||
m_simRange.Set(rng.value());
|
||||
void SharpIRSim::SetRange(units::meter_t range) {
|
||||
m_simRange.Set(range.value());
|
||||
}
|
||||
|
||||
@@ -133,10 +133,10 @@ class AddressableLED {
|
||||
* <p>By default, the driver is set up to drive WS2812B and WS2815, so nothing
|
||||
* needs to be set for those.
|
||||
*
|
||||
* @param highTime0 high time for 0 bit (default 400ns)
|
||||
* @param lowTime0 low time for 0 bit (default 900ns)
|
||||
* @param highTime1 high time for 1 bit (default 900ns)
|
||||
* @param lowTime1 low time for 1 bit (default 600ns)
|
||||
* @param highTime0 high time for 0 bit (default 400 ns)
|
||||
* @param lowTime0 low time for 0 bit (default 900 ns)
|
||||
* @param highTime1 high time for 1 bit (default 900 ns)
|
||||
* @param lowTime1 low time for 1 bit (default 600 ns)
|
||||
*/
|
||||
void SetBitTiming(units::nanosecond_t highTime0, units::nanosecond_t lowTime0,
|
||||
units::nanosecond_t highTime1,
|
||||
|
||||
@@ -63,10 +63,11 @@ class SharpIR : public wpi::Sendable, public wpi::SendableHelper<SharpIR> {
|
||||
* @param channel Analog input channel the sensor is connected to
|
||||
* @param a Constant A
|
||||
* @param b Constant B
|
||||
* @param minCM Minimum distance to report in centimeters
|
||||
* @param maxCM Maximum distance to report in centimeters
|
||||
* @param min Minimum distance to report
|
||||
* @param max Maximum distance to report
|
||||
*/
|
||||
SharpIR(int channel, double a, double b, double minCM, double maxCM);
|
||||
SharpIR(int channel, double a, double b, units::meter_t min,
|
||||
units::meter_t max);
|
||||
|
||||
/**
|
||||
* Get the analog input channel number.
|
||||
@@ -80,7 +81,7 @@ class SharpIR : public wpi::Sendable, public wpi::SendableHelper<SharpIR> {
|
||||
*
|
||||
* @return range of the target returned by the sensor
|
||||
*/
|
||||
units::centimeter_t GetRange() const;
|
||||
units::meter_t GetRange() const;
|
||||
|
||||
void InitSendable(wpi::SendableBuilder& builder) override;
|
||||
|
||||
@@ -92,8 +93,8 @@ class SharpIR : public wpi::Sendable, public wpi::SendableHelper<SharpIR> {
|
||||
|
||||
double m_A;
|
||||
double m_B;
|
||||
double m_minCM;
|
||||
double m_maxCM;
|
||||
units::meter_t m_min;
|
||||
units::meter_t m_max;
|
||||
};
|
||||
|
||||
} // namespace frc
|
||||
|
||||
@@ -25,7 +25,7 @@ class DifferentialDrivetrainSim {
|
||||
* system can be created with
|
||||
* LinearSystemId::DrivetrainVelocitySystem() or
|
||||
* LinearSystemId::IdentifyDrivetrainSystem().
|
||||
* @param trackWidth The robot's track width.
|
||||
* @param trackwidth The robot's trackwidth.
|
||||
* @param driveMotor A DCMotor representing the left side of the drivetrain.
|
||||
* @param gearingRatio The gearingRatio ratio of the left side, as output over
|
||||
* input. This must be the same ratio as the ratio used to
|
||||
@@ -41,7 +41,7 @@ class DifferentialDrivetrainSim {
|
||||
* starting point.
|
||||
*/
|
||||
DifferentialDrivetrainSim(
|
||||
LinearSystem<2, 2, 2> plant, units::meter_t trackWidth,
|
||||
LinearSystem<2, 2, 2> plant, units::meter_t trackwidth,
|
||||
DCMotor driveMotor, double gearingRatio, units::meter_t wheelRadius,
|
||||
const std::array<double, 7>& measurementStdDevs = {});
|
||||
|
||||
@@ -56,7 +56,7 @@ class DifferentialDrivetrainSim {
|
||||
* center.
|
||||
* @param mass The mass of the drivebase.
|
||||
* @param wheelRadius The radius of the wheels on the drivetrain.
|
||||
* @param trackWidth The robot's track width, or distance between left and
|
||||
* @param trackwidth The robot's trackwidth, or distance between left and
|
||||
* right wheels.
|
||||
* @param measurementStdDevs Standard deviations for measurements, in the form
|
||||
* [x, y, heading, left velocity, right velocity,
|
||||
@@ -70,7 +70,7 @@ class DifferentialDrivetrainSim {
|
||||
DifferentialDrivetrainSim(
|
||||
frc::DCMotor driveMotor, double gearing, units::kilogram_square_meter_t J,
|
||||
units::kilogram_t mass, units::meter_t wheelRadius,
|
||||
units::meter_t trackWidth,
|
||||
units::meter_t trackwidth,
|
||||
const std::array<double, 7>& measurementStdDevs = {});
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,9 +31,9 @@ class SharpIRSim {
|
||||
/**
|
||||
* Set the range returned by the distance sensor.
|
||||
*
|
||||
* @param rng range of the target returned by the sensor
|
||||
* @param range range of the target returned by the sensor
|
||||
*/
|
||||
void SetRange(units::centimeter_t rng);
|
||||
void SetRange(units::meter_t range);
|
||||
|
||||
private:
|
||||
hal::SimDouble m_simRange;
|
||||
|
||||
Reference in New Issue
Block a user