REM > Simplhex DLB 16-12-94 'BS2 READ 255,b0 :DEBUG b0 '0 #no_data #picaxe 18m2 SETFREQ M16 SERTXD(CR,"Simplhex 18m2 v2",CR) #rem PicAxe18m2 DAC ADC TOUCH IN OUT C.2 |1 18| C.1 IN OUT ADC TOUCH SRQ OUT SO C.3 |2 17| C.0 IN OUT ADC TOUCH IN SI C.4 |3 16| C.7 IN OUT KBD IN C.5 |4 15| C.6 IN OUT KBC 0V |5 14| V+ SRI IN OUT B.0 |6 13| B.7 IN OUT ADC TOUCH DSMOUT SDA ADC TOUCH IN OUT B.1 |7 12| B.6 IN OUT ADC TOUCH DSMIN HSERIN ADC TOUCH IN OUT B.2 |8 11| B.5 IN OUT ADC TOUCH HSEROUT PWM ADC TOUCH IN OUT B.3 |9 10| B.4 IN OUT ADC TOUCH SCL 'History '------- '13Apr21 v2 652 bytes ' added f_walking so IRcmnds R & L get back to Commander '12Apr21 v1 added IR control - memory used = 642 bytes out of 2048 '18-7-15 PicAxe18m2, 266 out of 2048, but never uploaded '5-5-97 b0 flag named, TRUE & FALSE added '8-4-97 if both feelers touched, now TURNs left, only waved legs before '7-4-97 pins rearanged to suit new Stamp board ' TURN bugs corrected, always turned left! '6-4-97 clockA, anticlockA was muddled , now corrected ' fromA etc now atA, I think I understand it better!? ' RT and LT now implemented, speed needs to be 2, 1 is very slow '10-3-95 from Simplhex, move now has gosub calc, more room left but slower ' walking and limit of 16 GOSUBS reached hence funny code. ' So still can't do a left turn! 'Note:- "fromA =midswingA :toA =fromA" if fromA is replaced by midswingA 'and simy for B then uses one more byte, why? 'simple walking based on Arc pgm servo configuration ' I7---\ _ /---I6 ' | | ' L1 --C B | |B D-- R1 ' R Br| |BrR ' | | ' L2 --D A | |A C-- R2 ' Y Or| |OrY ' | | ' L3 --C B |_|B D-- R3 ' BlGr GrBl ' servos ' A L2Or R2Or ' B L1Br L3Gn R3Gn R1Br ' C L1R L3Bl R2Y ' D L2Y R3Bl R1R ' 'BS1 Frame rate is about 25ms - there is no frame pause 'Pic16C84 MEL Frame rate is about 6ms - there is no frame pause 'w0 b1 b0 allmoved 'move flag 'w1 servo A b3 toA b2 atA 'middle swing, anticlock->2ms 'w2 servo B b5 toB b4 atB '4 corners swing, anticlock->2ms 'w3 servo C b7 toC b6 atC 'left front triangle, up=2ms 'w4 servo D b9 toD b8 atD 'right front triangle, down=2ms 'w5 b11 toX b10 atX #endrem SYMBOL servoA = B.0 'pin SYMBOL servoB = B.1 'pin SYMBOL servoC = B.2 'pin SYMBOL servoD = B.3 'pin SYMBOL feelR = pinB.6 SYMBOL feelL = pinB.7 SYMBOL IRpin = C.2 SYMBOL inIRpin = pinC.2 SYMBOL f_allmoved = bit0 SYMBOL f_standing = bit1 SYMBOL f_walking = bit2 SYMBOL atA = B2 SYMBOL toA = B3 SYMBOL atB = B4 SYMBOL toB = B5 SYMBOL atC = B6 SYMBOL toC = B7 SYMBOL atD = B8 SYMBOL toD = B9 SYMBOL atX = B10 SYMBOL toX = B11 SYMBOL cmnd = B12 SYMBOL IRcmnd = B13 SYMBOL Wpulse = W7 SYMBOL true = 1 SYMBOL false = 0 SYMBOL touched = 0 'feeler state for touched SYMBOL speed = 2 'if speed=2 then all positions must be even ' >2 then be carefull otherwise toX=atX never!!! SYMBOL upCsit = 170'180 SYMBOL upDsit = 100 SYMBOL upCwalk = 160 SYMBOL upDwalk = 120 SYMBOL downC = 120 SYMBOL downD = 160 SYMBOL clockA = 110 SYMBOL anticlockA = 150 SYMBOL clockB = 110 SYMBOL anticlockB = 150 SYMBOL midswingA = 140 SYMBOL midswingB = 140 '================================================================= TVR010_PicAxe_IR_controller: '--------------------------- 'Before use, the transmitter must be programmed with the 'Sony' transmit code. '1. Insert 2 AAA size batteries, preferably alkaline. '2. Press 'S' and 'B' at the same time. S is in the centre of the arrows. ' The top left red LED should light. '3. Press '0'. The LED should flash. '4. Press '1'. The LED should flash. '5. Press '3'. The LED should go out. '6. Press the red power button (top right). '------------------------------------------- 'IRin cmnds PicAxe controller 'DO NOT PRESS OTHER KEYS 'ie [A] [B] [C] [D] [E] [F] [G] 'They change the Mode and [B] has to be pressed to change back. '[square] [triangle] [()] [L] [X] [backwards F] have no effect '------------------------------------------- SYMBOL KEY_POWER = 21 'Sleep SYMBOL KEY_UP = 16 '[Fd] Step Forward [9][Fd]=set vitality Behaviour to faster SYMBOL KEY_DOWN = 17 '[Bk] Step Backward [9][Bk]=set vitality Behaviour to slower SYMBOL KEY_RIGHT = 18 '[Rt] Step Right SYMBOL KEY_LEFT = 19 '[Lt] Step Left SYMBOL KEY_BAR = 96 '[f|] learn an Act, next [key] selects an Act SYMBOL KEY_TENT = 54 '[f^] next [key] selects a Subroutine-Act SYMBOL KEY_VERT_CROSS = 37 'use synonym for easier coding SYMBOL KEY_VCROSS = 37 '[f+] Modify Mode {when routine included} ' [+] set USAwareAt in DUSawareAt ' [-] set UStoonear in DUStoonear ' {[Fd] alter PaceCentre in DpaceC} ' {[Bk] alter PaceCentre in DpaceC} ' {[Rt] alter RollCentre in DrollC} ' {[Lt] alter RollCentre in DrollC} ' { [-][+] to adjust } ' [Key_POWER] to quit SYMBOL KEY_DIAG_CROSS = 20 'use synonym for easier coding SYMBOL KEY_XCROSS = 20 '[fX] transfer EEPROM to PC for including in programs ' -- Subroutine-Act and Commands -- SYMBOL KEY_1 = 0 '[1] [f^][1]=>RockADo [9][1]=set speed slow SYMBOL KEY_2 = 1 '[2] [9][2]=set speed medium SYMBOL KEY_3 = 2 '[3] [9][3]=set speed fast SYMBOL KEY_4 = 3 '[4] [9][4]=set US behaviour to timid SYMBOL KEY_5 = 4 '[5] [9][5]=set US behaviour to normal SYMBOL KEY_6 = 5 '[6] [9][6]=set US behaviour to bold SYMBOL KEY_7 = 6 '[7] [9][7]=disable Whiskers test SYMBOL KEY_8 = 7 '[8] [9][8]=disable Ultrasonic test SYMBOL KEY_9 = 8 '[9] set Behaviour modes [9][9]=set US behaviour to User SYMBOL KEY_MINUS = 98 '[-] enable & test Whisker sensors and re-act, R_Whiskers: SYMBOL KEY_0 = 9 '[0] WANDER [9][0]=set vitality Behaviour to normal SYMBOL KEY_PLUS = 11 '[+] enable & test Ping sensor and re-act, R_Ping: '------------------------------------------- init: 'DIRS =%00111111 PINS =0 start: 'DEBUG "start",cr atA =midswingA :toA =atA 'middle legs straight out, see Note atB =midswingB :toB =atB 'corner legs straight out atC =upCsit atD =upDsit GOSUB sit 'wait: PAUSE 1000 GOSUB stand IF feelL<>touched AND feelR<>touched THEN walk Commander: SERTXD(">") f_walking =false GOSUB GetCmnd SELECT cmnd CASE "F" GOSUB paceF CASE "B" GOSUB paceB CASE "R" GOSUB turn CASE "L" GOSUB turn CASE "." IF f_standing=true THEN :GOSUB sit ELSE GOSUB stand ENDIF CASE "0" GOTO walk ENDSELECT GOTO Commander ' I7---\ _ /---I6 ' | | ' L1 --C B | |B D-- R1 ' R Br| |BrR ' | | ' L2 --D A | |A C-- R2 ' Y Or| |OrY ' | | ' L3 --C B |_|B D-- R3 ' BlGr GrBl ' servos ' A L2Or R2Or ' B L1Br L3Gn R3Gn R1Br ' C L1R L3Bl R2Y ' D L2Y R3Bl R1R walk: IF feelL=touched OR feelR=touched THEN turn f_walking =true GOSUB paceF GOTO walk 'A, is now anticlockwise, B clockwise turn: sertxd("t") GOSUB sit 'BS1 too many GOSUBs to directly RT / LT IF feelR=touched OR cmnd="L" THEN LT1 'if not feelL must be feelR, so RT RT1: toA =clockA :toB =toA :GOTO t1 LT1: toA =anticlockA :toB =toA t1: toC =downC GOSUB move LT2: toA =clockA :toB =toA 'setup LT check left, saves a GOTO IF feelR=touched OR cmnd="L" THEN t2 'if not feelR must be feelL, so RT2: toA =anticlockA :toB =toA 'RT t2: GOSUB move IF feelL=touched OR feelR=touched THEN turn IF f_walking=true THEN walk GOTO Commander paceF: f_standing =true GOSUB stand sertxd("f") toD =upDwalk :GOSUB move 'lift right front toA =clockA :toB =anticlockB :GOSUB move GOSUB stand toC =upCwalk :GOSUB move 'lift left front toA =anticlockA :toB =clockB :GOSUB move GOTO stand paceB: f_standing =true GOSUB stand sertxd("b") toC =upCwalk :GOSUB move 'lift right front toB =anticlockB :toA =clockA :GOSUB move GOSUB stand toD =upDwalk :GOSUB move 'lift left front toA =anticlockA : toB =clockB :GOSUB move ' fall through to stand, move and RETURN stand: sertxd("S")'DEBUG "stand",cr f_standing =true toC =downC :toD =downD GOTO move sit: sertxd("s") f_standing =false toC =upCsit :toD=upDsit 'fall through to move: move: 'DEBUG "move",cr f_allmoved =true 'if not finished calcnewmove sets allmoved =false atX =atA :toX =toA :GOSUB calcnewat :atA =atX atX =atB :toX =toB :GOSUB calcnewat :atB =atX atX =atC :toX =toC :GOSUB calcnewat :atC =atX atX =atD :toX =toD :GOSUB calcnewat :atD =atX anymore: IF f_allmoved=true THEN donemove pulse: IF f_walking=1 AND inIRpin=0 THEN Commander Wpulse =atA *4 '10us to 2.5us @16MHz PULSOUT servoA,Wpulse Wpulse =atB *4 '10us to 2.5us @16MHz PULSOUT servoB,Wpulse Wpulse =atC *4 '10us to 2.5us @16MHz PULSOUT servoC,Wpulse Wpulse =atD*4 '10us to 2.5us @16MHz PULSOUT servoD,Wpulse GOTO move donemove: RETURN calcnewat: IF atX=toX THEN endcalc 'calculate new servo position f_allmoved =false IF atX"z" THEN Gotcmnd LOOKDOWN IRcmnd,(KEY_POWER,KEY_UP,KEY_DOWN,KEY_RIGHT,KEY_LEFT,KEY_BAR,KEY_TENT,KEY_VCROSS,KEY_XCROSS),cmnd LOOKUP cmnd, ( ".", "F", "B", "R", "L", "r", "^", "v", "x"),cmnd IF cmnd<>"z" THEN GotCmnd 'if bad IR then carry on ENDIF 'refresh servos here IF f_standing=true THEN Wpulse =atA *4 '10us to 2.5us @16MHz PULSOUT servoA,Wpulse Wpulse =atB *4 '10us to 2.5us @16MHz PULSOUT servoB,Wpulse Wpulse =atC *4 '10us to 2.5us @16MHz PULSOUT servoC,Wpulse Wpulse =atD*4 '10us to 2.5us @16MHz PULSOUT servoD,Wpulse ENDIF GOTO GetCmnd GotCmnd: SERTXD(cmnd) RETURN