3.1 KiB
FIFO priority for FRI
Why it is needed
FRI exchanges a position command on every cycle. With a 10 ms period, a new packet should be handled about every 10 ms. The regular Linux scheduler can delay the control thread behind other processes. The log then contains messages such as:
Could not enable FIFO RT scheduling: Operation not permitted
Overrun might occur ... Read time: 11500 us
SCHED_FIFO is Linux scheduling for threads with fixed priority. This project requests priority 50 for controller_manager and priority 80 for the FRI worker. The FRI worker receives the higher priority so it can receive a KUKA packet and send the reply on time.
Configure this on the ROS 2 computer that runs cobot run. It does not require changes to the Sunrise Cabinet or cobot-setting.yaml.
Ubuntu 24.04 setup
On the ROS 2 computer, run these commands as the user who starts cobot:
sudo groupadd -f realtime
sudo usermod -aG realtime "$USER"
sudo tee /etc/security/limits.d/99-ros2-realtime.conf >/dev/null <<'EOF'
@realtime soft rtprio 99
@realtime soft priority 99
@realtime soft memlock unlimited
@realtime hard rtprio 99
@realtime hard priority 99
@realtime hard memlock unlimited
EOF
Log out of the desktop session completely and log in again, or reboot. An already open terminal does not receive the new group and limits.
Verification
In a new terminal, verify the group and limits:
id -nG | tr ' ' '\n' | grep -x realtime
ulimit -r
ulimit -l
The expected output is realtime, then 99, then unlimited.
Start FRI without commanding robot motion and check the log for:
FRI worker uses FIFO priority 80
You can also inspect the policies of all threads in the process:
PID=$(pgrep -n ros2_control_node)
ps -L -p "$PID" -o pid,tid,cls,rtprio,pri,comm
Realtime threads have FF in the CLS column. The FRI worker has RTPRIO 80 and the controller_manager main loop has 50.
!!! warning "Before the first motion"
First confirm that FRI connects and that the log contains FRI worker uses FIFO priority 80. Then make a short move at speed 0.1 with an operator supervising. FIFO reduces jitter on the computer; it does not replace network checks, robot limits, or a clear work area.
If setup does not work
- If
realtimeis missing fromid, log out and log in again. - If
ulimit -ris less than 80, check/etc/security/limits.d/99-ros2-realtime.confand that PAM loadspam_limits.so. - If the log still says
Operation not permitted, make surecobot runis started by the same user passed tousermod. - A Python virtualenv needs no extra setup: permissions are assigned to the user and inherited by Python.
- Docker requires
--cap-add=sys_nice --ulimit rtprio=99 --ulimit memlock=-1.
Rollback
To remove the setup, run:
sudo rm /etc/security/limits.d/99-ros2-realtime.conf
sudo gpasswd -d "$USER" realtime
After logging in again, processes use the regular Linux scheduler.
See the official ros2_control documentation for controller-manager priorities and limits.