11.5. Raspberry Pi Setup

Section author: Lennart Alff <thies.lennart.alff@tuhh.de>

11.5.1. Requirements

  • Raspberry Pi 4 (previous versions do not have enough UART devices!)

  • Ubuntu 22.04 Server image installed on Raspberry Pi

  • A ROS installation, no GUI dependencies, so the ros-iron-ros-base would suffice.

11.5.2. Enable UART

Modify the usercfg.txt, either pre-boot directly on the /boot partition or from the running Raspberry Pi in the /boot/firmware directory, and add the following lines:

dtoverlay=uart3
dtoverlay=uart4
dtoverlay=uart5

11.5.3. UDEV Rules

The Raspberry Pi uses its UARTs to communicate with the Faulhaber motors. The name of the UART ports depend on the number of activated UART devices on the dtoverlay. So it is hard to identify which of the /dev/ttyAMAn devices corresponds to which physical UART device.

To simplify things you can add UDEV rules.

Executing

$ udevadm info --name=/dev/ttyAMA2 --attribute-walk

produces the following output:

 1looking at device '/devices/platform/soc/fe201800.serial/tty/ttyAMA2':
 2  KERNEL=="ttyAMA2"
 3  SUBSYSTEM=="tty"
 4  DRIVER==""
 5
 6looking at parent device '/devices/ platform/soc/fe201800.serial':
 7  KERNELS=="fe201800.serial"
 8  SUBSYSTEMS=="amba"
 9  DRIVERS=="uart-pl011"
10  ATTRS{driver_override}=="(null)"
11  ATTRS{id}=="00241011"
12  ATTRS{irq0}=="14"
13
14looking at parent device '/devices/ platform/soc':
15  KERNELS=="soc"
16  SUBSYSTEMS=="platform"
17  DRIVERS==""
18  ATTRS{driver_override}=="(null)"
19
20looking at parent device '/devices/ platform':
21  KERNELS=="platform"
22  SUBSYSTEMS==""
23  DRIVERS==""

The identifier of the physical interface is defined by line 7 KERNELS=="fe201800.serial".

Since the value is defined in the parent device, you can not apply the UDEV rule to the /dev/ttyAMAn device, but you have to use an environment variable.

Note

In case the string for KERNELS changes in the future, please change the value for the following UDEV rule in the following part!

  • Motor X-Axis

    UART3

    Tx/Rx <-> GPIO4/GPIO5 (KERNELS=="fe201600.serial")
    
  • Motor Y-Axis

    UART4

    Tx/Rx <-> GPIO8/GPIO9 (KERNELS=="fe201800.serial")
    
  • Motor Z-Axis

    UART5

    Tx/Rx <-> GPIO12/GPIO13 (KERNELS=="fe201a00.serial")
    

The resulting UDEV rule in /etc/udev/rules.d/50-serial.rules is:

1KERNEL=="ttyAMA[0-9]*", GROUP="dialout", ENV{MOTOR_SERIAL}="motor_serial"
2
3ENV{MOTOR_SERIAL}=="motor_serial",  SUBSYSTEM=="tty", KERNELS=="fe201600.serial", SYMLINK+="motor_x"
4ENV{MOTOR_SERIAL}=="motor_serial",  SUBSYSTEM=="tty", KERNELS=="fe201800.serial", SYMLINK+="motor_y"
5ENV{MOTOR_SERIAL}=="motor_serial",  SUBSYSTEM=="tty", KERNELS=="fe201a00.serial", SYMLINK+="motor_z"

You can apply these changes by

$ sudo udevadm control --reload-rules && sudo udevadm trigger

To check, that the rule is applied correctly, you can execute

$ ls /dev/motor* -l

The output should show symbolic links for the three motor axes.

lrwxrwxrwx 1 root root 7 Aug  7 01:00 /dev/motor_x -> ttyAMA2
lrwxrwxrwx 1 root root 7 Aug  7 01:00 /dev/motor_y -> ttyAMA3
lrwxrwxrwx 1 root root 7 Aug  7 01:00 /dev/motor_z -> ttyAMA4

Note

The ttyAMA numbers might differ.