# Module 4.1: Open-Loop vs. Closed-Loop Feedback

- Course: [Course 4: Feedback Control & Robot Dynamics](https://roboticsconcepts.dev/courses/feedback-control-robot-dynamics.md)
- HTML Page: https://roboticsconcepts.dev/courses/feedback-control-robot-dynamics/open-loop-vs-closed-loop-feedback/
- Key Concepts: Open-loop drift & steady-state sag, Error signals & negative feedback, Disturbance rejection

Up to now, we've treated robot motion like drawing on graph paper — ask for an angle, and the arm magically snaps there. The first time you power up real motors on a workbench, you learn fast that physics pushes back. Gravity pulls links downward, joints stick with friction, and a blind motor command almost never lands where you hoped.

## Why blind commands sag and drift

Imagine holding your foot completely steady on a car's gas pedal at 30% throttle. On flat pavement, you might cruise happily at 45 mph. Hit a steep hill, catch a headwind, or load three friends into the back seat, and your speed drops even though your foot didn't move an inch. That's open-loop control: you send a command based on a guess, and you never look at what actually happened.

A robot arm running open-loop has the exact same problem. Suppose you calculate how much motor current it takes to hold a 1 kg arm horizontal, and you send that fixed current. If someone clips a 200 g camera onto the wrist, or the gearbox warms up and loses a bit of friction, the arm quietly sags below the target. Worse, if a breeze or a light bump knocks the arm aside, an open-loop controller has no idea anything went wrong.

## Closing the loop with an error signal

Closed-loop feedback fixes this by constantly asking one simple question: where do I want to be, minus where am I right now? That difference — target minus measured position — is the error signal e(t).

Once a joint encoder tells the controller the real angle hundreds or thousands of times a second, the motor can react automatically:

- If the arm sags below the target, error becomes positive and the motor pushes harder upward.
- If the arm overshoots above the target, error flips negative and the motor pulls back.
- If someone pokes the arm mid-task (an external disturbance), the encoder spots the deviation immediately and the controller fights to reject it.

## Interactive Sandbox: Gravity-Loaded Single-Joint Arm PID Tuner

In the Gravity-Loaded PID Tuner below, start by dragging Kp, Ki, and Kd down to zero (pure open-loop with zero torque) or turning Kp way down to see the arm sag under gravity. Then bring Kp up to around 25 and toggle 'Inject disturbance poke' to watch a closed loop catch and recover from a mid-air bump.

## The stubborn catch: proportional droop

Even with feedback turned on, notice something sneaky in the plot when Gravity Compensation is off and Ki is 0: the arm climbs up toward the target, stops oscillating, and then settles noticeably below the dashed target line.

Why doesn't a simple proportional controller finish the job? Because proportional torque equals Kp times error. If the arm ever reached zero error, the motor torque would drop to zero too — and gravity would immediately yank the arm right back down. So the arm finds a compromise angle where its sag creates just enough error to hold up its own weight.

## The feedback error signal

```text
e(t) = θ_target − θ_measured(t)   →   τ_fb = f(e, ė, ∫e dt)
```

Open-loop control ignores θ_measured entirely. Closed-loop control measures the gap at every tick and turns that gap into corrective motor torque.

## Check Your Intuition

**Question:** You command an open-loop motor torque calibrated for an empty gripper, then pick up a heavy wrench without changing the command. What happens?

- [ ] The arm still hits the exact target angle because the motor torque stayed constant
- [✓] The arm sags below the target because it has no encoder feedback to notice the extra weight
- [ ] The arm oscillates violently back and forth around the target

**Explanation:** Open-loop control never checks the actual joint angle. With extra payload torque pulling down and no feedback loop increasing motor current, the arm settles lower than planned.

## Where You'll See This in Modern Robotics

Even when a learned policy runs slowly at 20–50 Hz, real robots rely on a tight inner feedback loop running at 500–2,000 Hz right at the motor drivers to track targets cleanly and reject unexpected bumps.

## Companion Python Notebook: 01 · Open-Loop vs. Closed-Loop Feedback Lab

Simulate a single-joint arm under gravity and compare blind open-loop torque commands against closed-loop feedback under payload shifts.

- Open in molab (WASM): https://molab.marimo.io/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/course-4/01_open_loop_vs_closed_loop.py/wasm
- Open in Google Colab: https://colab.research.google.com/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/colab/course-4/01_open_loop_vs_closed_loop.ipynb
- Download .py: https://roboticsconcepts.dev/downloads/notebooks/course-4/01_open_loop_vs_closed_loop.py
- Download .ipynb: https://roboticsconcepts.dev/downloads/notebooks/colab/course-4/01_open_loop_vs_closed_loop.ipynb
- Run locally: `uvx marimo edit --sandbox notebooks/course-4/01_open_loop_vs_closed_loop.py`
