Problem 353794 · medium · Level 03 Linear Management & Searching

A Treadmill That Does Not Jerk

setpoint weighting · PI control · derivative of the setpoint · actuator kick

A gym treadmill's belt speed v (m/s) follows its motor command u (per cent of full power): each per cent accelerates the belt by 0.02 m/s², and the runner's feet and friction slow it with a time constant of 2 s. With steps of dt = 0.1 s,

v = v + 0.1 * (0.02 * u - v / 2)

A PI controller holds the speed the runner asks for. When the runner presses "faster", the setpoint jumps, the error jumps, and the proportional term Kp * (r - v) jumps with it: the motor lurches, which is unpleasant and wears the belt. Setpoint weighting fixes that: the proportional term uses only a share b of the setpoint, while the integral still uses the full error, so the speed still ends exactly at the setpoint:

e = r - v
I = I + e * 0.1
u = Kp * (b * r - v) + Ki * I
v = v + 0.1 * (0.02 * u - v / 2)

With b = 1 this is the ordinary PI controller; with b = 0 the setpoint reaches the command only through the integral, which changes smoothly.

setpoints holds the setpoint r for each step. For each weight b in weights, start at rest, v = 0, I = 0, with the command before the first step taken as u = 0, and run one step per setpoint in the order above. Record:

  1. jump: the largest change of the command between consecutive steps, abs(u - previous u) (the first step is compared with the 0 before it);
  2. peak: the highest command;
  3. over: the largest amount by which the speed after a step exceeds that step's setpoint, v - r, or 0.0 if it never does.

Write setpoint_kick(setpoints, Kp, Ki, weights) that returns a list with one tuple (jump, peak, over) per weight. Plot the commands for b = 1 and b = 0 to see the lurch disappear (and the speed respond a little more slowly).

Examples

Input:  setpoints = [2.0] * 100 + [3.0] * 100, Kp = 30, Ki = 20, weights = [1, 0.5, 0]
Output: [(64.0, 81.9775575, 0.02576045), (34.0, 76.3221018, 0.00486579), (4.0, 75.99794413, 0.00306216)]
Explanation: with b = 1 the first step jumps the command from 0 to 30 * 2 + 20 * 0.2 = 64 %.
With b = 0 the first command is just the integral term, 20 * 0.2 = 4 %.

Input:  setpoints = [1.5, 1.5, 1.5], Kp = 20, Ki = 20, weights = [1, 0]
Output: [(33.0, 35.968488, 0.0), (3.0, 8.604408, 0.0)]

Constraints

  • answers are compared with a tolerance of 1e-6; do not round

Goals

  • See that the proportional term turns a setpoint step into a step in the command
  • Weight the setpoint in the proportional term and keep the full error in the integral
  • Compare the command jump, the peak command and the overshoot for several weights
Starting Python…