Chapter 2 · The spring that always gets home
You will see why a robot glides home without wobbling, and how three knobs shape its arrival.
Your robot arm is holding a pose when you give its hand a push and let go. The hand glides home and stops, without wobbling, bouncing or creeping toward its destination. That neat homecoming comes from the part of a DMP we will meet in this chapter: a spring with a brake.
The picture
Think of the little arm at the top of a heavy door, drawing it shut after you walk through. Inside that door closer, a spring pulls while a damper, a piston full of oil, slows the movement. Without the spring the door would hang open; without the damper it would slam, bounce back and rattle in its frame.
Carry that picture over to the robot hand: the “door” is its position \(\krepro{y}\), and “shut” is the goal \(\kgoal{g}\). As a spring pulls \(\krepro{y}\) toward \(\kgoal{g}\), a damper fights the speed and softens the arrival.
The idea
As the hand travels home, the spring’s pull changes with the distance still to go: strong far away, gentle close by, and zero at the goal. The damper responds to speed instead, braking hard when the hand moves quickly and offering no brake when it stands still.
Working together, they let the hand start quickly, slow as it nears the goal, and settle into place. How much brake you add decides the style of that arrival.
- With too little brake, called under-damped, the hand overshoots the goal, swings back, and rings like a diving board.
- With just enough brake, called critically damped, the hand slides into place and stops without overshooting.
- With too much brake, called over-damped, the hand creeps toward the goal and takes a very long time to arrive.
Drag \(\beta_z\) (the spring’s stiffness is \(\alpha_z\beta_z\)) and watch the spring alone: at 6.25 the path slides into the goal, above that it overshoots and rings, and below it creeps.
The math
Intuition: a spring with a brake
Imagine the spring saying “go to the goal, harder when far”, while the damper answers “slow down, harder when fast”. Critical damping is the balance that lets the hand arrive as fast as it can without crossing the goal.
In Chapter 1, you met the full DMP, with a push \(\kforce{f(x)}\) on top of the spring. For now we switch that push off, setting \(f = 0\), so we can watch the spring and damper on their own. Together they form the spring–damper term, the middle piece of eq. (1), and the robot’s state is described by two numbers: position \(\krepro{y}\) and an auxiliary variable \(\krepro{z}\).
The math: eq. (1)–(2)
\[ \kphase{\tau}\,\krepro{\dot z} = \underbrace{\kspring{\alpha_z\big(\beta_z(\kgoal{g} - \krepro{y}) - \krepro{z}\big)}}_{\text{spring–damper term}} + \underbrace{\kforce{f(x)}}_{\text{forcing term}} \tag{1} \]
Read it aloud: the clock-scaled rate of change of \(z\) equals the spring pull toward the goal, minus the damper brake on \(z\), plus the forcing push (which is zero in this chapter).
\[ \kphase{\tau}\,\krepro{\dot y} = \krepro{z} \tag{2} \]
Read it aloud: the clock-scaled rate of change of the position is \(z\), so \(z\) is the speed, scaled by \(\kphase{\tau}\).
To get a feel for \(z\), look back at equation (2), where \(z\) is the speed multiplied by \(\tau\). That is why you will often hear \(z\) called the scaled velocity.
The math: eq. (E2)
\[ \krepro{z} = \kphase{\tau}\,\krepro{\dot y} \quad\text{(discrete)}, \qquad \krepro{z} = \frac{\krepro{\dot y}}{\kphase{\Omega}} \quad\text{(periodic)} \tag{E2} \]
Read it aloud: \(z\) is just \(\tau\) times the speed of the hand.
We can find the right amount of brake by multiplying out the spring–damper term of eq. (1). The pull toward the goal carries the factor \(\alpha_z \beta_z\), the spring’s stiffness, while the brake on \(z\) carries \(\alpha_z\), the damper’s strength. This means that changing \(\alpha_z\) changes both spring and damper, whereas changing \(\beta_z\) changes only the spring. To get the critically damped balance, the two gains must satisfy \(\alpha_z = 4\beta_z\). The kit achieves this with defaults \(\alpha_z = 25\) and \(\beta_z = 6.25\), or \(25/4\).1
Follow the hand through the three-panel plot, where \(\alpha_z\) stays at 25, keeping the damper the same while only the spring changes. In the top panel, \(\beta_z = 25\) is four times the balanced value \(\alpha_z/4\), making the spring too stiff for the damper, so the hand overshoots and rings. In the bottom panel, \(\beta_z = 1\) makes the spring so soft that the damper wins, leaving the path short of the goal after 3 seconds.
Now imagine turning a slow-motion knob: that is the parameter \(\kphase{\tau}\). Double \(\tau\) and the same path takes twice as long; halve it and the robot moves twice as fast, keeping the shape of its motion throughout.
Intuition: a computer takes small steps
A computer follows the smooth motion by taking tiny steps in time, asking at each one, “how fast is this value changing right now?” It then moves a little in that direction, building the path step by step.
The math: eq. (E4)
\[ s(t + \Delta t) = s(t) + \Delta t\cdot \dot s(t), \qquad s \in \{y, z, x, \phi\} \tag{E4} \]
Read it aloud: the new value equals the old value plus the time step \(\Delta t\) times the current rate of change.
This way of advancing the motion is called the explicit Euler step: first use (1) and (2) to find the rates of change of \(z\) and \(y\), then apply the step above to both. In the figures and most notebook cells, \(\Delta t = 0.001\) s makes one second of motion into 1,000 steps. You can follow every one of them in the kit’s loop, written out in plain NumPy.
Try it
Try it: 03_create_your_own.ipynb › Create 3.6 - Break it
Start with BREAK = dict(beta_z_run=6.25) and run the cell to watch the replay follow the demonstration at the balanced value it learned with. The printed overshoot is a fraction of the trip: 0.0079, below 1 %, and that small step past the goal is already in the demonstration.
Then try 25, followed by 100, and watch the hand’s arrival change. At 25 the overshoot grows only a little, to 0.0108, but at 100 it reaches 0.3945: about 40 % past the goal. The weights stay the same throughout; only \(\beta_z\) changes, making the spring stiffer while the damper stays the same.
Gotcha
Gotcha: break the 4-to-1 balance and the robot overshoots
Symptom: the hand swings past the goal and comes back, perhaps making the trip more than once. Cause: \(\beta_z\) is larger than \(\alpha_z/4\), giving the spring more strength than the damper can handle. This trips up everyone, because a bigger number can feel like “more precise”. Fix: keep \(\alpha_z = 4\beta_z\) after learning, and remember that on a real robot an overshoot can mean hitting the shelf.