From e52f40068772cd96546cc97a61b935514ff415a9 Mon Sep 17 00:00:00 2001 From: Sam Carlberg Date: Fri, 17 Jan 2025 02:24:11 -0500 Subject: [PATCH 01/33] [wpiunits] Add Measure.per overloads for all known unit types (#7699) Instead of only providing per(TimeUnit) Useful for making conversion factors easier, eg `Inches.of(10).per(Rotation)` vs `Inches.of(10).per(Rotation.one())` Update VelocityUnit.one() and VelocityUnit.zero() to return Velocity objects instead of generic Measure>; VelocityUnit is final, so the wildcard generic is unnecessary, and this makes the generated `per` functions possible for this type --- .../main/java/Measure-interface.java.jinja | 37 ++- .../wpi/first/units/measure/Acceleration.java | 125 +++++++- .../edu/wpi/first/units/measure/Angle.java | 125 +++++++- .../units/measure/AngularAcceleration.java | 125 +++++++- .../first/units/measure/AngularMomentum.java | 125 +++++++- .../first/units/measure/AngularVelocity.java | 125 +++++++- .../edu/wpi/first/units/measure/Current.java | 125 +++++++- .../first/units/measure/Dimensionless.java | 125 +++++++- .../edu/wpi/first/units/measure/Distance.java | 125 +++++++- .../edu/wpi/first/units/measure/Energy.java | 125 +++++++- .../edu/wpi/first/units/measure/Force.java | 125 +++++++- .../wpi/first/units/measure/Frequency.java | 125 +++++++- .../units/measure/LinearAcceleration.java | 125 +++++++- .../first/units/measure/LinearMomentum.java | 125 +++++++- .../first/units/measure/LinearVelocity.java | 125 +++++++- .../edu/wpi/first/units/measure/Mass.java | 125 +++++++- .../first/units/measure/MomentOfInertia.java | 125 +++++++- .../edu/wpi/first/units/measure/Mult.java | 125 +++++++- .../java/edu/wpi/first/units/measure/Per.java | 125 +++++++- .../edu/wpi/first/units/measure/Power.java | 125 +++++++- .../wpi/first/units/measure/Resistance.java | 125 +++++++- .../wpi/first/units/measure/Temperature.java | 125 +++++++- .../edu/wpi/first/units/measure/Time.java | 125 +++++++- .../edu/wpi/first/units/measure/Torque.java | 125 +++++++- .../edu/wpi/first/units/measure/Velocity.java | 125 +++++++- .../edu/wpi/first/units/measure/Voltage.java | 125 +++++++- .../java/edu/wpi/first/units/Measure.java | 275 +++++++++++++++++- .../edu/wpi/first/units/VelocityUnit.java | 8 +- 28 files changed, 3300 insertions(+), 145 deletions(-) diff --git a/wpiunits/src/generate/main/java/Measure-interface.java.jinja b/wpiunits/src/generate/main/java/Measure-interface.java.jinja index 80ffe0a7e0..608900f2b5 100644 --- a/wpiunits/src/generate/main/java/Measure-interface.java.jinja +++ b/wpiunits/src/generate/main/java/Measure-interface.java.jinja @@ -86,11 +86,6 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt default {{ helpers['type_usage'](name) }} divide(double divisor) { return ({{ helpers['type_usage'](name) }}) div(divisor); } - - @Override - default {{ config[name]['divide']['Time'] or "Velocity<{}>".format(helpers['mtou'](name)) }} per(TimeUnit period) { - return div(period.of(1)); - } {% for unit in math_units -%} {% if unit == "Dimensionless" %} @Override @@ -147,6 +142,15 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt default {{ config[name]['divide'][unit] }} divide({{ unit }} divisor) { return div(divisor); } + + @Override + default {{ config[name]['divide'][unit] }} per({{ helpers['mtou'](unit) }} divisorUnit) { +{%- if unit == "Mult" or unit == "Per" %} + return div(divisorUnit.ofNative(1)); +{%- else %} + return div(divisorUnit.one()); +{%- endif %} + } {% elif unit == "Time" %} @Override default Velocity<{{ helpers['mtou'](name) }}> div({{ unit }} divisor) { @@ -164,6 +168,15 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt default Velocity<{{ helpers['mtou'](name) }}> divide({{ unit }} divisor) { return div(divisor); } + + @Override + default Velocity<{{ helpers['mtou'](name) }}> per({{ helpers['mtou'](unit) }} divisorUnit) { +{%- if unit == "Mult" or unit == "Per" %} + return div(divisorUnit.ofNative(1)); +{%- else %} + return div(divisorUnit.one()); +{%- endif %} + } {% elif unit == name %} @Override default Dimensionless div({{ unit }} divisor) { @@ -181,6 +194,11 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt default Dimensionless divide({{ unit }} divisor) { return div(divisor); } + + @Override + default Dimensionless per({{ helpers['mtou'](unit) }} divisorUnit) { + return div(divisorUnit.one()); + } {% else %} @Override default Per<{{ helpers['mtou'](name) }}, {{ helpers['mtou'](unit) }}> div({{ unit }} divisor) { @@ -198,6 +216,15 @@ public interface {{ helpers['type_decl'](name) }} extends Measure<{{ helpers['mt default Per<{{ helpers['mtou'](name) }}, {{ helpers['mtou'](unit) }}> divide({{ unit }} divisor) { return div(divisor); } + + @Override + default Per<{{ helpers['mtou'](name) }}, {{ helpers['mtou'](unit) }}> per({{ helpers['mtou'](unit) }} divisorUnit) { +{%- if unit == "Mult" or unit == "Per" %} + return div(divisorUnit.ofNative(1)); +{%- else %} + return div(divisorUnit.one()); +{%- endif %} + } {% endif -%} {% endif -%} {% endfor -%} diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Acceleration.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Acceleration.java index ac4f686097..9a007dae74 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Acceleration.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Acceleration.java @@ -87,11 +87,6 @@ public interface Acceleration extends Measure) div(divisor); } - @Override - default Velocity> per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult, AccelerationUnit> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Acceleration extends Measure, AccelerationUnit> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngleUnit> times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Acceleration extends Measure, AngleUnit> per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularAccelerationUnit> times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Acceleration extends Measure, AngularAccelerationUnit> per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularMomentumUnit> times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Acceleration extends Measure, AngularMomentumUnit> per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularVelocityUnit> times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Acceleration extends Measure, AngularVelocityUnit> per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, CurrentUnit> times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Acceleration extends Measure, CurrentUnit> per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Acceleration div(Dimensionless divisor) { return (Acceleration) unit().of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Acceleration extends Measure, DistanceUnit> per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, EnergyUnit> times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Acceleration extends Measure, EnergyUnit> per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, ForceUnit> times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Acceleration extends Measure, ForceUnit> per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, FrequencyUnit> times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Acceleration extends Measure, FrequencyUnit> per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearAccelerationUnit> times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Acceleration extends Measure, LinearAccelerationUnit> per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearMomentumUnit> times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Acceleration extends Measure, LinearMomentumUnit> per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearVelocityUnit> times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Acceleration extends Measure, LinearVelocityUnit> per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MassUnit> times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Acceleration extends Measure, MassUnit> per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MomentOfInertiaUnit> times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Acceleration extends Measure, MomentOfInertiaUnit> per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MultUnit> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Acceleration extends Measure, MultUnit> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult, PerUnit> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Acceleration extends Measure, PerUnit> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult, PowerUnit> times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Acceleration extends Measure, PowerUnit> per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, ResistanceUnit> times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Acceleration extends Measure, ResistanceUnit> per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TemperatureUnit> times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Acceleration extends Measure, TemperatureUnit> per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TimeUnit> times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Acceleration extends Measure> per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TorqueUnit> times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Acceleration extends Measure, TorqueUnit> per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, VelocityUnit> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Acceleration extends Measure, VelocityUnit> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, VoltageUnit> times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Acceleration extends Measure, VoltageUnit> per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Angle.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Angle.java index 23b9957241..812b239a7b 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Angle.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Angle.java @@ -87,11 +87,6 @@ public interface Angle extends Measure { return (Angle) div(divisor); } - @Override - default AngularVelocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Dimensionless per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Angle div(Dimensionless divisor) { return (Angle) Radians.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularVelocity times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default AngularVelocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Angle extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularAcceleration.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularAcceleration.java index d5cac08a79..d90cbe2056 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularAcceleration.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularAcceleration.java @@ -87,11 +87,6 @@ public interface AngularAcceleration extends Measure { return (AngularAcceleration) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Dimensionless per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularAcceleration div(Dimensionless divisor) { return (AngularAcceleration) RadiansPerSecondPerSecond.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default AngularVelocity per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularVelocity times(Time multiplier) { @@ -597,6 +692,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface AngularAcceleration extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularMomentum.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularMomentum.java index 8d7bc6387e..ab1b0f15fd 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularMomentum.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularMomentum.java @@ -87,11 +87,6 @@ public interface AngularMomentum extends Measure { return (AngularMomentum) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Dimensionless per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default MomentOfInertia per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularMomentum div(Dimensionless divisor) { return (AngularMomentum) KilogramMetersSquaredPerSecond.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface AngularMomentum extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularVelocity.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularVelocity.java index 9347eafa8b..37b4a28d57 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularVelocity.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/AngularVelocity.java @@ -87,11 +87,6 @@ public interface AngularVelocity extends Measure { return (AngularVelocity) div(divisor); } - @Override - default AngularAcceleration per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Dimensionless per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularVelocity div(Dimensionless divisor) { return (AngularVelocity) RadiansPerSecond.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularAcceleration times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Angle times(Time multiplier) { @@ -597,6 +692,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default AngularAcceleration per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface AngularVelocity extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -665,5 +775,10 @@ public interface AngularVelocity extends Measure { default Per divide(Voltage divisor) { return div(divisor); } + + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } default Frequency asFrequency() { return Hertz.of(baseUnitMagnitude()); } } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Current.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Current.java index 84ae1e04db..734272a138 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Current.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Current.java @@ -87,11 +87,6 @@ public interface Current extends Measure { return (Current) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Dimensionless per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Current div(Dimensionless divisor) { return (Current) Amps.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Voltage times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Power times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Current extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Dimensionless.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Dimensionless.java index 27e01a77a1..4447c270ee 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Dimensionless.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Dimensionless.java @@ -87,11 +87,6 @@ public interface Dimensionless extends Measure { return (Dimensionless) div(divisor); } - @Override - default Frequency per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Angle times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularAcceleration times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularMomentum times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularVelocity times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Current times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Dimensionless div(Dimensionless divisor) { return (Dimensionless) Value.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Energy times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Force times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Frequency times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearAcceleration times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearMomentum times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearVelocity times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mass times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default MomentOfInertia times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Power times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Resistance times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Temperature times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Time times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Frequency per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Torque times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Voltage times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Dimensionless extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Distance.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Distance.java index 7bfc52f736..e0f53a620e 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Distance.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Distance.java @@ -87,11 +87,6 @@ public interface Distance extends Measure { return (Distance) div(divisor); } - @Override - default LinearVelocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Distance div(Dimensionless divisor) { return (Distance) Meters.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Dimensionless per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Torque times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearVelocity times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Time per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default LinearVelocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Distance extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Energy.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Energy.java index ed125befe3..a98f55d5a8 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Energy.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Energy.java @@ -87,11 +87,6 @@ public interface Energy extends Measure { return (Energy) div(divisor); } - @Override - default Power per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Energy div(Dimensionless divisor) { return (Energy) Joules.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Dimensionless per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Power times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Power per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Energy extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Force.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Force.java index fa69b143f1..0233742892 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Force.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Force.java @@ -87,11 +87,6 @@ public interface Force extends Measure { return (Force) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Force div(Dimensionless divisor) { return (Force) Newtons.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Dimensionless per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Mass per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default LinearAcceleration per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Force extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Frequency.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Frequency.java index 1b69009db5..d18973a84d 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Frequency.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Frequency.java @@ -87,11 +87,6 @@ public interface Frequency extends Measure { return (Frequency) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularVelocity times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularAcceleration times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Frequency div(Dimensionless divisor) { return (Frequency) Hertz.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Dimensionless per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearAcceleration times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Dimensionless times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Frequency extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -665,6 +775,11 @@ public interface Frequency extends Measure { default Per divide(Voltage divisor) { return div(divisor); } + + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } /** Converts this frequency to the time period between cycles. */ default Time asPeriod() { return Seconds.of(1 / baseUnitMagnitude()); } } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearAcceleration.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearAcceleration.java index dc8f6d26b8..875ef937b1 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearAcceleration.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearAcceleration.java @@ -87,11 +87,6 @@ public interface LinearAcceleration extends Measure { return (LinearAcceleration) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearAcceleration div(Dimensionless divisor) { return (LinearAcceleration) MetersPerSecondPerSecond.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default LinearVelocity per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Dimensionless per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearVelocity times(Time multiplier) { @@ -597,6 +692,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface LinearAcceleration extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearMomentum.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearMomentum.java index 2a7ce3341d..c1bf6d7f11 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearMomentum.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearMomentum.java @@ -87,11 +87,6 @@ public interface LinearMomentum extends Measure { return (LinearMomentum) div(divisor); } - @Override - default Force per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearMomentum div(Dimensionless divisor) { return (LinearMomentum) KilogramMetersPerSecond.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Force times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Dimensionless per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Mass per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default LinearVelocity per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Force per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface LinearMomentum extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearVelocity.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearVelocity.java index e45aa5474a..7ed8cc1e5f 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearVelocity.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/LinearVelocity.java @@ -87,11 +87,6 @@ public interface LinearVelocity extends Measure { return (LinearVelocity) div(divisor); } - @Override - default LinearAcceleration per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearVelocity div(Dimensionless divisor) { return (LinearVelocity) MetersPerSecond.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearAcceleration times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Dimensionless per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Distance times(Time multiplier) { @@ -597,6 +692,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default LinearAcceleration per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface LinearVelocity extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Mass.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Mass.java index 81a0f1507f..507977df5c 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Mass.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Mass.java @@ -87,11 +87,6 @@ public interface Mass extends Measure { return (Mass) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mass div(Dimensionless divisor) { return (Mass) Kilograms.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Force times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Dimensionless per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Mass extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/MomentOfInertia.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/MomentOfInertia.java index b831bcffc6..21f04fbeb7 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/MomentOfInertia.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/MomentOfInertia.java @@ -87,11 +87,6 @@ public interface MomentOfInertia extends Measure { return (MomentOfInertia) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularMomentum times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default MomentOfInertia div(Dimensionless divisor) { return (MomentOfInertia) KilogramSquareMeters.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Dimensionless per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface MomentOfInertia extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Mult.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Mult.java index 3b7dcf840c..5cee72363d 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Mult.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Mult.java @@ -87,11 +87,6 @@ public interface Mult extends Measure) div(divisor); } - @Override - default Velocity> per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult, AccelerationUnit> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Mult extends Measure, AccelerationUnit> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngleUnit> times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Mult extends Measure, AngleUnit> per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularAccelerationUnit> times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Mult extends Measure, AngularAccelerationUnit> per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularMomentumUnit> times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Mult extends Measure, AngularMomentumUnit> per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularVelocityUnit> times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Mult extends Measure, AngularVelocityUnit> per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, CurrentUnit> times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Mult extends Measure, CurrentUnit> per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult div(Dimensionless divisor) { return (Mult) unit().of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Mult extends Measure, DistanceUnit> per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, EnergyUnit> times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Mult extends Measure, EnergyUnit> per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, ForceUnit> times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Mult extends Measure, ForceUnit> per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, FrequencyUnit> times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Mult extends Measure, FrequencyUnit> per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearAccelerationUnit> times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Mult extends Measure, LinearAccelerationUnit> per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearMomentumUnit> times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Mult extends Measure, LinearMomentumUnit> per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearVelocityUnit> times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Mult extends Measure, LinearVelocityUnit> per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MassUnit> times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Mult extends Measure, MassUnit> per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MomentOfInertiaUnit> times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Mult extends Measure, MomentOfInertiaUnit> per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MultUnit> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Mult extends Measure, MultUnit> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult, PerUnit> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Mult extends Measure, PerUnit> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult, PowerUnit> times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Mult extends Measure, PowerUnit> per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, ResistanceUnit> times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Mult extends Measure, ResistanceUnit> per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TemperatureUnit> times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Mult extends Measure, TemperatureUnit> per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TimeUnit> times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Mult extends Measure> per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TorqueUnit> times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Mult extends Measure, TorqueUnit> per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, VelocityUnit> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Mult extends Measure, VelocityUnit> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, VoltageUnit> times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Mult extends Measure, VoltageUnit> per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Per.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Per.java index e46fb50f89..2c1af67794 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Per.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Per.java @@ -87,11 +87,6 @@ public interface Per extends Measur return (Per) div(divisor); } - @Override - default Velocity> per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult, AccelerationUnit> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, AccelerationUnit> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngleUnit> times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, AngleUnit> per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularAccelerationUnit> times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, AngularAccelerationUnit> per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularMomentumUnit> times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, AngularMomentumUnit> per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularVelocityUnit> times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, AngularVelocityUnit> per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, CurrentUnit> times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, CurrentUnit> per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Per div(Dimensionless divisor) { return (Per) unit().of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, DistanceUnit> per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, EnergyUnit> times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, EnergyUnit> per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, ForceUnit> times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, ForceUnit> per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, FrequencyUnit> times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, FrequencyUnit> per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearAccelerationUnit> times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, LinearAccelerationUnit> per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearMomentumUnit> times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, LinearMomentumUnit> per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearVelocityUnit> times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, LinearVelocityUnit> per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MassUnit> times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, MassUnit> per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MomentOfInertiaUnit> times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, MomentOfInertiaUnit> per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MultUnit> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, MultUnit> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult, PerUnit> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, PerUnit> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult, PowerUnit> times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, PowerUnit> per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, ResistanceUnit> times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, ResistanceUnit> per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TemperatureUnit> times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, TemperatureUnit> per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TimeUnit> times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Velocity> per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TorqueUnit> times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, TorqueUnit> per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, VelocityUnit> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Per extends Measur return div(divisor); } + @Override + default Per, VelocityUnit> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, VoltageUnit> times(Voltage multiplier) { @@ -665,6 +775,11 @@ public interface Per extends Measur default Per, VoltageUnit> divide(Voltage divisor) { return div(divisor); } + + @Override + default Per, VoltageUnit> per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } default Measure timesDivisor(Measure multiplier) { return (Measure) baseUnit().numerator().ofBaseUnits(baseUnitMagnitude() * multiplier.baseUnitMagnitude()); } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Power.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Power.java index a666094881..d94ddcde38 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Power.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Power.java @@ -87,11 +87,6 @@ public interface Power extends Measure { return (Power) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Voltage per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Power div(Dimensionless divisor) { return (Power) Watts.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Frequency per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Dimensionless per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Energy times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Power extends Measure { return div(divisor); } + @Override + default Current per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Resistance.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Resistance.java index 28932b2c70..52d15b091a 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Resistance.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Resistance.java @@ -87,11 +87,6 @@ public interface Resistance extends Measure { return (Resistance) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Voltage times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Resistance div(Dimensionless divisor) { return (Resistance) Ohms.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Dimensionless per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Resistance extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Temperature.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Temperature.java index b10efd810d..2d7983b846 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Temperature.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Temperature.java @@ -87,11 +87,6 @@ public interface Temperature extends Measure { return (Temperature) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Temperature div(Dimensionless divisor) { return (Temperature) Kelvin.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Dimensionless per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Temperature extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Time.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Time.java index dccfda609d..4244325a26 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Time.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Time.java @@ -87,11 +87,6 @@ public interface Time extends Measure { return (Time) div(divisor); } - @Override - default Dimensionless per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default AngularVelocity times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Angle times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Time div(Dimensionless divisor) { return (Time) Seconds.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Dimensionless times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default LinearVelocity times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Distance times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Dimensionless per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Time extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -665,5 +775,10 @@ public interface Time extends Measure { default Per divide(Voltage divisor) { return div(divisor); } + + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } default Frequency asFrequency() { return Hertz.of(1 / baseUnitMagnitude()); } } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Torque.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Torque.java index e53dbaad94..cc7ac69da5 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Torque.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Torque.java @@ -87,11 +87,6 @@ public interface Torque extends Measure { return (Torque) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Torque div(Dimensionless divisor) { return (Torque) NewtonMeters.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Force per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Distance per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Dimensionless per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Torque extends Measure { return div(divisor); } + @Override + default Per per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Velocity.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Velocity.java index 056924849e..ac6df04e1f 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Velocity.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Velocity.java @@ -87,11 +87,6 @@ public interface Velocity extends Measure> { return (Velocity) div(divisor); } - @Override - default Velocity> per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult, AccelerationUnit> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, AccelerationUnit> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngleUnit> times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, AngleUnit> per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularAccelerationUnit> times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, AngularAccelerationUnit> per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularMomentumUnit> times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, AngularMomentumUnit> per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, AngularVelocityUnit> times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, AngularVelocityUnit> per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, CurrentUnit> times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, CurrentUnit> per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Velocity div(Dimensionless divisor) { return (Velocity) unit().of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, DistanceUnit> per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, EnergyUnit> times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, EnergyUnit> per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, ForceUnit> times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, ForceUnit> per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, FrequencyUnit> times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, FrequencyUnit> per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearAccelerationUnit> times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, LinearAccelerationUnit> per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearMomentumUnit> times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, LinearMomentumUnit> per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, LinearVelocityUnit> times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, LinearVelocityUnit> per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MassUnit> times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, MassUnit> per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MomentOfInertiaUnit> times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, MomentOfInertiaUnit> per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, MultUnit> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, MultUnit> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult, PerUnit> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, PerUnit> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult, PowerUnit> times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, PowerUnit> per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, ResistanceUnit> times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, ResistanceUnit> per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TemperatureUnit> times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, TemperatureUnit> per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Measure times(Time multiplier) { return (Measure) unit().numerator().ofBaseUnits(baseUnitMagnitude() * multiplier.baseUnitMagnitude()); @@ -596,6 +691,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Velocity> per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, TorqueUnit> times(Torque multiplier) { @@ -619,6 +719,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, TorqueUnit> per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, VelocityUnit> times(Velocity multiplier) { @@ -642,6 +747,11 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, VelocityUnit> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult, VoltageUnit> times(Voltage multiplier) { @@ -665,4 +775,9 @@ public interface Velocity extends Measure> { return div(divisor); } + @Override + default Per, VoltageUnit> per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Voltage.java b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Voltage.java index 98ceecedaa..33404865fd 100644 --- a/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Voltage.java +++ b/wpiunits/src/generated/main/java/edu/wpi/first/units/measure/Voltage.java @@ -87,11 +87,6 @@ public interface Voltage extends Measure { return (Voltage) div(divisor); } - @Override - default Velocity per(TimeUnit period) { - return div(period.of(1)); - } - @Override default Mult> times(Acceleration multiplier) { @@ -115,6 +110,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per> per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Angle multiplier) { @@ -138,6 +138,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularAcceleration multiplier) { @@ -161,6 +166,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularMomentum multiplier) { @@ -184,6 +194,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(AngularVelocity multiplier) { @@ -207,6 +222,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Power times(Current multiplier) { @@ -230,6 +250,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Resistance per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Voltage div(Dimensionless divisor) { return (Voltage) Volts.of(baseUnitMagnitude() / divisor.baseUnitMagnitude()); @@ -275,6 +300,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Energy multiplier) { @@ -298,6 +328,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Force multiplier) { @@ -321,6 +356,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Frequency multiplier) { @@ -344,6 +384,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearAcceleration multiplier) { @@ -367,6 +412,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearMomentum multiplier) { @@ -390,6 +440,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(LinearVelocity multiplier) { @@ -413,6 +468,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Mass multiplier) { @@ -436,6 +496,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(MomentOfInertia multiplier) { @@ -459,6 +524,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Mult multiplier) { @@ -482,6 +552,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per> per(MultUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult> times(Per multiplier) { @@ -505,6 +580,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per> per(PerUnit divisorUnit) { + return div(divisorUnit.ofNative(1)); + } + @Override default Mult times(Power multiplier) { @@ -528,6 +608,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Resistance multiplier) { @@ -551,6 +636,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Current per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Temperature multiplier) { @@ -574,6 +664,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Time multiplier) { @@ -597,6 +692,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Velocity per(TimeUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Torque multiplier) { @@ -620,6 +720,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult> times(Velocity multiplier) { @@ -643,6 +748,11 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Per> per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + @Override default Mult times(Voltage multiplier) { @@ -666,4 +776,9 @@ public interface Voltage extends Measure { return div(divisor); } + @Override + default Dimensionless per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + } diff --git a/wpiunits/src/main/java/edu/wpi/first/units/Measure.java b/wpiunits/src/main/java/edu/wpi/first/units/Measure.java index 28d6d9614a..6a436194b7 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/Measure.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/Measure.java @@ -1021,6 +1021,270 @@ public interface Measure extends Comparable> { .ofBaseUnits(baseUnitMagnitude() / divisor.baseUnitMagnitude()); } + /** + * Divides this measure by an acceleration unit and returns the result in the most appropriate + * unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(AccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by an angle unit and returns the result in the most appropriate unit. This + * is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(AngleUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by an angular acceleration unit and returns the result in the most + * appropriate unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(AngularAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by an angular momentum unit and returns the result in the most appropriate + * unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(AngularMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by an angular velocity unit and returns the result in the most appropriate + * unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(AngularVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a unit of electric current and returns the result in the most + * appropriate unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(CurrentUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a distance unit and returns the result in the most appropriate unit. + * This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(DistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by an energy unit and returns the result in the most appropriate unit. + * This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(EnergyUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a force unit and returns the result in the most appropriate unit. This + * is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(ForceUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a frequency unit and returns the result in the most appropriate unit. + * This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(FrequencyUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a linear acceleration unit and returns the result in the most + * appropriate unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(LinearAccelerationUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a linear momentum unit and returns the result in the most appropriate + * unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(LinearMomentumUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a linear velocity unit and returns the result in the most appropriate + * unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(LinearVelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a mass unit and returns the result in the most appropriate unit. This + * is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(MassUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a moment of inertia unit and returns the result in the most appropriate + * unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(MomentOfInertiaUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a generic compound unit and returns the result in the most appropriate + * unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(MultUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a power unit and returns the result in the most appropriate unit. This + * is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(PowerUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a generic ratio unit and returns the result in the most appropriate + * unit. This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(PerUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a temperature unit and returns the result in the most appropriate unit. + * This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(TemperatureUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a time period and returns the result in the most appropriate unit. This + * is equivalent to {@code div(period.of(1))}. + * + * @param period the time period measurement to divide by. + * @return the division result + */ + default Measure per(TimeUnit period) { + return div(period.of(1)); + } + + /** + * Divides this measure by a torque unit and returns the result in the most appropriate unit. This + * is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(TorqueUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a velocity unit and returns the result in the most appropriate unit. + * This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(VelocityUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a voltage unit and returns the result in the most appropriate unit. + * This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(VoltageUnit divisorUnit) { + return div(divisorUnit.one()); + } + + /** + * Divides this measure by a resistance unit and returns the result in the most appropriate unit. + * This is equivalent to {@code div(divisorUnit.of(1))}. + * + * @param divisorUnit the unit to divide by. + * @return the division result + */ + default Measure per(ResistanceUnit divisorUnit) { + return div(divisorUnit.one()); + } + /** * Divides this measure by a unitless scalar and returns the result. * @@ -1371,17 +1635,6 @@ public interface Measure extends Comparable> { baseUnitMagnitude() / divisor.baseUnitMagnitude(), divisor.unit().denominator()); } - /** - * Divides this measure by a time period and returns the result in the most appropriate unit. This - * is equivalent to {@code div(period.of(1))}. - * - * @param period the time period measurement to divide by. - * @return the division result - */ - default Measure per(TimeUnit period) { - return div(period.of(1)); - } - /** * Checks if this measure is near another measure of the same unit. Provide a variance threshold * for use for a +/- scalar, such as 0.05 for +/- 5%. diff --git a/wpiunits/src/main/java/edu/wpi/first/units/VelocityUnit.java b/wpiunits/src/main/java/edu/wpi/first/units/VelocityUnit.java index d954166db4..45374cd39c 100644 --- a/wpiunits/src/main/java/edu/wpi/first/units/VelocityUnit.java +++ b/wpiunits/src/main/java/edu/wpi/first/units/VelocityUnit.java @@ -90,14 +90,14 @@ public final class VelocityUnit extends PerUnit { @Override @SuppressWarnings("unchecked") - public Measure> zero() { - return (Measure>) super.zero(); + public Velocity zero() { + return (Velocity) super.zero(); } @Override @SuppressWarnings("unchecked") - public Measure> one() { - return (Measure>) super.one(); + public Velocity one() { + return (Velocity) super.one(); } @Override From 4caa16e254fb4e668eb9f58a382d8f98e0d361fa Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 17 Jan 2025 14:53:20 -0700 Subject: [PATCH 02/33] [wpilibj] ADIS16470: Allow product ID of 16470 (#7704) C++ allows either 16982 or 16470, do the same for Java. --- wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java index c2700b82c9..169f13dd46 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java @@ -483,7 +483,8 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable { } readRegister(PROD_ID); // Dummy read // Validate the product ID - if (readRegister(PROD_ID) != 16982) { + int prodId = readRegister(PROD_ID); + if (prodId != 16982 && prodId != 16470) { DriverStation.reportError("Could not find an ADIS16470", false); close(); return false; From 5ab0409c15d70cb97ebc2fec7398057dccee82a8 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 17 Jan 2025 19:14:20 -0700 Subject: [PATCH 03/33] [wpilib] ADIS164xx: report product ID on mismatch (#7706) --- wpilibc/src/main/native/cpp/ADIS16448_IMU.cpp | 4 +++- wpilibc/src/main/native/cpp/ADIS16470_IMU.cpp | 4 +++- .../src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java | 5 +++-- .../src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/wpilibc/src/main/native/cpp/ADIS16448_IMU.cpp b/wpilibc/src/main/native/cpp/ADIS16448_IMU.cpp index 7d42876c01..bc1b3a244b 100644 --- a/wpilibc/src/main/native/cpp/ADIS16448_IMU.cpp +++ b/wpilibc/src/main/native/cpp/ADIS16448_IMU.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -374,7 +375,8 @@ bool ADIS16448_IMU::SwitchToStandardSPI() { // Validate the product ID uint16_t prod_id = ReadRegister(PROD_ID); if (prod_id != 16448) { - REPORT_ERROR("Could not find ADIS16448!"); + REPORT_ERROR( + fmt::format("Could not find ADIS16448; got product ID {}", prod_id)); Close(); return false; } diff --git a/wpilibc/src/main/native/cpp/ADIS16470_IMU.cpp b/wpilibc/src/main/native/cpp/ADIS16470_IMU.cpp index 3fef9505a5..2ff191376e 100644 --- a/wpilibc/src/main/native/cpp/ADIS16470_IMU.cpp +++ b/wpilibc/src/main/native/cpp/ADIS16470_IMU.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -355,7 +356,8 @@ bool ADIS16470_IMU::SwitchToStandardSPI() { // Validate the product ID uint16_t prod_id = ReadRegister(PROD_ID); if (prod_id != 16982 && prod_id != 16470) { - REPORT_ERROR("Could not find ADIS16470!"); + REPORT_ERROR( + fmt::format("Could not find ADIS16470; got product ID {}", prod_id)); Close(); return false; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java index 7ef4c17eb2..008b17864f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16448_IMU.java @@ -425,8 +425,9 @@ public class ADIS16448_IMU implements AutoCloseable, Sendable { } readRegister(PROD_ID); // Dummy read // Validate the product ID - if (readRegister(PROD_ID) != 16448) { - DriverStation.reportError("Could not find ADIS16448", false); + int prodId = readRegister(PROD_ID); + if (prodId != 16448) { + DriverStation.reportError("Could not find ADIS16448; got product ID " + prodId, false); close(); return false; } diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java index 169f13dd46..0a957e3d65 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/ADIS16470_IMU.java @@ -485,7 +485,7 @@ public class ADIS16470_IMU implements AutoCloseable, Sendable { // Validate the product ID int prodId = readRegister(PROD_ID); if (prodId != 16982 && prodId != 16470) { - DriverStation.reportError("Could not find an ADIS16470", false); + DriverStation.reportError("Could not find an ADIS16470; got product ID " + prodId, false); close(); return false; } From 8fc3767b30fc2fba64ab5e5cd607c663497ca876 Mon Sep 17 00:00:00 2001 From: Matthew Wozniak <106494504+wozniak@users.noreply.github.com> Date: Sat, 18 Jan 2025 01:19:21 -0500 Subject: [PATCH 04/33] [wpimath] Fix macro name typo (#7707) --- wpimath/src/main/native/include/units/base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpimath/src/main/native/include/units/base.h b/wpimath/src/main/native/include/units/base.h index 5d37594448..fc5ae4b29d 100644 --- a/wpimath/src/main/native/include/units/base.h +++ b/wpimath/src/main/native/include/units/base.h @@ -1759,7 +1759,7 @@ namespace units namespace traits { -#ifdef FOR_DOXYGEN_PURPOSOES_ONLY +#ifdef FOR_DOXYGEN_PURPOSES_ONLY /** * @ingroup TypeTraits * @brief Trait for accessing the publicly defined types of `units::unit_t` From 00445f4f27b54b125127581bd77b9e3066675b23 Mon Sep 17 00:00:00 2001 From: sciencewhiz Date: Sat, 18 Jan 2025 15:02:41 -0800 Subject: [PATCH 05/33] [hal] Add Kitbot framework usage reporting (#7709) Used in FIRST's kitbot code --- hal/src/generate/Instances.txt | 2 ++ hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java | 4 ++++ hal/src/generated/main/native/include/hal/FRCUsageReporting.h | 2 ++ hal/src/generated/main/native/include/hal/UsageReporting.h | 2 ++ 4 files changed, 10 insertions(+) diff --git a/hal/src/generate/Instances.txt b/hal/src/generate/Instances.txt index 20d2738d9a..c8b566d6d9 100644 --- a/hal/src/generate/Instances.txt +++ b/hal/src/generate/Instances.txt @@ -15,6 +15,8 @@ kFramework_ROS = 5 kFramework_RobotBuilder = 6 kFramework_AdvantageKit = 7 kFramework_MagicBot = 8 +kFramework_KitBotTraditional = 9 +kFramework_KitBotInline = 10 kRobotDrive_ArcadeStandard = 1 kRobotDrive_ArcadeButtonSpin = 2 kRobotDrive_ArcadeRatioCurve = 3 diff --git a/hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java b/hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java index 30ba993033..acb569d2de 100644 --- a/hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java +++ b/hal/src/generated/main/java/edu/wpi/first/hal/FRCNetComm.java @@ -317,6 +317,10 @@ public final class FRCNetComm { public static final int kFramework_AdvantageKit = 7; /** kFramework_MagicBot = 8. */ public static final int kFramework_MagicBot = 8; + /** kFramework_KitBotTraditional = 9. */ + public static final int kFramework_KitBotTraditional = 9; + /** kFramework_KitBotInline = 10. */ + public static final int kFramework_KitBotInline = 10; /** kRobotDrive_ArcadeStandard = 1. */ public static final int kRobotDrive_ArcadeStandard = 1; /** kRobotDrive_ArcadeButtonSpin = 2. */ diff --git a/hal/src/generated/main/native/include/hal/FRCUsageReporting.h b/hal/src/generated/main/native/include/hal/FRCUsageReporting.h index 65299cf91e..76bc53cf98 100644 --- a/hal/src/generated/main/native/include/hal/FRCUsageReporting.h +++ b/hal/src/generated/main/native/include/hal/FRCUsageReporting.h @@ -197,6 +197,8 @@ namespace HALUsageReporting { kFramework_RobotBuilder = 6, kFramework_AdvantageKit = 7, kFramework_MagicBot = 8, + kFramework_KitBotTraditional = 9, + kFramework_KitBotInline = 10, kRobotDrive_ArcadeStandard = 1, kRobotDrive_ArcadeButtonSpin = 2, kRobotDrive_ArcadeRatioCurve = 3, diff --git a/hal/src/generated/main/native/include/hal/UsageReporting.h b/hal/src/generated/main/native/include/hal/UsageReporting.h index e2fc6900d0..ca88ab4630 100644 --- a/hal/src/generated/main/native/include/hal/UsageReporting.h +++ b/hal/src/generated/main/native/include/hal/UsageReporting.h @@ -170,6 +170,8 @@ typedef enum kFramework_RobotBuilder = 6, kFramework_AdvantageKit = 7, kFramework_MagicBot = 8, + kFramework_KitBotTraditional = 9, + kFramework_KitBotInline = 10, kRobotDrive_ArcadeStandard = 1, kRobotDrive_ArcadeButtonSpin = 2, kRobotDrive_ArcadeRatioCurve = 3, From 72541c10e612575517278aa4262c033ed12a970e Mon Sep 17 00:00:00 2001 From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> Date: Sun, 19 Jan 2025 20:34:07 -0800 Subject: [PATCH 06/33] [wpilib, commands] Improve HID direction documentation (NFC) (#7672) --- .../generate/main/java/commandhid.java.jinja | 2 +- .../frc2/command/button/commandhid.h.jinja | 2 +- .../command/button/CommandPS4Controller.java | 8 ++-- .../command/button/CommandPS5Controller.java | 8 ++-- .../button/CommandStadiaController.java | 8 ++-- .../command/button/CommandXboxController.java | 8 ++-- .../command/button/CommandPS4Controller.h | 8 ++-- .../command/button/CommandPS5Controller.h | 8 ++-- .../command/button/CommandStadiaController.h | 8 ++-- .../command/button/CommandXboxController.h | 8 ++-- .../command/button/CommandJoystick.java | 24 ++++++++-- .../frc2/command/button/CommandJoystick.cpp | 8 ++++ .../frc2/command/button/CommandJoystick.h | 6 ++- .../main/native/include/frc/hid.h.jinja | 2 +- .../main/native/include/frc/PS4Controller.h | 8 ++-- .../main/native/include/frc/PS5Controller.h | 8 ++-- .../native/include/frc/StadiaController.h | 8 ++-- .../main/native/include/frc/XboxController.h | 8 ++-- wpilibc/src/main/native/cpp/Joystick.cpp | 8 ++++ .../src/main/native/include/frc/Joystick.h | 8 +++- wpilibj/src/generate/hids.json | 48 ++++++++++++------- wpilibj/src/generate/hids.schema.json | 7 ++- wpilibj/src/generate/main/java/hid.java.jinja | 2 +- .../edu/wpi/first/wpilibj/PS4Controller.java | 8 ++-- .../edu/wpi/first/wpilibj/PS5Controller.java | 8 ++-- .../wpi/first/wpilibj/StadiaController.java | 8 ++-- .../edu/wpi/first/wpilibj/XboxController.java | 8 ++-- .../java/edu/wpi/first/wpilibj/Joystick.java | 22 ++++++--- 28 files changed, 168 insertions(+), 99 deletions(-) diff --git a/wpilibNewCommands/src/generate/main/java/commandhid.java.jinja b/wpilibNewCommands/src/generate/main/java/commandhid.java.jinja index 331c7723a2..1198f6ae08 100644 --- a/wpilibNewCommands/src/generate/main/java/commandhid.java.jinja +++ b/wpilibNewCommands/src/generate/main/java/commandhid.java.jinja @@ -107,7 +107,7 @@ public class Command{{ ConsoleName }}Controller extends CommandGenericHID { {% endfor -%} {% for stick in sticks %} /** - * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. {{ stick.PositiveDirection }} is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generate/main/native/include/frc2/command/button/commandhid.h.jinja b/wpilibNewCommands/src/generate/main/native/include/frc2/command/button/commandhid.h.jinja index 8e1d54074d..0a0242cc27 100644 --- a/wpilibNewCommands/src/generate/main/native/include/frc2/command/button/commandhid.h.jinja +++ b/wpilibNewCommands/src/generate/main/native/include/frc2/command/button/commandhid.h.jinja @@ -71,7 +71,7 @@ class Command{{ ConsoleName }}Controller : public CommandGenericHID { {% endfor -%} {% for stick in sticks %} /** - * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. {{ stick.PositiveDirection }} is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java index 9c72f60cbd..a65dbaea72 100644 --- a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java +++ b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS4Controller.java @@ -348,7 +348,7 @@ public class CommandPS4Controller extends CommandGenericHID { } /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ @@ -357,7 +357,7 @@ public class CommandPS4Controller extends CommandGenericHID { } /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ @@ -366,7 +366,7 @@ public class CommandPS4Controller extends CommandGenericHID { } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ @@ -375,7 +375,7 @@ public class CommandPS4Controller extends CommandGenericHID { } /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java index 908d24e842..17f775a1ee 100644 --- a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java +++ b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandPS5Controller.java @@ -348,7 +348,7 @@ public class CommandPS5Controller extends CommandGenericHID { } /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ @@ -357,7 +357,7 @@ public class CommandPS5Controller extends CommandGenericHID { } /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ @@ -366,7 +366,7 @@ public class CommandPS5Controller extends CommandGenericHID { } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ @@ -375,7 +375,7 @@ public class CommandPS5Controller extends CommandGenericHID { } /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java index 0890bbde48..a67fc877de 100644 --- a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java +++ b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandStadiaController.java @@ -370,7 +370,7 @@ public class CommandStadiaController extends CommandGenericHID { } /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ @@ -379,7 +379,7 @@ public class CommandStadiaController extends CommandGenericHID { } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ @@ -388,7 +388,7 @@ public class CommandStadiaController extends CommandGenericHID { } /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ @@ -397,7 +397,7 @@ public class CommandStadiaController extends CommandGenericHID { } /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java index a5ea65da28..a6de3c3e39 100644 --- a/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java +++ b/wpilibNewCommands/src/generated/main/java/edu/wpi/first/wpilibj2/command/button/CommandXboxController.java @@ -338,7 +338,7 @@ public class CommandXboxController extends CommandGenericHID { } /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ @@ -347,7 +347,7 @@ public class CommandXboxController extends CommandGenericHID { } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ @@ -356,7 +356,7 @@ public class CommandXboxController extends CommandGenericHID { } /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ @@ -365,7 +365,7 @@ public class CommandXboxController extends CommandGenericHID { } /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS4Controller.h b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS4Controller.h index ac0920f1a5..5e650aef29 100644 --- a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS4Controller.h +++ b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS4Controller.h @@ -204,28 +204,28 @@ class CommandPS4Controller : public CommandGenericHID { .GetDefaultButtonLoop()) const; /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ double GetLeftX() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ double GetLeftY() const; /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ double GetRightX() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS5Controller.h b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS5Controller.h index a92693ea83..7aa66be6b8 100644 --- a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS5Controller.h +++ b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandPS5Controller.h @@ -204,28 +204,28 @@ class CommandPS5Controller : public CommandGenericHID { .GetDefaultButtonLoop()) const; /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ double GetLeftX() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ double GetLeftY() const; /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ double GetRightX() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandStadiaController.h b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandStadiaController.h index cbd89c2ada..727b9a434f 100644 --- a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandStadiaController.h +++ b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandStadiaController.h @@ -216,28 +216,28 @@ class CommandStadiaController : public CommandGenericHID { .GetDefaultButtonLoop()) const; /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ double GetLeftX() const; /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ double GetRightX() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ double GetLeftY() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandXboxController.h b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandXboxController.h index 9fb94f4825..f23d0a096a 100644 --- a/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandXboxController.h +++ b/wpilibNewCommands/src/generated/main/native/include/frc2/command/button/CommandXboxController.h @@ -190,28 +190,28 @@ class CommandXboxController : public CommandGenericHID { .GetDefaultButtonLoop()) const; /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ double GetLeftX() const; /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ double GetRightX() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ double GetLeftY() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java index 647369f401..00d913e669 100644 --- a/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java +++ b/wpilibNewCommands/src/main/java/edu/wpi/first/wpilibj2/command/button/CommandJoystick.java @@ -173,6 +173,9 @@ public class CommandJoystick extends CommandGenericHID { /** * Get the x position of the HID. * + *

This depends on the mapping of the joystick connected to the current port. On most + * joysticks, positive is to the right. + * * @return the x position */ public double getX() { @@ -182,6 +185,9 @@ public class CommandJoystick extends CommandGenericHID { /** * Get the y position of the HID. * + *

This depends on the mapping of the joystick connected to the current port. On most + * joysticks, positive is to the back. + * * @return the y position */ public double getY() { @@ -218,8 +224,8 @@ public class CommandJoystick extends CommandGenericHID { } /** - * Get the magnitude of the direction vector formed by the joystick's current position relative to - * its origin. + * Get the magnitude of the vector formed by the joystick's current position relative to its + * origin. * * @return The magnitude of the direction vector */ @@ -228,16 +234,26 @@ public class CommandJoystick extends CommandGenericHID { } /** - * Get the direction of the vector formed by the joystick and its origin in radians. + * Get the direction of the vector formed by the joystick and its origin in radians. 0 is forward + * and clockwise is positive. (Straight right is π/2.) * * @return The direction of the vector in radians */ public double getDirectionRadians() { + // https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system + // A positive rotation around the X axis moves the joystick right, and a + // positive rotation around the Y axis moves the joystick backward. When + // treating them as translations, 0 radians is measured from the right + // direction, and angle increases clockwise. + // + // It's rotated 90 degrees CCW (y is negated and the arguments are reversed) + // so that 0 radians is forward. return m_hid.getDirectionRadians(); } /** - * Get the direction of the vector formed by the joystick and its origin in degrees. + * Get the direction of the vector formed by the joystick and its origin in degrees. 0 is forward + * and clockwise is positive. (Straight right is 90.) * * @return The direction of the vector in degrees */ diff --git a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandJoystick.cpp b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandJoystick.cpp index ae25fb05ea..2d36ef7cb6 100644 --- a/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandJoystick.cpp +++ b/wpilibNewCommands/src/main/native/cpp/frc2/command/button/CommandJoystick.cpp @@ -26,5 +26,13 @@ double CommandJoystick::GetMagnitude() const { } units::radian_t CommandJoystick::GetDirection() const { + // https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system + // A positive rotation around the X axis moves the joystick right, and a + // positive rotation around the Y axis moves the joystick backward. When + // treating them as translations, 0 radians is measured from the right + // direction, and angle increases clockwise. + // + // It's rotated 90 degrees CCW (y is negated and the arguments are reversed) + // so that 0 radians is forward. return m_hid.GetDirection(); } diff --git a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandJoystick.h b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandJoystick.h index d1eeadfc2c..ee390d0aa5 100644 --- a/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandJoystick.h +++ b/wpilibNewCommands/src/main/native/include/frc2/command/button/CommandJoystick.h @@ -56,7 +56,7 @@ class CommandJoystick : public CommandGenericHID { class Trigger Top(frc::EventLoop* loop = CommandScheduler::GetInstance() .GetDefaultButtonLoop()) const; /** - * Get the magnitude of the direction vector formed by the joystick's + * Get the magnitude of the vector formed by the joystick's * current position relative to its origin. * * @return The magnitude of the direction vector @@ -64,7 +64,9 @@ class CommandJoystick : public CommandGenericHID { double GetMagnitude() const; /** - * Get the direction of the vector formed by the joystick and its origin. + * Get the direction of the vector formed by the joystick and its origin. 0 is + * forward and clockwise is positive. (Straight right is π/2 radians or 90 + * degrees.) * * @return The direction of the vector. */ diff --git a/wpilibc/src/generate/main/native/include/frc/hid.h.jinja b/wpilibc/src/generate/main/native/include/frc/hid.h.jinja index 5f26fe2435..af6d46d36c 100644 --- a/wpilibc/src/generate/main/native/include/frc/hid.h.jinja +++ b/wpilibc/src/generate/main/native/include/frc/hid.h.jinja @@ -47,7 +47,7 @@ class {{ ConsoleName }}Controller : public GenericHID, {{ ConsoleName }}Controller& operator=({{ ConsoleName }}Controller&&) = default; {% for stick in sticks %} /** - * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. {{ stick.PositiveDirection }} is positive. * * @return the axis value. */ diff --git a/wpilibc/src/generated/main/native/include/frc/PS4Controller.h b/wpilibc/src/generated/main/native/include/frc/PS4Controller.h index ed8f5a5cf2..01e8c49c47 100644 --- a/wpilibc/src/generated/main/native/include/frc/PS4Controller.h +++ b/wpilibc/src/generated/main/native/include/frc/PS4Controller.h @@ -45,28 +45,28 @@ class PS4Controller : public GenericHID, PS4Controller& operator=(PS4Controller&&) = default; /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return the axis value. */ double GetLeftX() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return the axis value. */ double GetLeftY() const; /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return the axis value. */ double GetRightX() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return the axis value. */ diff --git a/wpilibc/src/generated/main/native/include/frc/PS5Controller.h b/wpilibc/src/generated/main/native/include/frc/PS5Controller.h index 3a1c9217ee..2fd6557e25 100644 --- a/wpilibc/src/generated/main/native/include/frc/PS5Controller.h +++ b/wpilibc/src/generated/main/native/include/frc/PS5Controller.h @@ -45,28 +45,28 @@ class PS5Controller : public GenericHID, PS5Controller& operator=(PS5Controller&&) = default; /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return the axis value. */ double GetLeftX() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return the axis value. */ double GetLeftY() const; /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return the axis value. */ double GetRightX() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return the axis value. */ diff --git a/wpilibc/src/generated/main/native/include/frc/StadiaController.h b/wpilibc/src/generated/main/native/include/frc/StadiaController.h index 025377f600..89b7dab339 100644 --- a/wpilibc/src/generated/main/native/include/frc/StadiaController.h +++ b/wpilibc/src/generated/main/native/include/frc/StadiaController.h @@ -45,28 +45,28 @@ class StadiaController : public GenericHID, StadiaController& operator=(StadiaController&&) = default; /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return the axis value. */ double GetLeftX() const; /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return the axis value. */ double GetRightX() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return the axis value. */ double GetLeftY() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return the axis value. */ diff --git a/wpilibc/src/generated/main/native/include/frc/XboxController.h b/wpilibc/src/generated/main/native/include/frc/XboxController.h index 222fc2b0f8..e69f9bdb02 100644 --- a/wpilibc/src/generated/main/native/include/frc/XboxController.h +++ b/wpilibc/src/generated/main/native/include/frc/XboxController.h @@ -45,28 +45,28 @@ class XboxController : public GenericHID, XboxController& operator=(XboxController&&) = default; /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return the axis value. */ double GetLeftX() const; /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return the axis value. */ double GetRightX() const; /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return the axis value. */ double GetLeftY() const; /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return the axis value. */ diff --git a/wpilibc/src/main/native/cpp/Joystick.cpp b/wpilibc/src/main/native/cpp/Joystick.cpp index b58a514cbd..8ee437a3f5 100644 --- a/wpilibc/src/main/native/cpp/Joystick.cpp +++ b/wpilibc/src/main/native/cpp/Joystick.cpp @@ -119,5 +119,13 @@ double Joystick::GetMagnitude() const { } units::radian_t Joystick::GetDirection() const { + // https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system + // A positive rotation around the X axis moves the joystick right, and a + // positive rotation around the Y axis moves the joystick backward. When + // treating them as translations, 0 radians is measured from the right + // direction, and angle increases clockwise. + // + // It's rotated 90 degrees CCW (y is negated and the arguments are reversed) + // so that 0 radians is forward. return units::radian_t{std::atan2(GetX(), -GetY())}; } diff --git a/wpilibc/src/main/native/include/frc/Joystick.h b/wpilibc/src/main/native/include/frc/Joystick.h index 0f8e101491..399a304d84 100644 --- a/wpilibc/src/main/native/include/frc/Joystick.h +++ b/wpilibc/src/main/native/include/frc/Joystick.h @@ -148,6 +148,7 @@ class Joystick : public GenericHID { * Get the X value of the current joystick. * * This depends on the mapping of the joystick connected to the current port. + * On most joysticks, positive is to the right. */ double GetX() const; @@ -155,6 +156,7 @@ class Joystick : public GenericHID { * Get the Y value of the current joystick. * * This depends on the mapping of the joystick connected to the current port. + * On most joysticks, positive is to the back. */ double GetY() const; @@ -244,7 +246,7 @@ class Joystick : public GenericHID { BooleanEvent Top(EventLoop* loop) const; /** - * Get the magnitude of the direction vector formed by the joystick's + * Get the magnitude of the vector formed by the joystick's * current position relative to its origin. * * @return The magnitude of the direction vector @@ -252,7 +254,9 @@ class Joystick : public GenericHID { double GetMagnitude() const; /** - * Get the direction of the vector formed by the joystick and its origin. + * Get the direction of the vector formed by the joystick and its origin. 0 is + * forward and clockwise is positive. (Straight right is π/2 radians or 90 + * degrees.) * * @return The direction of the vector. */ diff --git a/wpilibj/src/generate/hids.json b/wpilibj/src/generate/hids.json index f27806458a..ed7d4f9e63 100644 --- a/wpilibj/src/generate/hids.json +++ b/wpilibj/src/generate/hids.json @@ -60,28 +60,32 @@ "left", "X" ], - "value": 0 + "value": 0, + "PositiveDirection": "Right" }, { "NameParts": [ "right", "X" ], - "value": 4 + "value": 4, + "PositiveDirection": "Right" }, { "NameParts": [ "left", "Y" ], - "value": 1 + "value": 1, + "PositiveDirection": "Back" }, { "NameParts": [ "right", "Y" ], - "value": 5 + "value": 5, + "PositiveDirection": "Back" } ], "triggers": [ @@ -175,28 +179,32 @@ "left", "X" ], - "value": 0 + "value": 0, + "PositiveDirection": "Right" }, { "NameParts": [ "left", "Y" ], - "value": 1 + "value": 1, + "PositiveDirection": "Back" }, { "NameParts": [ "right", "X" ], - "value": 2 + "value": 2, + "PositiveDirection": "Right" }, { "NameParts": [ "right", "Y" ], - "value": 5 + "value": 5, + "PositiveDirection": "Back" } ], "triggers": [ @@ -290,28 +298,32 @@ "left", "X" ], - "value": 0 + "value": 0, + "PositiveDirection": "Right" }, { "NameParts": [ "left", "Y" ], - "value": 1 + "value": 1, + "PositiveDirection": "Back" }, { "NameParts": [ "right", "X" ], - "value": 2 + "value": 2, + "PositiveDirection": "Right" }, { "NameParts": [ "right", "Y" ], - "value": 5 + "value": 5, + "PositiveDirection": "Back" } ], "triggers": [ @@ -412,28 +424,32 @@ "left", "X" ], - "value": 0 + "value": 0, + "PositiveDirection": "Right" }, { "NameParts": [ "right", "X" ], - "value": 3 + "value": 3, + "PositiveDirection": "Right" }, { "NameParts": [ "left", "Y" ], - "value": 1 + "value": 1, + "PositiveDirection": "Back" }, { "NameParts": [ "right", "Y" ], - "value": 4 + "value": 4, + "PositiveDirection": "Back" } ] } diff --git a/wpilibj/src/generate/hids.schema.json b/wpilibj/src/generate/hids.schema.json index 3b9dca3015..fa40e7d7f0 100644 --- a/wpilibj/src/generate/hids.schema.json +++ b/wpilibj/src/generate/hids.schema.json @@ -66,7 +66,8 @@ "type": "object", "required": [ "NameParts", - "value" + "value", + "PositiveDirection" ], "properties": { "NameParts": { @@ -80,6 +81,10 @@ "value": { "description": "The axis value", "type": "integer" + }, + "PositiveDirection": { + "description": "The positive direction of the axis.", + "type": "string" } } } diff --git a/wpilibj/src/generate/main/java/hid.java.jinja b/wpilibj/src/generate/main/java/hid.java.jinja index 242bf13f75..4becaf48b6 100644 --- a/wpilibj/src/generate/main/java/hid.java.jinja +++ b/wpilibj/src/generate/main/java/hid.java.jinja @@ -103,7 +103,7 @@ public class {{ ConsoleName }}Controller extends GenericHID implements Sendable } {% for stick in sticks %} /** - * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. + * Get the {{ stick.NameParts[1] }} axis value of {{ stick.NameParts[0] }} side of the controller. {{ stick.PositiveDirection }} is positive. * * @return The axis value. */ diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java index 70c1ce1c16..bf5ee2d59c 100644 --- a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS4Controller.java @@ -129,7 +129,7 @@ public class PS4Controller extends GenericHID implements Sendable { } /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ @@ -138,7 +138,7 @@ public class PS4Controller extends GenericHID implements Sendable { } /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ @@ -147,7 +147,7 @@ public class PS4Controller extends GenericHID implements Sendable { } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ @@ -156,7 +156,7 @@ public class PS4Controller extends GenericHID implements Sendable { } /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java index 7cd5bfd5f1..48da8e8415 100644 --- a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/PS5Controller.java @@ -129,7 +129,7 @@ public class PS5Controller extends GenericHID implements Sendable { } /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ @@ -138,7 +138,7 @@ public class PS5Controller extends GenericHID implements Sendable { } /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ @@ -147,7 +147,7 @@ public class PS5Controller extends GenericHID implements Sendable { } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ @@ -156,7 +156,7 @@ public class PS5Controller extends GenericHID implements Sendable { } /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java index 5443e5755b..f0a120bda1 100644 --- a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/StadiaController.java @@ -127,7 +127,7 @@ public class StadiaController extends GenericHID implements Sendable { } /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ @@ -136,7 +136,7 @@ public class StadiaController extends GenericHID implements Sendable { } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ @@ -145,7 +145,7 @@ public class StadiaController extends GenericHID implements Sendable { } /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ @@ -154,7 +154,7 @@ public class StadiaController extends GenericHID implements Sendable { } /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java index 78abae8ed7..04efec2217 100644 --- a/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java +++ b/wpilibj/src/generated/main/java/edu/wpi/first/wpilibj/XboxController.java @@ -121,7 +121,7 @@ public class XboxController extends GenericHID implements Sendable { } /** - * Get the X axis value of left side of the controller. + * Get the X axis value of left side of the controller. Right is positive. * * @return The axis value. */ @@ -130,7 +130,7 @@ public class XboxController extends GenericHID implements Sendable { } /** - * Get the X axis value of right side of the controller. + * Get the X axis value of right side of the controller. Right is positive. * * @return The axis value. */ @@ -139,7 +139,7 @@ public class XboxController extends GenericHID implements Sendable { } /** - * Get the Y axis value of left side of the controller. + * Get the Y axis value of left side of the controller. Back is positive. * * @return The axis value. */ @@ -148,7 +148,7 @@ public class XboxController extends GenericHID implements Sendable { } /** - * Get the Y axis value of right side of the controller. + * Get the Y axis value of right side of the controller. Back is positive. * * @return The axis value. */ diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Joystick.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Joystick.java index 08eebeef7d..8078eff208 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Joystick.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Joystick.java @@ -179,7 +179,7 @@ public class Joystick extends GenericHID { /** * Get the X value of the joystick. This depends on the mapping of the joystick connected to the - * current port. + * current port. On most joysticks, positive is to the right. * * @return The X value of the joystick. */ @@ -189,7 +189,7 @@ public class Joystick extends GenericHID { /** * Get the Y value of the joystick. This depends on the mapping of the joystick connected to the - * current port. + * current port. On most joysticks, positive is to the back. * * @return The Y value of the joystick. */ @@ -303,8 +303,8 @@ public class Joystick extends GenericHID { } /** - * Get the magnitude of the direction vector formed by the joystick's current position relative to - * its origin. + * Get the magnitude of the vector formed by the joystick's current position relative to its + * origin. * * @return The magnitude of the direction vector */ @@ -313,16 +313,26 @@ public class Joystick extends GenericHID { } /** - * Get the direction of the vector formed by the joystick and its origin in radians. + * Get the direction of the vector formed by the joystick and its origin in radians. 0 is forward + * and clockwise is positive. (Straight right is π/2.) * * @return The direction of the vector in radians */ public double getDirectionRadians() { + // https://docs.wpilib.org/en/stable/docs/software/basic-programming/coordinate-system.html#joystick-and-controller-coordinate-system + // A positive rotation around the X axis moves the joystick right, and a + // positive rotation around the Y axis moves the joystick backward. When + // treating them as translations, 0 radians is measured from the right + // direction, and angle increases clockwise. + // + // It's rotated 90 degrees CCW (y is negated and the arguments are reversed) + // so that 0 radians is forward. return Math.atan2(getX(), -getY()); } /** - * Get the direction of the vector formed by the joystick and its origin in degrees. + * Get the direction of the vector formed by the joystick and its origin in degrees. 0 is forward + * and clockwise is positive. (Straight right is 90.) * * @return The direction of the vector in degrees */ From 304b98c0c9df41fd06345143a0c7c67a1c5b712b Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Mon, 20 Jan 2025 11:10:03 -0500 Subject: [PATCH 07/33] [wpilibc] Alert: Fix first alert in group not publishing data (#7711) --- wpilibc/src/main/native/cpp/Alert.cpp | 4 ++-- wpilibc/src/test/native/cpp/AlertTest.cpp | 14 +++++++++++--- .../test/java/edu/wpi/first/wpilibj/AlertTest.java | 13 ++++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/wpilibc/src/main/native/cpp/Alert.cpp b/wpilibc/src/main/native/cpp/Alert.cpp index 17fa52f4ea..f74f0ab759 100644 --- a/wpilibc/src/main/native/cpp/Alert.cpp +++ b/wpilibc/src/main/native/cpp/Alert.cpp @@ -87,9 +87,9 @@ class Alert::SendableAlerts : public nt::NTSendable, wpi::SendableRegistry::EnsureInitialized(); static wpi::StringMap groups; - auto [iter, exists] = groups.try_emplace(group); + auto [iter, inserted] = groups.try_emplace(group); SendableAlerts& sendable = iter->second; - if (!exists) { + if (inserted) { frc::SmartDashboard::PutData(group, &iter->second); } return sendable; diff --git a/wpilibc/src/test/native/cpp/AlertTest.cpp b/wpilibc/src/test/native/cpp/AlertTest.cpp index a02e0166a8..b19f0dd0c4 100644 --- a/wpilibc/src/test/native/cpp/AlertTest.cpp +++ b/wpilibc/src/test/native/cpp/AlertTest.cpp @@ -33,8 +33,7 @@ class AlertsTest : public ::testing::Test { std::string GetGroupName() { const ::testing::TestInfo* testInfo = ::testing::UnitTest::GetInstance()->current_test_info(); - return fmt::format("{}_{}", testInfo->test_suite_name(), - testInfo->test_case_name()); + return fmt::format("{}_{}", testInfo->test_suite_name(), testInfo->name()); } template @@ -80,7 +79,16 @@ class AlertsTest : public ::testing::Test { #define EXPECT_STATE(type, ...) \ EXPECT_EQ(GetActiveAlerts(type), (std::vector{__VA_ARGS__})) -TEST_F(AlertsTest, SetUnset) { +TEST_F(AlertsTest, SetUnsetSingle) { + auto one = MakeAlert("one", kInfo); + EXPECT_FALSE(IsAlertActive("one", kInfo)); + one.Set(true); + EXPECT_TRUE(IsAlertActive("one", kInfo)); + one.Set(false); + EXPECT_FALSE(IsAlertActive("one", kInfo)); +} + +TEST_F(AlertsTest, SetUnsetMultiple) { auto one = MakeAlert("one", kError); auto two = MakeAlert("two", kInfo); EXPECT_FALSE(IsAlertActive("one", kError)); diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/AlertTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/AlertTest.java index 3e1f9b3abd..79e4bb0f88 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/AlertTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/AlertTest.java @@ -81,7 +81,18 @@ class AlertTest { } @Test - void setUnset() { + void setUnsetSingle() { + try (var one = makeAlert("one", AlertType.kInfo)) { + assertFalse(isAlertActive("one", AlertType.kInfo)); + one.set(true); + assertTrue(isAlertActive("one", AlertType.kInfo)); + one.set(false); + assertFalse(isAlertActive("one", AlertType.kInfo)); + } + } + + @Test + void setUnsetMultiple() { try (var one = makeAlert("one", AlertType.kError); var two = makeAlert("two", AlertType.kInfo)) { assertFalse(isAlertActive("one", AlertType.kError)); From 0690d3d8323b0f94f09c6a18fa4e07c54aeb02a8 Mon Sep 17 00:00:00 2001 From: sciencewhiz Date: Mon, 20 Jan 2025 08:14:27 -0800 Subject: [PATCH 08/33] [ci] Update labeler for wpical and usage reporting (#7710) --- .github/labeler.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/labeler.yml b/.github/labeler.yml index f9ae9fa6dd..5ec26eaa0f 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -54,3 +54,12 @@ 'component: wpiutil': - changed-files: - any-glob-to-any-file: wpiutil/** +'component: wpical': +- changed-files: + - any-glob-to-any-file: wpical/** +'component: usage reporting': +- changed-files: + - any-glob-to-any-file: hal/src/generate/** + 'attn: NI': +- changed-files: + - any-glob-to-any-file: hal/src/generate/** From d86a2ec83b599f1f8f6dec8cd11707fa04eead86 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 21 Jan 2025 11:51:48 -0800 Subject: [PATCH 09/33] [ci] Fix labeler indentation (#7716) --- .github/labeler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index 5ec26eaa0f..166e5bfdd2 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -60,6 +60,6 @@ 'component: usage reporting': - changed-files: - any-glob-to-any-file: hal/src/generate/** - 'attn: NI': +'attn: NI': - changed-files: - any-glob-to-any-file: hal/src/generate/** From 25d11524e89c170e1b8dd91e94f13babcfc75c6d Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Fri, 24 Jan 2025 00:46:13 -0500 Subject: [PATCH 10/33] [ci] Re-enable Artifactory cleaner cron job (#7721) The query now targets the local repo for extra safety. --- .github/workflows/aql/wpilib-mvn-development_unused.aql | 2 +- .github/workflows/artifactory-nightly-cleanup.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/aql/wpilib-mvn-development_unused.aql b/.github/workflows/aql/wpilib-mvn-development_unused.aql index 4fc627fbd3..365094310c 100644 --- a/.github/workflows/aql/wpilib-mvn-development_unused.aql +++ b/.github/workflows/aql/wpilib-mvn-development_unused.aql @@ -3,7 +3,7 @@ { "aql": { "items.find": { - "repo": "wpilib-mvn-development", + "repo": "wpilib-mvn-development-local", "path": { "$nmatch":"*edu/wpi/first/thirdparty*" }, "$or":[ { diff --git a/.github/workflows/artifactory-nightly-cleanup.yml b/.github/workflows/artifactory-nightly-cleanup.yml index f76ec77db7..7f694b6d75 100644 --- a/.github/workflows/artifactory-nightly-cleanup.yml +++ b/.github/workflows/artifactory-nightly-cleanup.yml @@ -2,6 +2,8 @@ name: Artifactory Nightly Cleanup on: workflow_dispatch: + schedule: + - cron: '15 2 * * *' jobs: wpilib-mvn-development_unused_cleanup: From b44a80c07a809cf4e1d1d10abc9afa2bac648da5 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Sat, 25 Jan 2025 02:26:09 -0500 Subject: [PATCH 11/33] [build] cmake: Install wpimath nanopb headers (#7731) --- wpimath/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/wpimath/CMakeLists.txt b/wpimath/CMakeLists.txt index 19780acd83..348fef5e99 100644 --- a/wpimath/CMakeLists.txt +++ b/wpimath/CMakeLists.txt @@ -189,6 +189,12 @@ target_include_directories( $ ) +install( + DIRECTORY src/generated/main/native/cpp/ + DESTINATION "${include_dest}/wpimath" + FILES_MATCHING + PATTERN "*.h" +) install(DIRECTORY src/main/native/include/ DESTINATION "${include_dest}/wpimath") target_include_directories( wpimath From b31fd17d050fe5e0115512fe8d3d7269625a9498 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 30 Jan 2025 12:33:39 -0800 Subject: [PATCH 12/33] =?UTF-8?q?[wpimath]=20Fix=20infinite=20loop=20in=20?= =?UTF-8?q?ArmFeedforward::Calculate(x=E2=82=96,=20v=E2=82=96,=20v?= =?UTF-8?q?=E2=82=96=E2=82=8A=E2=82=81)=20(#7745)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Small values of kₐ make the iterative solver ill-conditioned. This change reverts to the constant-acceleration feedforward in that case. It gives _very_ bad results (hence why we added the iterative solver in the first place), but it's better than hanging. ``` TEST(ArmFeedforwardTest, CalculateIllConditioned) { constexpr auto Ks = 0.5_V; constexpr auto Kv = 20_V / 1_rad_per_s; constexpr auto Ka = 1e-2_V / 1_rad_per_s_sq; constexpr auto Kg = 0_V; frc::ArmFeedforward armFF{Ks, Kg, Kv, Ka}; // Calculate(currentAngle, currentVelocity, nextAngle, dt) CalculateAndSimulate(armFF, 0_rad, 0_rad_per_s, 2_rad_per_s, 20_ms); } ``` This produces 1 V and doesn't accelerate the system at all. Using nextVelocity instead of currentVelocity in the feedforward outputs 41 V and still only accelerates to 0.4 rad/s of the requested 2 rad/s. I picked the kₐ cutoff by increasing kₐ until the iterative solver started converging. Fixes #7743. --- wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp b/wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp index 7c9c44609d..df1f89d984 100644 --- a/wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp +++ b/wpimath/src/main/native/cpp/controller/ArmFeedforward.cpp @@ -20,6 +20,13 @@ units::volt_t ArmFeedforward::Calculate( units::unit_t nextVelocity) const { using VarMat = sleipnir::VariableMatrix; + // Small kₐ values make the solver ill-conditioned + if (kA < units::unit_t{1e-1}) { + auto acceleration = (nextVelocity - currentVelocity) / m_dt; + return kS * wpi::sgn(currentVelocity.value()) + kV * currentVelocity + + kA * acceleration + kG * units::math::cos(currentAngle); + } + // Arm dynamics Matrixd<2, 2> A{{0.0, 1.0}, {0.0, -kV.value() / kA.value()}}; Matrixd<2, 1> B{{0.0}, {1.0 / kA.value()}}; From 18321e55515bf441ba2b0a5c5e67032c18c177a9 Mon Sep 17 00:00:00 2001 From: Sam Carlberg Date: Thu, 30 Jan 2025 15:34:51 -0500 Subject: [PATCH 13/33] [epilogue] Fix epilogue with package-info files (#7749) --- .../processor/AnnotationProcessor.java | 2 ++ .../processor/AnnotationProcessorTest.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java index 2781c055c8..fa623e64ee 100644 --- a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java +++ b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java @@ -68,7 +68,9 @@ public class AnnotationProcessor extends AbstractProcessor { customLoggers.putAll(processCustomLoggers(roundEnv, customLogger)); }); + // Get all root types (classes and interfaces), excluding packages and modules roundEnv.getRootElements().stream() + .filter(e -> e instanceof TypeElement) .filter( e -> processingEnv diff --git a/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/AnnotationProcessorTest.java b/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/AnnotationProcessorTest.java index ec4e52d5f4..7a1bdd44a3 100644 --- a/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/AnnotationProcessorTest.java +++ b/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/AnnotationProcessorTest.java @@ -1974,6 +1974,37 @@ class AnnotationProcessorTest { assertLoggerGenerates(source, expectedRootLogger); } + @Test + void doesNotBreakWithPackageInfo() { + String source = + """ + package example; + + import edu.wpi.first.epilogue.*; + + @Logged + class Example {} + """; + + String packageInfo = """ + package example; + """; + + Compilation compilation = + javac() + .withOptions(kJavaVersionOptions) + .withProcessors(new AnnotationProcessor()) + .compile( + JavaFileObjects.forSourceString("example.Example", source), + JavaFileObjects.forSourceString("example.package-info", packageInfo)); + + assertThat(compilation).succeeded(); + compilation.generatedSourceFiles().stream() + .filter(jfo -> jfo.getName().contains("Example")) + .findFirst() + .orElseThrow(() -> new IllegalStateException("Logger file was not generated!")); + } + private void assertCompilationError( String message, long lineNumber, long col, Diagnostic diagnostic) { assertAll( From 296986397b2160862df029053d644dcffe5ceb41 Mon Sep 17 00:00:00 2001 From: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:46:18 -0800 Subject: [PATCH 14/33] [wpimath] Document drift from desaturating discretized chassis speeds (NFC) (#7741) --- .../wpi/first/math/kinematics/ChassisSpeeds.java | 15 ++++++++++++--- .../math/kinematics/SwerveDriveKinematics.java | 16 ++++++++++++++++ .../include/frc/kinematics/ChassisSpeeds.h | 12 ++++++++++-- .../frc/kinematics/SwerveDriveKinematics.h | 10 ++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java index 4c806a52cb..c770d27de8 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/ChassisSpeeds.java @@ -96,7 +96,10 @@ public class ChassisSpeeds implements ProtobufSerializable, StructSerializable { * along the y-axis, and omega * dt around the z-axis). * *

This is useful for compensating for translational skew when translating and rotating a - * swerve drivetrain. + * holonomic (swerve or mecanum) drivetrain. However, scaling down the ChassisSpeeds after + * discretizing (e.g., when desaturating swerve module speeds) rotates the direction of net motion + * in the opposite direction of rotational velocity, introducing a different translational skew + * which is not accounted for by discretization. * * @param vxMetersPerSecond Forward velocity. * @param vyMetersPerSecond Sideways velocity. @@ -134,7 +137,10 @@ public class ChassisSpeeds implements ProtobufSerializable, StructSerializable { * along the y-axis, and omega * dt around the z-axis). * *

This is useful for compensating for translational skew when translating and rotating a - * swerve drivetrain. + * holonomic (swerve or mecanum) drivetrain. However, scaling down the ChassisSpeeds after + * discretizing (e.g., when desaturating swerve module speeds) rotates the direction of net motion + * in the opposite direction of rotational velocity, introducing a different translational skew + * which is not accounted for by discretization. * * @param vx Forward velocity. * @param vy Sideways velocity. @@ -157,7 +163,10 @@ public class ChassisSpeeds implements ProtobufSerializable, StructSerializable { * along the y-axis, and omega * dt around the z-axis). * *

This is useful for compensating for translational skew when translating and rotating a - * swerve drivetrain. + * holonomic (swerve or mecanum) drivetrain. However, scaling down the ChassisSpeeds after + * discretizing (e.g., when desaturating swerve module speeds) rotates the direction of net motion + * in the opposite direction of rotational velocity, introducing a different translational skew + * which is not accounted for by discretization. * * @param continuousSpeeds The continuous speeds. * @param dtSeconds The duration of the timestep the speeds should be applied for. diff --git a/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java b/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java index 45c3f3bb23..4979a7be10 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java +++ b/wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java @@ -274,6 +274,10 @@ public class SwerveDriveKinematics * reduce all the wheel speeds to make sure that all requested module speeds are at-or-below the * absolute threshold, while maintaining the ratio of speeds between modules. * + *

Scaling down the module speeds rotates the direction of net motion in the opposite direction + * of rotational velocity, which makes discretizing the chassis speeds inaccurate because the + * discretization did not account for this translational skew. + * * @param moduleStates Reference to array of module states. The array will be mutated with the * normalized speeds! * @param attainableMaxSpeedMetersPerSecond The absolute max speed that a module can reach. @@ -300,6 +304,10 @@ public class SwerveDriveKinematics * reduce all the wheel speeds to make sure that all requested module speeds are at-or-below the * absolute threshold, while maintaining the ratio of speeds between modules. * + *

Scaling down the module speeds rotates the direction of net motion in the opposite direction + * of rotational velocity, which makes discretizing the chassis speeds inaccurate because the + * discretization did not account for this translational skew. + * * @param moduleStates Reference to array of module states. The array will be mutated with the * normalized speeds! * @param attainableMaxSpeed The absolute max speed that a module can reach. @@ -318,6 +326,10 @@ public class SwerveDriveKinematics * reduce all the wheel speeds to make sure that all requested module speeds are at-or-below the * absolute threshold, while maintaining the ratio of speeds between modules. * + *

Scaling down the module speeds rotates the direction of net motion in the opposite direction + * of rotational velocity, which makes discretizing the chassis speeds inaccurate because the + * discretization did not account for this translational skew. + * * @param moduleStates Reference to array of module states. The array will be mutated with the * normalized speeds! * @param desiredChassisSpeed The desired speed of the robot @@ -365,6 +377,10 @@ public class SwerveDriveKinematics * reduce all the wheel speeds to make sure that all requested module speeds are at-or-below the * absolute threshold, while maintaining the ratio of speeds between modules. * + *

Scaling down the module speeds rotates the direction of net motion in the opposite direction + * of rotational velocity, which makes discretizing the chassis speeds inaccurate because the + * discretization did not account for this translational skew. + * * @param moduleStates Reference to array of module states. The array will be mutated with the * normalized speeds! * @param desiredChassisSpeed The desired speed of the robot diff --git a/wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h b/wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h index 396b33a618..90eef5d1e4 100644 --- a/wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h +++ b/wpimath/src/main/native/include/frc/kinematics/ChassisSpeeds.h @@ -59,7 +59,11 @@ struct WPILIB_DLLEXPORT ChassisSpeeds { * y-axis, and omega * dt around the z-axis). * * This is useful for compensating for translational skew when translating and - * rotating a swerve drivetrain. + * rotating a holonomic (swerve or mecanum) drivetrain. However, scaling down + * the ChassisSpeeds after discretizing (e.g., when desaturating swerve module + * speeds) rotates the direction of net motion in the opposite direction of + * rotational velocity, introducing a different translational skew which is + * not accounted for by discretization. * * @param vx Forward velocity. * @param vy Sideways velocity. @@ -94,7 +98,11 @@ struct WPILIB_DLLEXPORT ChassisSpeeds { * y-axis, and omega * dt around the z-axis). * * This is useful for compensating for translational skew when translating and - * rotating a swerve drivetrain. + * rotating a holonomic (swerve or mecanum) drivetrain. However, scaling down + * the ChassisSpeeds after discretizing (e.g., when desaturating swerve module + * speeds) rotates the direction of net motion in the opposite direction of + * rotational velocity, introducing a different translational skew which is + * not accounted for by discretization. * * @param continuousSpeeds The continuous speeds. * @param dt The duration of the timestep the speeds should be applied for. diff --git a/wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h b/wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h index 276f9a8818..41f56510e9 100644 --- a/wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h +++ b/wpimath/src/main/native/include/frc/kinematics/SwerveDriveKinematics.h @@ -335,6 +335,11 @@ class SwerveDriveKinematics * the absolute threshold, while maintaining the ratio of speeds between * modules. * + * Scaling down the module speeds rotates the direction of net motion in the + * opposite direction of rotational velocity, which makes discretizing the + * chassis speeds inaccurate because the discretization did not account for + * this translational skew. + * * @param moduleStates Reference to array of module states. The array will be * mutated with the normalized speeds! * @param attainableMaxSpeed The absolute max speed that a module can reach. @@ -370,6 +375,11 @@ class SwerveDriveKinematics * the absolute threshold, while maintaining the ratio of speeds between * modules. * + * Scaling down the module speeds rotates the direction of net motion in the + * opposite direction of rotational velocity, which makes discretizing the + * chassis speeds inaccurate because the discretization did not account for + * this translational skew. + * * @param moduleStates Reference to array of module states. The array will be * mutated with the normalized speeds! * @param desiredChassisSpeed The desired speed of the robot From b3b515e1dd56e6d06a40827fe4059a882c71e3f2 Mon Sep 17 00:00:00 2001 From: DeltaDizzy Date: Tue, 4 Feb 2025 18:12:00 -0500 Subject: [PATCH 15/33] [sysid] Error on missing tests in loaded DataLog (#7747) * add exception * detect missing tests * throw in analyzer * define tests setter * change to std::map * alignas fail * make missingTests parameter const& * const& impl * use set and naive comparison * use default comparison * add * Revert "alignas fail" This reverts commit 5e97940f3460141414e1b1c319041c76cecd9676. * indent validtests * format --- sysid/src/main/native/cpp/App.cpp | 4 +++- sysid/src/main/native/cpp/view/Analyzer.cpp | 18 +++++++++++++++ .../src/main/native/cpp/view/DataSelector.cpp | 11 ++++++++++ .../include/sysid/analysis/FilteringUtils.h | 22 ++++++++++++++++++- .../main/native/include/sysid/view/Analyzer.h | 8 +++++++ .../native/include/sysid/view/DataSelector.h | 7 ++++++ 6 files changed, 68 insertions(+), 2 deletions(-) diff --git a/sysid/src/main/native/cpp/App.cpp b/sysid/src/main/native/cpp/App.cpp index 6d1b9285a3..178a0f726c 100644 --- a/sysid/src/main/native/cpp/App.cpp +++ b/sysid/src/main/native/cpp/App.cpp @@ -106,8 +106,10 @@ void Application(std::string_view saveDir) { auto analyzer = std::make_unique(storage, gLogger); logLoader->unload.connect([ds = dataSelector.get()] { ds->Reset(); }); - dataSelector->testdata = [_analyzer = analyzer.get()](auto data) { + dataSelector->testdata = [_analyzer = analyzer.get(), + ds = dataSelector.get()](auto data) { _analyzer->m_data = data; + _analyzer->SetMissingTests(ds->m_missingTests); _analyzer->AnalyzeData(); }; diff --git a/sysid/src/main/native/cpp/view/Analyzer.cpp b/sysid/src/main/native/cpp/view/Analyzer.cpp index 03b39171b2..726042586d 100644 --- a/sysid/src/main/native/cpp/view/Analyzer.cpp +++ b/sysid/src/main/native/cpp/view/Analyzer.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -251,6 +252,13 @@ void Analyzer::Display() { } break; } + case AnalyzerState::kMissingTestsError: { + CreateErrorPopup(m_errorPopup, m_exception); + if (!m_errorPopup) { + m_state = AnalyzerState::kWaitingForData; + } + break; + } case AnalyzerState::kGeneralDataError: case AnalyzerState::kTestDurationError: case AnalyzerState::kVelocityThresholdError: { @@ -269,6 +277,9 @@ void Analyzer::Display() { void Analyzer::PrepareData() { WPI_INFO(m_logger, "{}", "Preparing data"); try { + if (m_missingTests.size() > 0) { + throw sysid::MissingTestsError{m_missingTests}; + } m_manager->PrepareData(); UpdateFeedforwardGains(); UpdateFeedbackGains(); @@ -281,6 +292,9 @@ void Analyzer::PrepareData() { } catch (const sysid::NoDynamicDataError& e) { m_state = AnalyzerState::kTestDurationError; HandleError(e.what()); + } catch (const sysid::MissingTestsError& e) { + m_state = AnalyzerState::kMissingTestsError; + HandleError(e.what()); } catch (const AnalysisManager::FileReadingError& e) { m_state = AnalyzerState::kFileError; HandleError(e.what()); @@ -324,6 +338,10 @@ void Analyzer::HandleError(std::string_view msg) { PrepareRawGraphs(); } +void Analyzer::SetMissingTests(const std::vector& missingTests) { + m_missingTests = missingTests; +} + void Analyzer::DisplayGraphs() { ImGui::SetNextWindowPos(ImVec2{kDiagnosticPlotWindowPos}, ImGuiCond_FirstUseEver); diff --git a/sysid/src/main/native/cpp/view/DataSelector.cpp b/sysid/src/main/native/cpp/view/DataSelector.cpp index 3409bf6ee3..f3c320c643 100644 --- a/sysid/src/main/native/cpp/view/DataSelector.cpp +++ b/sysid/src/main/native/cpp/view/DataSelector.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -111,6 +112,7 @@ void DataSelector::Display() { continue; } WPI_INFO(m_logger, "Loaded test state {}", it2->first); + m_executedTests.insert(it2->first); ++it2; } if (it->second.empty()) { @@ -132,6 +134,15 @@ void DataSelector::Display() { return; } + if (m_executedTests.size() < 4 && !m_testCountValidated) { + for (auto test : kValidTests) { + if (!m_executedTests.contains(test)) { + m_missingTests.push_back(test); + m_testCountValidated = true; + } + } + } + #if 0 // Test filtering if (ImGui::BeginCombo("Test", m_selectedTest.c_str())) { diff --git a/sysid/src/main/native/include/sysid/analysis/FilteringUtils.h b/sysid/src/main/native/include/sysid/analysis/FilteringUtils.h index 67266ae647..3948cdd121 100644 --- a/sysid/src/main/native/include/sysid/analysis/FilteringUtils.h +++ b/sysid/src/main/native/include/sysid/analysis/FilteringUtils.h @@ -4,15 +4,16 @@ #pragma once -#include #include #include #include #include #include +#include #include #include +#include #include #include #include @@ -68,6 +69,25 @@ class NoQuasistaticDataError : public std::exception { } }; +/** + * Exception for not all tests being present. + */ +class MissingTestsError : public std::exception { + public: + explicit MissingTestsError(std::vector MissingTests) + : missingTests(std::move(MissingTests)) { + errorString = fmt::format( + "The following tests were not detected: {}. Make sure to perform all " + "four tests as described in the SysId documentation.", + fmt::join(missingTests, ", ")); + } + const char* what() const noexcept override { return errorString.c_str(); } + + private: + std::vector missingTests; + std::string errorString; +}; + /** * Exception for Dynamic Data being completely removed. */ diff --git a/sysid/src/main/native/include/sysid/view/Analyzer.h b/sysid/src/main/native/include/sysid/view/Analyzer.h index bb7763f26f..4b6e258341 100644 --- a/sysid/src/main/native/include/sysid/view/Analyzer.h +++ b/sysid/src/main/native/include/sysid/view/Analyzer.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -46,6 +47,7 @@ class Analyzer : public glass::View { kVelocityThresholdError, kTestDurationError, kGeneralDataError, + kMissingTestsError, kFileError }; /** @@ -91,6 +93,11 @@ class Analyzer : public glass::View { */ void AnalyzeData(); + /** + * Used by DataSelector to import any missing tests. + */ + void SetMissingTests(const std::vector& missingTests); + private: /** * Kills the data preparation thread @@ -199,6 +206,7 @@ class Analyzer : public glass::View { // Stores the exception message. std::string m_exception; + std::vector m_missingTests; bool m_calcDefaults = false; diff --git a/sysid/src/main/native/include/sysid/view/DataSelector.h b/sysid/src/main/native/include/sysid/view/DataSelector.h index 71732a7ed7..e387837595 100644 --- a/sysid/src/main/native/include/sysid/view/DataSelector.h +++ b/sysid/src/main/native/include/sysid/view/DataSelector.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ class DataSelector : public glass::View { * Called when new test data is loaded. */ std::function testdata; + std::vector m_missingTests; private: wpi::Logger& m_logger; @@ -74,6 +76,11 @@ class DataSelector : public glass::View { int m_selectedAnalysis = 0; std::future m_testdataFuture; std::vector m_testdataStats; + std::set kValidTests = {"quasistatic-forward", + "quasistatic-reverse", "dynamic-forward", + "dynamic-reverse"}; + std::set m_executedTests; + bool m_testCountValidated = false; static Tests LoadTests(const glass::DataLogReaderEntry& testStateEntry); TestData BuildTestData(); From a0976a1fd93bfdef5dfdb7fac4ab191ff041cb37 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Fri, 7 Feb 2025 13:24:30 -0500 Subject: [PATCH 16/33] [build] Update developerRobot JRE (#7764) --- buildSrc/src/main/groovy/WPIJREArtifact.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/WPIJREArtifact.groovy b/buildSrc/src/main/groovy/WPIJREArtifact.groovy index ad929daa64..c23248f035 100644 --- a/buildSrc/src/main/groovy/WPIJREArtifact.groovy +++ b/buildSrc/src/main/groovy/WPIJREArtifact.groovy @@ -28,7 +28,7 @@ public class WPIJREArtifact extends MavenArtifact { private boolean checkJreVersion = true; - private final String artifactLocation = "edu.wpi.first.jdk:roborio-2024:17.0.9u7-1" + private final String artifactLocation = "edu.wpi.first.jdk:roborio-2024:17.0.9u7-3" @Inject public WPIJREArtifact(String name, RemoteTarget target) { From b60b2b64bd14f842c3a6ff4ee83f4c6be918d8e9 Mon Sep 17 00:00:00 2001 From: Ryan Blue Date: Fri, 7 Feb 2025 15:36:41 -0500 Subject: [PATCH 17/33] [hal, wpilib] AddressableLED: add support for other color orders (#7102) Many LED strips use different color order (GRB in particular is common). This makes the change at the HAL level. This solves 2 problems; first, no code needs to change in the high level drivers, which was challenging for C++, and second, simulation will behave properly as no conversion is needed. The HAL will accept an array of data objects in the same order no matter what the selected output order is, and will convert before sending it to the FPGA for output. To accomplish this, NEON bulk load/interleave instructions are utilized. The low level implementation (load, store, and alignment functions) come from the Simd Library. The high level implementations are inspired by the image conversion functions in the simd library, but have diverged significantly. Much of the implementation uses templates and inlined functions rather than runtime parameters; This is a trade off between the size of the generated code and the amount of function calls done at runtime. Currently, the entire conversion operation is inlined. --- ThirdPartyNotices.txt | 27 ++ .../edu/wpi/first/hal/AddressableLEDJNI.java | 17 ++ hal/src/main/native/athena/AddressableLED.cpp | 49 +++- .../main/native/athena/AddressableLEDSimd.h | 273 ++++++++++++++++++ hal/src/main/native/athena/simd/simd.h | 174 +++++++++++ .../main/native/cpp/jni/AddressableLEDJNI.cpp | 29 ++ .../main/native/include/hal/AddressableLED.h | 11 + .../native/include/hal/AddressableLEDTypes.h | 19 ++ hal/src/main/native/sim/AddressableLED.cpp | 4 + .../src/main/native/cpp/AddressableLED.cpp | 7 + .../main/native/include/frc/AddressableLED.h | 29 ++ .../edu/wpi/first/wpilibj/AddressableLED.java | 59 +++- 12 files changed, 695 insertions(+), 3 deletions(-) create mode 100644 hal/src/main/native/athena/AddressableLEDSimd.h create mode 100644 hal/src/main/native/athena/simd/simd.h diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt index 01e52c7fd3..4acb020f80 100644 --- a/ThirdPartyNotices.txt +++ b/ThirdPartyNotices.txt @@ -54,6 +54,7 @@ nanopb wpiutil/src/main/native/thirdparty/nanopb protobuf wpiutil/src/main/native/thirdparty/protobuf mrcal wpical/src/main/native/thirdparty/mrcal libdogleg wpical/src/main/native/thirdparty/libdogleg +Simd hal/src/main/native/athena/simd Additionally, glfw, memory, and nanopb were all modified for use in WPILib. @@ -1702,3 +1703,29 @@ This program is free software: you can redistribute it and/or modify it under th This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. The full text of the license is available at http://www.gnu.org/licenses + +============ +Simd License +============ + +MIT License + +Copyright (c) 2011-2017 Ihar Yermalayeu + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/hal/src/main/java/edu/wpi/first/hal/AddressableLEDJNI.java b/hal/src/main/java/edu/wpi/first/hal/AddressableLEDJNI.java index 4d4c1975ad..c14630ff28 100644 --- a/hal/src/main/java/edu/wpi/first/hal/AddressableLEDJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/AddressableLEDJNI.java @@ -10,6 +10,13 @@ package edu.wpi.first.hal; * @see "hal/AddressableLED.h" */ public class AddressableLEDJNI extends JNIWrapper { + public static final int COLOR_ORDER_RGB = 0; + public static final int COLOR_ORDER_RBG = 1; + public static final int COLOR_ORDER_BGR = 2; + public static final int COLOR_ORDER_BRG = 3; + public static final int COLOR_ORDER_GBR = 4; + public static final int COLOR_ORDER_GRB = 5; + /** * Initialize Addressable LED using a PWM Digital handle. * @@ -27,6 +34,16 @@ public class AddressableLEDJNI extends JNIWrapper { */ public static native void free(int handle); + /** + * Sets the color order for the addressable LED output. The default order is GRB. + * + *

This will take effect on the next call to {@link #setData(int, byte[])}. + * + * @param handle the Addressable LED handle + * @param colorOrder the color order + */ + public static native void setColorOrder(int handle, int colorOrder); + /** * Sets the length of the LED strip. * diff --git a/hal/src/main/native/athena/AddressableLED.cpp b/hal/src/main/native/athena/AddressableLED.cpp index 8aaa2f33b7..f698d59b4e 100644 --- a/hal/src/main/native/athena/AddressableLED.cpp +++ b/hal/src/main/native/athena/AddressableLED.cpp @@ -9,6 +9,7 @@ #include +#include "AddressableLEDSimd.h" #include "ConstantsInternal.h" #include "DigitalInternal.h" #include "FPGACalls.h" @@ -21,6 +22,7 @@ #include "hal/handles/LimitedHandleResource.h" using namespace hal; +using namespace hal::detail; namespace { struct AddressableLED { @@ -28,6 +30,7 @@ struct AddressableLED { void* ledBuffer; size_t ledBufferSize; int32_t stringLength = 1; + HAL_AddressableLEDColorOrder colorOrder = HAL_ALED_GRB; }; } // namespace @@ -47,6 +50,37 @@ void InitializeAddressableLED() { static constexpr const char* HmbName = "HMB_0_LED"; +static void ConvertAndCopyLEDData(void* dst, + const struct HAL_AddressableLEDData* src, + int32_t len, + HAL_AddressableLEDColorOrder order) { + switch (order) { + case HAL_ALED_GRB: + std::memcpy(dst, src, len * sizeof(HAL_AddressableLEDData)); + break; + case HAL_ALED_RGB: + ConvertPixels(reinterpret_cast(src), + reinterpret_cast(dst), len); + break; + case HAL_ALED_RBG: + ConvertPixels(reinterpret_cast(src), + reinterpret_cast(dst), len); + break; + case HAL_ALED_BGR: + ConvertPixels(reinterpret_cast(src), + reinterpret_cast(dst), len); + break; + case HAL_ALED_BRG: + ConvertPixels(reinterpret_cast(src), + reinterpret_cast(dst), len); + break; + case HAL_ALED_GBR: + ConvertPixels(reinterpret_cast(src), + reinterpret_cast(dst), len); + break; + } +} + extern "C" { HAL_AddressableLEDHandle HAL_InitializeAddressableLED( @@ -125,6 +159,19 @@ void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) { addressableLEDHandles->Free(handle); } +void HAL_SetAddressableLEDColorOrder(HAL_AddressableLEDHandle handle, + HAL_AddressableLEDColorOrder colorOrder, + int32_t* status) { + auto led = addressableLEDHandles->Get(handle); + + if (!led) { + *status = HAL_HANDLE_ERROR; + return; + } + + led->colorOrder = colorOrder; +} + void HAL_SetAddressableLEDOutputPort(HAL_AddressableLEDHandle handle, HAL_DigitalHandle outputPort, int32_t* status) { @@ -203,7 +250,7 @@ void HAL_WriteAddressableLEDData(HAL_AddressableLEDHandle handle, return; } - std::memcpy(led->ledBuffer, data, length * sizeof(HAL_AddressableLEDData)); + ConvertAndCopyLEDData(led->ledBuffer, data, length, led->colorOrder); asm("dmb"); diff --git a/hal/src/main/native/athena/AddressableLEDSimd.h b/hal/src/main/native/athena/AddressableLEDSimd.h new file mode 100644 index 0000000000..8d3be71420 --- /dev/null +++ b/hal/src/main/native/athena/AddressableLEDSimd.h @@ -0,0 +1,273 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +#pragma once +#include + +#include "hal/AddressableLEDTypes.h" +#include "simd/simd.h" + +// Timing info +// https://developer.arm.com/documentation/ddi0409/i/instruction-timing/instruction-specific-scheduling/advanced-simd-load-store-instructions?lang=en + +namespace hal::detail { + +using namespace Simd::Neon; + +template +using ConvertFunc = void (*)(T); + +/* + * Conversion funtions perform in-place conversion by swapping elements. + * The names of the functions indicate the wire output (default GRB), + * but the FPGA takes sequences of BGR_. + */ + +template +void ToRGB(T val) { + std::swap(val[1], val[2]); // swap G and R +} + +template +void ToRBG(T val) { + std::swap(val[1], val[2]); // swap G and R + std::swap(val[0], val[2]); // swap B and G +} + +template +void ToBGR(T val) { + std::swap(val[0], val[1]); // swap B and G + std::swap(val[0], val[2]); // swap G and R +} + +template +void ToBRG(T val) { + std::swap(val[0], val[1]); // swap B and G +} + +template +void ToGBR(T val) { + std::swap(val[0], val[2]); // swap B and R +} + +/** + * Copies 16 pixels from src to dst using NEON instructions, converting using + * the provided conversion function. Optimizes based on alignment of input and + * output arrays specified by srcAlign and dstAlign + * @tparam srcAlign whether src is aligned to the size of a NEON register (16 + * bytes) + * @tparam dstAlign whether dst is aligned to the size of a NEON register (16 + * bytes) + * @tparam the conversion function + * @param[in] src The source array + * @param[out] dst the destination array + * @pre src and dst must contain at least 64 bytes (16 pixels) + * @pre if srcAlign is true, src must be 16 byte aligned + * @pre if dstAlign is true, src muts be 16 byte aligned + */ +template Convert> +void ConvertNEON_16(const uint8_t* src, uint8_t* dst) { + uint8x16x4_t pixels = Load4(src); + Convert(pixels.val); + Store4(dst, pixels); +} + +/** + * Copies 8 pixels from src to dst using NEON instructions, converting using + * the provided conversion function. Optimizes based on alignment of input and + * output arrays specified by srcAlign and dstAlign + * @tparam srcAlign whether src is aligned to the size of a NEON register (16 + * bytes) + * @tparam dstAlign whether dst is aligned to the size of a NEON register (16 + * bytes) + * @tparam the conversion function + * @param[in] src The source array + * @param[out] dst the destination array + * @pre src and dst must contain at least 32 bytes (8 pixels) + * @pre if srcAlign is true, src must be 16 byte aligned + * @pre if dstAlign is true, src muts be 16 byte aligned + */ +template Convert> +void ConvertNEON_8(const uint8_t* src, uint8_t* dst) { + uint8x8x4_t pixels = LoadHalf4(src); + Convert(pixels.val); + Store4(dst, pixels); +} + +/** + * Copies 16 pixels from src to dst, converting from GRB (wire order) to order. + * Optimizes based on alignment of input and output arrays specified by srcAlign + * and dstAlign + * @tparam order the color order to convert to + * @tparam srcAlign whether src is aligned to the size of a NEON register (16 + * bytes) + * @tparam dstAlign whether dst is aligned to the size of a NEON register (16 + * bytes) + * @param[in] src The source array + * @param[out] dst the destination array + * @pre src and dst must contain at least 64 bytes (16 pixels) + * @pre if srcAlign is true, src must be 16 byte aligned + * @pre if dstAlign is true, src muts be 16 byte aligned + */ +template +void Convert16Pixels(const uint8_t* src, uint8_t* dst) { + switch (order) { + case HAL_ALED_RGB: + ConvertNEON_16(src, dst); + break; + case HAL_ALED_RBG: + ConvertNEON_16(src, dst); + break; + case HAL_ALED_BGR: + ConvertNEON_16(src, dst); + break; + case HAL_ALED_BRG: + ConvertNEON_16(src, dst); + break; + case HAL_ALED_GBR: + ConvertNEON_16(src, dst); + break; + } +} + +/** + * Copies 8 pixels from src to dst, converting from GRB (wire order) to order. + * Optimizes based on alignment of input and output arrays specified by srcAlign + * and dstAlign + * @tparam order the color order to convert to + * @tparam srcAlign whether src is aligned to the size of a NEON register (16 + * bytes) + * @tparam dstAlign whether dst is aligned to the size of a NEON register (16 + * bytes) + * @param[in] src The source array + * @param[out] dst the destination array + * @pre src and dst must contain at least 32 bytes (8 pixels) + * @pre if srcAlign is true, src must be 16 byte aligned + * @pre if dstAlign is true, src muts be 16 byte aligned + */ +template +void Convert8Pixels(const uint8_t* src, uint8_t* dst) { + switch (order) { + case HAL_ALED_RGB: + ConvertNEON_8(src, dst); + break; + case HAL_ALED_RBG: + ConvertNEON_8(src, dst); + break; + case HAL_ALED_BGR: + ConvertNEON_8(src, dst); + break; + case HAL_ALED_BRG: + ConvertNEON_8(src, dst); + break; + case HAL_ALED_GBR: + ConvertNEON_8(src, dst); + break; + } +} + +/** + * Copies 1 pixel from src to dst, converting from RGB to the specified order. + * @param[in] order the color order to convert to + * @param[in] in the source array + * @param[out] the destination array + * @pre in and out must contain at least 1 pixel (4 bytes). + */ +void Convert1Pixel(HAL_AddressableLEDColorOrder order, const uint8_t* src, + uint8_t* dst) { + uint8_t tmp[4]; + std::memcpy(tmp, src, 4); // Load 4 bytes + // convert based on order + switch (order) { + case HAL_ALED_RGB: + ToRGB(tmp); + break; + case HAL_ALED_RBG: + ToRBG(tmp); + break; + case HAL_ALED_BGR: + ToBGR(tmp); + break; + case HAL_ALED_BRG: + ToBRG(tmp); + break; + case HAL_ALED_GBR: + ToGBR(tmp); + break; + case HAL_ALED_GRB: + break; // this shouldn't ever get hit but compiler + // wants this to be exhaustive + } + std::memcpy(dst, tmp, 4); // Store 4 bytes +} +/** + * Copies len pixels from src to dst, converting from GRB (wire order) to order. + * Optimizes based on alignment of input and output arrays specified by srcAlign + * and dstAlign + * @tparam order the color order to convert to + * @tparam srcAlign whether src is aligned to the size of a NEON register (16 + * bytes) + * @tparam dstAlign whether dst is aligned to the size of a NEON register (16 + * bytes) + * @param[in] src The source array + * @param[out] dst the destination array + * @param[in] len the size (in pixels, len = (size in bytes) / 4) + * @pre src and dst must have at least len*4 capacity in bytes + * @pre if srcAlign is true, src must be 16 byte aligned + * @pre if dstAlign is true, src muts be 16 byte aligned + */ +template +void ConvertPixels(const uint8_t* src, uint8_t* dst, size_t len) { + if (len >= 16) { + constexpr size_t A4 = + A * 4; // Stride of 1 16-pixel conversion operation. (4 NEON registers) + size_t size = len * 4; + size_t aligned = Simd::AlignLo( + size, A4); // number of bytes we can copy with whole 16-pixel strides + for (size_t i = 0; i < aligned; i += A4) { + Convert16Pixels(src + i, dst + i); + } + if (aligned < size) { + Convert16Pixels( + src + size - A4, + dst + size - A4); // copy last 16 pixels, possibly recopying. + } + } else if (len >= 8) { + // If len between 8 and 16, we can do 1 or 2 8-pixel copies + Convert8Pixels(src, dst); + if (len > 8) { + size_t recopyOffset = (len * 4) - (HA * 4); + Convert8Pixels( + src + recopyOffset, + dst + recopyOffset); // copy last 8 pixels, possibly recopying + } + } else { + // Just copy pixel-by-pixel for <8 + for (size_t i = 0; i < len; i += 4) { + Convert1Pixel(order, src + i, dst + i); + } + } +} + +/** + * Copies pixelCount pixels from src to dst, converting from RGB to the + * specified order + * @tparam order the color order to convert to + * @param src the source array + * @param dst the destination array + * @param pixelCount the number of pixels to convert and copy + */ +template +void ConvertPixels(const uint8_t* src, uint8_t* dst, size_t pixelCount) { + if (Aligned(src) && Aligned(dst)) { + ConvertPixels(src, dst, pixelCount); + } else if (Aligned(src)) { + ConvertPixels(src, dst, pixelCount); + } else if (Aligned(dst)) { + ConvertPixels(src, dst, pixelCount); + } else { + ConvertPixels(src, dst, pixelCount); + } +} +} // namespace hal::detail diff --git a/hal/src/main/native/athena/simd/simd.h b/hal/src/main/native/athena/simd/simd.h new file mode 100644 index 0000000000..397dc54d3d --- /dev/null +++ b/hal/src/main/native/athena/simd/simd.h @@ -0,0 +1,174 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// This file contains modified snippets from the Simd Library by Ihar Yermalayeu +// (http://ermig1979.github.io/Simd). The original source file names are listed +// above each section. +/* + * Simd Library (http://ermig1979.github.io/Simd). + * + * Copyright (c) 2011-2024 Yermalayeu Ihar. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include + +#include +#include + +// SimdLib.h +#define SIMD_INLINE inline __attribute__((always_inline)) + +// SimdMemory.h +namespace Simd { +SIMD_INLINE size_t AlignLo(size_t size, size_t align) { + return size & ~(align - 1); +} + +SIMD_INLINE void* AlignLo(const void* ptr, size_t align) { + return reinterpret_cast(reinterpret_cast(ptr) & ~(align - 1)); +} + +SIMD_INLINE bool Aligned(size_t size, size_t align) { + return size == AlignLo(size, align); +} + +SIMD_INLINE bool Aligned(const void* ptr, size_t align) { + return ptr == AlignLo(ptr, align); +} +} // namespace Simd +namespace Simd::Neon { +SIMD_INLINE bool Aligned(size_t size, size_t align = sizeof(uint8x16_t)) { + return Simd::Aligned(size, align); +} + +SIMD_INLINE bool Aligned(const void* ptr, size_t align = sizeof(uint8x16_t)) { + return Simd::Aligned(ptr, align); +} +} // namespace Simd::Neon + +// SimdConst.h +namespace Simd::Neon { +const size_t A = sizeof(uint8x16_t); +const size_t DA = 2 * A; +const size_t QA = 4 * A; +const size_t OA = 8 * A; +const size_t HA = A / 2; +} // namespace Simd::Neon + +// SimdLoad.h +namespace Simd::Neon { +template +SIMD_INLINE uint8x8x4_t LoadHalf4(const uint8_t* p); + +template <> +SIMD_INLINE uint8x8x4_t LoadHalf4(const uint8_t* p) { +#if defined(__GNUC__) && SIMD_NEON_PREFECH_SIZE + __builtin_prefetch(p + SIMD_NEON_PREFECH_SIZE); +#endif + return vld4_u8(p); +} + +template <> +SIMD_INLINE uint8x8x4_t LoadHalf4(const uint8_t* p) { +#if defined(__GNUC__) +#if SIMD_NEON_PREFECH_SIZE + __builtin_prefetch(p + SIMD_NEON_PREFECH_SIZE); +#endif + uint8_t* _p = static_cast(__builtin_assume_aligned(p, 8)); + return vld4_u8(_p); +#elif defined(_MSC_VER) + return vld4_u8_ex(p, 64); +#else + return vld4_u8(p); +#endif +} + +template +SIMD_INLINE uint8x16x4_t Load4(const uint8_t* p); + +template <> +SIMD_INLINE uint8x16x4_t Load4(const uint8_t* p) { +#if defined(__GNUC__) && SIMD_NEON_PREFECH_SIZE + __builtin_prefetch(p + SIMD_NEON_PREFECH_SIZE); +#endif + return vld4q_u8(p); +} + +template <> +SIMD_INLINE uint8x16x4_t Load4(const uint8_t* p) { +#if defined(__GNUC__) +#if SIMD_NEON_PREFECH_SIZE + __builtin_prefetch(p + SIMD_NEON_PREFECH_SIZE); +#endif + uint8_t* _p = static_cast(__builtin_assume_aligned(p, 16)); + return vld4q_u8(_p); +#elif defined(_MSC_VER) + return vld4q_u8_ex(p, 128); +#else + return vld4q_u8(p); +#endif +} + +// SimdStore.h +template +SIMD_INLINE void Store4(uint8_t* p, uint8x16x4_t a); + +template <> +SIMD_INLINE void Store4(uint8_t* p, uint8x16x4_t a) { + vst4q_u8(p, a); +} + +template <> +SIMD_INLINE void Store4(uint8_t* p, uint8x16x4_t a) { +#if defined(__GNUC__) + uint8_t* _p = static_cast(__builtin_assume_aligned(p, 16)); + vst4q_u8(_p, a); +#elif defined(_MSC_VER) + vst4q_u8_ex(p, a, 128); +#else + vst4q_u8(p, a); +#endif +} + +template +SIMD_INLINE void Store4(uint8_t* p, uint8x8x4_t a); + +template <> +SIMD_INLINE void Store4(uint8_t* p, uint8x8x4_t a) { + vst4_u8(p, a); +} + +template <> +SIMD_INLINE void Store4(uint8_t* p, uint8x8x4_t a) { +#if defined(__GNUC__) + uint8_t* _p = static_cast(__builtin_assume_aligned(p, 8)); + vst4_u8(_p, a); +#elif defined(_MSC_VER) + vst4_u8_ex(p, a, 64); +#else + vst4_u8(p, a); +#endif +} + +} // namespace Simd::Neon diff --git a/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp b/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp index 1d9017da1c..e7459a2b86 100644 --- a/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp +++ b/hal/src/main/native/cpp/jni/AddressableLEDJNI.cpp @@ -15,6 +15,19 @@ using namespace wpi::java; static_assert(sizeof(jbyte) * 4 == sizeof(HAL_AddressableLEDData)); +static_assert(edu_wpi_first_hal_AddressableLEDJNI_COLOR_ORDER_RGB == + HAL_ALED_RGB); +static_assert(edu_wpi_first_hal_AddressableLEDJNI_COLOR_ORDER_RBG == + HAL_ALED_RBG); +static_assert(edu_wpi_first_hal_AddressableLEDJNI_COLOR_ORDER_BGR == + HAL_ALED_BGR); +static_assert(edu_wpi_first_hal_AddressableLEDJNI_COLOR_ORDER_BRG == + HAL_ALED_BRG); +static_assert(edu_wpi_first_hal_AddressableLEDJNI_COLOR_ORDER_GBR == + HAL_ALED_GBR); +static_assert(edu_wpi_first_hal_AddressableLEDJNI_COLOR_ORDER_GRB == + HAL_ALED_GRB); + extern "C" { /* * Class: edu_wpi_first_hal_AddressableLEDJNI @@ -46,6 +59,22 @@ Java_edu_wpi_first_hal_AddressableLEDJNI_free } } +/* + * Class: edu_wpi_first_hal_AddressableLEDJNI + * Method: setColorOrder + * Signature: (II)V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_hal_AddressableLEDJNI_setColorOrder + (JNIEnv* env, jclass, jint handle, jint colorOrder) +{ + int32_t status = 0; + HAL_SetAddressableLEDColorOrder( + static_cast(handle), + static_cast(colorOrder), &status); + CheckStatus(env, status); +} + /* * Class: edu_wpi_first_hal_AddressableLEDJNI * Method: setLength diff --git a/hal/src/main/native/include/hal/AddressableLED.h b/hal/src/main/native/include/hal/AddressableLED.h index 3181e7e2bb..c404688567 100644 --- a/hal/src/main/native/include/hal/AddressableLED.h +++ b/hal/src/main/native/include/hal/AddressableLED.h @@ -36,6 +36,17 @@ HAL_AddressableLEDHandle HAL_InitializeAddressableLED( */ void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle); +/** + * Sets the color order for the addressable LED output. The default order is + * GRB. This will take effect on the next call to HAL_WriteAddressableLEDData(). + * @param[in] handle the Addressable LED handle + * @param[in] colorOrder the color order + * @param[out] status the error code, or 0 for success + */ +void HAL_SetAddressableLEDColorOrder(HAL_AddressableLEDHandle handle, + HAL_AddressableLEDColorOrder colorOrder, + int32_t* status); + /** * Set the Addressable LED PWM Digital port. * diff --git a/hal/src/main/native/include/hal/AddressableLEDTypes.h b/hal/src/main/native/include/hal/AddressableLEDTypes.h index 48918f4b72..4dad3683c8 100644 --- a/hal/src/main/native/include/hal/AddressableLEDTypes.h +++ b/hal/src/main/native/include/hal/AddressableLEDTypes.h @@ -4,6 +4,7 @@ #pragma once +#include #include /** max length of LED strip supported by FPGA. */ @@ -16,3 +17,21 @@ struct HAL_AddressableLEDData { uint8_t r; ///< red value uint8_t padding; }; + +/** + * Order that color data is sent over the wire. + */ +HAL_ENUM(HAL_AddressableLEDColorOrder) { + HAL_ALED_RGB, + HAL_ALED_RBG, + HAL_ALED_BGR, + HAL_ALED_BRG, + HAL_ALED_GBR, + HAL_ALED_GRB +}; + +#ifdef __cplusplus +constexpr auto format_as(HAL_AddressableLEDColorOrder order) { + return static_cast(order); +} +#endif diff --git a/hal/src/main/native/sim/AddressableLED.cpp b/hal/src/main/native/sim/AddressableLED.cpp index bce3f1ddfd..2bf19d0102 100644 --- a/hal/src/main/native/sim/AddressableLED.cpp +++ b/hal/src/main/native/sim/AddressableLED.cpp @@ -91,6 +91,10 @@ void HAL_FreeAddressableLED(HAL_AddressableLEDHandle handle) { SimAddressableLEDData[led->index].initialized = false; } +void HAL_SetAddressableLEDColorOrder(HAL_AddressableLEDHandle handle, + HAL_AddressableLEDColorOrder colorOrder, + int32_t* status) {} + void HAL_SetAddressableLEDOutputPort(HAL_AddressableLEDHandle handle, HAL_DigitalHandle outputPort, int32_t* status) { diff --git a/wpilibc/src/main/native/cpp/AddressableLED.cpp b/wpilibc/src/main/native/cpp/AddressableLED.cpp index 7c70033fe3..7e55655664 100644 --- a/wpilibc/src/main/native/cpp/AddressableLED.cpp +++ b/wpilibc/src/main/native/cpp/AddressableLED.cpp @@ -35,6 +35,13 @@ AddressableLED::AddressableLED(int port) : m_port{port} { HAL_Report(HALUsageReporting::kResourceType_AddressableLEDs, port + 1); } +void AddressableLED::SetColorOrder(AddressableLED::ColorOrder order) { + int32_t status = 0; + HAL_SetAddressableLEDColorOrder( + m_handle, static_cast(order), &status); + FRC_CheckErrorStatus(status, "Port {} Color order {}", m_port, order); +} + void AddressableLED::SetLength(int length) { int32_t status = 0; HAL_SetAddressableLEDLength(m_handle, length, &status); diff --git a/wpilibc/src/main/native/include/frc/AddressableLED.h b/wpilibc/src/main/native/include/frc/AddressableLED.h index c7af852860..4e5bdefa2e 100644 --- a/wpilibc/src/main/native/include/frc/AddressableLED.h +++ b/wpilibc/src/main/native/include/frc/AddressableLED.h @@ -24,12 +24,27 @@ namespace frc { * By default, the timing supports WS2812B and WS2815 LEDs, but is configurable * using SetBitTiming() * + * Some LEDs use a different color order than the default GRB. The color order + * is configurable using SetColorOrder(). + * *

Only 1 LED driver is currently supported by the roboRIO. However, * multiple LED strips can be connected in series and controlled from the * single driver. */ class AddressableLED { public: + /** + * Order that color data is sent over the wire. + */ + enum ColorOrder { + kRGB = HAL_ALED_RGB, ///< RGB order + kRBG = HAL_ALED_RBG, ///< RBG order + kBGR = HAL_ALED_BGR, ///< BGR order + kBRG = HAL_ALED_BRG, ///< BRG order + kGBR = HAL_ALED_GBR, ///< GBR order + kGRB = HAL_ALED_GRB ///< GRB order. This is the default order. + }; + class LEDData : public HAL_AddressableLEDData { public: LEDData() : LEDData(0, 0, 0) {} @@ -95,6 +110,15 @@ class AddressableLED { AddressableLED(AddressableLED&&) = default; AddressableLED& operator=(AddressableLED&&) = default; + /** + * Sets the color order for this AddressableLED. The default order is GRB. + * + * This will take effect on the next call to SetData(). + * + * @param order the color order + */ + void SetColorOrder(ColorOrder order); + /** * Sets the length of the LED strip. * @@ -169,4 +193,9 @@ class AddressableLED { hal::Handle m_handle; int m_port; }; + +constexpr auto format_as(AddressableLED::ColorOrder order) { + return static_cast(order); +} + } // namespace frc diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLED.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLED.java index a8c160fa4b..613e8edf16 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLED.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/AddressableLED.java @@ -12,13 +12,57 @@ import edu.wpi.first.hal.PWMJNI; /** * A class for driving addressable LEDs, such as WS2812B, WS2815, and NeoPixels. * - *

By default, the timing supports WS2812B and WS2815 LEDs, but is configurable using - * setBitTiming() + *

By default, the timing supports WS2812B and WS2815 LEDs, but is configurable using {@link + * #setBitTiming(int, int, int, int)} + * + *

Some LEDs use a different color order than the default GRB. The color order is configurable + * using {@link #setColorOrder(ColorOrder)}. * *

Only 1 LED driver is currently supported by the roboRIO. However, multiple LED strips can be * connected in series and controlled from the single driver. */ public class AddressableLED implements AutoCloseable { + /** Order that color data is sent over the wire. */ + public enum ColorOrder { + /** RGB order. */ + kRGB(AddressableLEDJNI.COLOR_ORDER_RGB), + /** RBG order. */ + kRBG(AddressableLEDJNI.COLOR_ORDER_RBG), + /** BGR order. */ + kBGR(AddressableLEDJNI.COLOR_ORDER_BGR), + /** BRG order. */ + kBRG(AddressableLEDJNI.COLOR_ORDER_BRG), + /** GBR order. */ + kGBR(AddressableLEDJNI.COLOR_ORDER_GBR), + /** GRB order. This is the default order. */ + kGRB(AddressableLEDJNI.COLOR_ORDER_GRB); + + /** The native value for this ColorOrder. */ + public final int value; + + ColorOrder(int value) { + this.value = value; + } + + /** + * Gets a color order from an int value. + * + * @param value int value + * @return color order + */ + public ColorOrder fromValue(int value) { + return switch (value) { + case AddressableLEDJNI.COLOR_ORDER_RBG -> kRBG; + case AddressableLEDJNI.COLOR_ORDER_BGR -> kBGR; + case AddressableLEDJNI.COLOR_ORDER_BRG -> kBRG; + case AddressableLEDJNI.COLOR_ORDER_GRB -> kGRB; + case AddressableLEDJNI.COLOR_ORDER_GBR -> kGBR; + case AddressableLEDJNI.COLOR_ORDER_RGB -> kRGB; + default -> kGRB; + }; + } + } + private final int m_pwmHandle; private final int m_handle; @@ -43,6 +87,17 @@ public class AddressableLED implements AutoCloseable { } } + /** + * Sets the color order for this AddressableLED. The default order is GRB. + * + *

This will take effect on the next call to {@link #setData(AddressableLEDBuffer)}. + * + * @param order the color order + */ + public void setColorOrder(ColorOrder order) { + AddressableLEDJNI.setColorOrder(m_handle, order.value); + } + /** * Sets the length of the LED strip. * From d2611d4ad568ca5c56e6b8d35812c4793705d93d Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 9 Feb 2025 23:01:01 -0800 Subject: [PATCH 18/33] [hal] SPI: Remove byte limit on size in Java API (#7774) The underlying Linux spidev supports up to page size length. --- .../main/java/edu/wpi/first/hal/SPIJNI.java | 20 ++++++++-------- hal/src/main/native/cpp/jni/SPIJNI.cpp | 24 +++++++++---------- .../main/java/edu/wpi/first/wpilibj/SPI.java | 12 +++++----- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/hal/src/main/java/edu/wpi/first/hal/SPIJNI.java b/hal/src/main/java/edu/wpi/first/hal/SPIJNI.java index 242053ec38..b164e993ed 100644 --- a/hal/src/main/java/edu/wpi/first/hal/SPIJNI.java +++ b/hal/src/main/java/edu/wpi/first/hal/SPIJNI.java @@ -61,12 +61,12 @@ public class SPIJNI extends JNIWrapper { * @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP * @param dataToSend Buffer of data to send as part of the transaction. * @param dataReceived Buffer to read data into. - * @param size Number of bytes to transfer. [0..7] + * @param size Number of bytes to transfer. * @return Number of bytes transferred, -1 for error * @see "HAL_TransactionSPI" */ public static native int spiTransaction( - int port, ByteBuffer dataToSend, ByteBuffer dataReceived, byte size); + int port, ByteBuffer dataToSend, ByteBuffer dataReceived, int size); /** * Performs an SPI send/receive transaction. @@ -77,12 +77,12 @@ public class SPIJNI extends JNIWrapper { * @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP * @param dataToSend Buffer of data to send as part of the transaction. * @param dataReceived Buffer to read data into. - * @param size Number of bytes to transfer. [0..7] + * @param size Number of bytes to transfer. * @return Number of bytes transferred, -1 for error * @see "HAL_TransactionSPI" */ public static native int spiTransactionB( - int port, byte[] dataToSend, byte[] dataReceived, byte size); + int port, byte[] dataToSend, byte[] dataReceived, int size); /** * Executes a write transaction with the device. @@ -95,7 +95,7 @@ public class SPIJNI extends JNIWrapper { * @return The number of bytes written. -1 for an error * @see "HAL_WriteSPI" */ - public static native int spiWrite(int port, ByteBuffer dataToSend, byte sendSize); + public static native int spiWrite(int port, ByteBuffer dataToSend, int sendSize); /** * Executes a write transaction with the device. @@ -108,7 +108,7 @@ public class SPIJNI extends JNIWrapper { * @return The number of bytes written. -1 for an error * @see "HAL_WriteSPI" */ - public static native int spiWriteB(int port, byte[] dataToSend, byte sendSize); + public static native int spiWriteB(int port, byte[] dataToSend, int sendSize); /** * Executes a read from the device. @@ -121,11 +121,11 @@ public class SPIJNI extends JNIWrapper { * @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP * @param initiate initiates a transaction when true. Just reads when false. * @param dataReceived A pointer to the array of bytes to store the data read from the device. - * @param size The number of bytes to read in the transaction. [1..7] + * @param size The number of bytes to read in the transaction. * @return Number of bytes read. -1 for error. * @see "HAL_ReadSPI" */ - public static native int spiRead(int port, boolean initiate, ByteBuffer dataReceived, byte size); + public static native int spiRead(int port, boolean initiate, ByteBuffer dataReceived, int size); /** * Executes a read from the device. @@ -138,11 +138,11 @@ public class SPIJNI extends JNIWrapper { * @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP * @param initiate initiates a transaction when true. Just reads when false. * @param dataReceived A pointer to the array of bytes to store the data read from the device. - * @param size The number of bytes to read in the transaction. [1..7] + * @param size The number of bytes to read in the transaction. * @return Number of bytes read. -1 for error. * @see "HAL_ReadSPI" */ - public static native int spiReadB(int port, boolean initiate, byte[] dataReceived, byte size); + public static native int spiReadB(int port, boolean initiate, byte[] dataReceived, int size); /** * Closes the SPI port. diff --git a/hal/src/main/native/cpp/jni/SPIJNI.cpp b/hal/src/main/native/cpp/jni/SPIJNI.cpp index 0940de6da7..93e353250d 100644 --- a/hal/src/main/native/cpp/jni/SPIJNI.cpp +++ b/hal/src/main/native/cpp/jni/SPIJNI.cpp @@ -55,12 +55,12 @@ Java_edu_wpi_first_hal_SPIJNI_spiInitialize /* * Class: edu_wpi_first_hal_SPIJNI * Method: spiTransaction - * Signature: (ILjava/lang/Object;Ljava/lang/Object;B)I + * Signature: (ILjava/lang/Object;Ljava/lang/Object;I)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_hal_SPIJNI_spiTransaction (JNIEnv* env, jclass, jint port, jobject dataToSend, jobject dataReceived, - jbyte size) + jint size) { uint8_t* dataToSendPtr = nullptr; if (dataToSend != nullptr) { @@ -77,12 +77,12 @@ Java_edu_wpi_first_hal_SPIJNI_spiTransaction /* * Class: edu_wpi_first_hal_SPIJNI * Method: spiTransactionB - * Signature: (I[B[BB)I + * Signature: (I[B[BI)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_hal_SPIJNI_spiTransactionB (JNIEnv* env, jclass, jint port, jbyteArray dataToSend, - jbyteArray dataReceived, jbyte size) + jbyteArray dataReceived, jint size) { if (size < 0) { ThrowIllegalArgumentException(env, "SPIJNI.spiTransactionB() size < 0"); @@ -104,11 +104,11 @@ Java_edu_wpi_first_hal_SPIJNI_spiTransactionB /* * Class: edu_wpi_first_hal_SPIJNI * Method: spiWrite - * Signature: (ILjava/lang/Object;B)I + * Signature: (ILjava/lang/Object;I)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_hal_SPIJNI_spiWrite - (JNIEnv* env, jclass, jint port, jobject dataToSend, jbyte size) + (JNIEnv* env, jclass, jint port, jobject dataToSend, jint size) { uint8_t* dataToSendPtr = nullptr; if (dataToSend != nullptr) { @@ -123,11 +123,11 @@ Java_edu_wpi_first_hal_SPIJNI_spiWrite /* * Class: edu_wpi_first_hal_SPIJNI * Method: spiWriteB - * Signature: (I[BB)I + * Signature: (I[BI)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_hal_SPIJNI_spiWriteB - (JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jbyte size) + (JNIEnv* env, jclass, jint port, jbyteArray dataToSend, jint size) { jint retVal = HAL_WriteSPI(static_cast(port), reinterpret_cast( @@ -139,12 +139,12 @@ Java_edu_wpi_first_hal_SPIJNI_spiWriteB /* * Class: edu_wpi_first_hal_SPIJNI * Method: spiRead - * Signature: (IZLjava/lang/Object;B)I + * Signature: (IZLjava/lang/Object;I)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_hal_SPIJNI_spiRead (JNIEnv* env, jclass, jint port, jboolean initiate, jobject dataReceived, - jbyte size) + jint size) { if (size < 0) { ThrowIllegalArgumentException(env, "SPIJNI.spiRead() size < 0"); @@ -169,12 +169,12 @@ Java_edu_wpi_first_hal_SPIJNI_spiRead /* * Class: edu_wpi_first_hal_SPIJNI * Method: spiReadB - * Signature: (IZ[BB)I + * Signature: (IZ[BI)I */ JNIEXPORT jint JNICALL Java_edu_wpi_first_hal_SPIJNI_spiReadB (JNIEnv* env, jclass, jint port, jboolean initiate, jbyteArray dataReceived, - jbyte size) + jint size) { if (size < 0) { ThrowIllegalArgumentException(env, "SPIJNI.spiReadB() size < 0"); diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java index 9278fd8170..dd5d6a3463 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/SPI.java @@ -140,7 +140,7 @@ public class SPI implements AutoCloseable { if (dataToSend.length < size) { throw new IllegalArgumentException("buffer is too small, must be at least " + size); } - return SPIJNI.spiWriteB(m_port, dataToSend, (byte) size); + return SPIJNI.spiWriteB(m_port, dataToSend, size); } /** @@ -163,7 +163,7 @@ public class SPI implements AutoCloseable { if (dataToSend.capacity() < size) { throw new IllegalArgumentException("buffer is too small, must be at least " + size); } - return SPIJNI.spiWrite(m_port, dataToSend, (byte) size); + return SPIJNI.spiWrite(m_port, dataToSend, size); } /** @@ -184,7 +184,7 @@ public class SPI implements AutoCloseable { if (dataReceived.length < size) { throw new IllegalArgumentException("buffer is too small, must be at least " + size); } - return SPIJNI.spiReadB(m_port, initiate, dataReceived, (byte) size); + return SPIJNI.spiReadB(m_port, initiate, dataReceived, size); } /** @@ -211,7 +211,7 @@ public class SPI implements AutoCloseable { if (dataReceived.capacity() < size) { throw new IllegalArgumentException("buffer is too small, must be at least " + size); } - return SPIJNI.spiRead(m_port, initiate, dataReceived, (byte) size); + return SPIJNI.spiRead(m_port, initiate, dataReceived, size); } /** @@ -229,7 +229,7 @@ public class SPI implements AutoCloseable { if (dataReceived.length < size) { throw new IllegalArgumentException("dataReceived is too small, must be at least " + size); } - return SPIJNI.spiTransactionB(m_port, dataToSend, dataReceived, (byte) size); + return SPIJNI.spiTransactionB(m_port, dataToSend, dataReceived, size); } /** @@ -256,7 +256,7 @@ public class SPI implements AutoCloseable { if (dataReceived.capacity() < size) { throw new IllegalArgumentException("dataReceived is too small, must be at least " + size); } - return SPIJNI.spiTransaction(m_port, dataToSend, dataReceived, (byte) size); + return SPIJNI.spiTransaction(m_port, dataToSend, dataReceived, size); } /** From 53df127535f7b3302cd573faf33a3886a70812da Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Sun, 9 Feb 2025 23:01:51 -0800 Subject: [PATCH 19/33] [cmake] Suppress enum warning on all clang, not just Apple (#7771) --- cmake/modules/CompileWarnings.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/modules/CompileWarnings.cmake b/cmake/modules/CompileWarnings.cmake index fd4f9294ba..cadc9fe02e 100644 --- a/cmake/modules/CompileWarnings.cmake +++ b/cmake/modules/CompileWarnings.cmake @@ -46,7 +46,7 @@ macro(wpilib_target_warnings target) # Suppress warning "enumeration types with a fixed underlying type are a # Clang extension" - if(APPLE) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") target_compile_options(${target} PRIVATE $<$:-Wno-fixed-enum-extension>) endif() From b2584c6bdf84085a2a6eb4213f10ad2dd0c61a2c Mon Sep 17 00:00:00 2001 From: Michael Fisher <880111+mfisher31@users.noreply.github.com> Date: Mon, 10 Feb 2025 02:03:15 -0500 Subject: [PATCH 20/33] [cmake] Use binary output dir for generated field images code (#7772) --- .gitignore | 3 +++ fieldImages/CMakeLists.txt | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3cf9f62103..0d50414a43 100644 --- a/.gitignore +++ b/.gitignore @@ -255,3 +255,6 @@ bazel_auth.rc # ctest /Testing/ + +# Meson +.meson-subproject* diff --git a/fieldImages/CMakeLists.txt b/fieldImages/CMakeLists.txt index 93f8e13695..f1d435c30e 100644 --- a/fieldImages/CMakeLists.txt +++ b/fieldImages/CMakeLists.txt @@ -36,13 +36,13 @@ endif() generate_resources( src/main/native/resources/edu/wpi/first/fields - generated/main/cpp + ${CMAKE_CURRENT_BINARY_DIR}/generated/main/cpp FIELDS fields field_images_resources_src ) -add_library(fieldImages src/main/native/cpp/fields.cpp ${field_images_resources_src}) +add_library(fieldImages ${field_images_resources_src} src/main/native/cpp/fields.cpp) set_target_properties(fieldImages PROPERTIES DEBUG_POSTFIX "d") set_property(TARGET fieldImages PROPERTY FOLDER "libraries") From 9dbb0c8c3dc2dba2d7f117e81b40a9ecb009de42 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Mon, 10 Feb 2025 02:04:36 -0500 Subject: [PATCH 21/33] [ci] Turn on sync labels for the labeler (#7770) This means PRs that had labels for certain changes will have those labels removed if those changes are removed. --- .github/workflows/labeler.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml index e57cd86e2b..526323cea6 100644 --- a/.github/workflows/labeler.yml +++ b/.github/workflows/labeler.yml @@ -1,6 +1,6 @@ name: "Pull Request Labeler" on: -- pull_request_target + - pull_request_target jobs: labeler: @@ -9,4 +9,6 @@ jobs: pull-requests: write runs-on: ubuntu-latest steps: - - uses: actions/labeler@v5 + - uses: actions/labeler@v5 + with: + sync-labels: true From 1921d7b79a5224117ef1d2a07dbe199d85c5e623 Mon Sep 17 00:00:00 2001 From: Dustin Spicuzza Date: Wed, 12 Feb 2025 01:05:22 -0500 Subject: [PATCH 22/33] [wpilibc] Remove Alert magic static with map lookup (#7712) The magic static adds yet another thing that needs to be reset if you want to run a unit test with a completely reset wpilib state. Use the existing Sendable static map to store the data instead. This leaks memory if ResetSmartDashboardInstance is called. --- wpilibc/src/main/native/cpp/Alert.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/wpilibc/src/main/native/cpp/Alert.cpp b/wpilibc/src/main/native/cpp/Alert.cpp index f74f0ab759..7cce523377 100644 --- a/wpilibc/src/main/native/cpp/Alert.cpp +++ b/wpilibc/src/main/native/cpp/Alert.cpp @@ -82,17 +82,18 @@ class Alert::SendableAlerts : public nt::NTSendable, * @return the SendableAlerts for the group */ static SendableAlerts& ForGroup(std::string_view group) { - // Force initialization of SendableRegistry before our magic static to - // prevent incorrect destruction order. - wpi::SendableRegistry::EnsureInitialized(); - static wpi::StringMap groups; - - auto [iter, inserted] = groups.try_emplace(group); - SendableAlerts& sendable = iter->second; - if (inserted) { - frc::SmartDashboard::PutData(group, &iter->second); + SendableAlerts* salert = nullptr; + try { + auto* sendable = frc::SmartDashboard::GetData(group); + salert = dynamic_cast(sendable); + } catch (frc::RuntimeError&) { } - return sendable; + if (!salert) { + // this leaks if ResetSmartDashboardInstance is called, but that's fine + salert = new Alert::SendableAlerts; + frc::SmartDashboard::PutData(group, salert); + } + return *salert; } private: From d62ab12855389ce36c57177799037c433bfb4c67 Mon Sep 17 00:00:00 2001 From: Austin Schuh Date: Wed, 12 Feb 2025 15:17:11 -0800 Subject: [PATCH 23/33] [bazel] Add missing -ldl when building libuv in bazel (#7775) I was getting: external/arm_frc_linux_gnueabi_repo/bin/../arm-nilrt-linux-gnueabi/sysroot/usr/lib/gcc/arm-nilrt-linux-gnueabi/12/../../../../../../../arm-nilrt-linux-gnueabi/bin/ld: bazel-out/k8-opt--roborio/bin/external/com_github_wpilibsuite_allwpilib/wpinet/libwpinet.static.a(fs.o): undefined reference to symbol 'dlsym@@GLIBC_2.4' external/arm_frc_linux_gnueabi_repo/bin/../arm-nilrt-linux-gnueabi/sysroot/usr/lib/gcc/arm-nilrt-linux-gnueabi/12/../../../../../../../arm-nilrt-linux-gnueabi/bin/ld: external/arm_frc_linux_gnueabi_repo/bin/../arm-nilrt-linux-gnueabi/sysroot/lib/libdl.so.2: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status This fixes that error for me. Signed-off-by: Austin Schuh --- wpinet/BUILD.bazel | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wpinet/BUILD.bazel b/wpinet/BUILD.bazel index c6bdebae7a..eaaab42d24 100644 --- a/wpinet/BUILD.bazel +++ b/wpinet/BUILD.bazel @@ -121,6 +121,10 @@ cc_library( ] + ["native-srcs"], hdrs = glob(["src/main/native/include/**/*"]), includes = ["src/main/native/include"], + linkopts = select({ + "@bazel_tools//src/conditions:linux": ["-ldl"], + "//conditions:default": [], + }), strip_include_prefix = "src/main/native/include", visibility = ["//visibility:public"], deps = [ From 155b3d45e7912082e90c891ee57119095ee9ac7f Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 12 Feb 2025 22:54:41 -0800 Subject: [PATCH 24/33] [wpiutil] Remove broken StackWalker library (#7777) A Discord user reported that StackWalker gives blank stacktraces. MSVC's C++23 support is unstable, so we can't use std::stacktrace yet. In the meantime, we can just return an empty string and remove the unmaintained StackWalker library and its hacky upstream_utils script. --- .github/workflows/upstream-utils.yml | 6 - ThirdPartyNotices.txt | 30 - upstream_utils/stack_walker.py | 65 - .../0001-Add-advapi-pragma.patch | 21 - wpiutil/src/main/native/cpp/RuntimeCheck.cpp | 2 +- .../src/main/native/windows/StackTrace.cpp | 26 +- .../src/main/native/windows/StackWalker.cpp | 1549 ----------------- wpiutil/src/main/native/windows/StackWalker.h | 273 --- 8 files changed, 3 insertions(+), 1969 deletions(-) delete mode 100755 upstream_utils/stack_walker.py delete mode 100644 upstream_utils/stack_walker_patches/0001-Add-advapi-pragma.patch delete mode 100644 wpiutil/src/main/native/windows/StackWalker.cpp delete mode 100644 wpiutil/src/main/native/windows/StackWalker.h diff --git a/.github/workflows/upstream-utils.yml b/.github/workflows/upstream-utils.yml index 587c7a6b3b..a1de79b831 100644 --- a/.github/workflows/upstream-utils.yml +++ b/.github/workflows/upstream-utils.yml @@ -120,12 +120,6 @@ jobs: ./mpack.py clone ./mpack.py copy-src ./mpack.py format-patch - - name: Run stack_walker.py - run: | - cd upstream_utils - ./stack_walker.py clone - ./stack_walker.py copy-src - ./stack_walker.py format-patch - name: Run memory.py run: | cd upstream_utils diff --git a/ThirdPartyNotices.txt b/ThirdPartyNotices.txt index 4acb020f80..91bd7a2fb1 100644 --- a/ThirdPartyNotices.txt +++ b/ThirdPartyNotices.txt @@ -33,7 +33,6 @@ jQuery wpinet/src/main/native/resources/jquery-* popper.js wpinet/src/main/native/resources/popper-* units wpimath/src/main/native/include/units/ Eigen wpimath/src/main/native/thirdparty/eigen/include/ -StackWalker wpiutil/src/main/native/windows/StackWalker.* Team 254 Library wpimath/src/main/java/edu/wpi/first/math/spline/SplineParameterizer.java wpimath/src/main/java/edu/wpi/first/math/trajectory/TrajectoryParameterizer.java wpimath/src/main/native/include/frc/spline/SplineParameterizer.h @@ -1026,35 +1025,6 @@ Exhibit B - "Incompatible With Secondary Licenses" Notice defined by the Mozilla Public License, v. 2.0. -=================== -StackWalker License -=================== -Copyright (c) 2005-2013, Jochen Kalmbach -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. -Neither the name of Jochen Kalmbach nor the names of its contributors may be -used to endorse or promote products derived from this software without -specific prior written permission. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - ================ Team 254 Library ================ diff --git a/upstream_utils/stack_walker.py b/upstream_utils/stack_walker.py deleted file mode 100755 index d0499d20c6..0000000000 --- a/upstream_utils/stack_walker.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python3 - -import os -import shutil -import subprocess - -from upstream_utils import Lib - - -def crlf_to_lf(): - for root, _, files in os.walk("."): - if ".git" in root: - continue - - for fname in files: - filename = os.path.join(root, fname) - print(f"Converting CRLF -> LF for {filename}") - with open(filename, "rb") as f: - content = f.read() - content = content.replace(b"\r\n", b"\n") - - with open(filename, "wb") as f: - f.write(content) - - subprocess.check_call(["git", "add", "-A"]) - subprocess.check_call(["git", "commit", "-m", "Fix line endings"]) - - -def copy_upstream_src(wpilib_root): - wpiutil = os.path.join(wpilib_root, "wpiutil") - - shutil.copy( - os.path.join("Main", "StackWalker", "StackWalker.h"), - os.path.join(wpiutil, "src/main/native/windows/StackWalker.h"), - ) - - shutil.copy( - os.path.join("Main", "StackWalker", "StackWalker.cpp"), - os.path.join(wpiutil, "src/main/native/windows/StackWalker.cpp"), - ) - - -def main(): - name = "stack_walker" - url = "https://github.com/JochenKalmbach/StackWalker" - tag = "5b0df7a4db8896f6b6dc45d36e383c52577e3c6b" - - patch_options = { - "ignore_whitespace": True, - } - - stack_walker = Lib( - name, - url, - tag, - copy_upstream_src, - patch_options, - pre_patch_hook=crlf_to_lf, - pre_patch_commits=1, - ) - stack_walker.main() - - -if __name__ == "__main__": - main() diff --git a/upstream_utils/stack_walker_patches/0001-Add-advapi-pragma.patch b/upstream_utils/stack_walker_patches/0001-Add-advapi-pragma.patch deleted file mode 100644 index 599a7120c4..0000000000 --- a/upstream_utils/stack_walker_patches/0001-Add-advapi-pragma.patch +++ /dev/null @@ -1,21 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Thad House -Date: Sat, 22 Jul 2023 13:03:13 -0700 -Subject: [PATCH] Add advapi pragma - ---- - Main/StackWalker/StackWalker.cpp | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/Main/StackWalker/StackWalker.cpp b/Main/StackWalker/StackWalker.cpp -index 89545f8612d0d099d48fcf4184a2f2a30cf8577f..b2bcbaa447c5db1a3bcc155fb317ebc8a8050e79 100644 ---- a/Main/StackWalker/StackWalker.cpp -+++ b/Main/StackWalker/StackWalker.cpp -@@ -91,6 +91,7 @@ - #include - - #pragma comment(lib, "version.lib") // for "VerQueryValue" -+#pragma comment(lib, "Advapi32.lib") // for "GetUserName" - - #pragma warning(disable : 4826) - #if _MSC_VER >= 1900 diff --git a/wpiutil/src/main/native/cpp/RuntimeCheck.cpp b/wpiutil/src/main/native/cpp/RuntimeCheck.cpp index 6cead1a8ab..79ed623580 100644 --- a/wpiutil/src/main/native/cpp/RuntimeCheck.cpp +++ b/wpiutil/src/main/native/cpp/RuntimeCheck.cpp @@ -7,7 +7,7 @@ #ifdef _WIN32 #include #include - +#pragma comment(lib, "version.lib") // for VerQueryValueW #include "Windows.h" extern "C" int32_t WPI_IsRuntimeValid(uint32_t* foundMajor, uint32_t* foundMinor, diff --git a/wpiutil/src/main/native/windows/StackTrace.cpp b/wpiutil/src/main/native/windows/StackTrace.cpp index db17bf8e83..ed7cf61afb 100644 --- a/wpiutil/src/main/native/windows/StackTrace.cpp +++ b/wpiutil/src/main/native/windows/StackTrace.cpp @@ -6,35 +6,13 @@ #include -#include "StackWalker.h" -#include "wpi/ConvertUTF.h" -#include "wpi/SmallString.h" - #if defined(_MSC_VER) -namespace { -class StackTraceWalker : public StackWalker { - public: - explicit StackTraceWalker(std::string& output) : m_output(output) {} - - void OnOutput(LPCTSTR szText) override; - - private: - std::string& m_output; -}; -} // namespace - -void StackTraceWalker::OnOutput(LPCTSTR szText) { - m_output.append(szText); -} - namespace wpi { std::string GetStackTraceDefault(int offset) { - // TODO: implement offset - std::string output; - StackTraceWalker walker(output); - return output; + // FIXME: Use C++23 std::stacktrace + return ""; } } // namespace wpi diff --git a/wpiutil/src/main/native/windows/StackWalker.cpp b/wpiutil/src/main/native/windows/StackWalker.cpp deleted file mode 100644 index b2bcbaa447..0000000000 --- a/wpiutil/src/main/native/windows/StackWalker.cpp +++ /dev/null @@ -1,1549 +0,0 @@ -/********************************************************************** - * - * StackWalker.cpp - * https://github.com/JochenKalmbach/StackWalker - * - * Old location: http://stackwalker.codeplex.com/ - * - * - * History: - * 2005-07-27 v1 - First public release on http://www.codeproject.com/ - * http://www.codeproject.com/threads/StackWalker.asp - * 2005-07-28 v2 - Changed the params of the constructor and ShowCallstack - * (to simplify the usage) - * 2005-08-01 v3 - Changed to use 'CONTEXT_FULL' instead of CONTEXT_ALL - * (should also be enough) - * - Changed to compile correctly with the PSDK of VC7.0 - * (GetFileVersionInfoSizeA and GetFileVersionInfoA is wrongly defined: - * it uses LPSTR instead of LPCSTR as first parameter) - * - Added declarations to support VC5/6 without using 'dbghelp.h' - * - Added a 'pUserData' member to the ShowCallstack function and the - * PReadProcessMemoryRoutine declaration (to pass some user-defined data, - * which can be used in the readMemoryFunction-callback) - * 2005-08-02 v4 - OnSymInit now also outputs the OS-Version by default - * - Added example for doing an exception-callstack-walking in main.cpp - * (thanks to owillebo: http://www.codeproject.com/script/profile/whos_who.asp?id=536268) - * 2005-08-05 v5 - Removed most Lint (http://www.gimpel.com/) errors... thanks to Okko Willeboordse! - * 2008-08-04 v6 - Fixed Bug: Missing LEAK-end-tag - * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=2502890#xx2502890xx - * Fixed Bug: Compiled with "WIN32_LEAN_AND_MEAN" - * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=1824718#xx1824718xx - * Fixed Bug: Compiling with "/Wall" - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=2638243#xx2638243xx - * Fixed Bug: Now checking SymUseSymSrv - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1388979#xx1388979xx - * Fixed Bug: Support for recursive function calls - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1434538#xx1434538xx - * Fixed Bug: Missing FreeLibrary call in "GetModuleListTH32" - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=1326923#xx1326923xx - * Fixed Bug: SymDia is number 7, not 9! - * 2008-09-11 v7 For some (undocumented) reason, dbhelp.h is needing a packing of 8! - * Thanks to Teajay which reported the bug... - * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=2718933#xx2718933xx - * 2008-11-27 v8 Debugging Tools for Windows are now stored in a different directory - * Thanks to Luiz Salamon which reported this "bug"... - * http://www.codeproject.com/KB/threads/StackWalker.aspx?msg=2822736#xx2822736xx - * 2009-04-10 v9 License slightly corrected ( replaced) - * 2009-11-01 v10 Moved to http://stackwalker.codeplex.com/ - * 2009-11-02 v11 Now try to use IMAGEHLP_MODULE64_V3 if available - * 2010-04-15 v12 Added support for VS2010 RTM - * 2010-05-25 v13 Now using secure MyStrcCpy. Thanks to luke.simon: - * http://www.codeproject.com/KB/applications/leakfinder.aspx?msg=3477467#xx3477467xx - * 2013-01-07 v14 Runtime Check Error VS2010 Debug Builds fixed: - * http://stackwalker.codeplex.com/workitem/10511 - * - * - * LICENSE (http://www.opensource.org/licenses/bsd-license.php) - * - * Copyright (c) 2005-2013, Jochen Kalmbach - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Jochen Kalmbach nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - **********************************************************************/ - -#include "StackWalker.h" - -#include -#include -#include -#include -#include - -#pragma comment(lib, "version.lib") // for "VerQueryValue" -#pragma comment(lib, "Advapi32.lib") // for "GetUserName" - -#pragma warning(disable : 4826) -#if _MSC_VER >= 1900 -#pragma warning(disable : 4091) // For fix unnamed enums from DbgHelp.h -#endif - - -// If VC7 and later, then use the shipped 'dbghelp.h'-file -#pragma pack(push, 8) -#if _MSC_VER >= 1300 -#include -#else -// inline the important dbghelp.h-declarations... -typedef enum -{ - SymNone = 0, - SymCoff, - SymCv, - SymPdb, - SymExport, - SymDeferred, - SymSym, - SymDia, - SymVirtual, - NumSymTypes -} SYM_TYPE; -typedef struct _IMAGEHLP_LINE64 -{ - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_LINE64) - PVOID Key; // internal - DWORD LineNumber; // line number in file - PCHAR FileName; // full filename - DWORD64 Address; // first instruction of line -} IMAGEHLP_LINE64, *PIMAGEHLP_LINE64; -typedef struct _IMAGEHLP_MODULE64 -{ - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) - DWORD64 BaseOfImage; // base load address of module - DWORD ImageSize; // virtual size of the loaded module - DWORD TimeDateStamp; // date/time stamp from pe header - DWORD CheckSum; // checksum from the pe header - DWORD NumSyms; // number of symbols in the symbol table - SYM_TYPE SymType; // type of symbols loaded - CHAR ModuleName[32]; // module name - CHAR ImageName[256]; // image name - CHAR LoadedImageName[256]; // symbol file name -} IMAGEHLP_MODULE64, *PIMAGEHLP_MODULE64; -typedef struct _IMAGEHLP_SYMBOL64 -{ - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_SYMBOL64) - DWORD64 Address; // virtual address including dll base address - DWORD Size; // estimated size of symbol, can be zero - DWORD Flags; // info about the symbols, see the SYMF defines - DWORD MaxNameLength; // maximum size of symbol name in 'Name' - CHAR Name[1]; // symbol name (null terminated string) -} IMAGEHLP_SYMBOL64, *PIMAGEHLP_SYMBOL64; -typedef enum -{ - AddrMode1616, - AddrMode1632, - AddrModeReal, - AddrModeFlat -} ADDRESS_MODE; -typedef struct _tagADDRESS64 -{ - DWORD64 Offset; - WORD Segment; - ADDRESS_MODE Mode; -} ADDRESS64, *LPADDRESS64; -typedef struct _KDHELP64 -{ - DWORD64 Thread; - DWORD ThCallbackStack; - DWORD ThCallbackBStore; - DWORD NextCallback; - DWORD FramePointer; - DWORD64 KiCallUserMode; - DWORD64 KeUserCallbackDispatcher; - DWORD64 SystemRangeStart; - DWORD64 Reserved[8]; -} KDHELP64, *PKDHELP64; -typedef struct _tagSTACKFRAME64 -{ - ADDRESS64 AddrPC; // program counter - ADDRESS64 AddrReturn; // return address - ADDRESS64 AddrFrame; // frame pointer - ADDRESS64 AddrStack; // stack pointer - ADDRESS64 AddrBStore; // backing store pointer - PVOID FuncTableEntry; // pointer to pdata/fpo or NULL - DWORD64 Params[4]; // possible arguments to the function - BOOL Far; // WOW far call - BOOL Virtual; // is this a virtual frame? - DWORD64 Reserved[3]; - KDHELP64 KdHelp; -} STACKFRAME64, *LPSTACKFRAME64; -typedef BOOL(__stdcall* PREAD_PROCESS_MEMORY_ROUTINE64)(HANDLE hProcess, - DWORD64 qwBaseAddress, - PVOID lpBuffer, - DWORD nSize, - LPDWORD lpNumberOfBytesRead); -typedef PVOID(__stdcall* PFUNCTION_TABLE_ACCESS_ROUTINE64)(HANDLE hProcess, DWORD64 AddrBase); -typedef DWORD64(__stdcall* PGET_MODULE_BASE_ROUTINE64)(HANDLE hProcess, DWORD64 Address); -typedef DWORD64(__stdcall* PTRANSLATE_ADDRESS_ROUTINE64)(HANDLE hProcess, - HANDLE hThread, - LPADDRESS64 lpaddr); - -// clang-format off -#define SYMOPT_CASE_INSENSITIVE 0x00000001 -#define SYMOPT_UNDNAME 0x00000002 -#define SYMOPT_DEFERRED_LOADS 0x00000004 -#define SYMOPT_NO_CPP 0x00000008 -#define SYMOPT_LOAD_LINES 0x00000010 -#define SYMOPT_OMAP_FIND_NEAREST 0x00000020 -#define SYMOPT_LOAD_ANYTHING 0x00000040 -#define SYMOPT_IGNORE_CVREC 0x00000080 -#define SYMOPT_NO_UNQUALIFIED_LOADS 0x00000100 -#define SYMOPT_FAIL_CRITICAL_ERRORS 0x00000200 -#define SYMOPT_EXACT_SYMBOLS 0x00000400 -#define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS 0x00000800 -#define SYMOPT_IGNORE_NT_SYMPATH 0x00001000 -#define SYMOPT_INCLUDE_32BIT_MODULES 0x00002000 -#define SYMOPT_PUBLICS_ONLY 0x00004000 -#define SYMOPT_NO_PUBLICS 0x00008000 -#define SYMOPT_AUTO_PUBLICS 0x00010000 -#define SYMOPT_NO_IMAGE_SEARCH 0x00020000 -#define SYMOPT_SECURE 0x00040000 -#define SYMOPT_DEBUG 0x80000000 -#define UNDNAME_COMPLETE (0x0000) // Enable full undecoration -#define UNDNAME_NAME_ONLY (0x1000) // Crack only the name for primary declaration; -// clang-format on - -#endif // _MSC_VER < 1300 -#pragma pack(pop) - -// Some missing defines (for VC5/6): -#ifndef INVALID_FILE_ATTRIBUTES -#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) -#endif - -// secure-CRT_functions are only available starting with VC8 -#if _MSC_VER < 1400 -#define strcpy_s(dst, len, src) strcpy(dst, src) -#define strncpy_s(dst, len, src, maxLen) strncpy(dst, len, src) -#define strcat_s(dst, len, src) strcat(dst, src) -#define _snprintf_s _snprintf -#define _tcscat_s _tcscat -#endif - -static void MyStrCpy(char* szDest, size_t nMaxDestSize, const char* szSrc) -{ - if (nMaxDestSize <= 0) - return; - strncpy_s(szDest, nMaxDestSize, szSrc, _TRUNCATE); - // INFO: _TRUNCATE will ensure that it is null-terminated; - // but with older compilers (<1400) it uses "strncpy" and this does not!) - szDest[nMaxDestSize - 1] = 0; -} // MyStrCpy - -// Normally it should be enough to use 'CONTEXT_FULL' (better would be 'CONTEXT_ALL') -#define USED_CONTEXT_FLAGS CONTEXT_FULL - -class StackWalkerInternal -{ -public: - StackWalkerInternal(StackWalker* parent, HANDLE hProcess, PCONTEXT ctx) - { - m_parent = parent; - m_hDbhHelp = NULL; - pSC = NULL; - m_hProcess = hProcess; - pSFTA = NULL; - pSGLFA = NULL; - pSGMB = NULL; - pSGMI = NULL; - pSGO = NULL; - pSGSFA = NULL; - pSI = NULL; - pSLM = NULL; - pSSO = NULL; - pSW = NULL; - pUDSN = NULL; - pSGSP = NULL; - m_ctx.ContextFlags = 0; - if (ctx != NULL) - m_ctx = *ctx; - } - - ~StackWalkerInternal() - { - if (pSC != NULL) - pSC(m_hProcess); // SymCleanup - if (m_hDbhHelp != NULL) - FreeLibrary(m_hDbhHelp); - m_hDbhHelp = NULL; - m_parent = NULL; - } - - BOOL Init(LPCSTR szSymPath) - { - if (m_parent == NULL) - return FALSE; - // Dynamically load the Entry-Points for dbghelp.dll: - // First try to load the newest one from - TCHAR szTemp[4096]; - // But before we do this, we first check if the ".local" file exists - if (GetModuleFileName(NULL, szTemp, 4096) > 0) - { - _tcscat_s(szTemp, _T(".local")); - if (GetFileAttributes(szTemp) == INVALID_FILE_ATTRIBUTES) - { - // ".local" file does not exist, so we can try to load the dbghelp.dll from the "Debugging Tools for Windows" - // Ok, first try the new path according to the architecture: -#ifdef _M_IX86 - if ((m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0)) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (x86)\\dbghelp.dll")); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#elif _M_X64 - if ((m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0)) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (x64)\\dbghelp.dll")); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#elif _M_IA64 - if ((m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0)) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows (ia64)\\dbghelp.dll")); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#endif - // If still not found, try the old directories... - if ((m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0)) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows\\dbghelp.dll")); - // now check if the file exists: - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#if defined _M_X64 || defined _M_IA64 - // Still not found? Then try to load the (old) 64-Bit version: - if ((m_hDbhHelp == NULL) && (GetEnvironmentVariable(_T("ProgramFiles"), szTemp, 4096) > 0)) - { - _tcscat_s(szTemp, _T("\\Debugging Tools for Windows 64-Bit\\dbghelp.dll")); - if (GetFileAttributes(szTemp) != INVALID_FILE_ATTRIBUTES) - { - m_hDbhHelp = LoadLibrary(szTemp); - } - } -#endif - } - } - if (m_hDbhHelp == NULL) // if not already loaded, try to load a default-one - m_hDbhHelp = LoadLibrary(_T("dbghelp.dll")); - if (m_hDbhHelp == NULL) - return FALSE; - pSI = (tSI)GetProcAddress(m_hDbhHelp, "SymInitialize"); - pSC = (tSC)GetProcAddress(m_hDbhHelp, "SymCleanup"); - - pSW = (tSW)GetProcAddress(m_hDbhHelp, "StackWalk64"); - pSGO = (tSGO)GetProcAddress(m_hDbhHelp, "SymGetOptions"); - pSSO = (tSSO)GetProcAddress(m_hDbhHelp, "SymSetOptions"); - - pSFTA = (tSFTA)GetProcAddress(m_hDbhHelp, "SymFunctionTableAccess64"); - pSGLFA = (tSGLFA)GetProcAddress(m_hDbhHelp, "SymGetLineFromAddr64"); - pSGMB = (tSGMB)GetProcAddress(m_hDbhHelp, "SymGetModuleBase64"); - pSGMI = (tSGMI)GetProcAddress(m_hDbhHelp, "SymGetModuleInfo64"); - pSGSFA = (tSGSFA)GetProcAddress(m_hDbhHelp, "SymGetSymFromAddr64"); - pUDSN = (tUDSN)GetProcAddress(m_hDbhHelp, "UnDecorateSymbolName"); - pSLM = (tSLM)GetProcAddress(m_hDbhHelp, "SymLoadModule64"); - pSGSP = (tSGSP)GetProcAddress(m_hDbhHelp, "SymGetSearchPath"); - - if (pSC == NULL || pSFTA == NULL || pSGMB == NULL || pSGMI == NULL || pSGO == NULL || - pSGSFA == NULL || pSI == NULL || pSSO == NULL || pSW == NULL || pUDSN == NULL || - pSLM == NULL) - { - FreeLibrary(m_hDbhHelp); - m_hDbhHelp = NULL; - pSC = NULL; - return FALSE; - } - - // SymInitialize - if (this->pSI(m_hProcess, szSymPath, FALSE) == FALSE) - this->m_parent->OnDbgHelpErr("SymInitialize", GetLastError(), 0); - - DWORD symOptions = this->pSGO(); // SymGetOptions - symOptions |= SYMOPT_LOAD_LINES; - symOptions |= SYMOPT_FAIL_CRITICAL_ERRORS; - //symOptions |= SYMOPT_NO_PROMPTS; - // SymSetOptions - symOptions = this->pSSO(symOptions); - - char buf[StackWalker::STACKWALK_MAX_NAMELEN] = {0}; - if (this->pSGSP != NULL) - { - if (this->pSGSP(m_hProcess, buf, StackWalker::STACKWALK_MAX_NAMELEN) == FALSE) - this->m_parent->OnDbgHelpErr("SymGetSearchPath", GetLastError(), 0); - } - char szUserName[1024] = {0}; - DWORD dwSize = 1024; - GetUserNameA(szUserName, &dwSize); - this->m_parent->OnSymInit(buf, symOptions, szUserName); - - return TRUE; - } - - StackWalker* m_parent; - - CONTEXT m_ctx; - HMODULE m_hDbhHelp; - HANDLE m_hProcess; - -#pragma pack(push, 8) - typedef struct _IMAGEHLP_MODULE64_V3 - { - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) - DWORD64 BaseOfImage; // base load address of module - DWORD ImageSize; // virtual size of the loaded module - DWORD TimeDateStamp; // date/time stamp from pe header - DWORD CheckSum; // checksum from the pe header - DWORD NumSyms; // number of symbols in the symbol table - SYM_TYPE SymType; // type of symbols loaded - CHAR ModuleName[32]; // module name - CHAR ImageName[256]; // image name - CHAR LoadedImageName[256]; // symbol file name - // new elements: 07-Jun-2002 - CHAR LoadedPdbName[256]; // pdb file name - DWORD CVSig; // Signature of the CV record in the debug directories - CHAR CVData[MAX_PATH * 3]; // Contents of the CV record - DWORD PdbSig; // Signature of PDB - GUID PdbSig70; // Signature of PDB (VC 7 and up) - DWORD PdbAge; // DBI age of pdb - BOOL PdbUnmatched; // loaded an unmatched pdb - BOOL DbgUnmatched; // loaded an unmatched dbg - BOOL LineNumbers; // we have line number information - BOOL GlobalSymbols; // we have internal symbol information - BOOL TypeInfo; // we have type information - // new elements: 17-Dec-2003 - BOOL SourceIndexed; // pdb supports source server - BOOL Publics; // contains public symbols - } IMAGEHLP_MODULE64_V3, *PIMAGEHLP_MODULE64_V3; - - typedef struct _IMAGEHLP_MODULE64_V2 - { - DWORD SizeOfStruct; // set to sizeof(IMAGEHLP_MODULE64) - DWORD64 BaseOfImage; // base load address of module - DWORD ImageSize; // virtual size of the loaded module - DWORD TimeDateStamp; // date/time stamp from pe header - DWORD CheckSum; // checksum from the pe header - DWORD NumSyms; // number of symbols in the symbol table - SYM_TYPE SymType; // type of symbols loaded - CHAR ModuleName[32]; // module name - CHAR ImageName[256]; // image name - CHAR LoadedImageName[256]; // symbol file name - } IMAGEHLP_MODULE64_V2, *PIMAGEHLP_MODULE64_V2; -#pragma pack(pop) - - // SymCleanup() - typedef BOOL(__stdcall* tSC)(IN HANDLE hProcess); - tSC pSC; - - // SymFunctionTableAccess64() - typedef PVOID(__stdcall* tSFTA)(HANDLE hProcess, DWORD64 AddrBase); - tSFTA pSFTA; - - // SymGetLineFromAddr64() - typedef BOOL(__stdcall* tSGLFA)(IN HANDLE hProcess, - IN DWORD64 dwAddr, - OUT PDWORD pdwDisplacement, - OUT PIMAGEHLP_LINE64 Line); - tSGLFA pSGLFA; - - // SymGetModuleBase64() - typedef DWORD64(__stdcall* tSGMB)(IN HANDLE hProcess, IN DWORD64 dwAddr); - tSGMB pSGMB; - - // SymGetModuleInfo64() - typedef BOOL(__stdcall* tSGMI)(IN HANDLE hProcess, - IN DWORD64 dwAddr, - OUT IMAGEHLP_MODULE64_V3* ModuleInfo); - tSGMI pSGMI; - - // SymGetOptions() - typedef DWORD(__stdcall* tSGO)(VOID); - tSGO pSGO; - - // SymGetSymFromAddr64() - typedef BOOL(__stdcall* tSGSFA)(IN HANDLE hProcess, - IN DWORD64 dwAddr, - OUT PDWORD64 pdwDisplacement, - OUT PIMAGEHLP_SYMBOL64 Symbol); - tSGSFA pSGSFA; - - // SymInitialize() - typedef BOOL(__stdcall* tSI)(IN HANDLE hProcess, IN LPCSTR UserSearchPath, IN BOOL fInvadeProcess); - tSI pSI; - - // SymLoadModule64() - typedef DWORD64(__stdcall* tSLM)(IN HANDLE hProcess, - IN HANDLE hFile, - IN LPCSTR ImageName, - IN LPCSTR ModuleName, - IN DWORD64 BaseOfDll, - IN DWORD SizeOfDll); - tSLM pSLM; - - // SymSetOptions() - typedef DWORD(__stdcall* tSSO)(IN DWORD SymOptions); - tSSO pSSO; - - // StackWalk64() - typedef BOOL(__stdcall* tSW)(DWORD MachineType, - HANDLE hProcess, - HANDLE hThread, - LPSTACKFRAME64 StackFrame, - PVOID ContextRecord, - PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine, - PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine, - PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, - PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress); - tSW pSW; - - // UnDecorateSymbolName() - typedef DWORD(__stdcall WINAPI* tUDSN)(PCSTR DecoratedName, - PSTR UnDecoratedName, - DWORD UndecoratedLength, - DWORD Flags); - tUDSN pUDSN; - - typedef BOOL(__stdcall WINAPI* tSGSP)(HANDLE hProcess, PSTR SearchPath, DWORD SearchPathLength); - tSGSP pSGSP; - -private: -// **************************************** ToolHelp32 ************************ -#define MAX_MODULE_NAME32 255 -#define TH32CS_SNAPMODULE 0x00000008 -#pragma pack(push, 8) - typedef struct tagMODULEENTRY32 - { - DWORD dwSize; - DWORD th32ModuleID; // This module - DWORD th32ProcessID; // owning process - DWORD GlblcntUsage; // Global usage count on the module - DWORD ProccntUsage; // Module usage count in th32ProcessID's context - BYTE* modBaseAddr; // Base address of module in th32ProcessID's context - DWORD modBaseSize; // Size in bytes of module starting at modBaseAddr - HMODULE hModule; // The hModule of this module in th32ProcessID's context - char szModule[MAX_MODULE_NAME32 + 1]; - char szExePath[MAX_PATH]; - } MODULEENTRY32; - typedef MODULEENTRY32* PMODULEENTRY32; - typedef MODULEENTRY32* LPMODULEENTRY32; -#pragma pack(pop) - - BOOL GetModuleListTH32(HANDLE hProcess, DWORD pid) - { - // CreateToolhelp32Snapshot() - typedef HANDLE(__stdcall * tCT32S)(DWORD dwFlags, DWORD th32ProcessID); - // Module32First() - typedef BOOL(__stdcall * tM32F)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); - // Module32Next() - typedef BOOL(__stdcall * tM32N)(HANDLE hSnapshot, LPMODULEENTRY32 lpme); - - // try both dlls... - const TCHAR* dllname[] = {_T("kernel32.dll"), _T("tlhelp32.dll")}; - HINSTANCE hToolhelp = NULL; - tCT32S pCT32S = NULL; - tM32F pM32F = NULL; - tM32N pM32N = NULL; - - HANDLE hSnap; - MODULEENTRY32 me; - me.dwSize = sizeof(me); - BOOL keepGoing; - size_t i; - - for (i = 0; i < (sizeof(dllname) / sizeof(dllname[0])); i++) - { - hToolhelp = LoadLibrary(dllname[i]); - if (hToolhelp == NULL) - continue; - pCT32S = (tCT32S)GetProcAddress(hToolhelp, "CreateToolhelp32Snapshot"); - pM32F = (tM32F)GetProcAddress(hToolhelp, "Module32First"); - pM32N = (tM32N)GetProcAddress(hToolhelp, "Module32Next"); - if ((pCT32S != NULL) && (pM32F != NULL) && (pM32N != NULL)) - break; // found the functions! - FreeLibrary(hToolhelp); - hToolhelp = NULL; - } - - if (hToolhelp == NULL) - return FALSE; - - hSnap = pCT32S(TH32CS_SNAPMODULE, pid); - if (hSnap == (HANDLE)-1) - { - FreeLibrary(hToolhelp); - return FALSE; - } - - keepGoing = !!pM32F(hSnap, &me); - int cnt = 0; - while (keepGoing) - { - this->LoadModule(hProcess, me.szExePath, me.szModule, (DWORD64)me.modBaseAddr, - me.modBaseSize); - cnt++; - keepGoing = !!pM32N(hSnap, &me); - } - CloseHandle(hSnap); - FreeLibrary(hToolhelp); - if (cnt <= 0) - return FALSE; - return TRUE; - } // GetModuleListTH32 - - // **************************************** PSAPI ************************ - typedef struct _MODULEINFO - { - LPVOID lpBaseOfDll; - DWORD SizeOfImage; - LPVOID EntryPoint; - } MODULEINFO, *LPMODULEINFO; - - BOOL GetModuleListPSAPI(HANDLE hProcess) - { - // EnumProcessModules() - typedef BOOL(__stdcall * tEPM)(HANDLE hProcess, HMODULE * lphModule, DWORD cb, - LPDWORD lpcbNeeded); - // GetModuleFileNameEx() - typedef DWORD(__stdcall * tGMFNE)(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, - DWORD nSize); - // GetModuleBaseName() - typedef DWORD(__stdcall * tGMBN)(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, - DWORD nSize); - // GetModuleInformation() - typedef BOOL(__stdcall * tGMI)(HANDLE hProcess, HMODULE hModule, LPMODULEINFO pmi, DWORD nSize); - - HINSTANCE hPsapi; - tEPM pEPM; - tGMFNE pGMFNE; - tGMBN pGMBN; - tGMI pGMI; - - DWORD i; - //ModuleEntry e; - DWORD cbNeeded; - MODULEINFO mi; - HMODULE* hMods = NULL; - char* tt = NULL; - char* tt2 = NULL; - const SIZE_T TTBUFLEN = 8096; - int cnt = 0; - - hPsapi = LoadLibrary(_T("psapi.dll")); - if (hPsapi == NULL) - return FALSE; - - pEPM = (tEPM)GetProcAddress(hPsapi, "EnumProcessModules"); - pGMFNE = (tGMFNE)GetProcAddress(hPsapi, "GetModuleFileNameExA"); - pGMBN = (tGMFNE)GetProcAddress(hPsapi, "GetModuleBaseNameA"); - pGMI = (tGMI)GetProcAddress(hPsapi, "GetModuleInformation"); - if ((pEPM == NULL) || (pGMFNE == NULL) || (pGMBN == NULL) || (pGMI == NULL)) - { - // we couldn't find all functions - FreeLibrary(hPsapi); - return FALSE; - } - - hMods = (HMODULE*)malloc(sizeof(HMODULE) * (TTBUFLEN / sizeof(HMODULE))); - tt = (char*)malloc(sizeof(char) * TTBUFLEN); - tt2 = (char*)malloc(sizeof(char) * TTBUFLEN); - if ((hMods == NULL) || (tt == NULL) || (tt2 == NULL)) - goto cleanup; - - if (!pEPM(hProcess, hMods, TTBUFLEN, &cbNeeded)) - { - //_ftprintf(fLogFile, _T("%lu: EPM failed, GetLastError = %lu\n"), g_dwShowCount, gle ); - goto cleanup; - } - - if (cbNeeded > TTBUFLEN) - { - //_ftprintf(fLogFile, _T("%lu: More than %lu module handles. Huh?\n"), g_dwShowCount, lenof( hMods ) ); - goto cleanup; - } - - for (i = 0; i < cbNeeded / sizeof(hMods[0]); i++) - { - // base address, size - pGMI(hProcess, hMods[i], &mi, sizeof(mi)); - // image file name - tt[0] = 0; - pGMFNE(hProcess, hMods[i], tt, TTBUFLEN); - // module name - tt2[0] = 0; - pGMBN(hProcess, hMods[i], tt2, TTBUFLEN); - - DWORD dwRes = this->LoadModule(hProcess, tt, tt2, (DWORD64)mi.lpBaseOfDll, mi.SizeOfImage); - if (dwRes != ERROR_SUCCESS) - this->m_parent->OnDbgHelpErr("LoadModule", dwRes, 0); - cnt++; - } - - cleanup: - if (hPsapi != NULL) - FreeLibrary(hPsapi); - if (tt2 != NULL) - free(tt2); - if (tt != NULL) - free(tt); - if (hMods != NULL) - free(hMods); - - return cnt != 0; - } // GetModuleListPSAPI - - DWORD LoadModule(HANDLE hProcess, LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size) - { - CHAR* szImg = _strdup(img); - CHAR* szMod = _strdup(mod); - DWORD result = ERROR_SUCCESS; - if ((szImg == NULL) || (szMod == NULL)) - result = ERROR_NOT_ENOUGH_MEMORY; - else - { - if (pSLM(hProcess, 0, szImg, szMod, baseAddr, size) == 0) - result = GetLastError(); - } - ULONGLONG fileVersion = 0; - if ((m_parent != NULL) && (szImg != NULL)) - { - // try to retrieve the file-version: - if ((this->m_parent->m_options & StackWalker::RetrieveFileVersion) != 0) - { - VS_FIXEDFILEINFO* fInfo = NULL; - DWORD dwHandle; - DWORD dwSize = GetFileVersionInfoSizeA(szImg, &dwHandle); - if (dwSize > 0) - { - LPVOID vData = malloc(dwSize); - if (vData != NULL) - { - if (GetFileVersionInfoA(szImg, dwHandle, dwSize, vData) != 0) - { - UINT len; - TCHAR szSubBlock[] = _T("\\"); - if (VerQueryValue(vData, szSubBlock, (LPVOID*)&fInfo, &len) == 0) - fInfo = NULL; - else - { - fileVersion = - ((ULONGLONG)fInfo->dwFileVersionLS) + ((ULONGLONG)fInfo->dwFileVersionMS << 32); - } - } - free(vData); - } - } - } - - // Retrieve some additional-infos about the module - IMAGEHLP_MODULE64_V3 Module; - const char* szSymType = "-unknown-"; - if (this->GetModuleInfo(hProcess, baseAddr, &Module) != FALSE) - { - switch (Module.SymType) - { - case SymNone: - szSymType = "-nosymbols-"; - break; - case SymCoff: // 1 - szSymType = "COFF"; - break; - case SymCv: // 2 - szSymType = "CV"; - break; - case SymPdb: // 3 - szSymType = "PDB"; - break; - case SymExport: // 4 - szSymType = "-exported-"; - break; - case SymDeferred: // 5 - szSymType = "-deferred-"; - break; - case SymSym: // 6 - szSymType = "SYM"; - break; - case 7: // SymDia: - szSymType = "DIA"; - break; - case 8: //SymVirtual: - szSymType = "Virtual"; - break; - } - } - LPCSTR pdbName = Module.LoadedImageName; - if (Module.LoadedPdbName[0] != 0) - pdbName = Module.LoadedPdbName; - this->m_parent->OnLoadModule(img, mod, baseAddr, size, result, szSymType, pdbName, - fileVersion); - } - if (szImg != NULL) - free(szImg); - if (szMod != NULL) - free(szMod); - return result; - } - -public: - BOOL LoadModules(HANDLE hProcess, DWORD dwProcessId) - { - // first try toolhelp32 - if (GetModuleListTH32(hProcess, dwProcessId)) - return true; - // then try psapi - return GetModuleListPSAPI(hProcess); - } - - BOOL GetModuleInfo(HANDLE hProcess, DWORD64 baseAddr, IMAGEHLP_MODULE64_V3* pModuleInfo) - { - memset(pModuleInfo, 0, sizeof(IMAGEHLP_MODULE64_V3)); - if (this->pSGMI == NULL) - { - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - // First try to use the larger ModuleInfo-Structure - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V3); - void* pData = malloc( - 4096); // reserve enough memory, so the bug in v6.3.5.1 does not lead to memory-overwrites... - if (pData == NULL) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V3)); - static bool s_useV3Version = true; - if (s_useV3Version) - { - if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3*)pData) != FALSE) - { - // only copy as much memory as is reserved... - memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V3)); - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V3); - free(pData); - return TRUE; - } - s_useV3Version = false; // to prevent unnecessary calls with the larger struct... - } - - // could not retrieve the bigger structure, try with the smaller one (as defined in VC7.1)... - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2); - memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V2)); - if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3*)pData) != FALSE) - { - // only copy as much memory as is reserved... - memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V2)); - pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2); - free(pData); - return TRUE; - } - free(pData); - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } -}; - -// ############################################################# - -#if defined(_MSC_VER) && _MSC_VER >= 1400 && _MSC_VER < 1900 -extern "C" void* __cdecl _getptd(); -#endif -#if defined(_MSC_VER) && _MSC_VER >= 1900 -extern "C" void** __cdecl __current_exception_context(); -#endif - -static PCONTEXT get_current_exception_context() -{ - PCONTEXT * pctx = NULL; -#if defined(_MSC_VER) && _MSC_VER >= 1400 && _MSC_VER < 1900 - LPSTR ptd = (LPSTR)_getptd(); - if (ptd) - pctx = (PCONTEXT *)(ptd + (sizeof(void*) == 4 ? 0x8C : 0xF8)); -#endif -#if defined(_MSC_VER) && _MSC_VER >= 1900 - pctx = (PCONTEXT *)__current_exception_context(); -#endif - return pctx ? *pctx : NULL; -} - -bool StackWalker::Init(ExceptType extype, int options, LPCSTR szSymPath, DWORD dwProcessId, - HANDLE hProcess, PEXCEPTION_POINTERS exp) -{ - PCONTEXT ctx = NULL; - if (extype == AfterCatch) - ctx = get_current_exception_context(); - if (extype == AfterExcept && exp) - ctx = exp->ContextRecord; - this->m_options = options; - this->m_modulesLoaded = FALSE; - this->m_szSymPath = NULL; - this->m_MaxRecursionCount = 1000; - this->m_sw = NULL; - SetTargetProcess(dwProcessId, hProcess); - SetSymPath(szSymPath); - /* MSVC ignore std::nothrow specifier for `new` operator */ - LPVOID buf = malloc(sizeof(StackWalkerInternal)); - if (!buf) - return false; - memset(buf, 0, sizeof(StackWalkerInternal)); - this->m_sw = new(buf) StackWalkerInternal(this, this->m_hProcess, ctx); // placement new - return true; -} - -StackWalker::StackWalker(DWORD dwProcessId, HANDLE hProcess) -{ - Init(NonExcept, OptionsAll, NULL, dwProcessId, hProcess); -} - -StackWalker::StackWalker(int options, LPCSTR szSymPath, DWORD dwProcessId, HANDLE hProcess) -{ - Init(NonExcept, options, szSymPath, dwProcessId, hProcess); -} - -StackWalker::StackWalker(ExceptType extype, int options, PEXCEPTION_POINTERS exp) -{ - Init(extype, options, NULL, GetCurrentProcessId(), GetCurrentProcess(), exp); -} - -StackWalker::~StackWalker() -{ - SetSymPath(NULL); - if (m_sw != NULL) { - m_sw->~StackWalkerInternal(); // call the object's destructor - free(m_sw); - } - m_sw = NULL; -} - -bool StackWalker::SetSymPath(LPCSTR szSymPath) -{ - if (m_szSymPath) - free(m_szSymPath); - m_szSymPath = NULL; - if (szSymPath == NULL) - return true; - m_szSymPath = _strdup(szSymPath); - if (m_szSymPath) - m_options |= SymBuildPath; - return true; -} - -bool StackWalker::SetTargetProcess(DWORD dwProcessId, HANDLE hProcess) -{ - m_dwProcessId = dwProcessId; - m_hProcess = hProcess; - if (m_sw) - m_sw->m_hProcess = hProcess; - return true; -} - -PCONTEXT StackWalker::GetCurrentExceptionContext() -{ - return get_current_exception_context(); -} - -BOOL StackWalker::LoadModules() -{ - if (this->m_sw == NULL) - { - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - if (m_modulesLoaded != FALSE) - return TRUE; - - // Build the sym-path: - char* szSymPath = NULL; - if ((this->m_options & SymBuildPath) != 0) - { - const size_t nSymPathLen = 4096; - szSymPath = (char*)malloc(nSymPathLen); - if (szSymPath == NULL) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return FALSE; - } - szSymPath[0] = 0; - // Now first add the (optional) provided sympath: - if (this->m_szSymPath != NULL) - { - strcat_s(szSymPath, nSymPathLen, this->m_szSymPath); - strcat_s(szSymPath, nSymPathLen, ";"); - } - - strcat_s(szSymPath, nSymPathLen, ".;"); - - const size_t nTempLen = 1024; - char szTemp[nTempLen]; - // Now add the current directory: - if (GetCurrentDirectoryA(nTempLen, szTemp) > 0) - { - szTemp[nTempLen - 1] = 0; - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - - // Now add the path for the main-module: - if (GetModuleFileNameA(NULL, szTemp, nTempLen) > 0) - { - szTemp[nTempLen - 1] = 0; - for (char* p = (szTemp + strlen(szTemp) - 1); p >= szTemp; --p) - { - // locate the rightmost path separator - if ((*p == '\\') || (*p == '/') || (*p == ':')) - { - *p = 0; - break; - } - } // for (search for path separator...) - if (strlen(szTemp) > 0) - { - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - } - if (GetEnvironmentVariableA("_NT_SYMBOL_PATH", szTemp, nTempLen) > 0) - { - szTemp[nTempLen - 1] = 0; - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - if (GetEnvironmentVariableA("_NT_ALTERNATE_SYMBOL_PATH", szTemp, nTempLen) > 0) - { - szTemp[nTempLen - 1] = 0; - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - if (GetEnvironmentVariableA("SYSTEMROOT", szTemp, nTempLen) > 0) - { - szTemp[nTempLen - 1] = 0; - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - // also add the "system32"-directory: - strcat_s(szTemp, nTempLen, "\\system32"); - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, ";"); - } - - if ((this->m_options & SymUseSymSrv) != 0) - { - if (GetEnvironmentVariableA("SYSTEMDRIVE", szTemp, nTempLen) > 0) - { - szTemp[nTempLen - 1] = 0; - strcat_s(szSymPath, nSymPathLen, "SRV*"); - strcat_s(szSymPath, nSymPathLen, szTemp); - strcat_s(szSymPath, nSymPathLen, "\\websymbols"); - strcat_s(szSymPath, nSymPathLen, "*https://msdl.microsoft.com/download/symbols;"); - } - else - strcat_s(szSymPath, nSymPathLen, - "SRV*c:\\websymbols*https://msdl.microsoft.com/download/symbols;"); - } - } // if SymBuildPath - - // First Init the whole stuff... - BOOL bRet = this->m_sw->Init(szSymPath); - if (szSymPath != NULL) - free(szSymPath); - szSymPath = NULL; - if (bRet == FALSE) - { - this->OnDbgHelpErr("Error while initializing dbghelp.dll", 0, 0); - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - - bRet = this->m_sw->LoadModules(this->m_hProcess, this->m_dwProcessId); - if (bRet != FALSE) - m_modulesLoaded = TRUE; - return bRet; -} - -// The following is used to pass the "userData"-Pointer to the user-provided readMemoryFunction -// This has to be done due to a problem with the "hProcess"-parameter in x64... -// Because this class is in no case multi-threading-enabled (because of the limitations -// of dbghelp.dll) it is "safe" to use a static-variable -static StackWalker::PReadProcessMemoryRoutine s_readMemoryFunction = NULL; -static LPVOID s_readMemoryFunction_UserData = NULL; - -BOOL StackWalker::ShowCallstack(HANDLE hThread, - const CONTEXT* context, - PReadProcessMemoryRoutine readMemoryFunction, - LPVOID pUserData) -{ - CONTEXT c; - CallstackEntry csEntry; - IMAGEHLP_SYMBOL64* pSym = NULL; - StackWalkerInternal::IMAGEHLP_MODULE64_V3 Module; - IMAGEHLP_LINE64 Line; - int frameNum; - bool bLastEntryCalled = true; - int curRecursionCount = 0; - - if (m_modulesLoaded == FALSE) - this->LoadModules(); // ignore the result... - - if (this->m_sw->m_hDbhHelp == NULL) - { - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - - s_readMemoryFunction = readMemoryFunction; - s_readMemoryFunction_UserData = pUserData; - - if (context == NULL) - { - // If no context is provided, capture the context - // See: https://stackwalker.codeplex.com/discussions/446958 -#if _WIN32_WINNT <= 0x0501 - // If we need to support XP, we need to use the "old way", because "GetThreadId" is not available! - if (hThread == GetCurrentThread()) -#else - if (GetThreadId(hThread) == GetCurrentThreadId()) -#endif - { - if (m_sw->m_ctx.ContextFlags != 0) - c = m_sw->m_ctx; // context taken at Init - else - GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, USED_CONTEXT_FLAGS); - } - else - { - SuspendThread(hThread); - memset(&c, 0, sizeof(CONTEXT)); - c.ContextFlags = USED_CONTEXT_FLAGS; - - // TODO: Detect if you want to get a thread context of a different process, which is running a different processor architecture... - // This does only work if we are x64 and the target process is x64 or x86; - // It cannot work, if this process is x64 and the target process is x64... this is not supported... - // See also: http://www.howzatt.demon.co.uk/articles/DebuggingInWin64.html - if (GetThreadContext(hThread, &c) == FALSE) - { - ResumeThread(hThread); - return FALSE; - } - } - } - else - c = *context; - - // init STACKFRAME for first call - STACKFRAME64 s; // in/out stackframe - memset(&s, 0, sizeof(s)); - DWORD imageType; -#ifdef _M_IX86 - // normally, call ImageNtHeader() and use machine info from PE header - imageType = IMAGE_FILE_MACHINE_I386; - s.AddrPC.Offset = c.Eip; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Ebp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Esp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_X64 - imageType = IMAGE_FILE_MACHINE_AMD64; - s.AddrPC.Offset = c.Rip; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Rsp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Rsp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_IA64 - imageType = IMAGE_FILE_MACHINE_IA64; - s.AddrPC.Offset = c.StIIP; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.IntSp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrBStore.Offset = c.RsBSP; - s.AddrBStore.Mode = AddrModeFlat; - s.AddrStack.Offset = c.IntSp; - s.AddrStack.Mode = AddrModeFlat; -#elif _M_ARM64 - imageType = IMAGE_FILE_MACHINE_ARM64; - s.AddrPC.Offset = c.Pc; - s.AddrPC.Mode = AddrModeFlat; - s.AddrFrame.Offset = c.Fp; - s.AddrFrame.Mode = AddrModeFlat; - s.AddrStack.Offset = c.Sp; - s.AddrStack.Mode = AddrModeFlat; -#else -#error "Platform not supported!" -#endif - - pSym = (IMAGEHLP_SYMBOL64*)malloc(sizeof(IMAGEHLP_SYMBOL64) + STACKWALK_MAX_NAMELEN); - if (!pSym) - goto cleanup; // not enough memory... - memset(pSym, 0, sizeof(IMAGEHLP_SYMBOL64) + STACKWALK_MAX_NAMELEN); - pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); - pSym->MaxNameLength = STACKWALK_MAX_NAMELEN; - - memset(&Line, 0, sizeof(Line)); - Line.SizeOfStruct = sizeof(Line); - - memset(&Module, 0, sizeof(Module)); - Module.SizeOfStruct = sizeof(Module); - - for (frameNum = 0;; ++frameNum) - { - // get next stack frame (StackWalk64(), SymFunctionTableAccess64(), SymGetModuleBase64()) - // if this returns ERROR_INVALID_ADDRESS (487) or ERROR_NOACCESS (998), you can - // assume that either you are done, or that the stack is so hosed that the next - // deeper frame could not be found. - // CONTEXT need not to be supplied if imageTyp is IMAGE_FILE_MACHINE_I386! - if (!this->m_sw->pSW(imageType, this->m_hProcess, hThread, &s, &c, myReadProcMem, - this->m_sw->pSFTA, this->m_sw->pSGMB, NULL)) - { - // INFO: "StackWalk64" does not set "GetLastError"... - this->OnDbgHelpErr("StackWalk64", 0, s.AddrPC.Offset); - break; - } - - csEntry.offset = s.AddrPC.Offset; - csEntry.name[0] = 0; - csEntry.undName[0] = 0; - csEntry.undFullName[0] = 0; - csEntry.offsetFromSmybol = 0; - csEntry.offsetFromLine = 0; - csEntry.lineFileName[0] = 0; - csEntry.lineNumber = 0; - csEntry.loadedImageName[0] = 0; - csEntry.moduleName[0] = 0; - if (s.AddrPC.Offset == s.AddrReturn.Offset) - { - if ((this->m_MaxRecursionCount > 0) && (curRecursionCount > m_MaxRecursionCount)) - { - this->OnDbgHelpErr("StackWalk64-Endless-Callstack!", 0, s.AddrPC.Offset); - break; - } - curRecursionCount++; - } - else - curRecursionCount = 0; - if (s.AddrPC.Offset != 0) - { - // we seem to have a valid PC - // show procedure info (SymGetSymFromAddr64()) - if (this->m_sw->pSGSFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromSmybol), - pSym) != FALSE) - { - MyStrCpy(csEntry.name, STACKWALK_MAX_NAMELEN, pSym->Name); - // UnDecorateSymbolName() - this->m_sw->pUDSN(pSym->Name, csEntry.undName, STACKWALK_MAX_NAMELEN, UNDNAME_NAME_ONLY); - this->m_sw->pUDSN(pSym->Name, csEntry.undFullName, STACKWALK_MAX_NAMELEN, UNDNAME_COMPLETE); - } - else - { - this->OnDbgHelpErr("SymGetSymFromAddr64", GetLastError(), s.AddrPC.Offset); - } - - // show line number info, NT5.0-method (SymGetLineFromAddr64()) - if (this->m_sw->pSGLFA != NULL) - { // yes, we have SymGetLineFromAddr64() - if (this->m_sw->pSGLFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromLine), - &Line) != FALSE) - { - csEntry.lineNumber = Line.LineNumber; - MyStrCpy(csEntry.lineFileName, STACKWALK_MAX_NAMELEN, Line.FileName); - } - else - { - this->OnDbgHelpErr("SymGetLineFromAddr64", GetLastError(), s.AddrPC.Offset); - } - } // yes, we have SymGetLineFromAddr64() - - // show module info (SymGetModuleInfo64()) - if (this->m_sw->GetModuleInfo(this->m_hProcess, s.AddrPC.Offset, &Module) != FALSE) - { // got module info OK - switch (Module.SymType) - { - case SymNone: - csEntry.symTypeString = "-nosymbols-"; - break; - case SymCoff: - csEntry.symTypeString = "COFF"; - break; - case SymCv: - csEntry.symTypeString = "CV"; - break; - case SymPdb: - csEntry.symTypeString = "PDB"; - break; - case SymExport: - csEntry.symTypeString = "-exported-"; - break; - case SymDeferred: - csEntry.symTypeString = "-deferred-"; - break; - case SymSym: - csEntry.symTypeString = "SYM"; - break; -#if API_VERSION_NUMBER >= 9 - case SymDia: - csEntry.symTypeString = "DIA"; - break; -#endif - case 8: //SymVirtual: - csEntry.symTypeString = "Virtual"; - break; - default: - //_snprintf( ty, sizeof(ty), "symtype=%ld", (long) Module.SymType ); - csEntry.symTypeString = NULL; - break; - } - - MyStrCpy(csEntry.moduleName, STACKWALK_MAX_NAMELEN, Module.ModuleName); - csEntry.baseOfImage = Module.BaseOfImage; - MyStrCpy(csEntry.loadedImageName, STACKWALK_MAX_NAMELEN, Module.LoadedImageName); - } // got module info OK - else - { - this->OnDbgHelpErr("SymGetModuleInfo64", GetLastError(), s.AddrPC.Offset); - } - } // we seem to have a valid PC - - CallstackEntryType et = nextEntry; - if (frameNum == 0) - et = firstEntry; - bLastEntryCalled = false; - this->OnCallstackEntry(et, csEntry); - - if (s.AddrReturn.Offset == 0) - { - bLastEntryCalled = true; - this->OnCallstackEntry(lastEntry, csEntry); - SetLastError(ERROR_SUCCESS); - break; - } - } // for ( frameNum ) - -cleanup: - if (pSym) - free(pSym); - - if (bLastEntryCalled == false) - this->OnCallstackEntry(lastEntry, csEntry); - - if (context == NULL) - ResumeThread(hThread); - - return TRUE; -} - -BOOL StackWalker::ShowObject(LPVOID pObject) -{ - // Load modules if not done yet - if (m_modulesLoaded == FALSE) - this->LoadModules(); // ignore the result... - - // Verify that the DebugHelp.dll was actually found - if (this->m_sw->m_hDbhHelp == NULL) - { - SetLastError(ERROR_DLL_INIT_FAILED); - return FALSE; - } - - // SymGetSymFromAddr64() is required - if (this->m_sw->pSGSFA == NULL) - return FALSE; - - // Show object info (SymGetSymFromAddr64()) - DWORD64 dwAddress = DWORD64(pObject); - DWORD64 dwDisplacement = 0; - const SIZE_T symSize = sizeof(IMAGEHLP_SYMBOL64) + STACKWALK_MAX_NAMELEN; - IMAGEHLP_SYMBOL64* pSym = (IMAGEHLP_SYMBOL64*) malloc(symSize); - if (!pSym) - return FALSE; - memset(pSym, 0, symSize); - pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL64); - pSym->MaxNameLength = STACKWALK_MAX_NAMELEN; - if (this->m_sw->pSGSFA(this->m_hProcess, dwAddress, &dwDisplacement, pSym) == FALSE) - { - this->OnDbgHelpErr("SymGetSymFromAddr64", GetLastError(), dwAddress); - return FALSE; - } - // Object name output - this->OnOutput(pSym->Name); - - free(pSym); - return TRUE; -}; - -BOOL __stdcall StackWalker::myReadProcMem(HANDLE hProcess, - DWORD64 qwBaseAddress, - PVOID lpBuffer, - DWORD nSize, - LPDWORD lpNumberOfBytesRead) -{ - if (s_readMemoryFunction == NULL) - { - SIZE_T st; - BOOL bRet = ReadProcessMemory(hProcess, (LPVOID)qwBaseAddress, lpBuffer, nSize, &st); - *lpNumberOfBytesRead = (DWORD)st; - //printf("ReadMemory: hProcess: %p, baseAddr: %p, buffer: %p, size: %d, read: %d, result: %d\n", hProcess, (LPVOID) qwBaseAddress, lpBuffer, nSize, (DWORD) st, (DWORD) bRet); - return bRet; - } - else - { - return s_readMemoryFunction(hProcess, qwBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead, - s_readMemoryFunction_UserData); - } -} - -void StackWalker::OnLoadModule(LPCSTR img, - LPCSTR mod, - DWORD64 baseAddr, - DWORD size, - DWORD result, - LPCSTR symType, - LPCSTR pdbName, - ULONGLONG fileVersion) -{ - CHAR buffer[STACKWALK_MAX_NAMELEN]; - size_t maxLen = STACKWALK_MAX_NAMELEN; -#if _MSC_VER >= 1400 - maxLen = _TRUNCATE; -#endif - if (fileVersion == 0) - _snprintf_s(buffer, maxLen, "%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s'\n", - img, mod, (LPVOID)baseAddr, size, result, symType, pdbName); - else - { - DWORD v4 = (DWORD)(fileVersion & 0xFFFF); - DWORD v3 = (DWORD)((fileVersion >> 16) & 0xFFFF); - DWORD v2 = (DWORD)((fileVersion >> 32) & 0xFFFF); - DWORD v1 = (DWORD)((fileVersion >> 48) & 0xFFFF); - _snprintf_s( - buffer, maxLen, - "%s:%s (%p), size: %d (result: %d), SymType: '%s', PDB: '%s', fileVersion: %d.%d.%d.%d\n", - img, mod, (LPVOID)baseAddr, size, result, symType, pdbName, v1, v2, v3, v4); - } - buffer[STACKWALK_MAX_NAMELEN - 1] = 0; // be sure it is NULL terminated - OnOutput(buffer); -} - -void StackWalker::OnCallstackEntry(CallstackEntryType eType, CallstackEntry& entry) -{ - CHAR buffer[STACKWALK_MAX_NAMELEN]; - size_t maxLen = STACKWALK_MAX_NAMELEN; -#if _MSC_VER >= 1400 - maxLen = _TRUNCATE; -#endif - if ((eType != lastEntry) && (entry.offset != 0)) - { - if (entry.name[0] == 0) - MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, "(function-name not available)"); - if (entry.undName[0] != 0) - MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, entry.undName); - if (entry.undFullName[0] != 0) - MyStrCpy(entry.name, STACKWALK_MAX_NAMELEN, entry.undFullName); - if (entry.lineFileName[0] == 0) - { - MyStrCpy(entry.lineFileName, STACKWALK_MAX_NAMELEN, "(filename not available)"); - if (entry.moduleName[0] == 0) - MyStrCpy(entry.moduleName, STACKWALK_MAX_NAMELEN, "(module-name not available)"); - _snprintf_s(buffer, maxLen, "%p (%s): %s: %s\n", (LPVOID)entry.offset, entry.moduleName, - entry.lineFileName, entry.name); - } - else - _snprintf_s(buffer, maxLen, "%s (%d): %s\n", entry.lineFileName, entry.lineNumber, - entry.name); - buffer[STACKWALK_MAX_NAMELEN - 1] = 0; - OnOutput(buffer); - } -} - -void StackWalker::OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr) -{ - CHAR buffer[STACKWALK_MAX_NAMELEN]; - size_t maxLen = STACKWALK_MAX_NAMELEN; -#if _MSC_VER >= 1400 - maxLen = _TRUNCATE; -#endif - _snprintf_s(buffer, maxLen, "ERROR: %s, GetLastError: %d (Address: %p)\n", szFuncName, gle, - (LPVOID)addr); - buffer[STACKWALK_MAX_NAMELEN - 1] = 0; - OnOutput(buffer); -} - -void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName) -{ - CHAR buffer[STACKWALK_MAX_NAMELEN]; - size_t maxLen = STACKWALK_MAX_NAMELEN; -#if _MSC_VER >= 1400 - maxLen = _TRUNCATE; -#endif - _snprintf_s(buffer, maxLen, "SymInit: Symbol-SearchPath: '%s', symOptions: %d, UserName: '%s'\n", - szSearchPath, symOptions, szUserName); - buffer[STACKWALK_MAX_NAMELEN - 1] = 0; - OnOutput(buffer); - // Also display the OS-version -#if _MSC_VER <= 1200 - OSVERSIONINFOA ver; - ZeroMemory(&ver, sizeof(OSVERSIONINFOA)); - ver.dwOSVersionInfoSize = sizeof(ver); - if (GetVersionExA(&ver) != FALSE) - { - _snprintf_s(buffer, maxLen, "OS-Version: %d.%d.%d (%s)\n", ver.dwMajorVersion, - ver.dwMinorVersion, ver.dwBuildNumber, ver.szCSDVersion); - buffer[STACKWALK_MAX_NAMELEN - 1] = 0; - OnOutput(buffer); - } -#else - OSVERSIONINFOEXA ver; - ZeroMemory(&ver, sizeof(OSVERSIONINFOEXA)); - ver.dwOSVersionInfoSize = sizeof(ver); -#if _MSC_VER >= 1900 -#pragma warning(push) -#pragma warning(disable : 4996) -#endif - if (GetVersionExA((OSVERSIONINFOA*)&ver) != FALSE) - { - _snprintf_s(buffer, maxLen, "OS-Version: %d.%d.%d (%s) 0x%x-0x%x\n", ver.dwMajorVersion, - ver.dwMinorVersion, ver.dwBuildNumber, ver.szCSDVersion, ver.wSuiteMask, - ver.wProductType); - buffer[STACKWALK_MAX_NAMELEN - 1] = 0; - OnOutput(buffer); - } -#if _MSC_VER >= 1900 -#pragma warning(pop) -#endif -#endif -} - -void StackWalker::OnOutput(LPCSTR buffer) -{ - OutputDebugStringA(buffer); -} diff --git a/wpiutil/src/main/native/windows/StackWalker.h b/wpiutil/src/main/native/windows/StackWalker.h deleted file mode 100644 index 5ab241ec13..0000000000 --- a/wpiutil/src/main/native/windows/StackWalker.h +++ /dev/null @@ -1,273 +0,0 @@ -#ifndef __STACKWALKER_H__ -#define __STACKWALKER_H__ - -#if defined(_MSC_VER) - -/********************************************************************** - * - * StackWalker.h - * - * - * - * LICENSE (http://www.opensource.org/licenses/bsd-license.php) - * - * Copyright (c) 2005-2009, Jochen Kalmbach - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of Jochen Kalmbach nor the names of its contributors may be - * used to endorse or promote products derived from this software without - * specific prior written permission. - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * **********************************************************************/ -// #pragma once is supported starting with _MSC_VER 1000, -// so we need not to check the version (because we only support _MSC_VER >= 1100)! -#pragma once - -#include - -// special defines for VC5/6 (if no actual PSDK is installed): -#if _MSC_VER < 1300 -typedef unsigned __int64 DWORD64, *PDWORD64; -#if defined(_WIN64) -typedef unsigned __int64 SIZE_T, *PSIZE_T; -#else -typedef unsigned long SIZE_T, *PSIZE_T; -#endif -#endif // _MSC_VER < 1300 - -class StackWalkerInternal; // forward -class StackWalker -{ -public: - typedef enum ExceptType - { - NonExcept = 0, // RtlCaptureContext - AfterExcept = 1, - AfterCatch = 2, // get_current_exception_context - } ExceptType; - - typedef enum StackWalkOptions - { - // No addition info will be retrieved - // (only the address is available) - RetrieveNone = 0, - - // Try to get the symbol-name - RetrieveSymbol = 1, - - // Try to get the line for this symbol - RetrieveLine = 2, - - // Try to retrieve the module-infos - RetrieveModuleInfo = 4, - - // Also retrieve the version for the DLL/EXE - RetrieveFileVersion = 8, - - // Contains all the above - RetrieveVerbose = 0xF, - - // Generate a "good" symbol-search-path - SymBuildPath = 0x10, - - // Also use the public Microsoft-Symbol-Server - SymUseSymSrv = 0x20, - - // Contains all the above "Sym"-options - SymAll = 0x30, - - // Contains all options (default) - OptionsAll = 0x3F - } StackWalkOptions; - - StackWalker(ExceptType extype, int options = OptionsAll, PEXCEPTION_POINTERS exp = NULL); - - StackWalker(int options = OptionsAll, // 'int' is by design, to combine the enum-flags - LPCSTR szSymPath = NULL, - DWORD dwProcessId = GetCurrentProcessId(), - HANDLE hProcess = GetCurrentProcess()); - - StackWalker(DWORD dwProcessId, HANDLE hProcess); - - virtual ~StackWalker(); - - bool SetSymPath(LPCSTR szSymPath); - - bool SetTargetProcess(DWORD dwProcessId, HANDLE hProcess); - - PCONTEXT GetCurrentExceptionContext(); - -private: - bool Init(ExceptType extype, int options, LPCSTR szSymPath, DWORD dwProcessId, - HANDLE hProcess, PEXCEPTION_POINTERS exp = NULL); - -public: - typedef BOOL(__stdcall* PReadProcessMemoryRoutine)( - HANDLE hProcess, - DWORD64 qwBaseAddress, - PVOID lpBuffer, - DWORD nSize, - LPDWORD lpNumberOfBytesRead, - LPVOID pUserData // optional data, which was passed in "ShowCallstack" - ); - - BOOL LoadModules(); - - BOOL ShowCallstack( - HANDLE hThread = GetCurrentThread(), - const CONTEXT* context = NULL, - PReadProcessMemoryRoutine readMemoryFunction = NULL, - LPVOID pUserData = NULL // optional to identify some data in the 'readMemoryFunction'-callback - ); - - BOOL ShowObject(LPVOID pObject); - -#if _MSC_VER >= 1300 - // due to some reasons, the "STACKWALK_MAX_NAMELEN" must be declared as "public" - // in older compilers in order to use it... starting with VC7 we can declare it as "protected" -protected: -#endif - enum - { - STACKWALK_MAX_NAMELEN = 1024 - }; // max name length for found symbols - -protected: - // Entry for each Callstack-Entry - typedef struct CallstackEntry - { - DWORD64 offset; // if 0, we have no valid entry - CHAR name[STACKWALK_MAX_NAMELEN]; - CHAR undName[STACKWALK_MAX_NAMELEN]; - CHAR undFullName[STACKWALK_MAX_NAMELEN]; - DWORD64 offsetFromSmybol; - DWORD offsetFromLine; - DWORD lineNumber; - CHAR lineFileName[STACKWALK_MAX_NAMELEN]; - DWORD symType; - LPCSTR symTypeString; - CHAR moduleName[STACKWALK_MAX_NAMELEN]; - DWORD64 baseOfImage; - CHAR loadedImageName[STACKWALK_MAX_NAMELEN]; - } CallstackEntry; - - typedef enum CallstackEntryType - { - firstEntry, - nextEntry, - lastEntry - } CallstackEntryType; - - virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName); - virtual void OnLoadModule(LPCSTR img, - LPCSTR mod, - DWORD64 baseAddr, - DWORD size, - DWORD result, - LPCSTR symType, - LPCSTR pdbName, - ULONGLONG fileVersion); - virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry& entry); - virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr); - virtual void OnOutput(LPCSTR szText); - - StackWalkerInternal* m_sw; - HANDLE m_hProcess; - DWORD m_dwProcessId; - BOOL m_modulesLoaded; - LPSTR m_szSymPath; - - int m_options; - int m_MaxRecursionCount; - - static BOOL __stdcall myReadProcMem(HANDLE hProcess, - DWORD64 qwBaseAddress, - PVOID lpBuffer, - DWORD nSize, - LPDWORD lpNumberOfBytesRead); - - friend StackWalkerInternal; -}; // class StackWalker - -// The "ugly" assembler-implementation is needed for systems before XP -// If you have a new PSDK and you only compile for XP and later, then you can use -// the "RtlCaptureContext" -// Currently there is no define which determines the PSDK-Version... -// So we just use the compiler-version (and assumes that the PSDK is -// the one which was installed by the VS-IDE) - -// INFO: If you want, you can use the RtlCaptureContext if you only target XP and later... -// But I currently use it in x64/IA64 environments... -//#if defined(_M_IX86) && (_WIN32_WINNT <= 0x0500) && (_MSC_VER < 1400) - -#if defined(_M_IX86) -#ifdef CURRENT_THREAD_VIA_EXCEPTION -// TODO: The following is not a "good" implementation, -// because the callstack is only valid in the "__except" block... -#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ - do \ - { \ - memset(&c, 0, sizeof(CONTEXT)); \ - EXCEPTION_POINTERS* pExp = NULL; \ - __try \ - { \ - throw 0; \ - } \ - __except (((pExp = GetExceptionInformation()) ? EXCEPTION_EXECUTE_HANDLER \ - : EXCEPTION_EXECUTE_HANDLER)) \ - { \ - } \ - if (pExp != NULL) \ - memcpy(&c, pExp->ContextRecord, sizeof(CONTEXT)); \ - c.ContextFlags = contextFlags; \ - } while (0); -#else -// clang-format off -// The following should be enough for walking the callstack... -#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ - do \ - { \ - memset(&c, 0, sizeof(CONTEXT)); \ - c.ContextFlags = contextFlags; \ - __asm call x \ - __asm x: pop eax \ - __asm mov c.Eip, eax \ - __asm mov c.Ebp, ebp \ - __asm mov c.Esp, esp \ - } while (0) -// clang-format on -#endif - -#else - -// The following is defined for x86 (XP and higher), x64 and IA64: -#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \ - do \ - { \ - memset(&c, 0, sizeof(CONTEXT)); \ - c.ContextFlags = contextFlags; \ - RtlCaptureContext(&c); \ - } while (0); -#endif - -#endif //defined(_MSC_VER) - -#endif // __STACKWALKER_H__ From 23658a8c6263aa7ebb99f4fc15e5a1025cfcc427 Mon Sep 17 00:00:00 2001 From: Kevin-OConnor Date: Thu, 13 Feb 2025 20:53:11 -0500 Subject: [PATCH 25/33] [apriltag] Split 2025 AprilTag Maps (#7781) Splits maps for welded vs AndyMark field perimeters. More info about why and what fields are at what events will be in TU12. --- .../wpi/first/apriltag/AprilTagFields.java | 8 +- .../main/native/cpp/AprilTagFieldLayout.cpp | 10 +- .../include/frc/apriltag/AprilTagFields.h | 8 +- .../apriltag/2025-reefscape-andymark.csv | 23 + .../apriltag/2025-reefscape-andymark.json | 404 ++++++++++++++++++ ...eefscape.csv => 2025-reefscape-welded.csv} | 0 ...fscape.json => 2025-reefscape-welded.json} | 0 7 files changed, 444 insertions(+), 9 deletions(-) create mode 100644 apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-andymark.csv create mode 100644 apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-andymark.json rename apriltag/src/main/native/resources/edu/wpi/first/apriltag/{2025-reefscape.csv => 2025-reefscape-welded.csv} (100%) rename apriltag/src/main/native/resources/edu/wpi/first/apriltag/{2025-reefscape.json => 2025-reefscape-welded.json} (100%) diff --git a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java index 63a516aa38..2050ed3e08 100644 --- a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java +++ b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java @@ -14,14 +14,16 @@ public enum AprilTagFields { k2023ChargedUp("2023-chargedup.json"), /** 2024 Crescendo. */ k2024Crescendo("2024-crescendo.json"), - /** 2025 Reefscape. */ - k2025Reefscape("2025-reefscape.json"); + /** 2025 Reefscape Welded (see TU 12). */ + k2025ReefscapeWelded("2025-reefscape-welded.json"), + /** 2025 Reefscape AndyMark (see TU 12). */ + k2025ReefscapeAndyMark("2025-reefscape-andymark.json"); /** Base resource directory. */ public static final String kBaseResourceDir = "/edu/wpi/first/apriltag/"; /** Alias to the current game. */ - public static final AprilTagFields kDefaultField = k2025Reefscape; + public static final AprilTagFields kDefaultField = k2025ReefscapeWelded; /** Resource filename. */ public final String m_resourceFile; diff --git a/apriltag/src/main/native/cpp/AprilTagFieldLayout.cpp b/apriltag/src/main/native/cpp/AprilTagFieldLayout.cpp index 04d7a78c60..8388210b25 100644 --- a/apriltag/src/main/native/cpp/AprilTagFieldLayout.cpp +++ b/apriltag/src/main/native/cpp/AprilTagFieldLayout.cpp @@ -133,7 +133,8 @@ namespace frc { std::string_view GetResource_2022_rapidreact_json(); std::string_view GetResource_2023_chargedup_json(); std::string_view GetResource_2024_crescendo_json(); -std::string_view GetResource_2025_reefscape_json(); +std::string_view GetResource_2025_reefscape_welded_json(); +std::string_view GetResource_2025_reefscape_andymark_json(); } // namespace frc @@ -149,8 +150,11 @@ AprilTagFieldLayout AprilTagFieldLayout::LoadField(AprilTagField field) { case AprilTagField::k2024Crescendo: fieldString = GetResource_2024_crescendo_json(); break; - case AprilTagField::k2025Reefscape: - fieldString = GetResource_2025_reefscape_json(); + case AprilTagField::k2025ReefscapeWelded: + fieldString = GetResource_2025_reefscape_welded_json(); + break; + case AprilTagField::k2025ReefscapeAndyMark: + fieldString = GetResource_2025_reefscape_andymark_json(); break; case AprilTagField::kNumFields: throw std::invalid_argument("Invalid Field"); diff --git a/apriltag/src/main/native/include/frc/apriltag/AprilTagFields.h b/apriltag/src/main/native/include/frc/apriltag/AprilTagFields.h index 94ac799c85..2e1f5cc795 100644 --- a/apriltag/src/main/native/include/frc/apriltag/AprilTagFields.h +++ b/apriltag/src/main/native/include/frc/apriltag/AprilTagFields.h @@ -20,10 +20,12 @@ enum class AprilTagField { k2023ChargedUp, /// 2024 Crescendo. k2024Crescendo, - /// 2025 Reefscape. - k2025Reefscape, + /// 2025 Reefscape AndyMark (see TU12). + k2025ReefscapeAndyMark, + /// 2025 Reefscape Welded (see TU12). + k2025ReefscapeWelded, /// Alias to the current game. - kDefaultField = k2025Reefscape, + kDefaultField = k2025ReefscapeWelded, // This is a placeholder for denoting the last supported field. This should // always be the last entry in the enum and should not be used by users diff --git a/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-andymark.csv b/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-andymark.csv new file mode 100644 index 0000000000..76b77f4893 --- /dev/null +++ b/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-andymark.csv @@ -0,0 +1,23 @@ +ID,X,Y,Z,Z-Rotation,X-Rotation +1,656.98,24.73,58.5,126,0 +2,656.98,291.9,58.5,234,0 +3,452.4,316.21,51.25,270,0 +4,365.2,241.44,73.54,0,30 +5,365.2,75.19,73.54,0,30 +6,530.49,129.97,12.13,300,0 +7,546.87,158.3,12.13,0,0 +8,530.49,186.63,12.13,60,0 +9,497.77,186.63,12.13,120,0 +10,481.39,158.3,12.13,180,0 +11,497.77,129.97,12.13,240,0 +12,33.91,24.73,58.5,54,0 +13,33.91,291.9,58.5,306,0 +14,325.68,241.44,73.54,180,30 +15,325.68,75.19,73.54,180,30 +16,238.49,0.42,51.25,90,0 +17,160.39,129.97,12.13,240,0 +18,144,158.3,12.13,180,0 +19,160.39,186.63,12.13,120,0 +20,193.1,186.63,12.13,60,0 +21,209.49,158.3,12.13,0,0 +22,193.1,129.97,12.13,300,0 diff --git a/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-andymark.json b/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-andymark.json new file mode 100644 index 0000000000..60b60e5e74 --- /dev/null +++ b/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-andymark.json @@ -0,0 +1,404 @@ +{ + "tags": [ + { + "ID": 1, + "pose": { + "translation": { + "x": 16.687292, + "y": 0.628142, + "z": 1.4859 + }, + "rotation": { + "quaternion": { + "W": 0.4539904997395468, + "X": 0.0, + "Y": 0.0, + "Z": 0.8910065241883678 + } + } + } + }, + { + "ID": 2, + "pose": { + "translation": { + "x": 16.687292, + "y": 7.414259999999999, + "z": 1.4859 + }, + "rotation": { + "quaternion": { + "W": -0.45399049973954675, + "X": -0.0, + "Y": 0.0, + "Z": 0.8910065241883679 + } + } + } + }, + { + "ID": 3, + "pose": { + "translation": { + "x": 11.49096, + "y": 8.031733999999998, + "z": 1.30175 + }, + "rotation": { + "quaternion": { + "W": -0.7071067811865475, + "X": -0.0, + "Y": 0.0, + "Z": 0.7071067811865476 + } + } + } + }, + { + "ID": 4, + "pose": { + "translation": { + "x": 9.276079999999999, + "y": 6.132575999999999, + "z": 1.8679160000000001 + }, + "rotation": { + "quaternion": { + "W": 0.9659258262890683, + "X": 0.0, + "Y": 0.25881904510252074, + "Z": 0.0 + } + } + } + }, + { + "ID": 5, + "pose": { + "translation": { + "x": 9.276079999999999, + "y": 1.9098259999999998, + "z": 1.8679160000000001 + }, + "rotation": { + "quaternion": { + "W": 0.9659258262890683, + "X": 0.0, + "Y": 0.25881904510252074, + "Z": 0.0 + } + } + } + }, + { + "ID": 6, + "pose": { + "translation": { + "x": 13.474446, + "y": 3.3012379999999997, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": -0.8660254037844387, + "X": -0.0, + "Y": 0.0, + "Z": 0.49999999999999994 + } + } + } + }, + { + "ID": 7, + "pose": { + "translation": { + "x": 13.890498, + "y": 4.0208200000000005, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": 1.0, + "X": 0.0, + "Y": 0.0, + "Z": 0.0 + } + } + } + }, + { + "ID": 8, + "pose": { + "translation": { + "x": 13.474446, + "y": 4.740402, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": 0.8660254037844387, + "X": 0.0, + "Y": 0.0, + "Z": 0.49999999999999994 + } + } + } + }, + { + "ID": 9, + "pose": { + "translation": { + "x": 12.643358, + "y": 4.740402, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": 0.5000000000000001, + "X": 0.0, + "Y": 0.0, + "Z": 0.8660254037844386 + } + } + } + }, + { + "ID": 10, + "pose": { + "translation": { + "x": 12.227305999999999, + "y": 4.0208200000000005, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": 6.123233995736766e-17, + "X": 0.0, + "Y": 0.0, + "Z": 1.0 + } + } + } + }, + { + "ID": 11, + "pose": { + "translation": { + "x": 12.643358, + "y": 3.3012379999999997, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": -0.4999999999999998, + "X": -0.0, + "Y": 0.0, + "Z": 0.8660254037844387 + } + } + } + }, + { + "ID": 12, + "pose": { + "translation": { + "x": 0.8613139999999999, + "y": 0.628142, + "z": 1.4859 + }, + "rotation": { + "quaternion": { + "W": 0.8910065241883679, + "X": 0.0, + "Y": 0.0, + "Z": 0.45399049973954675 + } + } + } + }, + { + "ID": 13, + "pose": { + "translation": { + "x": 0.8613139999999999, + "y": 7.414259999999999, + "z": 1.4859 + }, + "rotation": { + "quaternion": { + "W": -0.8910065241883678, + "X": -0.0, + "Y": 0.0, + "Z": 0.45399049973954686 + } + } + } + }, + { + "ID": 14, + "pose": { + "translation": { + "x": 8.272272, + "y": 6.132575999999999, + "z": 1.8679160000000001 + }, + "rotation": { + "quaternion": { + "W": 5.914589856893349e-17, + "X": -0.25881904510252074, + "Y": 1.5848095757158825e-17, + "Z": 0.9659258262890683 + } + } + } + }, + { + "ID": 15, + "pose": { + "translation": { + "x": 8.272272, + "y": 1.9098259999999998, + "z": 1.8679160000000001 + }, + "rotation": { + "quaternion": { + "W": 5.914589856893349e-17, + "X": -0.25881904510252074, + "Y": 1.5848095757158825e-17, + "Z": 0.9659258262890683 + } + } + } + }, + { + "ID": 16, + "pose": { + "translation": { + "x": 6.057646, + "y": 0.010667999999999999, + "z": 1.30175 + }, + "rotation": { + "quaternion": { + "W": 0.7071067811865476, + "X": 0.0, + "Y": 0.0, + "Z": 0.7071067811865476 + } + } + } + }, + { + "ID": 17, + "pose": { + "translation": { + "x": 4.073905999999999, + "y": 3.3012379999999997, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": -0.4999999999999998, + "X": -0.0, + "Y": 0.0, + "Z": 0.8660254037844387 + } + } + } + }, + { + "ID": 18, + "pose": { + "translation": { + "x": 3.6576, + "y": 4.0208200000000005, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": 6.123233995736766e-17, + "X": 0.0, + "Y": 0.0, + "Z": 1.0 + } + } + } + }, + { + "ID": 19, + "pose": { + "translation": { + "x": 4.073905999999999, + "y": 4.740402, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": 0.5000000000000001, + "X": 0.0, + "Y": 0.0, + "Z": 0.8660254037844386 + } + } + } + }, + { + "ID": 20, + "pose": { + "translation": { + "x": 4.904739999999999, + "y": 4.740402, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": 0.8660254037844387, + "X": 0.0, + "Y": 0.0, + "Z": 0.49999999999999994 + } + } + } + }, + { + "ID": 21, + "pose": { + "translation": { + "x": 5.321046, + "y": 4.0208200000000005, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": 1.0, + "X": 0.0, + "Y": 0.0, + "Z": 0.0 + } + } + } + }, + { + "ID": 22, + "pose": { + "translation": { + "x": 4.904739999999999, + "y": 3.3012379999999997, + "z": 0.308102 + }, + "rotation": { + "quaternion": { + "W": -0.8660254037844387, + "X": -0.0, + "Y": 0.0, + "Z": 0.49999999999999994 + } + } + } + } + ], + "field": { + "length": 17.548, + "width": 8.042 + } +} diff --git a/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape.csv b/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-welded.csv similarity index 100% rename from apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape.csv rename to apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-welded.csv diff --git a/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape.json b/apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-welded.json similarity index 100% rename from apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape.json rename to apriltag/src/main/native/resources/edu/wpi/first/apriltag/2025-reefscape-welded.json From e648b9c86d76a3076cc92d99455861cafb37f8a3 Mon Sep 17 00:00:00 2001 From: Jonah Bonner <47046556+jwbonner@users.noreply.github.com> Date: Thu, 13 Feb 2025 21:10:02 -0500 Subject: [PATCH 26/33] [wpinet] Serve index HTML file from WebServer if available (#7780) --- wpinet/src/main/native/cpp/WebServer.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wpinet/src/main/native/cpp/WebServer.cpp b/wpinet/src/main/native/cpp/WebServer.cpp index 9efd76a190..baa8b9b4b1 100644 --- a/wpinet/src/main/native/cpp/WebServer.cpp +++ b/wpinet/src/main/native/cpp/WebServer.cpp @@ -270,6 +270,7 @@ void MyHttpConnection::ProcessRequest() { } // generate directory listing wpi::SmallString<64> formatBuf; + fs::path indexpath = fs::path{fullpath} / "index.html"; if (qmap.Get("format", formatBuf).value_or("") == "json") { wpi::json dirs = wpi::json::array(); wpi::json files = wpi::json::array(); @@ -288,6 +289,9 @@ void MyHttpConnection::ProcessRequest() { 200, "OK", "text/json", wpi::json{{"dirs", std::move(dirs)}, {"files", std::move(files)}} .dump()); + } else if (fs::exists(indexpath)) { + SendFileResponse(200, "OK", GetMimeType("html"), indexpath, + "Content-Disposition: filename=\"index.html\"\r\n"); } else { wpi::StringMap dirs; wpi::StringMap files; From e22f76ce73bf7bad369c287c53bbbaaaae25f765 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 13 Feb 2025 20:23:07 -0800 Subject: [PATCH 27/33] [build] Bump native-utils to 2025.9.1 (#7783) --- buildSrc/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 8a0ad0c1a9..36829299fb 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -9,5 +9,5 @@ repositories { } } dependencies { - implementation "edu.wpi.first:native-utils:2025.9.0" + implementation "edu.wpi.first:native-utils:2025.9.1" } From 4d126b158cb8056e0d9265d41b18ea9b34b76f01 Mon Sep 17 00:00:00 2001 From: Jade Date: Fri, 14 Feb 2025 13:09:28 +0800 Subject: [PATCH 28/33] [wpimath] Add setters to Feedforward gains (#7784) Signed-off-by: Jade Turner --- .../first/math/controller/ArmFeedforward.java | 44 +++++++++++++++++-- .../math/controller/ElevatorFeedforward.java | 44 +++++++++++++++++-- .../controller/SimpleMotorFeedforward.java | 33 ++++++++++++-- .../include/frc/controller/ArmFeedforward.h | 30 +++++++++++++ .../frc/controller/ElevatorFeedforward.h | 28 ++++++++++++ .../frc/controller/SimpleMotorFeedforward.h | 21 +++++++++ 6 files changed, 189 insertions(+), 11 deletions(-) diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java index d918f07fd8..af30cdbbdf 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java @@ -16,16 +16,16 @@ import edu.wpi.first.util.struct.StructSerializable; */ public class ArmFeedforward implements ProtobufSerializable, StructSerializable { /** The static gain, in volts. */ - private final double ks; + private double ks; /** The gravity gain, in volts. */ - private final double kg; + private double kg; /** The velocity gain, in V/(rad/s). */ - private final double kv; + private double kv; /** The acceleration gain, in V/(rad/s²). */ - private final double ka; + private double ka; /** The period, in seconds. */ private final double m_dt; @@ -95,6 +95,15 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable return ks; } + /** + * Sets the static gain. + * + * @param ks The static gain in volts. + */ + public void setKs(double ks) { + this.ks = ks; + } + /** * Returns the gravity gain in volts. * @@ -104,6 +113,15 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable return kg; } + /** + * Sets the gravity gain. + * + * @param kg The gravity gain in volts. + */ + public void setKg(double kg) { + this.kg = kg; + } + /** * Returns the velocity gain in V/(rad/s). * @@ -113,6 +131,15 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable return kv; } + /** + * Sets the velocity gain. + * + * @param kv The velocity gain in V/(rad/s). + */ + public void setKv(double kv) { + this.kv = kv; + } + /** * Returns the acceleration gain in V/(rad/s²). * @@ -122,6 +149,15 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable return ka; } + /** + * Sets the acceleration gain. + * + * @param ka The acceleration gain in V/(rad/2²). + */ + public void setKa(double ka) { + this.ka = ka; + } + /** * Returns the period in seconds. * diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java index 60060bb610..816d2bb086 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java @@ -15,16 +15,16 @@ import edu.wpi.first.util.struct.StructSerializable; */ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializable { /** The static gain, in volts. */ - private final double ks; + private double ks; /** The gravity gain, in volts. */ - private final double kg; + private double kg; /** The velocity gain, in V/(m/s). */ - private final double kv; + private double kv; /** The acceleration gain, in V/(m/s²). */ - private final double ka; + private double ka; /** The period, in seconds. */ private final double m_dt; @@ -95,6 +95,15 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ return ks; } + /** + * Sets the static gain. + * + * @param ks The static gain in volts. + */ + public void setKs(double ks) { + this.ks = ks; + } + /** * Returns the gravity gain in volts. * @@ -104,6 +113,15 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ return kg; } + /** + * Sets the gravity gain. + * + * @param kg The gravity gain in volts. + */ + public void setKg(double kg) { + this.kg = kg; + } + /** * Returns the velocity gain in V/(m/s). * @@ -113,6 +131,15 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ return kv; } + /** + * Sets the velocity gain. + * + * @param kv The velocity gain in V/(rad/s). + */ + public void setKv(double kv) { + this.kv = kv; + } + /** * Returns the acceleration gain in V/(m/s²). * @@ -122,6 +149,15 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ return ka; } + /** + * Sets the acceleration gain. + * + * @param ka The acceleration gain in V/(rad/2²). + */ + public void setKa(double ka) { + this.ka = ka; + } + /** * Returns the period in seconds. * diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java index b7603a6bfb..73ff6dc342 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java @@ -12,13 +12,13 @@ import edu.wpi.first.util.struct.StructSerializable; /** A helper class that computes feedforward outputs for a simple permanent-magnet DC motor. */ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSerializable { /** The static gain, in volts. */ - private final double ks; + private double ks; /** The velocity gain, in V/(units/s). */ - private final double kv; + private double kv; /** The acceleration gain, in V/(units/s²). */ - private final double ka; + private double ka; /** The period, in seconds. */ private final double m_dt; @@ -92,6 +92,15 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria return ks; } + /** + * Sets the static gain. + * + * @param ks The static gain in volts. + */ + public void setKs(double ks) { + this.ks = ks; + } + /** * Returns the velocity gain in V/(units/s). * @@ -103,6 +112,15 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria return kv; } + /** + * Sets the velocity gain. + * + * @param kv The velocity gain in V/(rad/s). + */ + public void setKv(double kv) { + this.kv = kv; + } + /** * Returns the acceleration gain in V/(units/s²). * @@ -114,6 +132,15 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria return ka; } + /** + * Sets the acceleration gain. + * + * @param ka The acceleration gain in V/(rad/2²). + */ + public void setKa(double ka) { + this.ka = ka; + } + /** * Returns the period in seconds. * diff --git a/wpimath/src/main/native/include/frc/controller/ArmFeedforward.h b/wpimath/src/main/native/include/frc/controller/ArmFeedforward.h index ace4b9c06f..aa524ef936 100644 --- a/wpimath/src/main/native/include/frc/controller/ArmFeedforward.h +++ b/wpimath/src/main/native/include/frc/controller/ArmFeedforward.h @@ -4,6 +4,8 @@ #pragma once +#include + #include #include @@ -249,6 +251,13 @@ class WPILIB_DLLEXPORT ArmFeedforward { */ constexpr units::volt_t GetKs() const { return kS; } + /** + * Returns the static gain. + * + * @param kS The static gain. + */ + constexpr void SetKs(units::volt_t kS) { this->kS = kS; } + /** * Returns the gravity gain. * @@ -256,6 +265,13 @@ class WPILIB_DLLEXPORT ArmFeedforward { */ constexpr units::volt_t GetKg() const { return kG; } + /** + * Returns the gravity gain. + * + * @param kG The gravity gain. + */ + constexpr void SetKg(units::volt_t kG) { this->kG = kG; } + /** * Returns the velocity gain. * @@ -263,6 +279,13 @@ class WPILIB_DLLEXPORT ArmFeedforward { */ constexpr units::unit_t GetKv() const { return kV; } + /** + * Returns the velocity gain. + * + * @param kV The velocity gain. + */ + constexpr void SetKv(units::unit_t kV) { this->kV = kV; } + /** * Returns the acceleration gain. * @@ -270,6 +293,13 @@ class WPILIB_DLLEXPORT ArmFeedforward { */ constexpr units::unit_t GetKa() const { return kA; } + /** + * Returns the acceleration gain. + * + * @param kA The acceleration gain. + */ + constexpr void SetKa(units::unit_t kA) { this->kA = kA; } + private: /// The static gain, in volts. units::volt_t kS; diff --git a/wpimath/src/main/native/include/frc/controller/ElevatorFeedforward.h b/wpimath/src/main/native/include/frc/controller/ElevatorFeedforward.h index 9be72a4ff6..68565b0fac 100644 --- a/wpimath/src/main/native/include/frc/controller/ElevatorFeedforward.h +++ b/wpimath/src/main/native/include/frc/controller/ElevatorFeedforward.h @@ -223,6 +223,13 @@ class ElevatorFeedforward { */ constexpr units::volt_t GetKs() const { return kS; } + /** + * Returns the static gain. + * + * @param kS The static gain. + */ + constexpr void SetKs(units::volt_t kS) { this->kS = kS; } + /** * Returns the gravity gain. * @@ -230,6 +237,13 @@ class ElevatorFeedforward { */ constexpr units::volt_t GetKg() const { return kG; } + /** + * Returns the gravity gain. + * + * @param kG The gravity gain. + */ + constexpr void SetKg(units::volt_t kG) { this->kG = kG; } + /** * Returns the velocity gain. * @@ -237,6 +251,13 @@ class ElevatorFeedforward { */ constexpr units::unit_t GetKv() const { return kV; } + /** + * Returns the velocity gain. + * + * @param kV The velocity gain. + */ + constexpr void SetKv(units::unit_t kV) { this->kV = kV; } + /** * Returns the acceleration gain. * @@ -244,6 +265,13 @@ class ElevatorFeedforward { */ constexpr units::unit_t GetKa() const { return kA; } + /** + * Returns the acceleration gain. + * + * @param kA The acceleration gain. + */ + constexpr void SetKa(units::unit_t kA) { this->kA = kA; } + private: /// The static gain. units::volt_t kS; diff --git a/wpimath/src/main/native/include/frc/controller/SimpleMotorFeedforward.h b/wpimath/src/main/native/include/frc/controller/SimpleMotorFeedforward.h index 87099047f5..297bee8003 100644 --- a/wpimath/src/main/native/include/frc/controller/SimpleMotorFeedforward.h +++ b/wpimath/src/main/native/include/frc/controller/SimpleMotorFeedforward.h @@ -201,6 +201,13 @@ class SimpleMotorFeedforward { */ constexpr units::volt_t GetKs() const { return kS; } + /** + * Returns the static gain. + * + * @param kS The static gain. + */ + constexpr void SetKs(units::volt_t kS) { this->kS = kS; } + /** * Returns the velocity gain. * @@ -208,6 +215,13 @@ class SimpleMotorFeedforward { */ constexpr units::unit_t GetKv() const { return kV; } + /** + * Returns the velocity gain. + * + * @param kV The velocity gain. + */ + constexpr void SetKv(units::unit_t kV) { this->kV = kV; } + /** * Returns the acceleration gain. * @@ -215,6 +229,13 @@ class SimpleMotorFeedforward { */ constexpr units::unit_t GetKa() const { return kA; } + /** + * Returns the acceleration gain. + * + * @param kA The acceleration gain. + */ + constexpr void SetKa(units::unit_t kA) { this->kA = kA; } + /** * Returns the period. * From 7e6077c5463159d9380380148d768e12a50c78a1 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 13 Feb 2025 23:20:08 -0800 Subject: [PATCH 29/33] [wpimath] Fix up order and docs for Feedforward gain setters (#7788) --- .../first/math/controller/ArmFeedforward.java | 72 +++++++++---------- .../math/controller/ElevatorFeedforward.java | 72 +++++++++---------- .../controller/SimpleMotorFeedforward.java | 54 +++++++------- .../include/frc/controller/ArmFeedforward.h | 56 +++++++-------- .../frc/controller/ElevatorFeedforward.h | 56 +++++++-------- .../frc/controller/SimpleMotorFeedforward.h | 42 +++++------ 6 files changed, 176 insertions(+), 176 deletions(-) diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java index af30cdbbdf..bf50a0c521 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ArmFeedforward.java @@ -86,15 +86,6 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable this(ks, kg, kv, 0); } - /** - * Returns the static gain in volts. - * - * @return The static gain in volts. - */ - public double getKs() { - return ks; - } - /** * Sets the static gain. * @@ -104,15 +95,6 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable this.ks = ks; } - /** - * Returns the gravity gain in volts. - * - * @return The gravity gain in volts. - */ - public double getKg() { - return kg; - } - /** * Sets the gravity gain. * @@ -122,15 +104,6 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable this.kg = kg; } - /** - * Returns the velocity gain in V/(rad/s). - * - * @return The velocity gain. - */ - public double getKv() { - return kv; - } - /** * Sets the velocity gain. * @@ -140,6 +113,42 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable this.kv = kv; } + /** + * Sets the acceleration gain. + * + * @param ka The acceleration gain in V/(rad/s²). + */ + public void setKa(double ka) { + this.ka = ka; + } + + /** + * Returns the static gain in volts. + * + * @return The static gain in volts. + */ + public double getKs() { + return ks; + } + + /** + * Returns the gravity gain in volts. + * + * @return The gravity gain in volts. + */ + public double getKg() { + return kg; + } + + /** + * Returns the velocity gain in V/(rad/s). + * + * @return The velocity gain. + */ + public double getKv() { + return kv; + } + /** * Returns the acceleration gain in V/(rad/s²). * @@ -149,15 +158,6 @@ public class ArmFeedforward implements ProtobufSerializable, StructSerializable return ka; } - /** - * Sets the acceleration gain. - * - * @param ka The acceleration gain in V/(rad/2²). - */ - public void setKa(double ka) { - this.ka = ka; - } - /** * Returns the period in seconds. * diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java index 816d2bb086..e33de90b15 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/ElevatorFeedforward.java @@ -86,15 +86,6 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ this(ks, kg, kv, 0); } - /** - * Returns the static gain in volts. - * - * @return The static gain in volts. - */ - public double getKs() { - return ks; - } - /** * Sets the static gain. * @@ -104,15 +95,6 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ this.ks = ks; } - /** - * Returns the gravity gain in volts. - * - * @return The gravity gain in volts. - */ - public double getKg() { - return kg; - } - /** * Sets the gravity gain. * @@ -122,6 +104,42 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ this.kg = kg; } + /** + * Sets the velocity gain. + * + * @param kv The velocity gain in V/(m/s). + */ + public void setKv(double kv) { + this.kv = kv; + } + + /** + * Sets the acceleration gain. + * + * @param ka The acceleration gain in V/(m/s²). + */ + public void setKa(double ka) { + this.ka = ka; + } + + /** + * Returns the static gain in volts. + * + * @return The static gain in volts. + */ + public double getKs() { + return ks; + } + + /** + * Returns the gravity gain in volts. + * + * @return The gravity gain in volts. + */ + public double getKg() { + return kg; + } + /** * Returns the velocity gain in V/(m/s). * @@ -131,15 +149,6 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ return kv; } - /** - * Sets the velocity gain. - * - * @param kv The velocity gain in V/(rad/s). - */ - public void setKv(double kv) { - this.kv = kv; - } - /** * Returns the acceleration gain in V/(m/s²). * @@ -149,15 +158,6 @@ public class ElevatorFeedforward implements ProtobufSerializable, StructSerializ return ka; } - /** - * Sets the acceleration gain. - * - * @param ka The acceleration gain in V/(rad/2²). - */ - public void setKa(double ka) { - this.ka = ka; - } - /** * Returns the period in seconds. * diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java index 73ff6dc342..10540a2e18 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java @@ -83,15 +83,6 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria this(ks, kv, 0); } - /** - * Returns the static gain in volts. - * - * @return The static gain in volts. - */ - public double getKs() { - return ks; - } - /** * Sets the static gain. * @@ -101,6 +92,33 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria this.ks = ks; } + /** + * Sets the velocity gain. + * + * @param kv The velocity gain in V/(units/s). + */ + public void setKv(double kv) { + this.kv = kv; + } + + /** + * Sets the acceleration gain. + * + * @param ka The acceleration gain in V/(units/2²). + */ + public void setKa(double ka) { + this.ka = ka; + } + + /** + * Returns the static gain in volts. + * + * @return The static gain in volts. + */ + public double getKs() { + return ks; + } + /** * Returns the velocity gain in V/(units/s). * @@ -112,15 +130,6 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria return kv; } - /** - * Sets the velocity gain. - * - * @param kv The velocity gain in V/(rad/s). - */ - public void setKv(double kv) { - this.kv = kv; - } - /** * Returns the acceleration gain in V/(units/s²). * @@ -132,15 +141,6 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria return ka; } - /** - * Sets the acceleration gain. - * - * @param ka The acceleration gain in V/(rad/2²). - */ - public void setKa(double ka) { - this.ka = ka; - } - /** * Returns the period in seconds. * diff --git a/wpimath/src/main/native/include/frc/controller/ArmFeedforward.h b/wpimath/src/main/native/include/frc/controller/ArmFeedforward.h index aa524ef936..d6bdc0f81c 100644 --- a/wpimath/src/main/native/include/frc/controller/ArmFeedforward.h +++ b/wpimath/src/main/native/include/frc/controller/ArmFeedforward.h @@ -244,6 +244,34 @@ class WPILIB_DLLEXPORT ArmFeedforward { return MaxAchievableAcceleration(-maxVoltage, angle, velocity); } + /** + * Sets the static gain. + * + * @param kS The static gain. + */ + constexpr void SetKs(units::volt_t kS) { this->kS = kS; } + + /** + * Sets the gravity gain. + * + * @param kG The gravity gain. + */ + constexpr void SetKg(units::volt_t kG) { this->kG = kG; } + + /** + * Sets the velocity gain. + * + * @param kV The velocity gain. + */ + constexpr void SetKv(units::unit_t kV) { this->kV = kV; } + + /** + * Sets the acceleration gain. + * + * @param kA The acceleration gain. + */ + constexpr void SetKa(units::unit_t kA) { this->kA = kA; } + /** * Returns the static gain. * @@ -251,13 +279,6 @@ class WPILIB_DLLEXPORT ArmFeedforward { */ constexpr units::volt_t GetKs() const { return kS; } - /** - * Returns the static gain. - * - * @param kS The static gain. - */ - constexpr void SetKs(units::volt_t kS) { this->kS = kS; } - /** * Returns the gravity gain. * @@ -265,13 +286,6 @@ class WPILIB_DLLEXPORT ArmFeedforward { */ constexpr units::volt_t GetKg() const { return kG; } - /** - * Returns the gravity gain. - * - * @param kG The gravity gain. - */ - constexpr void SetKg(units::volt_t kG) { this->kG = kG; } - /** * Returns the velocity gain. * @@ -279,13 +293,6 @@ class WPILIB_DLLEXPORT ArmFeedforward { */ constexpr units::unit_t GetKv() const { return kV; } - /** - * Returns the velocity gain. - * - * @param kV The velocity gain. - */ - constexpr void SetKv(units::unit_t kV) { this->kV = kV; } - /** * Returns the acceleration gain. * @@ -293,13 +300,6 @@ class WPILIB_DLLEXPORT ArmFeedforward { */ constexpr units::unit_t GetKa() const { return kA; } - /** - * Returns the acceleration gain. - * - * @param kA The acceleration gain. - */ - constexpr void SetKa(units::unit_t kA) { this->kA = kA; } - private: /// The static gain, in volts. units::volt_t kS; diff --git a/wpimath/src/main/native/include/frc/controller/ElevatorFeedforward.h b/wpimath/src/main/native/include/frc/controller/ElevatorFeedforward.h index 68565b0fac..93575276c5 100644 --- a/wpimath/src/main/native/include/frc/controller/ElevatorFeedforward.h +++ b/wpimath/src/main/native/include/frc/controller/ElevatorFeedforward.h @@ -216,6 +216,34 @@ class ElevatorFeedforward { return MaxAchievableAcceleration(-maxVoltage, velocity); } + /** + * Sets the static gain. + * + * @param kS The static gain. + */ + constexpr void SetKs(units::volt_t kS) { this->kS = kS; } + + /** + * Sets the gravity gain. + * + * @param kG The gravity gain. + */ + constexpr void SetKg(units::volt_t kG) { this->kG = kG; } + + /** + * Sets the velocity gain. + * + * @param kV The velocity gain. + */ + constexpr void SetKv(units::unit_t kV) { this->kV = kV; } + + /** + * Sets the acceleration gain. + * + * @param kA The acceleration gain. + */ + constexpr void SetKa(units::unit_t kA) { this->kA = kA; } + /** * Returns the static gain. * @@ -223,13 +251,6 @@ class ElevatorFeedforward { */ constexpr units::volt_t GetKs() const { return kS; } - /** - * Returns the static gain. - * - * @param kS The static gain. - */ - constexpr void SetKs(units::volt_t kS) { this->kS = kS; } - /** * Returns the gravity gain. * @@ -237,13 +258,6 @@ class ElevatorFeedforward { */ constexpr units::volt_t GetKg() const { return kG; } - /** - * Returns the gravity gain. - * - * @param kG The gravity gain. - */ - constexpr void SetKg(units::volt_t kG) { this->kG = kG; } - /** * Returns the velocity gain. * @@ -251,13 +265,6 @@ class ElevatorFeedforward { */ constexpr units::unit_t GetKv() const { return kV; } - /** - * Returns the velocity gain. - * - * @param kV The velocity gain. - */ - constexpr void SetKv(units::unit_t kV) { this->kV = kV; } - /** * Returns the acceleration gain. * @@ -265,13 +272,6 @@ class ElevatorFeedforward { */ constexpr units::unit_t GetKa() const { return kA; } - /** - * Returns the acceleration gain. - * - * @param kA The acceleration gain. - */ - constexpr void SetKa(units::unit_t kA) { this->kA = kA; } - private: /// The static gain. units::volt_t kS; diff --git a/wpimath/src/main/native/include/frc/controller/SimpleMotorFeedforward.h b/wpimath/src/main/native/include/frc/controller/SimpleMotorFeedforward.h index 297bee8003..eb48be1c31 100644 --- a/wpimath/src/main/native/include/frc/controller/SimpleMotorFeedforward.h +++ b/wpimath/src/main/native/include/frc/controller/SimpleMotorFeedforward.h @@ -194,6 +194,27 @@ class SimpleMotorFeedforward { return MaxAchievableAcceleration(-maxVoltage, velocity); } + /** + * Sets the static gain. + * + * @param kS The static gain. + */ + constexpr void SetKs(units::volt_t kS) { this->kS = kS; } + + /** + * Sets the velocity gain. + * + * @param kV The velocity gain. + */ + constexpr void SetKv(units::unit_t kV) { this->kV = kV; } + + /** + * Sets the acceleration gain. + * + * @param kA The acceleration gain. + */ + constexpr void SetKa(units::unit_t kA) { this->kA = kA; } + /** * Returns the static gain. * @@ -201,13 +222,6 @@ class SimpleMotorFeedforward { */ constexpr units::volt_t GetKs() const { return kS; } - /** - * Returns the static gain. - * - * @param kS The static gain. - */ - constexpr void SetKs(units::volt_t kS) { this->kS = kS; } - /** * Returns the velocity gain. * @@ -215,13 +229,6 @@ class SimpleMotorFeedforward { */ constexpr units::unit_t GetKv() const { return kV; } - /** - * Returns the velocity gain. - * - * @param kV The velocity gain. - */ - constexpr void SetKv(units::unit_t kV) { this->kV = kV; } - /** * Returns the acceleration gain. * @@ -229,13 +236,6 @@ class SimpleMotorFeedforward { */ constexpr units::unit_t GetKa() const { return kA; } - /** - * Returns the acceleration gain. - * - * @param kA The acceleration gain. - */ - constexpr void SetKa(units::unit_t kA) { this->kA = kA; } - /** * Returns the period. * From 13626063dc590389366891635f2abbfedf7552cb Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Thu, 13 Feb 2025 23:22:44 -0800 Subject: [PATCH 30/33] [wpimath] Fix units typo (#7789) --- .../edu/wpi/first/math/controller/SimpleMotorFeedforward.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java index 10540a2e18..7c04f4e4ec 100644 --- a/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java +++ b/wpimath/src/main/java/edu/wpi/first/math/controller/SimpleMotorFeedforward.java @@ -104,7 +104,7 @@ public class SimpleMotorFeedforward implements ProtobufSerializable, StructSeria /** * Sets the acceleration gain. * - * @param ka The acceleration gain in V/(units/2²). + * @param ka The acceleration gain in V/(units/s²). */ public void setKa(double ka) { this.ka = ka; From bd2211119fee2559e2b1eb12171509a9571b5413 Mon Sep 17 00:00:00 2001 From: Sam Carlberg Date: Wed, 19 Feb 2025 00:48:51 -0500 Subject: [PATCH 31/33] [epilogue] Make nonloggable type warnings configurable (#7792) Now a flag at the class level controls whether warning messages are printed. Defaults to false (no warning messages). --- .../processor/AnnotationProcessor.java | 18 ++++++++++++------ .../epilogue/processor/LoggerGenerator.java | 5 +++++ .../processor/AnnotationProcessorTest.java | 2 +- .../java/edu/wpi/first/epilogue/Logged.java | 8 ++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java index fa623e64ee..398569702e 100644 --- a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java +++ b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/AnnotationProcessor.java @@ -269,12 +269,18 @@ public class AnnotationProcessor extends AbstractProcessor { return false; } - processingEnv - .getMessager() - .printMessage( - Diagnostic.Kind.NOTE, - "[EPILOGUE] Excluded from logs because " + type + " is not a loggable data type", - element); + var classConfig = element.getEnclosingElement().getAnnotation(Logged.class); + + if (classConfig == null || classConfig.warnForNonLoggableTypes()) { + // Not loggable and not explicitly opted out of logging; print a warning message + processingEnv + .getMessager() + .printMessage( + Diagnostic.Kind.NOTE, + "[EPILOGUE] Excluded from logs because " + type + " is not a loggable data type", + element); + } + return true; } diff --git a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/LoggerGenerator.java b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/LoggerGenerator.java index e7cb686f71..496a773095 100644 --- a/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/LoggerGenerator.java +++ b/epilogue-processor/src/main/java/edu/wpi/first/epilogue/processor/LoggerGenerator.java @@ -71,6 +71,11 @@ public class LoggerGenerator { public Naming defaultNaming() { return Naming.USE_CODE_NAME; } + + @Override + public boolean warnForNonLoggableTypes() { + return false; + } }; public LoggerGenerator(ProcessingEnvironment processingEnv, List handlers) { diff --git a/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/AnnotationProcessorTest.java b/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/AnnotationProcessorTest.java index 7a1bdd44a3..8f1d9f2b19 100644 --- a/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/AnnotationProcessorTest.java +++ b/epilogue-processor/src/test/java/edu/wpi/first/epilogue/processor/AnnotationProcessorTest.java @@ -1772,7 +1772,7 @@ class AnnotationProcessorTest { """ package edu.wpi.first.epilogue; - @Logged + @Logged(warnForNonLoggableTypes = true) class Example { Throwable t; } diff --git a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/Logged.java b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/Logged.java index 2d76c9bfbe..c939d019d3 100644 --- a/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/Logged.java +++ b/epilogue-runtime/src/main/java/edu/wpi/first/epilogue/Logged.java @@ -124,4 +124,12 @@ public @interface Logged { * for all logged fields and methods in an annotated class */ Naming defaultNaming() default Naming.USE_CODE_NAME; + + /** + * Class-level only: if {@link #strategy()} is {@link Strategy#OPT_OUT}, this can be used to quiet + * the warnings that are printed for non-loggable fields and methods detected within the class. + * + * @return true if warnings should be printed, or false if warnings should not be printed + */ + boolean warnForNonLoggableTypes() default false; } From c898853b4dbe8cbda153d91a109c0c64e9c79679 Mon Sep 17 00:00:00 2001 From: HarryXChen <51322624+HarryXChen3@users.noreply.github.com> Date: Wed, 19 Feb 2025 01:49:28 -0500 Subject: [PATCH 32/33] [wpilib] LinearSystemSim.setState: calculate new output state (#7799) Establishes the invariant that the state and measurement always match up, even immediately after construction. --- .../include/frc/simulation/LinearSystemSim.h | 15 ++++-- .../native/cpp/simulation/ElevatorSimTest.cpp | 9 ++++ .../simulation/SingleJointedArmSimTest.cpp | 9 ++++ .../wpilibj/simulation/LinearSystemSim.java | 9 +++- .../wpilibj/simulation/ElevatorSimTest.java | 11 +++++ .../simulation/SingleJointedArmSimTest.java | 48 +++++++++++++------ 6 files changed, 80 insertions(+), 21 deletions(-) diff --git a/wpilibc/src/main/native/include/frc/simulation/LinearSystemSim.h b/wpilibc/src/main/native/include/frc/simulation/LinearSystemSim.h index 788d5ceeed..8747a0d18c 100644 --- a/wpilibc/src/main/native/include/frc/simulation/LinearSystemSim.h +++ b/wpilibc/src/main/native/include/frc/simulation/LinearSystemSim.h @@ -52,11 +52,11 @@ class LinearSystemSim { * @param dt The time between updates. */ void Update(units::second_t dt) { - // Update x. By default, this is the linear system dynamics x_k+1 = Ax_k + - // Bu_k + // Update x. By default, this is the linear system dynamics xₖ₊₁ = Axₖ + + // Buₖ. m_x = UpdateX(m_x, m_u, dt); - // y = Cx + Du + // yₖ = Cxₖ + Duₖ m_y = m_plant.CalculateY(m_x, m_u); // Add noise. If the user did not pass a noise vector to the @@ -115,7 +115,14 @@ class LinearSystemSim { * * @param state The new state. */ - void SetState(const Vectord& state) { m_x = state; } + void SetState(const Vectord& state) { + m_x = state; + + // Update the output to reflect the new state. + // + // yₖ = Cxₖ + Duₖ + m_y = m_plant.CalculateY(m_x, m_u); + } protected: /** diff --git a/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp index dd835650cd..2777ee48c0 100644 --- a/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/ElevatorSimTest.cpp @@ -44,6 +44,15 @@ TEST(ElevatorSimTest, StateSpaceSim) { EXPECT_NEAR(controller.GetSetpoint(), sim.GetPosition().value(), 0.2); } +TEST(ElevatorSimTest, InitialState) { + constexpr auto startingHeight = 0.5_m; + frc::sim::ElevatorSim sim(frc::DCMotor::KrakenX60(2), 20, 8_kg, 0.1_m, 0_m, + 1_m, true, startingHeight, {0.01, 0.0}); + + EXPECT_DOUBLE_EQ(startingHeight.value(), sim.GetPosition().value()); + EXPECT_DOUBLE_EQ(0, sim.GetVelocity().value()); +} + TEST(ElevatorSimTest, MinMax) { frc::sim::ElevatorSim sim(frc::DCMotor::Vex775Pro(4), 14.67, 8_kg, 0.75_in, 0_m, 1_m, true, 0_m, {0.01}); diff --git a/wpilibc/src/test/native/cpp/simulation/SingleJointedArmSimTest.cpp b/wpilibc/src/test/native/cpp/simulation/SingleJointedArmSimTest.cpp index 1311a0ebf6..3f6a1446ce 100644 --- a/wpilibc/src/test/native/cpp/simulation/SingleJointedArmSimTest.cpp +++ b/wpilibc/src/test/native/cpp/simulation/SingleJointedArmSimTest.cpp @@ -21,3 +21,12 @@ TEST(SingleJointedArmTest, Disabled) { // The arm should swing down. EXPECT_NEAR(sim.GetAngle().value(), -std::numbers::pi / 2, 0.01); } + +TEST(SingleJointedArmTest, InitialState) { + constexpr auto startingAngle = 45_deg; + frc::sim::SingleJointedArmSim sim(frc::DCMotor::KrakenX60(2), 125, 3_kg_sq_m, + 30_in, 0_deg, 90_deg, true, startingAngle); + + EXPECT_EQ(startingAngle, sim.GetAngle()); + EXPECT_DOUBLE_EQ(0, sim.GetVelocity().value()); +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java index ec296fde3d..e277902530 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/simulation/LinearSystemSim.java @@ -75,10 +75,10 @@ public class LinearSystemSim state) { m_x = state; + + // Update the output to reflect the new state. + // + // yₖ = Cxₖ + Duₖ + m_y = m_plant.calculateY(m_x, m_u); } /** diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/ElevatorSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/ElevatorSimTest.java index deade245fa..99ffbcd976 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/ElevatorSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/ElevatorSimTest.java @@ -63,6 +63,17 @@ class ElevatorSimTest { } } + @Test + void testInitialState() { + double startingHeightMeters = 0.5; + var sim = + new ElevatorSim( + DCMotor.getKrakenX60(2), 20, 8.0, 0.1, 0.0, 1.0, true, startingHeightMeters, 0.01, 0.0); + + assertEquals(startingHeightMeters, sim.getPositionMeters()); + assertEquals(0, sim.getVelocityMetersPerSecond()); + } + @Test void testMinMax() { var sim = diff --git a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSimTest.java b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSimTest.java index 928fd3edc8..4c7a876592 100644 --- a/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSimTest.java +++ b/wpilibj/src/test/java/edu/wpi/first/wpilibj/simulation/SingleJointedArmSimTest.java @@ -12,28 +12,46 @@ import edu.wpi.first.math.util.Units; import org.junit.jupiter.api.Test; class SingleJointedArmSimTest { - SingleJointedArmSim m_sim = - new SingleJointedArmSim( - DCMotor.getVex775Pro(2), - 300, - 3.0, - Units.inchesToMeters(30.0), - -Math.PI, - 0.0, - true, - Math.PI / 2.0); - @Test void testArmDisabled() { + SingleJointedArmSim sim = + new SingleJointedArmSim( + DCMotor.getVex775Pro(2), + 300, + 3.0, + Units.inchesToMeters(30.0), + -Math.PI, + 0.0, + true, + Math.PI / 2.0); + // Reset Arm angle to 0 - m_sim.setState(VecBuilder.fill(0.0, 0.0)); + sim.setState(VecBuilder.fill(0.0, 0.0)); for (int i = 0; i < 12 / 0.02; i++) { - m_sim.setInput(0.0); - m_sim.update(0.020); + sim.setInput(0.0); + sim.update(0.020); } // the arm should swing down - assertEquals(-Math.PI / 2.0, m_sim.getAngleRads(), 0.1); + assertEquals(-Math.PI / 2.0, sim.getAngleRads(), 0.1); + } + + @Test + void testInitialState() { + double startingAngleRads = Math.PI / 4.0; + SingleJointedArmSim sim = + new SingleJointedArmSim( + DCMotor.getKrakenX60(2), + 125, + 3.0, + Units.inchesToMeters(30.0), + 0, + Math.PI / 2.0, + true, + startingAngleRads); + + assertEquals(startingAngleRads, sim.getAngleRads()); + assertEquals(0, sim.getVelocityRadPerSec()); } } From 0c3c2c1fdaa5a2581eb73ce087ab685263f576f1 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Wed, 19 Feb 2025 21:08:39 -0800 Subject: [PATCH 33/33] [sysid] Remove extra period from exception messages (#7805) --- sysid/src/main/native/include/sysid/analysis/FilteringUtils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysid/src/main/native/include/sysid/analysis/FilteringUtils.h b/sysid/src/main/native/include/sysid/analysis/FilteringUtils.h index 3948cdd121..d14333800e 100644 --- a/sysid/src/main/native/include/sysid/analysis/FilteringUtils.h +++ b/sysid/src/main/native/include/sysid/analysis/FilteringUtils.h @@ -41,7 +41,7 @@ class InvalidDataError : public std::exception { */ explicit InvalidDataError(std::string_view message) { m_message = fmt::format( - "{}. Please verify that your units and data is reasonable and then " + "{} Please verify that your units and data is reasonable and then " "adjust your velocity threshold, test duration, and/or window size to " "try to fix this issue.", message);