Chapter 3 · A clock that runs down
You will discover why a DMP keeps its own clock and how to make it run faster or slower.
Picture a robot halfway through a motion when someone gently holds its hand, then lets go. You want it to carry on from where it is, without leaping ahead to wherever the wall clock says it should be. That calls for a clock of its own, one it can read whenever it needs to know how far through the motion it has come. In this chapter we build that clock, the smallest piece of a DMP and the one everything else hangs on.1
The picture
Imagine a candle with marks painted along its side, starting tall and burning down quickly before its descent slows. In our picture, its height keeps shrinking toward the table without ever quite reaching it.
The candle’s height is the phase, written \(\kphase{x}\), a clock that runs from 1 down toward 0. At the start of the motion \(x = 1\), and by the time the motion is nearly over, \(x\) is tiny. To find your place in the movement, you read the candle.
The idea
The candle offers something the wall clock \(t\) does not: it belongs to the robot. Whenever another part of the DMP needs to know “how far along are we?”, the candle gives the answer \(x\).
You have two knobs to control this candle: \(\kphase{\alpha_x}\) sets how fast it burns, with a bigger \(\alpha_x\) giving a faster, hungrier flame. The other knob, \(\kphase{\tau}\), stretches everything in time, so doubling \(\tau\) makes the candle burn twice as slowly and the whole motion take twice as long.
Along the way, this clock brings a useful bonus: each joint of a robot can have its own spring and push while reading the same candle as all the others. Sharing the clock keeps them in step, like dancers following one drummer.
The math
Intuition: a candle that burns fast, then slow
At each moment, the candle loses a fixed fraction of its height rather than a fixed amount, which means a tall candle loses a lot and a short one loses a little. That shrinking loss is why its height slides smoothly toward zero without quite arriving.
We can capture that candle in one small equation, saying that the speed of the burn is proportional to the height still left.
The math: eq. (3)
\[ \kphase{\tau}\,\kphase{\dot x} = \underbrace{-\kphase{\alpha_x}\,\kphase{x}}_{\text{the clock runs down}} \tag{3} \]
Read aloud: the time scale \(\tau\) times the speed of the phase equals minus \(\alpha_x\) times the phase, so the taller the candle, the faster it burns down.
Once we set the starting phase to \(x(0) = 1\), the equation has a known solution that you can use without having to derive it.
The math: eq. (E1)
\[ \kphase{x(t)} = \exp\!\big(-\kphase{\alpha_x}\,t/\kphase{\tau}\big) \tag{E1} \]
Read aloud: the phase at time \(t\) is \(e\) raised to minus \(\alpha_x\) times \(t\) divided by \(\tau\), which is a smooth slide from 1 toward 0.
In the notebooks you do not run the clock from (E1); instead you step equation (3) forward in small time steps, using the explicit Euler step from chapter 2, which takes the following form when applied to the phase.
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 aloud: the new value of the state is its old value plus the time step \(\Delta t\) times its rate of change. For the clock, \(s\) is the phase \(x\) and its rate is minus \(\alpha_x\) times \(x\), divided by \(\tau\).
As you build the clock in code, the exact answer (E1) gives you a useful companion: with \(\Delta t = 0.001\) s, the stepped values should agree with it to about 0.002 all along. A larger gap tells you something in the code needs attention.
Where is the candle at the end?
When the motion reaches its end at \(t = \tau\), equation (E1) gives \(x(\tau) = e^{-\alpha_x}\), which means the candle’s remaining height depends only on \(\alpha_x\).
Follow the figure to the end of the motion, using \(\tau = 1\) s and three values of \(\alpha_x\). With \(\alpha_x = 2\) the candle still stands at about 0.14, while \(\alpha_x = 4\) leaves about 0.018 and \(\alpha_x = 8.33\) leaves about 0.0002.
The kit’s default is \(\alpha_x = 25/3 \approx 8.33\).2 With that default, the candle is almost out by the time the robot reaches the goal, letting the push fade so the spring alone can finish the job.
Try it
Try it: 01_discrete_playground.ipynb › Simulate 1.4 - Goal, start, tau and number of basis functions
Open the cell and move the slider for \(\tau\), watching the clock slow as you make it bigger and the same path take longer to finish. Move it back down and the path fits into less time, keeping its shape as the speed changes. Along the way, follow the printed line that tells you where the motion ends.
Gotcha
Gotcha: the candle burns too fast
Symptom: the path starts well, but its final stretch looks lazy or wrong. Cause: a large \(\alpha_x\) leaves \(x\) tiny long before \(t = \tau\), and the forcing term in eq. (4) is multiplied by \(x\), leaving almost no push for the last part of the motion. This trips up everyone, because a plot of \(x\) alone can still look “fine”. Fix: keep \(\alpha_x\) moderate, or give the late bumps of the forcing term larger weights, as the kit does. You can read about the effect in 10.1177/02783649231201196, section 2.1.1.3, p. 1139.