207b
<< <> >>

The solution

Fit the motors with a gas tank.

The fuel

  1. Even when standing still, the motor uses 13 liters per segment (the number of PLOP's, the number of steps to complete the wanted angle).
  2. When the fuel goes out, exactly 30 liters are tanked (the number of segments, the largest angle).

The reasoning

Per segment 13 liters are used, over 30 segments: 30 * 13 liters.
30 * 13 = 13 * 30. How many times do we need to refuel? Right, 13 times.
And how many steps were we supposed to make? ...

So here's the solution:

If we run out of fuel in a segment, do a refuel and perform PLOP. The other (17) segments are PILI. Now remove those fuel tanks and just remember the reasoning, because that's what we'll use in the following code.

The Forth code

Forth file: ec207.frt
\ ROBOT ARM (Albert Nijhof)

FORTH DEFINITIONS   DECIMAL
: VARIABLES
  CREATE ( n -- ) CELLS ALLOT
  DOES>  ( index body -- addres ) SWAP CELLS + ;

5 DUP CONSTANT #MOTORS
DUP VARIABLES WHERE            \ List of motor positions
DUP VARIABLES THERE            \ List of target positions
DUP VARIABLES STEP             \ -1 or +1 (directions)
DUP VARIABLES TANK             \ Amount of fuel
DUP VARIABLES USAGE        \ Amount of fuel used per segment
CELLS  0 WHERE  SWAP 0 FILL

20 VALUE WAIT                  \ Physical motor limitation
 0 VALUE #SEGMENTS             \ Longest segment

: TARGET ( m0 m1 m2 m3 m4 -- ) \ Set target
  #MOTORS BEGIN 1-
                TUCK THERE !
                ?DUP 0=
          UNTIL ;
          
>>