Skip to content

udev_rules

Felix von Drigalski edited this page Nov 26, 2019 · 1 revision

Initial Setup

This tutorial is to setup persistent usb-serial names and how to make them accessible from the docker. The contents are largely based on this and that

Step 1: Check the idVendor, idProduct, and SerialNumber of each usb-serial device (to be done outside the docker)

  1. Exit the docker. (Step 1, 2, 3 are to be done in the host, outside the docker.)

  2. Unplug the usb device.

  3. Open a terminal and run the command below.

    '''shell cd /var/log/ '''

  4. Plug the usb device.

  5. Run the command below from the same terminal (from insider folder /var/log)

    '''shell gedit syslog '''

  6. Search for the latest log about a usb device being plugged in. For 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 '''

  7. Find and take note of the idVendor, idProduct, and SerialNumber. In the case above for u2d2, the result can be summarised below. Each u2d2 will have the same idVendor and idProduct, but a unique SerialNumber.

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

  8. 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 (to be done outside the docker)

  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(i.e. SerialNumber) to the ones retrieved from Step 1. Moreover, here, the persistent name is going to be set as /dev/for_docker/fastener_gripper_1. There is a need to add a subdirectory (here it is called for_docker) because we need to allow docker to have access, and we do not want docker to have full access to the /dev/ directory. Save the file.

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

  4. Unplug and plug the usb serial which name has been set. You can run the command below from a terminal to check if the persistent name is correctly set. For the name set above in this tutorial '/dev/for_docker/fastener_gripper_1', the terminal should be similar to what is shown below.

    '''shell osx@ros13:~$ ls -l /dev/for_docker/fastener_gripper_1 #the output should be similar to what is written below. lrwxrwxrwx 1 root root 10 8月 16 15:32 /dev/for_docker/fastener_gripper_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: Allow docker have access to the subdirectory (to be done outside the docker, can be skipped if the subdirectory is called for_docker, because it is already added)

  1. Open a terminal and run the command below.

    '''shell cd ~/ur_o2as/docker '''

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

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

  3. Look at the volume part. Here, assume the script below is the volume part that is written.

    '''shell volumes:

    Map ROS workspace folders.

    • ./scripts/:/root/scripts/
    • ../catkin_ws/:/root/catkin_ws/
    • /mnt/docker/share/:/root/share/
    • /mnt/docker/ur-o2as/_.ros/:/root/.ros/ '''
  4. Add '- /dev/for_docker:/dev/for_docker' to the last line. In our case, the script becomes as seen below. You can change 'for_docker' with your subdirectory name, which is defined in Step 2.

    '''shell volumes:

    Map ROS workspace folders.

    • ./scripts/:/root/scripts/
    • ../catkin_ws/:/root/catkin_ws/
    • /mnt/docker/share/:/root/share/
    • /mnt/docker/ur-o2as/_.ros/:/root/.ros/

    the line below is to add the persistent usb serial name to docker

    • /dev/for_docker:/dev/for_docker '''
  5. Save the file. Go back to the ~/ur_o2as/ directory, and run docker. '''shell cd ~/ur_o2as ./RUN_DOCKER_CONTAINER.sh '''