Skip to content

1. BIG PICTURE — WHY CONTROL LOOP EXISTS

Image

Image

Image

Image

Image

Image

Image

A machine never hits the target perfectly in one shot. There is always a gap between the setpoint (giá trị mục tiêu) and the actual position (vị trí thực tế), and that gap is called error (sai số). Even the most expensive semiconductor machine still has error because of physics, friction, delay, and noise.

Một máy không bao giờ đạt đúng mục tiêu ngay lập tức. Luôn tồn tại khoảng cách giữa setpoint (giá trị mục tiêu) và vị trí thực tế (actual position), và khoảng cách đó gọi là error (sai số). Ngay cả những máy bán dẫn đắt tiền nhất vẫn có sai số do vật lý, ma sát, độ trễ và nhiễu.

The control loop (vòng lặp điều khiển) exists to continuously reduce that error. It doesn’t try to be perfect in one move — instead, it constantly measures, corrects, and improves the system state in real time.

Vòng lặp điều khiển (control loop) tồn tại để liên tục giảm sai số đó. Nó không cố gắng đạt hoàn hảo trong một lần — mà liên tục đo, điều chỉnh và cải thiện trạng thái hệ thống theo thời gian thực.


2. BASIC CONTROL LOOP (INTUITION FIRST)

Image

Image

Image

Image

Image

Image

Image

At the simplest level, a control loop is just a repeating cycle: measure → compare → correct → repeat. This loop runs continuously, often thousands of times per second in high-precision machines.

Ở mức đơn giản nhất, một vòng lặp điều khiển là chu trình lặp lại: đo → so sánh → điều chỉnh → lặp lại. Chu trình này chạy liên tục, thường hàng nghìn lần mỗi giây trong các máy có độ chính xác cao.

A sensor (cảm biến) reads the current state (position, speed, temperature). The controller (bộ điều khiển) compares it with the setpoint and calculates the error. Then it sends a command to the actuator (cơ cấu chấp hành) to reduce that error.

Một cảm biến (sensor) đọc trạng thái hiện tại (vị trí, tốc độ, nhiệt độ). Bộ điều khiển (controller) so sánh với setpoint và tính toán sai số. Sau đó gửi lệnh tới actuator (cơ cấu chấp hành) để giảm sai số.

This loop never stops while the machine is operating. Even when the machine “looks stable,” it is still constantly correcting tiny deviations.

Vòng lặp này không bao giờ dừng khi máy đang hoạt động. Ngay cả khi máy “trông ổn định”, nó vẫn liên tục điều chỉnh những sai lệch rất nhỏ.


3. OPEN LOOP VS CLOSED LOOP

Image

Image

Image

Image

Image

Image

An open-loop system has no feedback (phản hồi). It sends commands and assumes the machine behaves exactly as expected. For example: “rotate motor 100 steps” and just trust it worked.

Hệ thống open-loop (mở) không có phản hồi (feedback). Nó gửi lệnh và giả định máy hoạt động đúng như mong đợi. Ví dụ: “quay motor 100 bước” và tin rằng nó đã thực hiện đúng.

A closed-loop system uses feedback. It continuously measures the actual result and corrects it. This is what almost all precision systems use: wafer stages, robot arms, CNC machines.

Hệ thống closed-loop (đóng) sử dụng phản hồi. Nó liên tục đo kết quả thực tế và điều chỉnh. Đây là cách mà hầu hết các hệ thống chính xác cao sử dụng: bàn wafer, robot, máy CNC.

The trade-off is simple: open-loop is simpler but inaccurate; closed-loop is more complex but much more reliable and precise.

Đánh đổi rất rõ: open-loop đơn giản nhưng không chính xác; closed-loop phức tạp hơn nhưng đáng tin cậy và chính xác hơn nhiều.


4. PID — THE MOST COMMON CONTROL METHOD

Image

Image

Image

Image

Image

Image

Image

The most common controller used in industry is PID (bộ điều khiển PID). You will see it everywhere — from temperature control to high-speed motion systems.

Bộ điều khiển phổ biến nhất trong công nghiệp là PID. Bạn sẽ thấy nó ở khắp nơi — từ điều khiển nhiệt độ đến hệ thống chuyển động tốc độ cao.

P (Proportional) reacts to the current error. If the error is large, it pushes hard. If the error is small, it pushes gently. It’s the main driving force of correction.

P (Proportional) phản ứng với sai số hiện tại. Nếu sai số lớn, nó tác động mạnh. Nếu sai số nhỏ, nó tác động nhẹ. Đây là lực chính để điều chỉnh.

I (Integral) looks at accumulated error over time. If the system is slightly off for a long time, I slowly corrects it. It eliminates steady-state error.

I (Integral) xem xét sai số tích lũy theo thời gian. Nếu hệ thống lệch nhẹ trong thời gian dài, I sẽ từ từ điều chỉnh. Nó giúp loại bỏ sai số lâu dài.

D (Derivative) reacts to how fast the error is changing. It predicts future behavior and helps prevent overshoot (vượt quá).

D (Derivative) phản ứng với tốc độ thay đổi của sai số. Nó dự đoán hành vi tương lai và giúp tránh vượt quá (overshoot).


5. REAL BEHAVIOR OF PID (VERY IMPORTANT)

Image

Image

Image

Image

Image

Image

Image

Image

In real machines, PID is not clean or perfect. You will see behaviors like overshoot (vượt quá), where the system goes beyond the target before coming back.

Trong máy thực tế, PID không hề “đẹp” hay hoàn hảo. Bạn sẽ thấy hiện tượng như overshoot (vượt quá), khi hệ thống vượt qua mục tiêu rồi mới quay lại.

Oscillation (dao động) happens when the system keeps going back and forth around the target. This usually means the controller is too aggressive.

Dao động (oscillation) xảy ra khi hệ thống liên tục qua lại quanh mục tiêu. Điều này thường nghĩa là controller quá “mạnh”.

Slow response (phản hồi chậm) happens when tuning is too conservative. The system reaches the target but takes too long.

Phản hồi chậm xảy ra khi tuning quá “an toàn”. Hệ thống vẫn đạt mục tiêu nhưng mất rất nhiều thời gian.

Worst case is instability (mất ổn định), where the system diverges and becomes uncontrollable. This is dangerous in real machines.

Trường hợp tệ nhất là mất ổn định, khi hệ thống không hội tụ mà ngày càng sai lệch. Điều này rất nguy hiểm trong máy thực tế.


6. TUNING — WHERE ENGINEERS SPEND TIME

Image

Image

Image

Image

Image

Image

Image

Tuning PID parameters is where a lot of real engineering effort goes. There is no universal formula — every machine behaves differently.

Tinh chỉnh PID là nơi kỹ sư dành rất nhiều thời gian. Không có công thức chung — mỗi máy có hành vi khác nhau.

You constantly balance trade-offs: fast vs stable, aggressive vs smooth, precise vs robust. Improving one usually makes another worse.

Bạn luôn phải cân bằng: nhanh vs ổn định, mạnh vs mượt, chính xác vs bền vững. Cải thiện một cái thường làm cái khác tệ đi.

In production, tuning is iterative: adjust → test → observe → repeat. Often done with real hardware, not simulation.

Trong thực tế, tuning là quá trình lặp: chỉnh → test → quan sát → lặp lại. Thường thực hiện trực tiếp trên phần cứng thật, không phải mô phỏng.


7. REAL-WORLD PROBLEMS

Image

Image

Image

Image

Image

Image

Image

Image

Image

Real systems are messy. Sensors have noise (nhiễu), so the feedback is not clean. The controller may react to noise and create instability.

Hệ thống thực tế rất “bẩn”. Cảm biến có nhiễu, nên phản hồi không sạch. Controller có thể phản ứng với nhiễu và gây mất ổn định.

There is always delay (độ trễ) — signal processing, communication, mechanical response. Delay makes control much harder.

Luôn có độ trễ — xử lý tín hiệu, truyền thông, phản ứng cơ khí. Độ trễ làm điều khiển khó hơn nhiều.

Mechanical issues like friction and backlash (độ rơ) create non-linear behavior. The same command may produce different results depending on direction or load.

Các vấn đề cơ khí như ma sát và độ rơ tạo ra hành vi phi tuyến. Cùng một lệnh nhưng kết quả khác nhau tùy hướng hoặc tải.

This is why perfect control is impossible. You are always managing imperfections.

Đây là lý do không thể có điều khiển hoàn hảo. Bạn luôn đang quản lý những sai lệch.


8. HOW SOFTWARE ENGINEERS SEE THIS

Image

Image

Image

Image

Image

Image

As a software engineer, you rarely write the PID algorithm from scratch — it is usually inside a controller or drive. But you interact with its behavior through data.

Là kỹ sư phần mềm, bạn hiếm khi tự viết PID — nó thường nằm trong controller hoặc drive. Nhưng bạn tương tác với nó qua dữ liệu.

You monitor position, velocity, and error. You look at trends and detect abnormal patterns like oscillation or drift.

Bạn theo dõi vị trí, tốc độ và sai số. Bạn xem biểu đồ và phát hiện các hành vi bất thường như dao động hoặc lệch dần.

Debugging is hard because problems may come from hardware, physics, or software timing — not just code.

Debug rất khó vì vấn đề có thể đến từ phần cứng, vật lý hoặc timing — không chỉ từ code.


9. SIMPLE END-TO-END EXAMPLE

Image

Image

Image

Image

Image

Image

Image

Image

Image

Imagine a command: “move to 100mm.” The motor accelerates toward the target, but due to inertia, it may overshoot to 102mm.

Hãy tưởng tượng lệnh: “di chuyển tới 100mm.” Motor tăng tốc về phía mục tiêu, nhưng do quán tính, nó có thể vượt tới 102mm.

The control loop detects the error (now negative), reverses slightly, and corrects back toward 100mm.

Vòng lặp điều khiển phát hiện sai số (lúc này là âm), đảo chiều nhẹ và điều chỉnh về 100mm.

After a few small corrections, the system stabilizes around the target within an acceptable tolerance.

Sau vài lần điều chỉnh nhỏ, hệ thống ổn định quanh mục tiêu trong phạm vi sai số cho phép.


10. HOW TO THINK ABOUT CONTROL LOOPS

There is no “done” state in control systems. The system is always adjusting, even when it looks stable.

Không có trạng thái “hoàn thành” trong hệ điều khiển. Hệ thống luôn đang điều chỉnh, ngay cả khi nhìn có vẻ ổn định.

Control is not about perfection — it is about continuous correction under imperfect conditions.

Điều khiển không phải là đạt hoàn hảo — mà là liên tục điều chỉnh trong điều kiện không hoàn hảo.

Small delays, noise, or wrong assumptions can destabilize the system. That’s why real-world control engineering is as much about handling imperfections as it is about algorithms.

Những độ trễ nhỏ, nhiễu hoặc giả định sai có thể làm hệ thống mất ổn định. Vì vậy, điều khiển trong thực tế không chỉ là thuật toán mà còn là xử lý những sai lệch.

Docs-first project memory for AI-assisted implementation.