0.4 Optimize for Gas, Time, and Comfort

0.2 optimized time. 0.3 optimized gas. Real deliveries care about both — and about whether the ride feels like a roller coaster. That third score is comfort, and it starts with jerk.

What is jerk?

Acceleration aa is how fast velocity changes. Jerk jj is how fast acceleration changes:

j=a˙=dadt=d3xdt3.j = \dot{a} = \frac{\mathrm{d}a}{\mathrm{d}t} = \frac{\mathrm{d}^{3}x}{\mathrm{d}t^{3}}.

Units are m/s³. In the bang-bang plans of 0.2–0.3, force (and aa) jumped instantly between levels. That is an infinite spike of jerk at each switch — fine for a math toy, rough on a pizza and a neck.

Here the vehicle still obeys mx¨=Fm\ddot{x} = F with a=F/ma = F/m, but aa may only slew toward a commanded value at a limited rate ∣j∣≤jmax⁡|j| \le j_{\max}. Soft jmax⁡j_{\max} means gentle ramps of aa; large jmax⁡j_{\max} recovers nearly bang-bang.

Comfort as peak |jerk|

Many comfort metrics exist (∫j2 dt\int j^{2}\,\mathrm{d}t, ride indices, …). We use a simple one that matches the hardware knob:

Jpeak=max⁡t ∣j(t)∣.J_{\mathrm{peak}} = \max_{t}\,\lvert j(t)\rvert.

If the plan never asks for more than jmax⁡j_{\max}, then Jpeak≤jmax⁡J_{\mathrm{peak}} \le j_{\max}. Lower jmax⁡j_{\max} → lower peak jerk → more comfortable (and usually slower).

A three-term cost with equal weights

Time TT, gas G=∫0T∣F∣ dtG = \int_0^{T}\lvert F\rvert\,\mathrm{d}t, and comfort JpeakJ_{\mathrm{peak}} have different units. You cannot literally add seconds to newton-seconds to m/s³. So we normalize each term by a fixed reference, then sum with equal weights wT=wG=wC=1w_T = w_G = w_C = 1:

J=wT TTref+wG GGref+wC JpeakJref=TTref+GGref+JpeakJref.\mathcal{J} = w_T\,\frac{T}{T_{\mathrm{ref}}} + w_G\,\frac{G}{G_{\mathrm{ref}}} + w_C\,\frac{J_{\mathrm{peak}}}{J_{\mathrm{ref}}} = \frac{T}{T_{\mathrm{ref}}} + \frac{G}{G_{\mathrm{ref}}} + \frac{J_{\mathrm{peak}}}{J_{\mathrm{ref}}}.

The references (TrefT_{\mathrm{ref}}, GrefG_{\mathrm{ref}}, JrefJ_{\mathrm{ref}}) are constants shown in the playground — yardsticks so a “1” means “about as bad as a harsh baseline on that axis.” Changing the references would change the trade-off; keeping weights equal and refs fixed makes comparisons fair across presets.

Still the same door constraints:

x(T)=D,v(T)=0,a(T)=0.x(T) = D, \qquad v(T) = 0, \qquad a(T) = 0.

Try it

Compare Harsh, Balanced, Comfort, and Sip gas + soft. Read the three normalized terms and the total J\mathcal{J}. Open Data for aa, jj, vv, xx, and the running cost.

Playground — time + gas + comfort (peak |jerk|), equal weights after normalizing
Time T
0.00 s → T/T_ref = 0.00
Gas G = ∫|F| dt
0 → G/G_ref = 0.00
Comfort (peak |j|)
0.00 m/s³ → J_peak/J_ref = 0.00
Total cost J
0.00 = sum of the three (equal weights)

Acceleration slews toward ±F/m at |j| ≤ j_max. Soft jerk = comfort; watch the cost.

Refs (fixed): T_ref = 12 s, G_ref = 40000, J_ref = 8 m/s³.

Discussion

A single number J\mathcal{J} hides a fight among objectives. Slamming force and jerk wins the clock and loses comfort (and often gas). Feathering jmax⁡j_{\max} wins comfort and loses time. Small peak force sips gas but stretches TT. Equal weights after normalizing do not mean “equally important in the real world” — they mean “we chose to treat a reference amount of each as one unit of regret.”

Later, Section 4.1 (LQR) will put those tastes into matrices QQ and RR. Here the pizza run is enough: move the sliders, watch J\mathcal{J}, and feel that multi-objective control is about choosing what hurts.

A note about not reaching the door exactly

The math wants x(T)=Dx(T) = D on the nose. The playground usually lands a little short.

Braking starts when a quick preview says “a jerk-limited stop still fits in the remaining distance.” That preview is discrete and padded slightly so the car does not blow past the door. Starting a bit early, plus freezing xx while aa settles to zero in the rest phase, means v→0v \to 0 with x<Dx < D more often than not.

“At the door” here means within a small tolerance — about half a meter, or 2%2\% of DD, whichever is larger — the same spirit as sections 0.2 and 0.3. Only if the trajectory overshoots does the sim snap xx back to DD. Exact landing is a harder planning problem; for this chapter, a comfortable stop near the door is enough.

If you want to learn how to reach x=Dx = D without error, keep reading — that comes in Section 4.2.