Skip to content

Allow use of keyboard for control in sim #28

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

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

Conversation

TheFlameFish
Copy link
Contributor

Using sim to develop without a real robot is currently difficult, as it requires an Xbox controller.
This PR adds a boolean in constants titled useKeyboard. If useKeyboard is true and currentMode is SIM, use keyboard bindings instead of Xbox controller bindings.
Tested in sim with changes on #17.

@nolanhergert
Copy link
Contributor

I understand making a default keyboard map, which I assume simgui-ds.json is doing. Can you confirm?

However, I hesitate forcing it on by default. What if a someone does have an XBox controller? What is inconvenient about the current method of dragging the joystick/keyboard on the Sim GUI?
https://docs.wpilib.org/en/stable/docs/software/wpilib-tools/robot-simulation/simulation-gui.html#adding-a-system-joystick-to-joysticks

@TheFlameFish
Copy link
Contributor Author

I understand making a default keyboard map, which I assume simgui-ds.json is doing. Can you confirm?

However, I hesitate forcing it on by default. What if a someone does have an XBox controller? What is inconvenient about the current method of dragging the joystick/keyboard on the Sim GUI? https://docs.wpilib.org/en/stable/docs/software/wpilib-tools/robot-simulation/simulation-gui.html#adding-a-system-joystick-to-joysticks

Yes, simgui-ds.json sets the keybindings for keyboard 0 to match the axes and buttons of an Xbox controller.

In my testing, dragging the keyboard to the joystick 0 slot doesn't work. I think the XBoxController class doesn't accept keyboard even if its bindings match an XBox controller. I also expect we'll be using sim without an Xbox controller on hand more frequently than with one.

@Ace5tar
Copy link
Member

Ace5tar commented Feb 27, 2025

i dont see an issue merging this, but i do want to comment that configuring a keyboard control scene in sim gui is very trivial, so this may be an overcomplication

@TheFlameFish
Copy link
Contributor Author

TheFlameFish commented Feb 27, 2025

On my computer (MacOS), the keyboard sim control (as described in docs) does not seem to work with the XboxController class. With joystick 0 being set to keyboard 0 and with the keybindings being set to match the inputs of an Xbox controller, all keyboard inputs are ignored by the simulated robot. Do other devices behave differently in this regard?

@@ -48,6 +48,9 @@ public final class Constants {
? Mode.REAL
: Mode.SIM; // You need to manually switch betweeen SIM and REPLAY.

/** If true and in sim, use keyboard bindings instead of XBox controller. */
public static final Boolean useKeyboard = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Were you unable to find something that detected if an XBox controller was connected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think the CommandXboxController.isConnected method will work.

nolanhergert
nolanhergert previously approved these changes Mar 2, 2025
@TheFlameFish TheFlameFish added the enhancement New feature or request. Useful but not vital label Mar 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request. Useful but not vital
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants