Skip to content

[wpimath] Update units library - #9297

Open
Gold856 wants to merge 22 commits into
wpilibsuite:mainfrom
Gold856:update-units-library
Open

[wpimath] Update units library#9297
Gold856 wants to merge 22 commits into
wpilibsuite:mainfrom
Gold856:update-units-library

Conversation

@Gold856

@Gold856 Gold856 commented Aug 16, 2026

Copy link
Copy Markdown
Member

No description provided.

@Gold856
Gold856 requested review from a team as code owners August 16, 2026 04:30
@github-actions github-actions Bot added os: simulation component: ntcore NetworkTables library component: wpilibc WPILib C++ component: command-based WPILib Command Based Library component: wpimath Math library component: glass Glass app and backend type: testing Related to testing. build Monorepo organization, Gradle/CMake/Bazel, upstream_utils, etc component: apriltag AprilTag library component: examples component: sysid SysId app robotpy Issues that affect RobotPy (Python) support component: xrp XRP vendordep component: romi Romi vendordep labels Aug 16, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Gold856
Gold856 force-pushed the update-units-library branch 7 times, most recently from 93ff9f3 to 50bdfe2 Compare August 18, 2026 00:55

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50bdfe2603

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread wpimath/src/main/native/thirdparty/units/include/wpi/units/core.hpp
Comment thread wpimath/src/main/native/thirdparty/units/include/wpi/units/core.hpp
@@ -179,7 +177,7 @@ constexpr T CopyDirectionPow(T value, double exponent,
* the input range.
*/
template <typename T, int N>
requires std::is_arithmetic_v<T> || wpi::units::traits::is_unit_t_v<T>
requires std::is_arithmetic_v<T> || wpi::units::traits::is_unit_v<T>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reapply unit scale after processing unit vectors

When T is a ratio-scaled dimensionless unit such as percent<>, the unit branch converts vector elements to double as normalized fractions but converts the processed doubles back by invoking T(double), which interprets them as named-unit points. For example, CopyDirectionPow([50_pct], 2, 100_pct) returns 0.25_pct instead of 25_pct; the analogous round trip in the vector ApplyDeadband() overload is wrong by the same scale factor. Convert to and from raw values consistently, or reconstruct results through a base-dimensionless unit before converting to T.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, we're going to disable unit vector with ratio-dimensionless units due to bugs in upstream code.

@Gold856
Gold856 force-pushed the update-units-library branch 2 times, most recently from 96759a8 to 8ebfb9b Compare August 19, 2026 22:20
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@Gold856
Gold856 force-pushed the update-units-library branch from d049c78 to a2283d4 Compare August 22, 2026 07:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2283d4181

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread wpimath/src/main/native/thirdparty/units/include/wpi/units/core.hpp Outdated
Comment on lines +250 to +251
table.SetProperty(name, "unit", "\"" #abbrev "\""); \
table.Log(name, value.value()); \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Log ratio-scaled units in their named scale

For ratio-scaled dimensionless units, value() returns the normalized fraction while the emitted metadata names the original unit. For example, logging percent<>{50} writes 0.5 with unit "pct", so telemetry consumers interpret the value as 0.5 percent instead of 50 percent; ppm and ppb have larger errors. Log value.raw() here so the numeric payload matches the advertised abbreviation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're just going to keep ratio-dimensionless units as normalized fractions.

@Gold856
Gold856 force-pushed the update-units-library branch from a2283d4 to e1944a8 Compare August 24, 2026 06:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1944a81e1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Underlying accumulator = Underlying(0);
for (Eigen::Index i = 0; i < v.size(); ++i)
{
const Underlying raw = v(i).template to<Underlying>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve ratio-scaled values when computing unit norms

When the vector scalar is a ratio-scaled dimensionless unit, to<Underlying>() returns the normalized fraction, but line 192 reconstructs Unit as though that fraction were expressed in the named scale. For example, the norm of [3_pct, 4_pct] becomes 0.05_pct instead of 5_pct. Accumulate raw named-unit values, or reconstruct the result through base dimensionless units before converting back.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? You couldn't have told me this 3 days ago?


Eigen::Matrix<Underlying, VectorDerived::RowsAtCompileTime, 1> raw;
for (Eigen::Index i = 0; i < vector.size(); ++i)
raw(i) = vector(i).template to<Underlying>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve ratio-scaled values through unit transforms

For a ratio-scaled dimensionless vector, this unwraps each element to its normalized fraction and line 275 then interprets the transformed fraction as points in the named unit. Even an identity transform changes [3_pct, 4_pct] into [0.03_pct, 0.04_pct]. Use raw() consistently for the matrix operation, or convert the results from a base dimensionless unit before constructing Unit.

Useful? React with 👍 / 👎.

Comment thread wpimath/src/main/native/thirdparty/units/include/wpi/units/core.hpp
Comment thread wpimath/src/main/native/thirdparty/units/include/wpi/units/core.hpp
Comment thread wpimath/src/main/native/thirdparty/units/include/wpi/units/core.hpp
@Gold856
Gold856 force-pushed the update-units-library branch from e1944a8 to f3ca10e Compare August 25, 2026 05:50
@Gold856
Gold856 force-pushed the update-units-library branch from f3ca10e to 9a53ac3 Compare August 25, 2026 06:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a53ac300e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

namespace pybind11 {
namespace detail {
template <> struct handle_type_name<wpi::units::radians_per_second_cubed<>> {
static constexpr auto name = _("wpimath.units.radians_per_second_cubed");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Define aliases for the newly exported unit casters

When a binding uses this newly added angular-jerk type, its generated signature or stub refers to wpimath.units.radians_per_second_cubed, but wpimath/units.py defines no such attribute. The same mismatch affects the other newly exported caster families, including jerk, luminance, energy density, irradiance, substance concentration, viscosity, and volume flow rate. Even after updating the renamed legacy aliases, these new annotations remain unresolved for downstream RobotPy bindings; add corresponding float aliases for the newly exported names.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Monorepo organization, Gradle/CMake/Bazel, upstream_utils, etc component: apriltag AprilTag library component: command-based WPILib Command Based Library component: drivers component: examples component: glass Glass app and backend component: ntcore NetworkTables library component: romi Romi vendordep component: sysid SysId app component: wpilibc WPILib C++ component: wpimath Math library component: xrp XRP vendordep os: simulation robotpy Issues that affect RobotPy (Python) support type: testing Related to testing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants