iron-ox / fadecandy_ros

ROS Driver for the fandecandy LED driver board
6 stars 6 forks source link

fix: Handle reconnections properly #17

Closed reinzor closed 3 years ago

reinzor commented 3 years ago

Release the USB device and restart the driver when an IOError has been raised while sending to the USB device. This way, we can recover from unplugging and plugging the USB device.

Resolves #16

wongkaiweng commented 3 years ago

Thanks @reinzor. We will also try it out on our end. We will update our result here soon.

wongkaiweng commented 3 years ago

We will need some more time to test the unplugging and plugging of the USB device. The node is running for us so far. Hopefully later today we will have time to do so.

reinzor commented 3 years ago

@wongkaiweng , I will test again tomorrow if I experience any issues with the reconnection and I will look into the "before first connection diagnostic issue".

reinzor commented 3 years ago

Tested the reconnection:

[INFO][/led_driver][1612258934.901630]: Connecting to Fadecandy device ..
[WARN][/led_driver][1612258934.931809]: Failed to connect to Fadecandy device: Found Fadecandy device but could not connect; will retry every second
[INFO][/led_driver][1612258936.922690]: Connected to Fadecandy device
[ERROR][/led_driver][1612259026.478644]: Failed to set colors: [Errno 5] Input/Output Error; reconnecting to device ..
[INFO][/led_driver][1612259026.480453]: Connecting to Fadecandy device ..
[WARN][/led_driver][1612259026.500137]: Failed to connect to Fadecandy device: No Fadecandy interfaces found; will retry every second
[INFO][/led_driver][1612259071.503544]: Connected to Fadecandy device

Seems to work nicely here.

reinzor commented 3 years ago

Added a commit that resolves the missing diagnostics when no connection can be set-up at start.

Could you post a log what is still going wrong at your end @wongkaiweng ?

wongkaiweng commented 3 years ago

@reinzor We also tried the PR and we got a similar log:

[/fadecandy_node] [1612296776.131896]: Connected to Fadecandy device
[33m[/fadecandy_node] [1612296957.794791]: Failed to connect to Fadecandy device: Found Fadecandy device but could not connect
[/fadecandy_node] [1612297003.431348]: Connected to Fadecandy device
[33m[/fadecandy_node] [1612300268.780480]: Failed to connect to Fadecandy device: Found Fadecandy device but could not connect
[/fadecandy_node] [1612300689.062052]: Connected to Fadecandy device
[33m[/fadecandy_node] [1612301487.367711]: Failed to connect to Fadecandy device: Found Fadecandy device but could not connect
[/fadecandy_node] [1612301561.859279]: Connected to Fadecandy device

However, we cannot control the LEDs after a reconnection. For example, we can run a blinking sequence but after unplugging and replugging, the LED does not respond to any commands on our side. We are publishing to set_leds. The way we can resolve this is by stopping and restarting the node. Did you run into a similar situation?

reinzor commented 3 years ago

Hi @wongkaiweng , tested again but it seems to work nicely here. What ROS version are you using? We are using Noetic.

wongkaiweng commented 3 years ago

@reinzor Interesting, we are using melodic. I wonder why that would be the case. Let me see if I can create a standalone test. We have been testing with some other things running. Let me make sure it's not some other bugs on our side.

wongkaiweng commented 3 years ago

@reinzor Just want to give you a quick update. We will be able to do our testing again on Tuesday and I will get back to you once I have the result.

wongkaiweng commented 3 years ago

@reinzor Just another update. We did a test but it wasn't properly configured. We have to wait for another chance on our side to redo the test. Sorry for the delay. It may take another week.

reinzor commented 3 years ago

Thanks for keeping me in the loop!

wongkaiweng commented 3 years ago

@reinzor I tested this out again on our end. Here are my findings: 1.This fix would allow reconnection if we unplug and replug the fadecandy.

  1. This fix does not fix the problem in which our fadecandy reconnects only on restarting the node if the first try failed.

Since this PR is to solve 1., this is good to go. Thank you for making the fix. I will open another issue for the second one.

wongkaiweng commented 3 years ago

@reinzor I will leave this to you and let you merge the PR :).