I’ve yet to see a software stack for a mobile robot that does not support teleoperation. Game-controller-based interfaces are ubiquitous, but I’ve also seen teleoperation implemented via mouse/GUI or even as simply as with a keyboard.
Usually, the presence of an input device is verified at system startup. If no input device is found, the teleop driver node typically exits with an error. More sophisticated implementations print a warning and keep running, albeit without teleoperation support. This concept is known as graceful degradation.
In this article, however, I’d like to suggest a different approach. Users can’t always be bothered to keep the input device connected to the computer running the teleoperation code. In all likelihood, the input device is only plugged in when the robot is stuck in a situation it cannot get itself out of.

Restarting the whole software stack, or even just the parts related to teleoperation, is an unnecessary chore. It makes much more sense to receive a notification when a new input device is added, then open that device and stream its data via ROS. Throughout this article I’ll assume the input device is a joystick that shows up as /dev/input/js0 when connected.
libudev allows monitoring hardware events on Linux. First, we set up a monitor that listens for device events of the input subsystem:
| |
Next, a dedicated thread continuously polls the monitor’s file descriptor to check whether a device event has occurred:
| |
If an event for the input subsystem is pending, rc is greater than 0. By inspecting the event’s action and devnode properties, we can determine whether our desired input device has been added:
| |
To use libudev in your ROS package, add the following lines to your CMakeLists.txt:
| |
The same mechanism can be extended to detect when the input device is unplugged during operation (action equals "remove"). The teleop node can then close the device and wait for it to reappear, degrading gracefully instead of crashing.
PS: Don’t forget to free allocated resources ;) :
| |
