207a
<< <> >>

207

The programming language Forth
home
This program coordinates processes that run with different speeds:
they'll start at the same time, run smoothly, and stop at the same time.

Robot arm with (e.g.) five stepper motors

The chairman of the Dutch Forth Users group tinkered with a five-motor robot arm (two in the shoulder, one in the elbow and two in the wrist) and asked me to develop an algorithm to make it move smoothly.

- But I have absolutely no experience with hardware.

- Send a number to one of the steppers. It'll move abruptly to the position corresponding to that number. It is not necessary to know the present stepper position. I'll take care of the lowest level driver routines myself.

Armed with this hardware knowledge I thought up a program, and, it works! After some tweaking of the word >MOTOR, of course. Because I don't have any hardware myself, I've tested the result with output to the terminal screen (using .HERE).

Because no specific knowledge of the arm is used, there is no protection against commanding the arm steppers to impossible positions.
It is trivial to choose the number of motors differently. The program coordinates processes that run with different speeds: they start at the same time, run smoothly, and stop at the same time. Other applications are possible. Examples are cartoons of Achilles and the Tortoise, or drawing straight lines with that five-dimensional plotter you have always wanted to build.

The problem

Say, we move from position <0 0 0 0 0> to position <10 20 13 7 30>. The last motor rotates over the largest angle: 30. This largest angle (30) is the starting point of the algorithm: we'll distribute the movement of each motor over 30 segments. Per segment a motor either does a single step (PLOP), or it does nothing (PILI).

The last motor does 1 step in each segment (30 times PLOP). This is simple. Let's look at the other motors.
>>