I am writing simple Python code to control an XRP robot using the xrpcode.wpi.edu web browser interface. I want to control movement of the robot with a simple “wasd” scheme of keystrokes - forward, turn left, backward, turn right. I can’t figure out how to capture the keystrokes; or rather, I can’t figure out how to import the keyboard library in a way that this environment requires. Any tips?
A few tips:
1 - The new gamepad API supports wasd if you want to use that.
2 - You can get the input directly in your program. When doing this you need to make sure that the Shell window in the XRPCode is the selected window so that your typed input is going to the micropython program.
import sys
sys.stdin.read(1)
3 - if you wanted a non-blocking keyboard input you can look up the micropython select object.
how do you use the new gamepad feature? I have tried to use it but no luck.
Currently it only works over Bluetooth. But if you have a use case for when it is connected via usb we would be interested.
I do have the xrp connected over Bluetooth. Does the game pad have to be connected via Bluetooth also?
Nope, the gamepad should be connected to the PC running XRPCode. When you push a button or move the joystick a gamepad icon should show on the top bar of XRPCode. There is a gamepad example program in the examples directory.
Thank you I got it to work thank you
Do you know where to find the example code?