Inspiration

What it does

How we built it

Challenges we ran into

Accomplishments that we're proud of

What we learned

What's next for rt-arm

Inspiration

A robot arm controller is a loop that has to run on time, every millisecond, no matter what else the computer is doing. In a surgical or collaborative robot, a late command means the arm keeps moving on stale data. I wanted to see, with numbers instead of marketing, what a real-time OS buys you when the CPU is busy, and to write it up so anyone can repeat the test for free.

What it does

rt-arm is a 1 kHz joint controller (PD + gravity compensation for 7 joints, plus a watchdog e-stop) that runs on QNX 8.0 inside QEMU and drives a simulated Franka Panda arm in MuJoCo on the host over UDP. The same C file builds for Linux, so the two can be compared side by side under the same CPU load. Scripts log every tick and turn the logs into tables and histograms.

Measured (8000 ticks each, busy laptop, logs in results/):

  • Linux, controller + 1 CPU hog on the same core, normal priority: sd 247.1 us, max 4660.5 us, 88 late ticks.
  • QNX 8.0, 2 CPU hogs at priority 10, controller also at priority 10: mean period 7097.9 us, 7999 of 8000 late.
  • QNX 8.0, same hogs, controller at priority 50: mean 1000.0 us, sd 5.9 us, max 1114.7 us, 1 late tick.
  • The run recorded live in the video: sd 10.1 us, max 1330.4 us, 4 late.
  • E-stop when the plant link drops (10 trials each): Linux 20.00/20.30/21.00 ms, QNX 20.00/20.70/21.00 ms (min/mean/max). Both meet the 20 ms watchdog because the check is time-based; QNX wins on the loop, not the e-stop.

How we built it

  • QNX side: a timer (timer_create on CLOCK_MONOTONIC) delivers a pulse to a private channel (ChannelCreate) every 1 ms; the loop blocks in MsgReceivePulse, reads the latest arm state from UDP, computes torques, sends them back, and logs the tick time. -r 50 sets SCHED_FIFO priority 50. Built with qcc from QNX SDP 8.0 (QNX Everywhere license); the QEMU image is made with mkqnximage.
  • Host side: a MuJoCo Franka Panda (MuJoCo Menagerie) steps once per command and answers with joint state.
  • Load tests: busy-loop hogs started in the guest with on -p 10, checked with pidin; on Linux a hog pinned to the controller's core with taskset.
  • Measurement: scripts/measure.py and plot_panels.py on the tick logs; estop_latency.py for the watchdog trials.
  • Built with Claude Code (an AI coding agent), directed by me: I set the goals and checks, and every number comes from logged runs produced by the scripts in the repo.

Challenges we ran into

The first version used SIGEV_PULSE_PRIO_INHERIT for the timer pulse. On QNX the thread that receives a pulse runs at the pulse's priority, so even when started with -r 50 the controller dropped to priority 10 after every MsgReceivePulse and shared round-robin with the hogs: about 7 ms periods. Setting the pulse priority explicitly (SIGEV_PULSE_INIT with pprio = the -r priority) fixed it. One argument is the difference between the prio 10 and prio 50 rows. A Linux benchmark run also silently failed once because the plant could not bind its port; the bench script now stops if a plant does not start, and both sets of files are kept in results/.

Accomplishments that we're proud of

A closed loop that holds 1 ms within a few microseconds on QNX while two CPU hogs run, measured with the same code and logs as the Linux baseline, and a README that is a full codelab from a free QNX license to the measured table.

What we learned

QNX priorities are strict and pulses carry priority. Priority inheritance through pulses is a feature, and it will quietly undo your real-time thread if you do not set it. Also: an idle QEMU vCPU adds wake-up latency through KVM, so jitter on an idle guest was higher than with low-priority load; that is a virtualisation effect, not QNX.

Honest limits

QEMU/KVM on a busy laptop, not real hardware: the point is relative behaviour, not absolute microseconds. The Linux baseline is SCHED_OTHER (no root for SCHED_FIFO / PREEMPT_RT on this machine). The plant does not model sensor latency or real arm limits.

What's next

Run the controller on a Raspberry Pi 4 with QNX 8.0 and a real servo, add slog2 logging, and test PREEMPT_RT Linux as a fairer baseline.

Credits

MuJoCo (Apache-2.0), MuJoCo Menagerie Franka Panda (Apache-2.0), QNX SDP 8.0 under the QNX Everywhere non-commercial license. Built with Claude Code (AI coding agent) directed by Ferbin Richard.

Links

Built With

  • c
  • claude-code
  • kvm
  • matplotlib
  • mujoco
  • numpy
  • python
  • qcc
  • qemu
  • qnx
  • qnx-sdp-8.0
  • udp
Share this project:

Updates

Submission history