B113 of 56
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 d=vmax2/a 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?

Name it

Derivatives from samples

For positions xi sampled every h seconds, the central differences

vi≈xi+1−xi−12h,ai≈xi+1−2xi+xi−1h2

are accurate to order h2: the velocity's error is about h26x⋯. 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 h2, 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 vmax, a move of length d takes

T=dvmax+vmaxa(d≥vmax2/a),T=2da(otherwise).

Range from a height

Launched at speed v0 and angle θ from height h, a projectile lands at R=v0cos⁡θg(v0sin⁡θ+v02sin2⁡θ+2gh). The best angle is tan−1⁡v0v02+2gh, a little under 45°.

Checking a stepping method

Euler's method on v˙=g−v/τ gives vn=gτ(1−(1−h/τ)n) 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 x=3t2−t3 are sampled every 0.1 s. What do central differences give for the velocity and acceleration at t = 1 s?

Show the solution
  1. Exact values. v=6t−3t2=3m/sa=6−6t=0
  2. The samples. x(0.9)=1.701x(1)=2x(1.1)=2.299
  3. Central differences. v≈2.299−1.7010.2=2.99m/sa≈2.299−4+1.7010.01=0
  4. The errors. The velocity is off by exactly h26x⋯=0.016×(−6)=−0.01m/s 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
  1. Ramps. Reaching 2.5 m/s takes 2.5 s and covers 3.125 m; braking takes the same.
  2. Cruise. That leaves 23.75 m of cruising, 9.5 s at 2.5 m/s.
  3. Total. 2.5+9.5+2.5=14.5s which matches 302.5+2.51.
  4. 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
  1. Best angle. θ=tan−1⁡15225+2×9.8×10=tan−1⁡1520.52=36.2°
  2. Range at that angle. R=v0v02+2ghg=15×20.529.8=31.4m
  3. Compare with 45°. At 45° it would land at 30.5 m. The higher the launch compared with v02g, 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 v˙=g−v/τ 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, v˙=g(1−v2/vt2) and x˙=v, 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?

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.