ros-industrial / ros_canopen

CANopen driver framework for ROS (http://wiki.ros.org/ros_canopen)
GNU Lesser General Public License v3.0
344 stars 274 forks source link

Recovery from USB disconnection #467

Closed BenArtes closed 2 years ago

BenArtes commented 2 years ago

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.

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?

BenArtes commented 2 years ago

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.