Odd behavior with Gamepad

I am having an intermittent problem with Gamepad. My DiddyBorg has a PI 4 2Gb "brain" and when not roaming the house on its own is manually controlled by a PS3 controller and Gamepad. I last updated the RPi OS about a week ago.

Every now and again while manually driving the robot the software will stop responding to button presses from the controller. Strangely enough the axis commands from the joysticks will still function. The problem is resolved by a reboot of the Pi so I'm pretty sure it's not a problem with the controller.

The python3 script I am currently running is far too long and convoluted to post on here (with several different threads for the compass, lidar and camera) but I thought I would ask if anyone else had had this problem and could give me a pointer as to how to solve it?

piborg's picture

I have not seen that problem before, but we have seen some quirky behaviour from gamepads occasionally. The most obvious of these was a short phantom joystick reading when the gamepad had been left idle for a while, causing a quick nudge forward :(

One thought, did you try just restarting the script to see what happens?

If restarting the script on its own fixes the problem then it is probably a bug lurking in the script.

If restarting the script on its own makes no difference then the problem probably lives in either the drivers or the library which is reading the gamepad inputs.

Thanks for the suggestion, restarting the script rather than rebooting does fix the problem, until the next random time that it fails. I can also confirm that the controller is still sending button events when the fault occurs as I also have "qjjoypad" running in the background and that still responds to button presses. (Note that the fault first occurred before I installed qjoypad.)

As the axis/joysticks are processed by Gamepad Asynchronous mode and the buttons by Gamepad Event mode I guess that something in my code is stopping the Event mode from running in the background. It's not helped by the random way in which the fault occurs, sometimes quite soon after starting the script and other times it will run without fault.

I'll try "remming" out bits of my script that may be suspects but if you have any ideas I would be grateful.

piborg's picture

It is possible that their might be a bug in the Gamepad library itself that we have not seen before...

Other things that might be worth checking:

  1. If one of the button event callbacks goes into an infinite loop it would prevent any further button events from being processed (they are handled one at a time).
  2. Is it possible that removeAllEventHandlers is being called somewhere and de-registering the event callbacks?
  3. An unhandled exception in one of the event callbacks would probably cause problems as well

Thanks piborg. I would be surprised if the problem is a bug in the Gamepad library as I have no problems when running other, earlier versions of my script. I would also discount item 2 in your list.

Items 1 and 3, however, are well worth further investigation. Strangely enough I had no problems this evening even though I spent an hour or so manually driving Diddy around recording new routes for him to follow. Of the two I suspect an unhandled exception is the most likely culprit. I shall add a few more "try - except" handlers.

Subscribe to Comments for "Odd behavior with Gamepad"