Skip to content

udev rules

Felix von Drigalski edited this page Oct 1, 2021 · 1 revision

Initial Setup

This tutorial helps to set up persistent usb-serial names and make them accessible from the docker container. Based on this and this.

Step 1: Check the idVendor, idProduct, and SerialNumber of each usb-serial device (on the host PC)

  1. Exit the docker container. (Step 1, 2, 3 are performed on the host, outside the docker container.)

  2. Unplug the usb device and plug it back in.

  3. Run the command below (from insider folder /var/log)

    '''shell gedit /var/log/syslog '''

  4. Search for the latest log about a usb device being plugged in. For a u2d2, it should be similar to what is shown below.

    '''shell Aug 16 13:56:03 ros13 kernel: [359480.600215] usb 1-10: New USB device found, idVendor=0403, idProduct=6014 Aug 16 13:56:03 ros13 kernel: [359480.600221] usb 1-10: New USB device strings: Mfr=1, Product=2, SerialNumber=3 Aug 16 13:56:03 ros13 kernel: [359480.600226] usb 1-10: Product: USB <-> Serial Converter Aug 16 13:56:03 ros13 kernel: [359480.600230] usb 1-10: Manufacturer: FTDI Aug 16 13:56:03 ros13 kernel: [359480.600233] usb 1-10: SerialNumber: FT1YCHUH Aug 16 13:56:03 ros13 kernel: [359480.603487] ftdi_sio 1-10:1.0: FTDI USB Serial Device converter detected Aug 16 13:56:03 ros13 kernel: [359480.603572] usb 1-10: Detected FT232H Aug 16 13:56:03 ros13 kernel: [359480.603862] usb 1-10: FTDI USB Serial Device converter now attached to ttyUSB0 Aug 16 13:56:03 ros13 mtp-probe: checking bus 1, device 18: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-10" Aug 16 13:56:03 ros13 mtp-probe: bus: 1, device: 18 was not an MTP device '''

  5. Find and take note of the idVendor, idProduct, and SerialNumber. In the case of the u2d2, the result is as below. Each u2d2 will have the same idVendor and idProduct, but a unique SerialNumber.

    '''shell idVendor=0403 idProduct=6014 SerialNumber=FT1YCHUH '''

  6. If there is no need to search for idVendor and idProduct (for multiple u2d2, for example), we can find the Serial number using the command below. (Here, we assume the name to be /dev/ttyUSB0

    '''shell udevadm info -a -n /dev/ttyUSB0 | grep '{serial}' | head -n1

    #The output for the device above will be as follows. ATTRS{serial}=="FT1YCHUH" '''

Step 2: Make a .rules file to specify a persistent name for each usb-serial device (on the host PC)

  1. Open a terminal and run the command below.

    '''shell cd /etc/udev/rules.d '''

  2. Run this command from the same terminal. This will create a .rules file named 99-usb-serial.rules '''shell sudo gedit 99-usb-serial.rules '''

  3. From inside gedit, copy and paste the command below. Change the content of the idVendor, idProduct, and serial(SerialNumber) to the ones retrieved from Step 1. The persistent name is set to /dev/for_docker/tool_1 , because we only give the Docker container access to a subdirectory, not the whole /dev directory. Save the file.

    '''shell SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6014", ATTRS{serial}=="FT1YCHUH", SYMLINK+="for_docker/tool_1" '''

  4. Unplug and plug the usb serial device for which the name has been set. Run the command below from a terminal to check if the persistent name is correctly set. For the name used above (/dev/for_docker/tool_1), the terminal should look like this:

    '''shell osx@ros13:~$ ls -l /dev/for_docker/tool_1 #the output should be similar to what is written below. lrwxrwxrwx 1 root root 10 8月 16 15:32 /dev/for_docker/tool_1 -> ../ttyUSB0

    #we can also call the /dev/ttyUSB0 directly. osx@ros13:~$ ls -l /dev/ttyUSB0 #the output should be similar to the line below. crw-rw---- 1 root dialout 188, 0 8月 16 15:32 /dev/ttyUSB0

    '''

Step 3: OPTIONAL: Allow docker have access to the subdirectory (on the host PC) (Skip if you are using the for_docker subdirectory)

  1. Open a terminal and run the command below.

    '''shell cd ~/o2ac-ur/docker '''

  2. Run the following terminal to open docker-compose.yml

    '''shell gedit docker-compose.yml '''

  3. Add '- /dev/for_docker:/dev/for_docker' to the volumes entry:

    '''shell volumes:

    Give access to persistent USB interfaces

    • /dev/for_docker:/dev/for_docker '''
  4. Save the file. Go back to the ~/o2ac-ur/ directory, and run docker. '''shell cd ~/o2ac-ur ./RUN-DOCKER-CONTAINER.sh '''