Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wpimath] Add vector slewrate limiter #7806

Open
wants to merge 48 commits into
base: main
Choose a base branch
from

Conversation

OhmV-IR
Copy link

@OhmV-IR OhmV-IR commented Feb 20, 2025

Intends to close #4708
Adds a function in MathUtil which takes an initial Translation(2d or 3d), and a second translation, the time interval between them and a max velocity. The function will return the output translation, which is the translation with the capped speed(if the speed of the translation is less than the maxVelocity, then the translation should be unchanged).
will mark PR as ready for review when java code is completed

@github-actions github-actions bot added the component: wpimath Math library label Feb 20, 2025
@OhmV-IR
Copy link
Author

OhmV-IR commented Feb 21, 2025

I can see I have some work to do on this. Will mark as ready for review when I resolve all the current feedback

@OhmV-IR OhmV-IR requested a review from calcmogul February 21, 2025 16:28
@KangarooKoala
Copy link
Contributor

KangarooKoala commented Feb 21, 2025

Does using diff * (maxVelocity * dt / dist) work? There should be an implicit conversion from dimensionless unit_t to double that you can then multiply the Translation2d by. See the below:

/**
* @brief implicit type conversion.
* @details only enabled for scalar unit types.
*/
template<class Ty, std::enable_if_t<traits::is_dimensionless_unit<Units>::value && std::is_arithmetic<Ty>::value, int> = 0>
constexpr operator Ty() const noexcept
{
// this conversion also resolves any PI exponents, by converting from a non-zero PI ratio to a zero-pi ratio.
return static_cast<Ty>(units::convert<Units, unit<std::ratio<1>, units::category::scalar_unit>>((*this)()));
}

Oopsies on my part for forgetting that the unit operations need to be grouped together so that the Translation2d doesn't get multiplied by a unit type.

@calcmogul
Copy link
Member

calcmogul commented Feb 21, 2025

You'll need to add #include <numbers> to the C++ test for the constants in std::numbers. Also, it seems https://en.cppreference.com/w/cpp/header/numbers doesn't list a std::numbers::inv_sqrt2, so you can just use std::numbers::sqrt2.

@OhmV-IR OhmV-IR requested a review from calcmogul February 21, 2025 20:47
@OhmV-IR
Copy link
Author

OhmV-IR commented Feb 21, 2025

builds on my machine fine now

@OhmV-IR OhmV-IR requested a review from calcmogul February 22, 2025 02:30
Copy link
Contributor

@KangarooKoala KangarooKoala left a comment

Choose a reason for hiding this comment

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

Nice work! Just one tiny nitpick that I noticed. (The last 5% of the work always takes the longest, but I think you're nearly there)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vector slew rate limiter
3 participants