TT Lab
Blog

한국어 English 日本語 中文

Get started
Blog

Blog

Control: PID, feedforward, computed torque, FOC current loop and position loop layers, control period

Status: Draft (2026-10-18), Measured. Numbers are calculated using Python 3.9.6 and numpy 2.0.2 on a laptop (Apple M1 Max, macOS 26.5). Numerical simulation values. The physical constants of the joints, arms, and motors are assumed values, and nothing has been measured with actual motors and controllers (hardware unmeasured). Raw data and code: working directory measure/robot-arm-basics/of m09_control.py, out/m09_control.json. References were accessed on 2026-10-18. Writing rules: Measured data is the default, unmeasured items are marked as 「Unmeasured」, and unverified items are marked as 「Unverified」.

Table of Contents

1. Intuition: Two Ways of Following

Think of a driver following the car ahead. One driver only watches the distance to the car ahead: stepping on the pedal when it gets further and releasing it when it gets closer. They are always a step behind. The other driver looks at the brake lights and road signs to know what the car ahead will do in advance. Thus, they press the pedal before the distance opens up. The former is feedback, and the latter is feedforward.

The trajectory of the table tennis robot was already fully calculated in Part 8. Every moment, the desired position, velocity, andaccelerationare known. Therefore, there is no reason not to use feedforward. Feedback only needs to correct as much as the model is wrong. This article uses simulations to measure how large that difference is, and why the control period and the current loop inside the motor are important.

2. Diagram: Layers of Control

제어의 층: 느린 바깥 루프, 빠른 안쪽 루프 궤적 생성 q_r, q̇_r, q̈_r 위치·속도 PD + 피드포워드 1 kHz 전류 PI(FOC) i_q 목표 → 전압 30 kHz τ 인버터·모터 토크 ≈ k_t · i_q 관절·링크 J q̈ = τ − 마찰 엔코더 각·속도(1 kHz 로 읽음) 상 전류 안쪽 루프의 대역폭은 바깥 루프보다 충분히 높아야 한다. 바깥에서 보면 안쪽 루프는 「명령한 토크가 곧바로 나오는 장치」처럼 보여야 하기 때문이다. 30 kHz 는 오픈 제어기 moteus 의 기본 스위칭 주파수(위치·전류 루프 모두).
Figure: Control hierarchy leading from trajectory generation, 1 kHz position/velocity loop, 30 kHz current loop, to motors and joints

Looking at open-source motor controllers, the periods differ across layers. The documentation for moteus states that both the position loop and current loop run at the switching frequency (default 30 kHz). ODrive 0.6.12 documentation describes control loop iteration counters and assumes an 8 kHz control loop frequency. Robot controllers above that are typically much slower. The table tennis robot in Koç et al. 2018 issued commands at a 500 Hz real-time control rate, Google 2023's learning policy at 100 Hz, and Google DeepMind 2024's low-level skills at 50 Hz.

3. Calculations

3.1 PID and Feedforward

PD:            τ = K_p e + K_d ė                         e = q_r − q
PID:           τ = K_p e + K_d ė + K_i ∫e dt
PD + 앞먹임:   τ = J q̈_r + b q̇_r + τ_c sign(q̇_r)  +  K_p e + K_d ė
                   └ 역동역학(관성·점성·쿨롱 마찰) ┘    └ 되먹임 ┘

The gains were set according to the inertia J and target bandwidth ω_n: K_p = J ω_n², K_d = 2 J ω_n (critical damping). All comparisons use the same ω_n = 2π·20 Hz.

3.2 Computed Torque Control

When an arm has multiple joints, the acceleration of one joint exerts force on another (inertial coupling). Centrifugal force, Coriolis force, and gravity also vary depending on the posture. The equation of motion for the entire arm is as follows.

M(q) q̈ + C(q, q̇) q̇ + g(q) = τ

Computed torque control uses this equation directly to cancel out the couplings. Equation (11.35) in Modern Robotics is in this form, and the same book notes that K_i is often set to 0 in practice.

τ = M̃(q) (q̈_r + K_p e + K_d ė) + C̃(q, q̇) q̇ + g̃(q)          (~ 는 모델 값)

If the model is accurate, the error for each joint follows the independent second-order differential equation ë + K_d ė + K_p e = 0.

3.3 Current Loop

The q-axis current is a first-order circuit with phase resistance R and inductance L. Setting the PI gains to K_p = L ω_c and K_i = R ω_c cancels the pole of the circuit, resulting in a first-order response with bandwidth ω_c. Since digital controllers output the voltage calculated from measured currents in the next cycle , if ω_c is too high relative to the loop period, oscillations occur due to this single-cycle delay.

3.4 Simulation Setup

4. Measurement (Simulation)

4.1 Controller and Control Period

같은 이득, 다른 제어기와 주기: 최대 추종 오차 0.1 1 10 100 8.5 10 0.2 2 kHz 8.5 10 0.4 1 kHz 8.5 10 0.9 500 Hz 40 50 35 200 Hz PD PID PD + 피드포워드 최대 오차(mrad, 로그) 시뮬레이션: 관성 0.015 kg·m², 대역폭 20 Hz 이득, 한 주기 지연. 실기 미실측.
Figure: Maximum tracking error by controller and control period
Period Controller Max Error RMS Error Position Error at Strike Velocity Error at Strike
1 kHz PD 8.5 mrad 5.1 mrad 4.3 mrad −0.20 rad/s
1 kHz PID 10.3 5.1 −1.0 −0.22
1 kHz PD + Feedforward 0.42 0.28 −0.29 −0.007
2 kHz PD + Feedforward 0.21 0.14 −0.15 −0.003
500 Hz PD + Feedforward 0.86 0.46 −0.58 −0.014
200 Hz PD 39.9 17.5 −2.6 2.25
200 Hz PD + Feedforward 34.8 14.4 1.1 3.37

What happens if we increase the gains? A PD controller with ω_n doubled to 2π·40 Hz reduced the maximum error from 8.5 to 2.2 mrad at 1 kHz, but nearly diverged to 134 mrad at 200 Hz. Increasing gains in a slow loop is dangerous, and even in a fast loop, it is inferior to feedforward.

Feedforward with an inaccurate model was also measured. The maximum error for feedforward (1 kHz) with inertia underestimated or overestimated by 20% was 1.8 and 1.9 mrad. Although 4 times worse than the accurate model (0.42), it is still 4 times better than PD (8.5).

4.2 Effect of Current Loop Delay on the Position Loop

The above experiments assumed that the commanded torque was produced instantly. In reality, it takes time for the current loop to generate torque. Assuming torque is produced with a first-order delay of bandwidth f_i, the error of the 1 kHz PD + feedforward was measured again.

Current (Torque) Bandwidth Max Error RMS Error Velocity Error at Strike
No Delay 0.42 mrad 0.28 mrad −0.007 rad/s
1,000 Hz 0.46 0.31 −0.007
300 Hz 0.58 0.35 −0.009
100 Hz 0.90 0.48 −0.014
50 Hz 1.42 0.68 −0.021

When the current loop bandwidth is similar to the position loop period (1 kHz), there is almost no difference, but when it drops below 100 Hz, the error increases two- to three-fold. This numerical result embodies the principle of hierarchical control: "The inner loop must be sufficiently faster than the outer loop."

4.3 Current Loop Itself: How Fast Can It Go at 30 kHz

The q-axis current with a phase resistance of 0.2 Ω and inductance of 100 µH was step-responded to 10 A using 30 kHz PI control (voltage limit 48 V, one-cycle delay).

Target Bandwidth 10→90% Rise Time Ideal 1st-Order Response Overshoot
500 Hz 578 µs 700 µs 0%
1 kHz 212 µs 350 µs 0%
2 kHz 63 µs 175 µs 16.5%
4 kHz 30 µs 88 µs 84%
8 kHz 17 µs 44 µs 200%

When the target bandwidth exceeded 1/15th of the loop frequency (2 kHz), overshoot occurred, and at 1/4th (8 kHz), it practically oscillated. This is because the single-cycle delay (33 µs) erodes phase margin. Consequently, the practical bandwidth achievable with a 30 kHz current loop is 1 to 2 kHz, meaning the position loop above it runs at hundreds of Hz to 1 kHz, and robot policies above that run at tens to hundreds of Hz. Each layer slows down by a factor of roughly 10.

4.4 Two-Link Arm: Coupling and Gravity

Controller (1 kHz, torque limit 60 N·m) Max Error RMS Position / Velocity Error at Strike
PD 41.0 mrad 20.0 30.7 mrad / 0.95 rad/s
PD + Gravity Compensation 37.8 18.8 27.9 / 0.92
Computed Torque (Exact Model) 1.7 0.83 1.0 / 0.11
Computed Torque (Mass 20% Underestimated) 10.5 4.7 8.4 / 0.28
Computed Torque (Mass 20% Overestimated) 7.0 3.1 7.0 / 0.03

Lowering the torque limit to 30 N·m (less than the 40 N·m required by the trajectory) caused both computed torque (max error 264 mrad) and PD (218 mrad) to collapse. A controller cannot execute an impossible trajectory. When creating a trajectory (Part 8), you must first check whether the inverse dynamics torque is within limits.

5. Limitations

6. Conclusion

Titi's note. You already know where the racket is going, so why wait until an error occurs? Just generate the required force beforehand, and use feedback only to correct for the discrepancy!

References

All materials were accessed on 2026-10-18.

Sign in to like

Comments

No comments yet.

Sign in to leave a comment