Zero2 Software BBC/Spectrum June 1985 ============================ ========= BBC Programs ------------ STEST', SIMPLE, JOYSTIK,LISTC, LINEMAN The above programs occur in the above sequence on the cassette tape provided. They should be loaded using the CH."" command Documentation for the individual programs is included, note that they are provided for convenience rather than sophistication. More advanced and flexible software will become available as special applications are developed and third parties write special programs/games. A 6502 machine code interface or binary file does not yet feature on the initial issue of cassette software. When it does, it will be accessible from Logo, as Logo's machine code interface to the robot and from BASIC as code to be called in subroutines. ZX Spectrum Programs -------------------- LEARNLINEF (Basic loader program which loads two machine code files): * which is the Zero2 logo screen loaded when running LEARNLINEF ** which is the learn/linefollowing object code itself - start 61000 ROBOT BIN machine code loading address 63464, length 1536 bytes This is the machine code file used by Logo to run the robot and which can have routines in it called by the following two BASIC sub-programs, i.e. zerol bas and zero2 bas. 'zerol bas' ( 2 spaces in file name ) BASIC A set of BASIC subroutines which themselves hook into the ROBOT BIN machine code file which drives the robot. Typically these are accessed by GOTO and GOSUB commands, having prepared certain variables to pass and receive arguments from the routines governing the robot's activities. Details of these feature in the ZERO 2 Instruction Manual. 'zero2 bas' ( 2 spaces in file name ) BASIC As 'zerol bas' except that these are more advanced routines. LOGO procedures There are two files, zerol LOG and zero2 LOG. These have not now been included on the cassette tape, as the file storage appears to work, but retrieval of SAVEd procedures from tape is unreliable. This is an inherent fault in Sinclair Logo at the time of writing. Retrieval from Microdrive is troublefree, however. The routines concerned are listed in the LOGO section of the ZERO 2 Instruction Manual. They are the Logo equivalents of the subroutines in the zeroN bas BASIC sub-programs mentioned above. Tape loading instructions ------------------------- LEARNLINEF LOAD "LEARNLINEF" or LOAD "" this program is auto-run and when running, automatically loads the ZERO 2 screen and the learnline code. ROBOT BIN ( 2 spaces in file name ) LOAD "ROBOT BIN"CODE zero1 bas ( " " " " " ) LOAD "zerol bas" or LOAD "" zero2 bas ( " " " " " ) LOAD "zero2 bas" or LOAD "" What the programs do -------------------- The functions of the BASIC subroutines, ROBOT BIN file and LOGO procedures has been described and further information is available from the ZER02 Instruction Manual. LEARNLINEF This program falls into two parts, which are accessed from the various menus presented. 1) LEARN - This section of the program allows you to guide the robot through any moves of your choice using either the keyboard or a joystick if attached. Forwards, Backwards, Right and Left motions, Pen Mechanism UP/Down, LED'S on/off, Horn High/Low can all be activated by this means. The computer at the same time acts as a 'teaching pendant' and all moves/actions are stored by the micro, to be repeated on selections. The program itself is simple enough in operation, but can eliminate a lot of programming when a basic motion/activity sequence is required. Linefollowing ------------- This program allows the robot to follow a 5mm or wider black line. It is a simple algorithm and more intelligent and sophisticated algorithms are possible using the linefollower hardware provided. Try illuminating the LED indicators and running the program in the dark! 'zerol bas' - ZX Spectrum --------------------------- Variables r0 used to pass routine number a1, a2, a3 used for input parameters o1, o2, o3 used for output parameters a8, b8, c8, k8, n8 used as scratch variables 9000 REM define subroutines 9002 RESTORE 9050 9004 READ init, border, ornge, call, move, fd, bk, lt, rt, lfd, rfd, lbk, rbk, continue, setscal, setspd, padj, setpen, pu, pd, pu1, pd1, setspp, setleds, sethorn, fuzz, setsens, sethole, setline, setbump 9006 READ peek, error, stepos, scale, spd, spp, leds, horn, sensor, sensp, hole, line, bump 9008 REM define variables 9010 READ usrcall, routine, argl, arg2, arg3, err, mask, inv, off, on 9022 REM define adjust 9024 READ adjust 9026 REM variables for adjust 9028 READ zdstart,disfac,rotfac 9050 DATA 9100, 9102, 9104, 9106, 9108, 9110, 9112, 9114, 9116, 9118, 9120, 9122, 9124, 9126, 9128, 9130, 9132, 9136, 9138, 9140, 9142, 9144, 9146, 9148, 9150, 9160, 9152, 9154, 9156, 9158 9052 DATA 9180, 9182, 9184, 9186, 9188, 9190, 9192, 9194, 9196, 9198, 9200, 9202, 9204 9054 DATA 64966, 64981, 64982, 64983, 64984, 64976, 7, 0, 0, 1 9056 DATA 9212, 64958, 64978, 64977 9070 REM go check for additional subroutines 9080 GO SUB 9300 9090 REM fall through to INIT 9099 REM commands 9100 LET mask=PEEK 64980: POKE routine,0: RANDOMIZE USR usrcall: RETURN 9102 IF al>7 THEN GO TO ornge 9103 POKE 23750,al: RETURN 9104 PRINT "OUT OF RANGE": STOP 9106 POKE routine,rO: POKE argl,al: RANDOMIZE USR usrcall: RETURN 9108 LET a2=INT (al/256): LET a1=a1-a2*256: POKE arg2,a2: GO TO call 9110 LET r0=l: GO TO move 9112 LET r0=2: GO TO move 9114 LET r0=3: GO TO move 9116 LET r0=4: GO TO move 9118 LET r0=5: GO TO move 9120 LET r0=6: GO TO move 9122 LET r0=7: GO TO move 9124 LET r0=8: GO TO move 9126 LET r0=22: LET al=0: GO TO call 9128 LET r0=18: GO TO call 9130 LET r0=16: GO TO call 9132 LET r0 = 9: LET al=0 9133 GO SUB call: PAUSE 10: IF INKEY$="" THEN GO TO 9133 9134 RETURN 9136 PRINT "PRESS ANY KEY WHEN PEN AT TOP": GO TO padj 9138 LET r0=12: LET al=0: GO TO call 9140 LET r0=13: LET al=0: GO TO call 9142 LET r0=10: LET al=0: GO TO call 9144 LET r0=ll: LET al=0: GO TO call 9146 LET r0=17: GO TO call 9148 LET r0=14: GO TO call 9150 LET r0=15: GO TO call 9152 POKE arg3,inv: POKE arg2,a2: LET rO=18: GO SUB call: GO SUB error: IF ol=3 THEN GO TO ornge 9153 RETURN 9154 LET a1=0: GO TO setsens 9156 LET al=1: IF a2<>off THEN LET a2=mask 9157 GO TO setsens 9158 LET al=2: GO TO setsens 9160 LET a8=al: LET al=l: GO SUB setleds: LET al=l: GO SUB sethorn: PAUSE 10: FOR i=1 TO a8: LET al=3: GO SUB setleds: LET al=3: GO SUB sethorn: PAUSE 25: NEXT i: LET al=0: GO SUB setleds: LET al=0: GO SUB sethorn: RETURN 9170 REM functions 9180 POKE routine,r0: RANDOMIZE USR usrcall: LET ol=PEEK (arg1): RETURN 9182 LET ol=PEEK (err): RETURN 9184 LET r0=42: GO SUB peek: LET ol=ol+256*PEEK (arg2): RETURN 9186 LET r0=48: GO TO peek 9188 LET r0=46: GO TO peek 9190 LET r0=47: GO TO peek 9192 LET r0=44: GO TO peek 9194 LET r0=45: GO TO peek 9196 POKE argl,al: LET r0=39: GO SUB peek: LET a8=o 1: GO SUB error: IF o1=3 THEN GO TO ornge 9197 LET O1=a8: RETURN 9198 GO SUB peek: LET o2=PEEK (arg2): RETURN 9200 LET r0=31: GO TO sensp 9202 LET r0=30: GO TO sensp 9204 LET r0=32: GO TO sensp 9210 REM adjust routine 9212 CLS: PRINT "Centre robot on A4 sheet of paper , then press ""s"" to start or ""Q"" to stop" 9214 LET a$=INKEY$: IF a$="Q" OR a$="q" THEN RETURN 9216 LET al=2: GO SUB fd: GO SUB pd: LET al=200: GO SUB fd: LET al=90: GO SUB rt: LET al=200: GO SUB fd: GO SUB pu: LET al=100: GO SUB fd 9218 CLS: PRINT "Enter the length in mm of each side and the distance between the two end points": PRINT 9220 INPUT "Side 1 :";b8: INPUT "Side 2 :";c8: INPUT "Ends :";a8 9222 LET k8=PEEK disfac: LET n8=(b8+c8)/2: LET k8=INT (200*k8/n8 + .5) 9224 POKE disfac,k8: PRINT "Distance factor is";k8 9226 LET k8=PEEK rotfac: LET n8=180-(ACS (b8*b8 + c8*c8 - a8*a8)/(2*b8*c8)): LET k8=INT (90*k8/n8 +.5) 9228 POKE rotfac,k8: PRINT "Rotation factor is";k8 9230 RETURN 9300 REM additional subroutines from file zero2 go here 9399 RETURN 'zero2 bas' BASIC FILE LISTING ------------------------------ Variables r0 used to pass routine number a1, a2, a3 used for input parameters o1, o2, o3 used for output parameters a8, b8, c8, k8, n8 used as scratch variables 9300 REM additional subroutines 9302 RESTORE 9320 9304 REM define subroutines 9306 READ write, outp, userl ,user2, read, inp, ready, split, lastbyte 9308 REM define variables 9310 READ zdend, usrloc, usr1, usr2 9320 DATA 9330, 9332, 9334, 9336, 9340, 9342, 9344, 9346, 9348 9322 DATA 64960, 64958, 94970, 64973 9330 POKE arg2,a2: LET rO=23: GO SUB call: GO SUB error: IF o1=3 THEN GO TO ornge 9331 RETURN 9332 LET rO=24: GO TO call 9334 POKE arg2,a2: POKE arg3,a3: LET rO=25: GO TO call 9336 POKE arg2,a2: POKE arg3,a3: LET rO=26: GO TO call 9338 POKE argl,al: GO SUB peek: LET o8=ol: GO SUB error: IF ol=3 THEN GO TO ornge 9339 LET ol=o8: RETURN 9340 LET rO=49: GO TO 9338 9342 LET rO=50: GO TO peek 9344 LET rO=40: GO TO peek 9346 POKE argl,al: GO SUB peek: LET o2=PEEK (arg2): RETURN 9348 LET rO=43: GO TO 9338 'LEARNLINEF' - Loader for machine code program TAPE VERSION 10 BORDER 1 15 CLEAR 60999 20 LOAD ""SCREEN$ 30 PRINT AT 19,0;"" 35 LOAD ""CODE 37 PRINT #1;"PRESS ANY KEY" 38 PAPER 6 40 PAUSE 0 50 RANDOMIZE USR 61000 MICRODRIVE VERSION 10 BORDER 1 15 CLEAR 60999 20 LOAD *"M";1;"*"SCREEN$ 30 PRINT AT 19,0;"" 35 LOAD *"M";1;"**"CODE 37 PRINT #1;" PRESS ANY KEY" 38 PAPER 6 40 PAUSE 0 50 RANDOMIZE USR 61000 FOUR PROGRAMS FOR ZER02 FROM INTERGALACTIC ROBOTS TO RUN ON A BBC MICRO 1. STEST, a self-test routine in BASIC makes ZERO2 run through its commands, while indicating on the screen that it is doing so. (It was written by a twelve—year old and should not be taken as a model of BBC BASIC programming style!) 2. SIMPLE is a simple BASIC program and is intended as a set of simple routines for hacking. As the program stands it just draws a square. 3. JOYSTIK allows you to set a fast speed (maximum about 80). It responds more quickly than the list-creating program, as it does not have to build a list.(BASIC and assembler) 4. LISTC is a list creating program. It is a convenient and user friendly environment in which you can get Zero2 to do most things, without needing to know BASIC. There are two MENUS, and you can alternate between the two by pressing the spacebar. The entry-menu is the first one you come to. Type in a series of instructions such as F1OO (Forward 1OOmm) and so on and the program will make a list of them: then press the spacebar to change to the second menu. Choose to eXecute the list, or Edit, Save or List it out, or maybe Delete it. Press the spacebar to get back to the first menu with your list intact, to add to it. If you would like Zero2 to move as you build the list, press 'I' to enter 'Immediate mode. Now Zero2 will move as you hold the keys down (only one at a time!) and at the same time clock up the distance or number of degrees turned. In this way you can drive Zero2 round in any pattern, then 'play it back' again afterwards, perhaps having edited the values in the meantime. If you want to set the Height of the pen-holder without affecting the list, you can do so by pressing "H" while in Immediate Mode. If you want to alter the speed Zero2 moves at, use the Cursor—Up and Cursor-Down arrows. Maximum is about 208, depending on the surface. If you set it too high it will stall. A joystick can be used instead of the keyboard, or in combination, (in Immediate Mode only), provided that it was plugged in when the program was first RUN. (RUN it again if necessary). The fire button controls PENDOWN. (Penup is in practice the same). When you eXecute the List you can have it REPEATED any number of times (watch the prompts) or run BACKWARDS. A convenience is provided when you REPEAT, to avoid the pen being lifted and dropped too much, as follows:- If you have a pendown/up command at the beginning and end of the list of commands, when you set it to repeat the list several times (and this is an easy way to draw a circle, for example) the program will ignore those pen movements except at the actual beginning and actual end. (BASIC and assembler) BBC Lineman Program --------------------- LOAD and RUN or CHAIN "LINEMAN". Place ZER02 straddling a black line 1 to 2 cm wide on a white background. Note that an optically black line may not be black, i.e. non-reflective, to infra-red. On pressing the spacebar the robot will start to follow the line, clearly showing on the screen the last 20 decisions made. To stop, press 'escape' or 'break'. To experiment with the sharpness of the turns ZERO2 makes, follow the instructions given on the screen. If all sensors see black ZERO2 reports a 'black line'. If the centre sensor sees white while the outer sensors see black, ZER02 reports a 'hole in line'. * * * * * * * PROBLEMS? SOME CAUSES OF BAD DRAWING Grease or dust on tyres. Wipe with Meths on tissue as wheels rotate. Pen set too low, lifting wheels! Table not level. Paper moving. CAUSE OF HESITATING Friction under front skid too great for motor—drive speed. Reduce friction OR s1ow motors down a little. KINK ON CORNERS Pen not centra11y located in clip. Straight pens are best. TOO SLOW Machine code delay set too high. ACCELERATES, THEN JUDDERS TO A STOP OR SLEWS ROUND Machine code delay set TOO LOW