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

[cmd] Add deadband trigger methods to CommandGenericHID #7085

Merged
merged 22 commits into from
Oct 11, 2024

Conversation

narmstro2020
Copy link
Contributor

@narmstro2020 narmstro2020 commented Sep 15, 2024

This should make creating triggers from axis values being non-zero a little more ergonomic without having to write an inline supplier. First drafted with Java. C++ coming soon

@narmstro2020 narmstro2020 requested a review from a team as a code owner September 15, 2024 21:45
Copy link
Contributor

This PR modifies commands. Please open a corresponding PR in Python Commands and include a link to this PR.

@narmstro2020 narmstro2020 changed the title [wpilibNewCommands] added a deadband trigger methods to CommandHID [wpilibNewCommands] added deadband trigger methods to CommandHID Sep 15, 2024
@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020 narmstro2020 changed the title [wpilibNewCommands] added deadband trigger methods to CommandHID [wpilibNewCommands] added deadband trigger methods to CommandGenericHID Sep 15, 2024
@narmstro2020
Copy link
Contributor Author

/format

@KangarooKoala
Copy link
Contributor

KangarooKoala commented Sep 16, 2024

Could you give an example of a specific control binding that would use this? (e.g., when trigger is pressed more than a certain threshold, shoot) axisGreaterThan() and axisLessThan() already exist, and I'm having trouble thinking of a reasonably common use case that can't be solved by those.

Reading the initial comment for this PR again, I see that the provided example was "axis values being non-negative". Is there a reason why axisGreaterThan(deadband) wouldn't work?

@calcmogul calcmogul changed the title [wpilibNewCommands] added deadband trigger methods to CommandGenericHID [cmd] added deadband trigger methods to CommandGenericHID Sep 16, 2024
@calcmogul calcmogul changed the title [cmd] added deadband trigger methods to CommandGenericHID [wpilibNewCommands] Add deadband trigger methods to CommandGenericHID Sep 16, 2024
@calcmogul calcmogul changed the title [wpilibNewCommands] Add deadband trigger methods to CommandGenericHID [cmd] Add deadband trigger methods to CommandGenericHID Sep 16, 2024
@narmstro2020
Copy link
Contributor Author

narmstro2020 commented Sep 16, 2024

Reading the initial comment for this PR again, I see that the provided example was "axis values being non-negative". Is there a reason why axisGreaterThan(deadband) wouldn't work?

Unless I'm misreading axisGreatherThan would only check if the value is above a threshold, not non-negative. (EDIT: non-zero) So for example. Let's say I want to Trigger manual control when a joystick enters a non-negative (EDIT: non-zero) value (after the deadband).

You would have to do. new Trigger(() -> MathUtil.applydeadband(controller.getLeftY(), deadband) != 0) and then check an onTrue, whileTrue, etcetera.

EDIT: The original post had a typo. non-negative should've read non-zero. Fixed in the top level PR comment

@KangarooKoala
Copy link
Contributor

Could you describe to me what you mean by non-negative? To me, the meaning of non-negative means >=0, which means axisGreaterThan(0) (or axisGreaterThan(deadband)) will produce a trigger that's true when the axis is non-negative.

@narmstro2020
Copy link
Contributor Author

narmstro2020 commented Sep 16, 2024

Could you describe to me what you mean by non-negative? To me, the meaning of non-negative means >=0, which means axisGreaterThan(0) (or axisGreaterThan(deadband)) will produce a trigger that's true when the axis is non-negative.

I meant to say non-zero. Not non-negative. Fixing the initial comment. Sorry about that.

@KangarooKoala
Copy link
Contributor

No worries! The question still remains, though- What's a concrete example of a binding to an axis being non-zero?

@narmstro2020
Copy link
Contributor Author

narmstro2020 commented Sep 16, 2024

No worries! The question still remains, though- What's a concrete example of a binding to an axis being non-zero?

So activate manual control of a device (drive, elevator, arm, shooter, etc) via

new Trigger(() -> MathUtil.applydeadband(controller.getLeftY(), deadband) != 0).onTrue(device.drive(MathUtil.applydeadband(controller.getLeftY(), deadband);

Excuse the crudity of this model. There are more elegant ways to pass the deadbanded joystick into the device.drive method.

device.drive would be a Command factory of some sort.

This would reduce it down to

controller.axisActive(0, 0.1).onTrue(... command binding)

@KangarooKoala
Copy link
Contributor

That example makes sense! Give me a moment to write up a review with some things I noticed.

@narmstro2020
Copy link
Contributor Author

That example makes sense! Give me a moment to write up a review with some things I noticed.

No problem. That'll get me a chance to write the C++.

narmstro2020 and others added 3 commits September 15, 2024 23:44
…/button/CommandGenericHID.java

Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
…/button/CommandGenericHID.java

Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020
Copy link
Contributor Author

Is this tools build related to my PR

@KangarooKoala
Copy link
Contributor

Based on the errors ("Could not resolve ..."), it seems to be a CI network issue. (Which is unrelated to the PR)

@narmstro2020
Copy link
Contributor Author

/format

@narmstro2020
Copy link
Contributor Author

Do I need to do the python item mentioned in Github-actions above?

@WispySparks
Copy link
Contributor

Do I need to do the python item mentioned in Github-actions above?

I would say yes, https://github.com/robotpy/robotpy-commands-v2/blob/main/commands2/button/commandgenerichid.py

narmstro2020 and others added 3 commits September 17, 2024 20:19
…/button/CommandGenericHID.java

Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
@narmstro2020
Copy link
Contributor Author

anything left to do on this one?

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.

Looks good to me, for what it's worth.

@PeterJohnson PeterJohnson merged commit 968bdf0 into wpilibsuite:main Oct 11, 2024
33 checks passed
spacey-sooty pushed a commit to spacey-sooty/allwpilib that referenced this pull request Oct 26, 2024
…uite#7085)

Co-authored-by: Joseph Eng <91924258+KangarooKoala@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants