Software icon indicating copy to clipboard operation
Software copied to clipboard

Add Xbox controller support to Thunderscope

Open Bvasilchikov opened this issue 1 year ago • 13 comments
trafficstars

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 evdev API using a python package
  • [x] Updated logic inside RobotCommunication to 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 MANUAL control is set and Xbox is toggled in diagnostics.
  • [ ] Test multiple robots move when using MANUAL and Xbox
  • [ ] 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 .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/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

Bvasilchikov avatar Nov 26 '23 00:11 Bvasilchikov

you can tag issue #2562

itsarune avatar Dec 02 '23 20:12 itsarune

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

Bvasilchikov avatar Mar 17 '24 16:03 Bvasilchikov

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.

Bvasilchikov avatar Mar 29 '24 04:03 Bvasilchikov

Also function docs :weary:

Bvasilchikov avatar Mar 29 '24 04:03 Bvasilchikov

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.type value which is annoying to switch on)
  • [ ] Bugs with processing old and out-of-date events that occur when DIAGNOSTICS mode is enabled.
  • [ ] Refactor back to an elif chain for readability, and make conditionals work on a common input discriminant value
  • [ ] Disable ChickerWidget controls in HANDHELD mode
  • [ ] Potentially simplify ChickerWidget UI accessibility logic.
  • [ ] Various clean-up pointed out in reviews.

Bvasilchikov avatar Mar 31 '24 01:03 Bvasilchikov

Controller connected. diagnostics input: connected_diagnostics

Controller connected. handheld input: connected_handheld

Controller disconnected: disconnected

Bvasilchikov avatar Apr 05 '24 07:04 Bvasilchikov

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.

Bvasilchikov avatar Apr 06 '24 19:04 Bvasilchikov

interesting, ya as far as I know, there's nothing stopping us from upgrading the pyqt version if we want.

itsarune avatar Apr 16 '24 08:04 itsarune

Take a look at screenshots here :):

https://github.com/UBC-Thunderbots/Software/pull/3064#issuecomment-2039177590

Bvasilchikov avatar Apr 16 '24 13:04 Bvasilchikov

Good for another round of review. Field testing done and everything working as expected.

Controller Disconnected: Screenshot from 2024-05-20 15-43-09

Controller Connected, Diagnostics Mode: Screenshot from 2024-05-20 15-43-16

Controller Connected, Handheld Device Mode: Screenshot from 2024-05-20 15-43-19

Bvasilchikov avatar May 20 '24 22:05 Bvasilchikov

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

williamckha avatar Sep 24 '24 04:09 williamckha

I will take a look of the rest of thing later. Need to work on mini project for CPEN 221.

Mr-Anyone avatar Sep 26 '24 02:09 Mr-Anyone

Just completed a major refactor of the code

  • HandheldController is the new class responsible for reading input events from the controller

    • Switched to using InputDevice.read_loop which uses the select syscall, instead of endlessly calling InputDevice.read_one in a loop which wastes CPU time busy waiting

    • HandheldController has no public methods that mutate its state so it should be thread safe. No need for mutex

  • Removed DiagnosticsInputWidget for toggling between diagnostics/xbox control (too much inter-widget communication with signals). Replaced with a "Enable Input" checkbox in the HandheldControllerWidget

  • DriveAndDribblerWidget and ChickerWidget are now the only classes responsible for sending out MotorControl/PowerControl protos. The handheld controller inputs are converted into MotorControl/PowerControl values in HandheldControllerWidget and those values are forwarded to DriveAndDribblerWidget/ChickerWidget to 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

williamckha avatar Oct 09 '24 04:10 williamckha