Using keyboard to drive in simulation

Recently, my team and I have been trying to implement simulations into our robot software. We got everything to work, including autonomous drive routines, but for some reason the keyboard just doesn’t work. When I run the simulation and connect the keyboard to port 0 in the simulation GUI, it registers the values from the keyboard. However, it doesn’t get to the drivetrain. The function in the drive that the command calls has been tested before, and it works. The GenericHID input from the keyboard is declared in the compile time of the command.

Here is the command: (1.0 KB)

I tried deleting all other GenericHID objects in the code, including an Xbox controller that was connected to port 0, but that had no effect. The axis indexes are correct (according to the sim GUI). Here is a screenshot of the sim GUI window:

Has anyone run into this issue before, and knows what to do?

1 Like

You have your keyboard as “joystick” 16, 17, and 18. Are those the numbers you’re using in code? If youre expecting it to function as a direct replacement for a gamepad/xbox controller/etc, then it needs to be one of 1-4, and be configured with the right number of buttons/axes (see the pane in the bottom left for configuration).

Are you sure that the command is being scheduled and executed properly? That would be the next thing to check, if the function that the command calls works.

Those are just the numbers in the list of system joysticks that the simgui presents- the OP has put “keyboard 0” into joystick slot 0 as shown in the joysticks window.

I’m sure

Perhaps a silly question, are you enabling the sim robot? (upper left corner in the pic you sent)

It isn’t functioning as a replacement. I just created a GenericHID object, and I’m using the raw axis values.


1 Like

We need to see your whole codebase then.

:man_facepalming: you’re 100% right… I’ve apparently completely forgotten how to use simgui in the last couple months.

Here is the link GitHub - Galaxia5987/Sim-bot-2023

Ah hold on, i forgot to push the changes. It will take me a couple hours until i can do that.

I uploaded the updated version of the code.

It looks like your default command is still XboxDrive. Is that the one you want to use with the keyboard?

Ah hold on, I’ll change it to the correct one. I changed it, the changes should be visible soon.

If you test the code now, does the keyboard work?

No, still doesn’t move

Um, well this is embarrassing. It turns out you have to be on the sim GUI window in order for the values to actually register. All this time I’ve been switching to my AdvantageScope window so that I could see the drivetrain moving.

If you have a USB game controller at home, you can use the “Use Real DriverStation” checkbox when starting sim and it won’t require you to be focused on the DS or the sim window to use the controller in sim.

Yeah for some reason the controller works anyway. But I wanted to have the option of a keyboard so that we wouldn’t have to depend on USB controllers.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.