Skip to content

No disconnect detection #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fsofras opened this issue Apr 6, 2019 · 4 comments
Open

No disconnect detection #9

fsofras opened this issue Apr 6, 2019 · 4 comments

Comments

@fsofras
Copy link

fsofras commented Apr 6, 2019

I am using a wireless controller to control a rover. Despite the fact that the handheld is switched off, the joy.connected attribute is True. Any idea why?

@FRC4564
Copy link
Owner

FRC4564 commented Apr 13, 2019

The streamed output of xboxdrv is expected to change whenever a controller loses connectivity. Normally, the output of xboxdrv is a full set of control states for the Xbox 360 controller. When a disconnect occurs, xboxdrv normally detects the change and sends an event string that is unique (it switches to an original Xbox controller layout, rather than the 360 layout). You should be able to see this for yourself by running xboxdrv interactively

sudo xboxdrv --detach-kernel-driver

While the controller is connected, you'll see state changes streamed to the console, showing a consistent format that includes all of the controls of a 360 controller. If you pop-out the battery from the controller, to force a disconnect, you should see a final event streamed that has a unique format to it. Here is how it appears for me (note how the 'black' and 'white' states appear, which are unique to the original Xbox controller):

Press Ctrl-C to quit, use '--silent' to suppress the event output X1: -3458 Y1: 159 X2: 408 Y2: 151 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0 X1: -3458 Y1: 159 X2: 714 Y2: 151 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0 X1: 0 Y1: 0 X2: 0 Y2: 0 du:0 dd:0 dl:0 dr:0 start:0 back:0 TL:0 TR:0 A: 0 B: 0 X: 0 Y: 0 black: 0 white: 0 LT: 0 RT: 0

If you confirm that xboxdrv is working in this manner on your system, then xbox.py should be able to detect the loss of connection. Running sample.py is a good way to confirm that all is well.

If xboxdrv isn't sending a unique event string on disconnect, then xbox.py will not be able to detect the disconnect. I'd be curious to learn what you are seeing.

For reference, I was using xboxdrv version 0.8.8 on Ubuntu, for the sample above. I'm also using an original Microsoft USB Xbox receiver.

@fsofras
Copy link
Author

fsofras commented Apr 15, 2019

Thank you very much for taking the time to reply.
I am using the same version of xboxdrv on a raspberry 3B+ with the latest raspbian. The controller is a clone and is detected as

Microsoft Corp. Xbox360 Controller

(a wireless version)
The command sudo xboxdrv --detach-kernel-driver produces the following string:

X1: 0 Y1: -256 X2: 0 Y2: -256 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0
and sample.py works as expected.
Swiching it off does not produce a different string, it just zeros everything ( as it should I think)

@FRC4564
Copy link
Owner

FRC4564 commented Apr 22, 2019

That is definitely different than I've seen with Microsoft receivers. If xboxdrv doesn't provide some unique output, then xbox.py won't be able to identify a disconnect. There might be a simple workaround for you,

I see that your output is showing the Y1 and Y2 axis values registering as -256, while X1 and X2 come through as zeros, which is fairly unique. If the values are always X1: 0 Y1: -256 X2: 0 Y2: -256 whenever the controller is disconnected, you could test for this condition specifically within the 'refresh' method of xbox.py. Currently the block of code for determining connected status looks like this:

if len(response) == 140:
    self.connectStatus = True
    self.reading = response
else:  #Any other response means we have lost wireless or controller battery
    self.connectStatus = False

Try changing the 'if' statement to:

if len(response) == 140 and not response.startswith("X1: 0 Y1: -256 X2: 0 Y2: -256 du:0 dd:0 dl:0 dr:0 back:0 guide:0 start:0 TL:0 TR:0 A:0 B:0 X:0 Y:0 LB:0 RB:0 LT: 0 RT: 0"):

I can't really test it with my hardware, but you can give it a try.

@fsofras
Copy link
Author

fsofras commented Apr 24, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants