Boomaa23 / open-ds

A reverse-engineered lightweight cross-platform FRC Driver Station
https://boomaa23.github.io/open-ds/
Other
42 stars 8 forks source link

Index Out of Bounds Exception Preventing Control #6

Closed IsaacIngram closed 2 years ago

IsaacIngram commented 2 years ago

I am able to connect to my robot over WiFi. I am on the correct network and I have my correct team number in the team number box. I can see the voltage oscillating, but as soon as I click the enable box I receive the following error:

Exception in thread "rioTcp" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at com.boomaa.opends.usb.HIDDevice.getAxis(HIDDevice.java:95)
    at com.boomaa.opends.data.send.SendTag.lambda$static$3(SendTag.java:87)
    at com.boomaa.opends.data.send.SendTag.getBytes(SendTag.java:357)
    at com.boomaa.opends.data.send.creator.Creator2020.dsToRioTcp(Creator2020.java:59)
    at com.boomaa.opends.display.DisplayEndpoint$1.onCycle(DisplayEndpoint.java:51)
    at com.boomaa.opends.util.Clock.run(Clock.java:32)
Exception in thread "rioUdp" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at com.boomaa.opends.usb.HIDDevice.getAxis(HIDDevice.java:95)
    at com.boomaa.opends.data.send.SendTag.lambda$static$0(SendTag.java:40)
    at com.boomaa.opends.data.send.SendTag.getBytes(SendTag.java:357)
    at com.boomaa.opends.data.send.creator.Creator2020.dsToRioUdp(Creator2020.java:48)
    at com.boomaa.opends.display.DisplayEndpoint$2.onCycle(DisplayEndpoint.java:71)
    at com.boomaa.opends.util.Clock.run(Clock.java:32)

This causes the driver station to disconnect from the robot. Both my Radio and Rio have been flashed with the latest version and my radio is configured with the correct team number.

Boomaa23 commented 2 years ago

Do you have any USB devices plugged in? Also what OS (+version) are you using?

IsaacIngram commented 2 years ago

I am using MacOS 12.0.1. I do not have any USB devices plugged in since my team uses Xbox Controllers and Mac doesn't have drivers for it. I have used the Bluetooth functionality of the Xbox Controllers to control a robot simulation, but a controller connected via Bluetooth doesn't appear to work with OpenDS. I suppose that's something for another issue.

Because I couldn't get an Xbox Controller to work with OpenDS, I selected my Mac's trackpad as the USB device to use. Doing this procuced some different errors:

java.net.UnknownHostException: github.com
    at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:567)
    at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:333)
    at java.base/java.net.Socket.connect(Socket.java:648)
    at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:290)
    at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
    at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
    at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:177)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1194)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1082)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:163)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1595)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1523)
    at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:308)
    at com.boomaa.opends.display.DisplayEndpoint.checkForUpdates(DisplayEndpoint.java:191)
    at com.boomaa.opends.display.DisplayEndpoint.main(DisplayEndpoint.java:146)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: arraycopy: source index -1 out of bounds for object array[10]
    at java.base/java.lang.System.arraycopy(Native Method)
    at java.base/java.util.Vector.insertElementAt(Vector.java:596)
    at java.desktop/javax.swing.DefaultListModel.add(DefaultListModel.java:469)
    at com.boomaa.opends.usb.ControlDevices.findAll(ControlDevices.java:35)
    at com.boomaa.opends.display.DisplayEndpoint.main(DisplayEndpoint.java:152)
Exception in thread "rioTcp" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
    at com.boomaa.opends.usb.HIDDevice.getAxis(HIDDevice.java:95)
    at com.boomaa.opends.data.send.SendTag.lambda$static$3(SendTag.java:87)
    at com.boomaa.opends.data.send.SendTag.getBytes(SendTag.java:357)
    at com.boomaa.opends.data.send.creator.Creator2020.dsToRioTcp(Creator2020.java:59)
    at com.boomaa.opends.display.DisplayEndpoint$1.onCycle(DisplayEndpoint.java:51)
    at com.boomaa.opends.util.Clock.run(Clock.java:32)

It is worth noting that I am connecting to my robot over WiFi rather than over Ethernet.

IsaacIngram commented 2 years ago

To clarify the above, the original log output was posted without any USB devices connected. The log posted above is with the Trackpad/Keyboard set as a USB device using the "auto" feature.

Boomaa23 commented 2 years ago

Hmm okay MacOS is a bit tricky for me since I don't have regular access to a testing computer. I believe this is a similar issue to #5 though. I made a workaround to have that work but there might be some C driver issues with that. I'll look into it but it might be a while.

The UnknownHostException thing is a different issue that I can fix and commit ASAP!

Bluetooth support...yeah that might be a very long time. But I can work on it if there's enough demand. Another issue would be a good idea.

EDIT: okay so the trackpad being a joystick will 100% not work IIRC due to it not having "axes" or something like that. Try with a normal joystick over USB if you can.

IsaacIngram commented 2 years ago

That's alright. FIRST supports Windows pretty much exclusively and I'm sure for good reason. I assume the UnknownHostException is the culprit of the connection dropping out, and that's the reason for this particular issue.

I tried to use Logitech Extreme 3D Pro joystick instead of the keyboard and trackpad. My steps for doing so were as follows:

  1. Connect to the robot over WiFi
  2. Enter the team number to actually connect to the robot At this point I could see that I was connected to the robot and the voltage displayed on the driver station was fluctuating.
  3. Open the joystick menu and plug in the Logitech Extreme 3D Pro controller.

The controller briefly showed up in the list of Joysticks but went away as soon as I interacted with the UI. I tried using another Joystick of the same type and the issue still occurred. The errors can be found here.

My assumption is that there is a lack of drivers on MacOS, but I haven't done the research to be sure.

I'll open another issue for Bluetooth support, but that's more of a feature request than an actual issue.

Boomaa23 commented 2 years ago

Hi @IsaacIngram! Apologies for the long wait. I've patched the problem which had to do with not filtering out generic input devices (i.e. the keyboard) and incorrectly treating those devices as gamepads/joysticks with axes. You should be able to use any joystick/gamepad input device (including over bluetooth, I tested that too). Commit that fixes this is 4d5c2a99c0eec30f76b1372631461b8de20c4e81.

Please let me know if this works for you. I will close this issue now as the bug has been resolved.

IsaacIngram commented 2 years ago

No problem, thanks for patching! I don't have easy access to a robot now that the season is over but once I do have access I'll give it a go and let you know if it works.