ros-industrial/ros_canopen

Recovery from USB disconnection

BenArtes opened this issue · 1 comments

We're using socketcan_interface for communicating with CAN devices. Due to some electrical issues power / USB connections have dropped out and communications fail. Obviously we're investigating the hardware issues causing this, but I attempted to add automated software recovery.

  • Made sure that Linux was configured for hotplug functionality and automatically configuring / bringing up the CAN interfaces
  • Tried to driver->recover

The recover call seems to hang. I'm investigating the cause, but is there a suggested way of handling disconnection / re-connection of a CAN interface?

Just got back to working on this.

The direct cause of the lockup I was experiencing was that I was calling driver_->recover() from within the stateCallback. This locked up the thread while it waited for itself to release the state mutex.

After the driver would 'recover', but it wouldn't receive any new messages. I believe this is because I was using the ThreadedSocketCANInterface which was missing an overridden 'recover' method to restart the run_thread. I applied the modifications in #469 which resolved my issues.