Classic Computer Magazine Archive ANTIC VOL. 3, NO. 3 / JULY 1984


Or at least move your leg



This is the fourth in a series of articles that discuss experiments in practical robotics that can be performed with Atari computers. The first three articles appeared in the December,1983, and January, and June, 1984, issues of Antic. To benefit from the information and programs presented here, you should first read the other articles in the series, and build the "robot." To do this, you'll also need either BASIC or Forth. To the best of our knowledge, the programs in this series run on all Atari computers.

This time we're going to connect a number of servos (as many as eight) and run them simultaneously. To do this, we need to generate accurate and consistent pulses of a duration between one and two milliseconds; these tell each servo where to position itself. The Atari Operating System (OS) performs many time-critical tasks, so there are only a few timeslots during which you can generate such impulses without being interrupted by the ANTIC chip as it updates the display.

So, to keep the code short, we'll turn ANTIC off while we generate pulses. As a result, the screen will be blank while the servos are running, but our code will fit into Page Six of memory (a free area in BASIC and most versions of Forth). There's room for listings in both languages this month. (Commands mentioned in this article will appear in the following format: BASIC Code /// Forth Code.)

Figure 1 is a closeup of a leg that is made out of two servos and a few pieces from the Erector construction set, but you also can use a different constructior kit, or wire- hangers and a lot of patience.

The leg's upper servo, which we'll call the hip, is connected to the "knee" servo by means of an L-beam (the thigh). And the knee-bone's connected to the shin-bone. At the end of the shin is the foot. The shoes were a lucky find in terms of humor, but they also provide stability for the leg.

I also made one addition to the construutiion set. If you use the Erector set, buy about two dozen 8-32x1 1/2-inch flat-head machine screws to hold down the servos. I drilled the servo arms to fit the construction pieces (see Figure 2), but I suspect that five-minute epoxy will also work. Just keep the glue out of the works and away from the screw that holds the small servo-arm onto the servo.

Figure 1: Even the simplest robot can be customized.


We covered this in previous articles, but here's a brief recap. The servos' black wires are all ground wires. They should be tied together and connected to pin 8 (ground) of a joystick port. Pin 8 is the third from the left on the bottom row.

The red servo wires are all positive voltage, and should be tied to a 5V-DC(not AC) power supply. If you use a lantern battery, connect one or two diodes in series coming from it. This reduces the voltage from its nominal six volts to five. The 5V-DC power supply is not directly connected to the computer.

The third and final wire coming from the servo can be colored in different ways (e.g., white, orange, yellow, etc.). Each should be tied to a different pin in the range of 1-4 in joystick Ports 1 and 2.


Your first robot need not resemble the one pictured here. If you want to build something that resembles a living creature, think about the creature's form and how its viarious parts function in relation to one another.

Heres an example. In most bipeds, the shin can be extended (the knee can be bent all the way back) so that the calf touches the thigh. Most four-legged animals' hind Iegs bend backward, perhaps to aid in springing. Birds' legs are similar. Elephants' knees bend forward; perhaps this is good for strolling. At any rate, if you're clever, you can make your robot's knees bend 90 degrees each way so that the algorithms for walking backwards are similar to the ones for walking forward. This can create problems with ground clearance, however. Build and learn.


Actually, six legs are best, which may explain why insects evolved before we did. Unless you give your robot extremely large feet, you'll have problems with stability with anything less than five legs.

Consider the horse, whose center of gravity lies along the center line of its body. When it lifts a leg, it has a tendency to tip over. To counter this, a horse can place a lifted leg down quickly or can shift its weight temporarily to its other three legs.

Four legs' worth of servos can cost a lot of money, though! To use only two, we must bend the rules. My robot uses a frame made of four struts, which are partially visible in Figure 3. Like a baby's walking trainer, this frame keeps the robot roughly level. My robot's shuffling walk actually drags this frame along. See if you can do better.


Type in either the BASIC or Forth code. The program controls the first four servos with pins 1-4 on Port 1, and the next four with pins 1-4 on Port 2. You can attach up to eight servos for use with this program listing.

RUN the BASIC code to install the servo-driver routine or do 50 LOAD from Forth. In Forth, screen 52's word SETUP installs the routine. To run a short test program, type GOTO 2000 from BASIC or type TEST in Forth. If everything is OK, the screen will go blank and your servos will oscillate one at a time near their center positions.

If you let the demo run, it will stop by itself and the screen will turn on again. If you press [BREAK] before it stops, however, you'll need to follow this procedure to restore the screen. Press [SHIFT INSERT] to open up a line, then carefully type GOSUB 1100 to remove vertical-blank routine and the disable-POKEY interrupts. Note that the test program executes this subroutine before it ends, and that it starts with GOSUB 1000 to install the vertical-blank vector and the POKEY-interrupt enable. In Forth, use START to enable servo control, and STOP to disable it. To stop the Forth test program, simply press and hold a console key ([START], [SELECT], or [OPTION]) for a few seconds.

Figure 2: The servo arms were drilled to fit the construction pieces.


Now we'll "zero" or calibrate the servos, so that when you poke zero into a SERVOn (see below) location, the servo will go all the way to one stop and no further. You can jump in and out of servo-control by using the following commands:

GOSUB 1000 /// START
GOSUB 1100 ///STOP

Use these freely to turn the screen off and on while you make and check the adjustments. But be careful not to type the wrong number with GOSUB, or you may have to re-RUN the program or re-boot the system.

Note that there are eight addresses, SERVO0 to SERVO7, in each listing. There are also eight other addresses called OPULS0 to OPULS7. As in previous articles, the values in the SERVOn addresses represent the servo's position, and the OPULSn values determine where the servo will be when SERVOn's value is zero. To adjust the zero point for SERVO0, use:


and then adjust the value in OPULS0. The initial value of all OPULSn's is 64 (decimal). You should POKE or C! numbers that are slightly greater or less than 64 into OPULS0 for centering. Don't use numbers below 10 or above 100, however, or you may create some timing problems.

You may have to reduce the OPULS0 value slightly to push the servo to its stop, and then increase it to remove the pressure. Next, print the value in OPULS0:


and edit this value into the code on line 530 /// screen 51, lines 5 and 6. Do the same for each servo, and then LIST"D: SERV8BAS" or CSAVE /// FLUSH to save your changes for the next session. If you don't rewire anything, the zero-points should remain about the same.

Finally, you should determine the greatest value that can be held by SERVOn without letting the servo hit the stop. This value generally lies between 50 and 70 (decimal). Jot these numbers down; you'll need them later.

Figure 3: The robot's frame functions like a baby's walker.


For helpful hints on how to construct your robot, observe how people and animals actually move. Hold pour body rigid, then lift one leg. If you don't fall over, you're not learning -- you're cheating. Get down on all fours and try the same thing. As the saying goes, you don't know a robot until you've walked a mile in its pod covers.

As you build, keep lengths adjustable and use creativity in constructing linkages. For instance, the trick of swinging one servo on the arm of another is simple, but it reduces the amount of torque available to do work. Your local hobby store has a variety of inexpensive linkages and levers.

And have fun! Dress up creations. Gloves, a face, or a tiny saddle can make your robot much more entertaining. Finally think about how your robot and program might handle data from sensors. We'll try to cover this in a future issue.

Evan Rosen is the co-author of VaI-FORTH from Valpar International.

Listing: ROBOT.BAS Download

Listing: ROBOT.4TH Download / View