Skip to content
JohanneLun edited this page Jan 30, 2020 · 11 revisions

General

This page is about the udev rules on the cyborg. They bind spesific USB-ports or hardware characteristics to static names, so that you won't have to look for the right usb connection in the /dev folder, but rather just use the designated name.

The designated names are:

  • Led Dome: led_dome
  • Mode Selector Box: mode_selector_box
  • Zed Camera: zed_camera

Take a look at the file CyborgUsbRules in the CyborgRobotInfo folder in the workspace for what the rules are. You can copy them into a new rule file (with the name below) if you need them on your computer, and don't need to add new rules. Have a look at this website for more information about writing udev rules: http://www.reactivated.net/writing_udev_rules.html. In this ( <-- the linked website) they use udevinfo which doesn't exist anymore, use udevadm info instead as the commands below use. The same goes for udevtriggerand udevcontrol.

Remember to change the rules if any of the components are changed, and add any changes to the rule file in the catkin_ws/CyborgRobotInfo/CyborgUsbRules.txt file.

The udev rule file should be named: 90_cyborg_usb_rules.rules

Setting up the existing rules on a new or reset computer

Assuming the CyborgUsbRules file is up-to-date, copy all the rules from that file. Create a new file called 90_cyborg_usb_rules.rules and save it in the /etc/udev/rules.d/ directory. Then do point 4 below to update and confirm that the rules work.

Creating a new rule

  1. Plug in your device and find out what port its connected to. Depending on what it is, it might be ttyUSB* or video*, or something else.
  2. Get udev info about each device by running the commands below. The output from the first should look something like this /devices/platform/tegra-xhci/usb1/1-3/1-3.3/1-3.3:1.0/tty/ttyUSB0. Use that as the path in the second command.

$ udevadm info -n /dev/<your-device>

$ udevadm info -a -p /path/from/previous/step

  1. Read through the attributes, the output of the second command, to find some that are unique for that device. Be sure to choose attributes that are distinct for each thing you make a rule for and keep in mind that you can only combine attributes from the device and a single parent device, and not mix-and-match from multiple parent devices. Also, rules cannot span several lines in the rule-file. Write your chosen attributes, the chosen name, any owner groups, etc. into the udev rule file which needs to be saved in /etc/udev/rules.d/ folder. See examples of rules below.

  2. Close and save the file, and update the udev rules to activate them using the commands below. To check that everything works, use ls -ltrh /dev/<symlink_name>. You should now see that it links to the port it's connected to.

$ sudo udevadm control --reload

$ sudo udevadm trigger

Possible Errors

If you encounter a "permission denied" error when using the rules, it might be because one or several have been bound to an event instead of the usbport. To check the rule in /dev write ls -l <rulename> and see what it points to. If it is a ttyUSB* then it should be working, otherwise it might be pointing to and event. In the event case try:

  • Write sudp rm <rulename> to delete the rule from /dev and then reload the rules using sudo udevadm control --reload, and then sudo udevadm trigger, in that order. This should add the rule to /dev again. Check it again to see if it's working.

Another reason for "permission denied" might be that you are not added to the dialout group. To add your user, run the command sudo usermod -a -G dialout <user>. For this change to take effect you need to log out and in from your computer.

Rule Examples

ATTRS{idProduct}=="62f0", KERNELS=="1-3.4", SYMLINK+="camera_drive"

ATTRS{idProduct}=="6001", KERNELS=="1-2.3", SYMLINK+="sensor_imu_sbg"

KERNEL=="video*", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="62f0", GROUP=="video", SYMLINK+="camera_drive"

ATTRS{idProduct}=="0043", GROUP=="dialout", SYMLINK+="arduino_uno"

KERNEL=="js*", ENV{ID_VENDOR}=="Sony", ENV{ID_MODEL}=="PLAYSTATION_R_3_Controller", NAME="ps3joy", SYMLINK+="ps3joy"