Software
Software copied to clipboard
Add Xbox controller support to Thunderscope
Description
This PR adds XBox controller support to Thunderscope.
Work Done
- [x] Added a handler class for managing the controller USB connection, through the builtin linux
evdevAPI using a python package - [x] Updated logic inside
RobotCommunicationto handle using GUI or controller input values and passing that through to the robots - [x] Bumped PyQtGraph major version
- [x] Added button to load Xbox controller and a status view for the controller
- [x] Removed geneva UI slider
Testing (Needed To Be) Done
- [x] Test XBox controller only works when
MANUALcontrol is set andXboxis toggled in diagnostics. - [ ] Test multiple robots move when using
MANUALandXbox - [ ] Test that XBox can still control 1 or more robots, when AI is running.
Resolved Issues
- [x] No longer need to frantically find & fix the branch with xbox code for a demo in 5.
- [x] #2562
Review Checklist
It is the reviewers responsibility to also make sure every item here has been covered
- [x] Function & Class comments: All function definitions (usually in the
.hfile) should have a javadoc style comment at the start of them. For examples, see the functions defined inthunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class. - [x] Remove all commented out code
- [x] Remove extra print statements: for example, those just used for testing
- [x] Resolve all TODO's: All
TODO(or similar) statements should either be completed or associated with a github issue
you can tag issue #2562
I just need high-level reviews for now to make sure I'm on the right track. The work that still needs to be done:
- [x] UI loading/showing correctly with/without controller connected
- [x] Read and log values from controller
- [x] Propogate controller values to
robot_communication.py - [x] Disable toggle switch if no controller connected
- [ ] Field tested on robots
Should be good for a review now.
All that's left is to field test on a robot and I might also add dynamically moving sliders for fun just to gauge the values of the controller inputs visually.
Also function docs :weary:
thanks for the reviews, there's gonna be some logic refactoring to make sure I can properly support new controllers easier:
- [ ] Change to use int event codes instead of strings (There is a unique int code for each input event, while that isn't necessarily true for the string codes - some buttons have a string list for the
event.typevalue which is annoying to switch on) - [ ] Bugs with processing old and out-of-date events that occur when
DIAGNOSTICSmode is enabled. - [ ] Refactor back to an
elifchain for readability, and make conditionals work on a common input discriminant value - [ ] Disable
ChickerWidgetcontrols inHANDHELDmode - [ ] Potentially simplify
ChickerWidgetUI accessibility logic. - [ ] Various clean-up pointed out in reviews.
Controller connected. diagnostics input:
Controller connected. handheld input:
Controller disconnected:
qt.qpa.input.events: scroll event from unregistered device 17 log is spammed when plugging/unplugging controller, bug on pyqt side, with the only fix being to bump pyqt version from 6.5.0 to 6.6.1 @itsarune fyi.
interesting, ya as far as I know, there's nothing stopping us from upgrading the pyqt version if we want.
Take a look at screenshots here :):
https://github.com/UBC-Thunderbots/Software/pull/3064#issuecomment-2039177590
Good for another round of review. Field testing done and everything working as expected.
Controller Disconnected:
Controller Connected, Diagnostics Mode:
Controller Connected, Handheld Device Mode:
I've resolved all remaining comments and cleaned up the code. There were also some thread safety issues with HandheldDeviceManager which I've fixed. I'm giving myself a pat on the back and approving this PR lol
I will take a look of the rest of thing later. Need to work on mini project for CPEN 221.
Just completed a major refactor of the code
-
HandheldControlleris the new class responsible for reading input events from the controller-
Switched to using
InputDevice.read_loopwhich uses theselectsyscall, instead of endlessly callingInputDevice.read_onein a loop which wastes CPU time busy waiting -
HandheldControllerhas no public methods that mutate its state so it should be thread safe. No need for mutex
-
-
Removed
DiagnosticsInputWidgetfor toggling between diagnostics/xbox control (too much inter-widget communication with signals). Replaced with a "Enable Input" checkbox in theHandheldControllerWidget -
DriveAndDribblerWidgetandChickerWidgetare now the only classes responsible for sending outMotorControl/PowerControlprotos. The handheld controller inputs are converted intoMotorControl/PowerControlvalues inHandheldControllerWidgetand those values are forwarded toDriveAndDribblerWidget/ChickerWidgetto be sent out. This prevents duplication of some logic and safety code (e.g. chicker timeout) -
Fixed bugs where kick/chip buttons are enabled/disabled at the wrong time or chicker timeout is ignored