' {$STAMP BS1} '>Gaze21 DLB 24-4-95 'READ 255,B0 :DEBUG B0 '4 too FULL with this in '-- History 'Gaze21 18-11-03, renamed from Head21, all GazeControl Head files renamed Gaze 'head21 28-11-99, W2 seeded with $F0F0 so turn gets going immediately, ' lo bit gets altered and ripples up thru word. ' randseed a constant, autolim changed to 225, now no HeadxxA. ' mame pfreq changed to pwait since lower value is higher frequency. ' gazewait changed from 5sec to 2 sec 'head20a demo version of Head20 with autolim =170 ie 1:3 chance of autotrig. 'head20 prior to #35 12v motors were running on 5v! xxxspeedadjust was 40. 'Head19 gazeleft: was 'gaze =pos +turn MAX maxgaze +pgaze /2', pgaze ->gaze 'Head18a demo version of Head18 with autolim =170 ie 1:3 chance of autotrig. 'Head18 pturn calc '+20-10' removed, POT pfreq now included in waiting loop. ' tests in move loops moved from UNTIL to WHEN so turn=0 really is 0. ' maxgaze reduced by 10 to 220 and mingaze increased by 10 to 45, ' #4 demo head unit on auto trig. went right round to the left! 'Head17 revised auto so removal of trigger plug is not neccessary ' had to take out debug prog size though, - full!! 'Head16 is demo version of head15 'Head15 - documentation corrected, autolim=245, ie 1:25 chance 'Head14 - now has auto-trigger, set at powerup, on Gaze1, as well as ' normal Gaze1 operation 'Head13 - based on 11, pot reading reordered, now in order wanted by pgm 'Head12 - didn't work tried to interupt moves by trigers 'Head11 - self adjusting minimun speed 'Modified from HServo4, back to PWM drive 'HServo4 - LOW 4 taken out of init., pins set to 0 at start:, saved 1 byte '-- Notes ' anticlock pot clockwise ' Gaze1 high pgaze low ' Gaze2 high pgaze low ' Speed low pspeed high ' Freq high pwait low ' Gaze high pgaze low ' Turn low pturn high '-- Registers 'W0 b1 turn b0 tries 'W1 b3 pos b2 waitcount 'W2 rand b5 randhi b4 randlo 'W3 b7 pwait b6 pspeed 'W4 b9 pgaze b8 pturn 'W5 b11 speedadjust b10 gaze 'W6 GOSUB b13 b12 paux1 'no GOSUBs used SYMBOL randseed =$F0F0 'to get RANDOM going SYMBOL maxspeed =255 SYMBOL gazespeed =255 SYMBOL gazewait =2000 '2 secs SYMBOL gazecycles =4 SYMBOL gazetries =200 'tries to get to gaze position SYMBOL pscale =115 'POT scale factor, POT reads 7 to 240 about SYMBOL headpscale =255 'POT scale factor, POT reads 7 to 240 about SYMBOL maxgaze =210 SYMBOL mingaze =45 SYMBOL minspeedadjust =1 'program errors if <1 SYMBOL loopwait =500 '500ms per loop =>max of 2min, max av. 1min 'with seed triggers at 0,6,17,18, .., moves 'SYMBOL autolim =245 '1 in 25 chance of triggering on auto SYMBOL autolim =225 '1 in 8 chance of triggering on auto 'SYMBOL autolim =200 '1 in 5 chance of triggering on auto SYMBOL tries =B0 SYMBOL turn =B1 SYMBOL waitcount =B2 :waitcount =0 SYMBOL pos =B3 :pos =128 'guess head is set to midd position SYMBOL rand =W2 SYMBOL randlo =B4 SYMBOL randhi =B5 SYMBOL pspeed =B6 SYMBOL pwait =B7 SYMBOL pturn =B8 SYMBOL pgaze =B9 SYMBOL gaze =B10 SYMBOL speedadjust =B11 :speedadjust =minspeedadjust SYMBOL paux1 =B12 'address0 pin 0 'address1 pin 1 'address2 pin 2 'pot pin 3 SYMBOL motorgo =4 'pin SYMBOL aux1 =5 'pin - aux1 relay SYMBOL aux2 =6 'pin - aux2 relay SYMBOL motordir =7 'pin 'if trig1 closed on powerup then pot reading=paux1 is used as the auto 'trigger position for Gaze1, triggers every time randhi>=autolim initauto: DIRS =7 PINS =5 :POT 3,pscale,paux1 ' rand=randseed W2 =$F0F0 start: 'debug "start" RANDOM W2 'debug %w2 waitcount =0 readpots: DIRS =%11100111 'reset output port in case 'noise has corrupted it PINS =PINS & %10001000 | 5 'Aux relays off 'multiplexer address to 5, motor off PAUSE loopwait 'pause for waitcount 'don't change mtr relay, it clicks! triggerinputs: IF paux1<>0 AND randhi0 THEN trig1 'auto now check1: POT 3,pscale,pgaze 'read gaze1 IF pgaze=0 THEN check2 'trig input1 open so next trig1: pspeed =gazespeed HIGH aux1 'aux1 relay is on pin 5 GOTO dotriggaze check2: PINS =PINS +1 'increment address to 6 POT 3,pscale,pgaze 'read gaze2 IF pgaze=0 THEN continue1 'trig input2 open so next pspeed =gazespeed HIGH aux2 'aux2 relay is on pin6 GOTO dotriggaze continue1: PINS =PINS & %10001000 'Aux relays off 'multiplexer address to 0,motor off 'don't change mtr relay, it clicks! POT 3,pscale,pspeed 'speed pspeed =pspeed +speedadjust MAX maxspeed HIGH 0 'increment address to 1 POT 3,pscale,pwait 'look for new pwait pwait =pwait *randlo /256 'OK!! so we do the sum each loop! LOW 0 :HIGH 1 'increment address to 2 POT 3,pscale,pturn 'pturn pturn =pturn MIN 20 -20 'ensure 0 is reachable turn =randhi *pturn /256 HIGH 0 'increment address to 3 POT 3,pscale,pgaze 'gaze waitcount =waitcount +1 'debug waitcount,pwait IF waitcount0 dogaze: PINS =PINS & %11101000 | 4 'multiplexer address to 4 'don't change motor relay tries =0 gaze =pgaze MAX maxgaze MIN mingaze IF gaze>pos THEN gazeleft 'drift to gaze set on pot gazeright: HIGH motordir turn =turn MAX pos 'so pos -turn NOT<0 in next line gaze =pos -turn MIN mingaze +gaze /2 'really drift 'even if turn=0 PAUSE 255 'wait for relay, crashes otherwise !!! moveright: POT 3,headpscale,pos 'head position IF pos<=gaze OR tries>gazetries THEN donegaze PWM motorgo,pspeed,gazecycles tries =tries +1 GOTO moveright gazeleft: LOW motordir gaze =pos +turn MAX maxgaze +gaze /2 'really drift 'even if turn=0 PAUSE 255 'wait for relay, crashes otherwise !!! moveleft: POT 3,headpscale,pos 'head position IF pos>=gaze OR tries>gazetries THEN donegaze PWM motorgo,pspeed,gazecycles tries = tries +1 GOTO moveleft donegaze: IF tries