SCREEN 12 PRINT "Simulation of closed-loop system with `live input'" PRINT "ERROR Phase-plane is shown - velocity against position ERROR" PRINT INPUT "Feedback, damping (suggest 8,2 to start) "; f, d CLS VIEW (2, 20)-(638, 318), 8, 4 WINDOW (-3, -2.5)-(3, 2.5) LINE (-2.5, 0)-(2.5, 0), 9 LINE (0, -2.5)-(0, 2.5), 9 PRINT "Press number keys 0 to 9 to change the target, to quit" LOCATE 24, 1: PRINT "Velocity versus position ERROR "; PRINT "Range is +/- 2.5 in pos and vel"; ulim = 4 'Experiment by changing this limit on u LOCATE 25, 1 PRINT "Input u limited at +/-"; ulim; ' dt = .01 'Make dt larger to speed up running b = 1 x = 1 'Initial values v = 0 t = 0 target = 0 'until a key is pressed PSET (x - target, v) 'move to the first point DO a$ = INKEY$ IF a$ > " " THEN target = .5 * (VAL(a$) - 5) PSET (x - target, v) END IF u = f * (target - x) - d * v 'u is determined by feedback IF ABS(u) > ulim THEN 'limit u to +/- ulim u = ulim * SGN(u) COLOR 12 'Show plot in red if limited ELSE COLOR 15 END IF x = x + v * dt 'This is the simulation v = v + b * u * dt ' t = t + dt LINE -(x - target, v) 'This displays the result LOOP UNTIL a$ = " " '