About udev rules while using ROS and robotic platforms
Disclaimer: This is not a tutorial or guide on using and configuring udev rules for robotic platforms but rather a collection of useful links about it.
Why
Robotic platforms use a myriad of sensors nowadays. While one can plug the sensor into a robotic platform and, with the right configurations, receive data from, let's say, ttyUSB0. In the long term, the maintenance of the robotic platform and the code to read the sensor's data can become at least dramatic. Even more, if you want to reuse the same code between different platforms that share the same set of sensors.
This is where udev rules become handy in managing sensor connections allowing to define a “name” to the port where the sensor is plugged. By doing it, we can share the same code and port configurations in multiple robots. We just need to worry about naming consistency in udev rules. Also, instead of ttyUSB0, the name robot/sensor_whatever is much more convenient, for example.
Get info about a device/sensor
udevadm info -a -p $(udevadm info -q path -n <devpath>)
or
udevadm info --name=<devpath> --attribute-walkwhere devpath can be
/dev/ttyS1 or /dev/ttyUSB0 ...
sources here and here
udev rules folder
/etc/udev/rules.d/
Udev rules USB
See this USB serial example and complement it with the info from the following link; this saved me. Otherwise, it won’t work; another example.
Good-Tutorials
General udev rules examples
A robot udev example
# Serial ports
KERNEL=="ttyS1", SYMLINK+="robot/gps"
KERNEL=="ttyS2", SYMLINK+="robot/altimeter"
KERNEL=="ttyS3", SYMLINK+="robot/bms"# USB ports
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{serial}=="Z80426TH", MODE="0666", SYMLINK+="robot/bluetooth"
SUBSYSTEM=="tty", SUBSYSTEMS=="usb", DRIVERS=="usb", ATTRS{serial}=="NG21J03K", MODE="0666", SYMLINK+="robot/imu"SUBSYSTEMS=="usb", ATTRS{idVendor}=="r2j5", ATTRS{idProduct}=="0406", SYMLINK+="robot/thrusters_usb", GROUP="dialout", MODE="777"
Reload udev rules
sudo udevadm control --reload-rules && sudo service udev restart && sudo udevadm trigger