13 Robotics

One of the most exciting applications of digital electronics and computers is robotics. While a robotics control system is beyond the scope of this book, what you'll find here are some ideas to get you started.
     The actions of most robots are carried out by motors. To move, for instance, a mobile robot's wheels are turned; when a robot's arm goes up, the arm's joints are moved by motors. These motors, in turn, are controlled by a computer. The computer is programmed to turn the motors on and off so that the robot moves in a coordinated fashion to perform a task.
     You already have enough expertise to control a dc motor with your computer. You can simply switch it on and off by using an electronic switch circuit. If you use a second electronic switch circuit, with a DPDT relay in place of the SPDT, you can control a dc motor to turn in both directions.
Though you've already built an electronic switch circuit in Chapter 8, it will be easier if you just begin from scratch when putting together a dc motor control circuit. Here's what you'll need:

parts
Quantity
Part
Part
Number
1
9-pin D-subminiature female
276-1538
2
2N2222 NPN transistors
276-1617
2
2.2K ohm resistors
271-8027
2
IN914 diodes
276-1620
1
5-volt SPDT DIP relay
275-243
1
DPDT DIP relay 5-volt coil
275-215
1
Solderless Breadboard
276-175
1
7400 IC (Atari)
276-1801
1
DC battery-powered motor
None
You'll also need some solid copper wire for connections to the 9-pin plug, motor, and battery, as well as for jumpers on the solderless breadboard.
     If you're building the Atari version of the control circuit, you'll need a longer than normal solderless breadboard.

Figure 13-1. Layout-Commodore Version

step-by-step
The Commodore Version
Here's how to build the Commodore version of the dc motor control circuit.

1. Wire the 9-pin plug. Cut four pieces of wire, each about four inches long, and remove about 1/4 inch of the insulation from the wires' ends.
2. Solder wires to pins 1, 2, 7, and 8 of the 9-pin plug.
3. Connect the four wires as follows: The wire from pin 8 connects to point Y1 on the solderless breadboard. The wire from pin 7 connects to point X1 of the solderless breadboard. The last two lines, from pins 1 and 2, connect to locations A3 and A6 respectively.
4. Connect the two 2.2K ohm resistors between points C3 and F3, and points C6 and F6 on the solderless breadboard.
5. Mount one 2N2222 transistor so that its base inserts into point H3, its emitter into point H2, and its collector into point H3.
6. The second 2N2222 transistor should be mounted so that its base inserts into location H6, its emitter into point H7, and its collector into H5.
7. The first diode is connected so that its cathode lead inserts into point X4 of the solderless breadboard and its anode lead connects to point A4. (A band around one end of the diode is generally used to identify the cathode lead.)
8. The second diode should be placed so that its cathode lead goes into location X7, while its anode lead connects to point A7.
9. The SPDT relay is inserted so that its normally open and normally closed pins attach to points F9 and E9 respectively. The common pin connects to point E14. Its coil terminal should be connected to points E10 and F10.
10. Insert the DPDT relay so that its normally open pins 1 and 2 attach to points E23 and F23 respectively. Its normally closed pins 1 and 2 should be connected to points E21 and F21 respectively. The two common pins, 1 and 2, are attached to locations E19 and F19. Finally, the coil terminal is connected to points E16 and F16.
11. The following jumper connections are required:

Wire   From    To
 1        X10      A10
 2        X16      A16
 3        E4        F4
 4        E7        F7
 5        A21     J23
 6        A23     J21
 7        H9       H19
 8        I4        I10
 9        J7        J16
 10      J2        Y2
 11      J5        Y4

 12. Solder two wires to the battery you'll use, one wire to the positive pole, the other to the negative pole.
 13. Connect the positive pole wire to point 123 of the solderless breadboard. Connect the negative pole wire to point B23.
 14. Solder two wires to the dc motor, one to its positive pole, the other to its negative pole.
 15. Connect the positive pole wire to point A19 of the breadboard and the negative pole wire to location A14.

Figure 13-2. Finished Commodore Board


Changes When Constructing the Atari Version
Refer to Figure 13-3 for the layout of the Atari version.

step-by-step
Substitute the following steps in the Atari version:

 3. The wires from pins 1 and 2 connect to points J25 and A26 respectively.
11. These are the jumper connections for the Atari version:
Wire   From    To
 1        X10      A10
 2        X16      A16
 3        E4         F4
 4        E7         F7
 5        B3        G30
 6        B6        B31
 7        D26     C27
 8        D28     D29
 9        C29      D30
 10      H25      G26
 11      G27      G28
 12      H28      G29
 13      A21      J23
 14      A23      J21
 15      J31       Y31
 16      H9        H19
 17      I4          I10
 18      J7          J16
 19      J2         Y2
 20      J5         Y4

13. Connect the positive pole wire from the battery to point I23 of the solderless breadboard. Connect the negative pole wire to point I21.
16. Insert the 7400 IC into the solderless breadboard so that its pins 1 and 8 go into plug points F25 and E31 respectively.

attention
Warning: If you use a larger motor, remember to mind the ratings of the solderless breadboard and its relays.
     The circuit uses two signals from the computer-one to switch on the motor and the other to reverse the battery polarity to the motor. Reversing the battery polarity to a dc motor causes its shaft to rotate in the opposite direction.
     The motor can be used to turn the wheels of a small mobile "turtle" robot. If you use a dc gear motor with a reasonably low rpm speed and enough torque, you can even control a joint of a robot, such as the elbow or shoulder of a mechanical arm. You can use several of these motor control circuits to operate a multijoint robot. Consider using a demultiplexer to send the digital signals to different motor control circuits.
     Some robots simply turn on their motors for a certain amount of time, assuming that the parts manipulated by the motors reach particular points. But if, for example, something obstructs their movements, these robots continue working, oblivious to their situations. More intelligent robots use sensors to inform them about their environments. If you build a mobile robot, you can use microswitches to check whether your robot has bumped into a wall. If it requires several such sensors, you may have to use a multiplexing circuit. You can also mount potentiometers to turn with the joints of a mechanical-arm robot. The values returned by the A/D converter of your computer allow you to keep track of the arms' positions.
     Once you build the motor control circuit, you can control it from your computer in much the same way as the following demonstration program does. Plug the circuit into control port 1 of your computer. (The Commodore 64/128 version of the program requires that you insert a joystick into control port 2.)

Figure 13-3. Layout-Atari Version

Program 13-1-Commodore 64/128

AK 100 REM MOTOR CONTROL DEMONSTRATION
SS 110 REM REQUIRES A JOYSTICK
HC 115 PRINT "JOYSTICK CONTROLS":PRINT
SA 120 PRINT"UP - MOTOR TURNS IN ONE DIRECTION"
CH 130 PRINT"DOWN - MOTOR TURNS IN OPPOSITE DIRECTION"
CE 132 PRINT:PRINT"PRESS FIRE BUTTON TO {SPACE}EXIT DEMO"
DB 135 B=0
HK 140 A=PEEK(56320)
CG 150 IF(A AND 2↑0)=0 THEN GOSUB 1000: GOTO 140
EP 160 IF (A AND 2↑1)=0 THEN GOSUB 2000: GOTO 140
CQ 170 GOSUB 3000
PM 180 IF (A AND 2↑4)=0 THEN END
JX 190 GOTO 140
CB 1000 REM TURN MOTOR ON IN ONE DIRECTION
CM 1010 REM CHECK IF THIS HAS ALREADY BEEN DONE
FK 1020 IF B=1 THEN 1100
MA 1030 REM SET FIRST DATA LINE FOR OUTPUT
SM 1040 POKE 56323,PEEK(56323)OR(2↑0)
GD 1050 REM SET FIRST DATA LINE LOGIC LOW TO TURN ON MOTOR
EG 1060 POKE 56321,PEEK(56321)ANDNOT(2↑0)
KD 1070 B=1
RF 1100 RETURN
JJ 2000 REM TURN ON MOTOR IN OTHER DIRECTION
KJ 2010 REM CHECK IF THIS HAS ALREADY BEEN DONE
KK 2020 IF B=2 THEN 2100
CR 2030 REM SET BOTH DATA LINES FOR OUTPUT
QX 2040 POKE 56323,PEEK(56323)OR(2↑0+2↑1)
CM 2050 REM SET BOTH DATA LINES LOGIC LOW TO TURN ON MOTOR AND REVERSE POLARITY
MQ 2060 POKE 56321,PEEK(56321)ANDNOT(2↑0+2↑1)
RC 2070 B=2
MC 2100 RETURN

MC 3000 REM TURN MOTOR OFF
EC 3010 REM CHECK AND SEE IF THIS HAS BEEN DONE
JP 3020 IF B=0 THEN 3100
KM 3030 REM TURN BOTH DATA LINES LOGIC HIGH
BM 3040 POKE 56321,PEEK(56321)OR(2↑0+2↑1)
SG 3050 REM RESET BOTH DATA LINES FOR INPUT
PX 3060 POKE 56323,PEEK(56323)ANDNOT(2↑0+2↑1)
XS 3070 B=0
HA 3100 RETURN


Program 13-1-VIC-20

XS 10 PRINT "KEYBOARD CONTROLS":PRINT
SB 20 PRINT"< - MOTOR TURNS IN ONE DIRECTION"
KR 30 PRINT"> - MOTOR TURNS IN OPPOSITE{SPACE}DIRECTION"
DE 40 PRINT:PRINT"PRESS SPACE BAR TO EXIT DEMO"
CH 50 B=0
EH 60 A=PEEK(197)
MS 70 IF A=29 THEN GOSUB120:GOTO60
PS 80 IF A=37 THEN GOSUB210:GOTO60
MK 90 GOSUB300
XD 100 IF A=32 THEN POKE 198,0:END
CP 110 GOT060
FJ 120 REM TURN MOTOR ON IN ONE DIRECTION
PP 130 REM CHECK IF THIS HAS ALREADY BEEN DONE
SE 140 IF B=1 THEN200
XK 150 REM SET FIRST DATA LINE FOR OUTPUT
FJ 160 POKE 37139,PEEK(37139)OR(2↑2)
CS 170 REM SET FIRST DATA LINE LOGIC LOW TO TURN ON MOTOR
RF 180 POKE 37137,PEEK(37137)ANDNOT(2↑2)
FF 190 B=1
MC 200 RETURN
JQ 210 REM TURN ON MOTOR IN OTHER DIRECTION
QR 220 REM CHECK IF THIS HAS ALREADY BEEN DONE
QC 230 IF B=2 THEN290

PR 240 REM SET BOTH DATA LINES FOR OUTPUT
PR 250 POKE 37139,PEEK(37139)OR(2↑2+2↑3)
PX 260 REM SET BOTH DATA LINES LOGIC LOW TO TURN ON MOTOR AND REVERSE POLARITY
AG 270 POKE 37137,PEEK(37137)ANDNOT(2↑2+2↑3)
MM 280 B=2
SK 290 RETURN
RP 300 REM TURN MOTOR OFF
CR 310 REM CHECK AND SEE IF THIS HAS BEEN DONE
EG 320 IF B=0 THEN380
BM 330 REM TURN BOTH DATA LINES LOGIC HIGH
QQ 340 POKE 37137,PEEK(37137)OR(2↑2+2↑3)
FH 350 REM RESET BOTH DATA LINES FOR INPUT
CQ 360 POKE 37139,PEEK(37139)ANDNOT(2↑2+2↑3)
KX 370 B=0
HS 380 RETURN


Program 13-1-Atari

AO 100 REM MOTOR CONTROL DEMONSTRATION
NF 110 PRINT "KEYBOARD CONTROL"
CA 120 PRINT
BF 130 PRINT "G - MOTOR TURNS IN ONE DIRECTION"
KJ 140 PRINT "> - MOTOR TURNS IN OPPOSITE DIRECTION"
LO 150 PRINT "S - STOP MOTOR"
AK 155 PRINT :PRINT "X - EXIT PROGRAM"
EG 160 B=0
CN 170 A=PEEK(764)
IK 180 IF A=54 THEN GOSUB 1000:GOTO 170
IN 190 IF A=55 THEN GOSUB 2000:GOTO 170
NF 200 GOSUB 3000
AK 210 IF A=22 THEN END
GF 220 GOTO 170
DG 1000 REM TURN MOTOR ON IN ONE DIRECTION
OJ 1010 REM CHECK IF THIS HAS ALREADY BEEN DONE
PD 1020 IF B=1 THEN 1100
AD 1030 REM SET DATA LINES FOR OUTPUT
IP 1032 POKE 54018,48
F6 1034 POKE 54016,3
IO 1036 POKE 54018,52
NJ 1040 REM SET FIRST DATA LINE LOCIC LOW TO TURN ON MOTOR
FD 1050 POKE 54016,2
HH 1060 B=1
KC 1100 RETURN
NH 2000 REM TURN ON MOTOR IN OTHER DIRECTION
OK 2010 REM CHECK IF THIS HAS ALREADY BEEN DONE
PG 2020 IF B=2 THEN 2100
CP 2030 REM SET BOTH DATA LINES FOR OUTPUT
JA 2032 POKE 54018,48
FH 2034 POKE 54016,3
IP 2036 POKE 54018,52
DF 2040 REM SET BOTH DATA LINES LOGIC LOW TO TURN ON MOTOR AND REVERSE POLARITY
FC 2050 POKE 54016,0
NJ 2060 B=2
KD 2100 RETURN
FM 3000 REM TURN MOTOR OFF
JJ 3010 REM CHECK AND SEE IF THIS HAS BEEN DONE
P6 3020 IF B=0 THEN 3100
JD 3030 REM SET BOTH DATA LINE LOGIC HIGH
FF 3040 POKE 54016,3
DL 3050 REM RESET DATA LINES FOR INPUT
JC 3060 POKE 54018,48
FF 3070 POKE 54016,0
JA 3090 POKE 54018,52
IA 3095 B=0
KE 3100 RETURN

Download (Saved BASIC)
Download / View (Listed BASIC)


Return to Table of Contents | Previous Chapter | Next Chapter