B1 · Lesson 13 · Motion lab
Velocity from position data, planned moves, and drag solutions checked by simulation
Real motion arrives as data. An encoder on a motor shaft or a GPS receiver reports position at regular ticks, and velocity and acceleration have to be computed from it. A motion controller works the other way: it plans a move from a distance, an acceleration limit and a top speed. And the exact drag solutions of lesson 8 are only worth trusting once a simulation agrees with them. In this lab you'll write all three: differentiating data, planning moves, and integrating motion with drag.
- A motion controller moves a stage a distance d with acceleration a and a top speed limit. The curve is the planned speed against time: speed up, cruise, slow down.
- Shorten the move, or lower the acceleration: below the stage never reaches top speed and the profile becomes a triangle.
- The readouts give the move time and the peak speed. You'll write the same calculation in step 2.
Predict
A stage must move 3 m with 1 m/s² of acceleration and a 2.5 m/s speed limit. Does it reach 2.5 m/s?
No. Reaching 2.5 m/s and stopping again takes m, more than the 3 m available. So the stage accelerates for half the distance and brakes for the other half, peaking at m/s, and the move takes s.
Name it
Derivatives from samples
For positions sampled every h seconds, the central differences
are accurate to order : the velocity's error is about . They need a point on each side, so the first and last samples get no estimate. Noise is the catch: each difference divides by h or , so a millimeter of noise sampled every millisecond becomes meters per second of velocity noise, and real controllers filter before or after differentiating.
Trapezoidal moves
With acceleration a and speed limit , a move of length d takes
Range from a height
Launched at speed and angle θ from height h, a projectile lands at . The best angle is , a little under 45°.
Checking a stepping method
Euler's method on gives exactly, so its error can be predicted as well as measured. Halving the step halves Euler's error and divides RK4's by 16, which is how you tell which method you've actually written.
Worked example
Positions are sampled every 0.1 s. What do central differences give for the velocity and acceleration at t = 1 s?
Show the solution
- Exact values.
- The samples.
- Central differences.
- The errors. The velocity is off by exactly The second difference is exact for a cubic, since its error depends on the fourth derivative.
Answer the central differences give 2.99 m/s (exact value 3 m/s) and an acceleration of 0, which is exact.
Worked example
How long does a 30 m move take with 1 m/s² of acceleration and a 2.5 m/s limit?
Show the solution
- Ramps. Reaching 2.5 m/s takes 2.5 s and covers 3.125 m; braking takes the same.
- Cruise. That leaves 23.75 m of cruising, 9.5 s at 2.5 m/s.
- Total. which matches .
- What limits it. Doubling the acceleration saves only 1.25 s here, while raising the speed limit to 5 m/s saves 3.5 s: long moves are limited by speed, short ones by acceleration.
Answer the move takes 14.5 s.
Worked example
A stone is thrown at 15 m/s from the top of a 10 m cliff. What angle throws it farthest, and how far?
Show the solution
- Best angle.
- Range at that angle.
- Compare with 45°. At 45° it would land at 30.5 m. The higher the launch compared with , the flatter the best throw, since the long fall already provides the flight time.
Answer throw at 36.2° above horizontal; the stone goes 31.4 m.
Check
Step 1. Write derivatives(t, x) that returns two NumPy arrays: the central-difference velocity and acceleration at the interior samples (all but the first and last). The samples are evenly spaced.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write move_time(d, a, vmax) that returns the time of a trapezoidal move of length d, or of a triangular one when the stage can't reach vmax.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write range_from_height(v0, theta, h) (theta in degrees, g = 9.8) and best_angle(v0, h), which searches angles from 20° to 60° in steps of 0.1° and returns the one with the longest range.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 4. Write euler_fall(tau, T, n) that takes n Euler steps of from rest up to time T and returns v. (Use g = 9.8.)
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 5. Write fall(vt, T, dt) that integrates a fall from rest with quadratic drag, and , by RK4, and returns (v, x) at time T. Check it against lesson 8's exact formulas.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A stage moves 2 m with 1 m/s² of acceleration and a 5 m/s limit.
(a)
What peak speed does it reach?
Write units the way you normally would: 1.5 m/s, 1500 mm/s and 0.0015 km/s are the same answer.
(b)
How long does the move take?
Check
Position samples are spaced 0.02 s apart, and the motion has a constant third derivative (jerk) of 6 m/s³. How large is the central-difference velocity's error?
Write units the way you normally would: 1.5 m/s, 1500 mm/s and 0.0015 km/s are the same answer.
Explain why
Why is a central difference more accurate than a forward difference for the same sample spacing?
A forward difference, , really measures the average velocity over the next interval, which is the velocity half a step later than the point it's assigned to, so its error is proportional to h times the acceleration. A central difference spans one step on each side, so the effects of acceleration on the two sides cancel by symmetry: the leading error term drops out, and what's left is proportional to times the third derivative. Halving the spacing therefore halves a forward difference's error but quarters a central one's.
Practice
Keep practicing
4 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.