REM > Simplhex DLB 16-12-94 'BS2 READ 255,b0 :DEBUG b0 '0 #no_data #picaxe 18m2 SETFREQ M32 SERTXD(CR,"Simplhex 18m2 v4",CR) '@38400 SYMBOL pulsescale =8 'for M32 'SYMBOL pulsescale =4 'for M16 #rem PicAxe18m2 IR 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+ A SRI IN OUT B.0 |6 13| B.7 IN OUT ADC TOUCH $L B DSMOUT SDA ADC TOUCH IN OUT B.1 |7 12| B.6 IN OUT ADC TOUCH $R C DSMIN HSERIN ADC TOUCH IN OUT B.2 |8 11| B.5 IN OUT ADC TOUCH HSEROUT F D PWM ADC TOUCH IN OUT B.3 |9 10| B.4 IN OUT ADC TOUCH SCL E IR commands - TVR010_PicAxe_IR_controller [^] pace F [v] pace B [>] R turn step [<] L turn step [Power] IF standing THEN sit ELSE stand [0] walk [1] speed =1 [2] speed =2 [3] speed =3 [4] speed =4 [5] speed =5 [6] speed =6 'History '------- .01May21 v4 978 bytes, added single instead of double steps and stood-up turns. now M32 '13Apr21 v3 726 bytes ' added speeds 1,2,4,6,8 on IRkeys 1,2,3,4,5 - default is speed 2 ' 8 doesn't complete full leg travel but smooth and fast. '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 v0 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 --A C | |C B-- R1 ' R Br| |BrR ' | | ' L2 --E D | |D F-- R2 ' Y Or| |OrY ' | | ' L3 --A C |_|C B-- R3 ' BlGr GrBl ' servos Leg#, Limb/Hip, colour -Red,Blue,Green,Yellow ' A L1LR L3LBl ' B R3LBl R1LR ' C L1HBr L3HGn R3HGn R1HBr ' D L2HOr R2HOr ' E L2LY ' F R2LY 'Hitec HS300 - 4.8,6v 0.19sec,0.15sec 3kg.cm(41.66oz.in),3.7kg.cm(51.38oz.in) 'step is about 2" - all feet vary 1 7/8" - 2 1/4" 'speed5 3.75sec for 3ft - 1.25sec / ft, ~0.2sec/step - 9.6" /sec 'PicAxe18m2 Frame rate is about 14ms - there is no frame pause 'Pic16C84 MEL Frame rate is about 6ms - there is no frame pause 'BS1 Frame rate is about 25ms - there is no frame pause 'w0 b1 b0 flags 'w1 servo A b3 toA b2 atA 'Left front triangle up =2ms 'w2 servo B b5 toB b4 atB 'Right front triangle, down =2ms 'w3 servo C b7 toC b6 atC '4 corners swing, anticlock=2ms 'w4 servo D b9 toD b8 atD 'middle swing anticlock=2ms 'w5 servo E b11 toE b10 atE 'middle Right,Up 2ms 'w6 servo F b13 toE b12 atF 'middle Left Down 2ms 'w1 b15 toX b14 atX #endrem SYMBOL servoA = B.0 'pin SYMBOL servoB = B.1 'pin SYMBOL servoC = B.2 'pin SYMBOL servoD = B.3 'pin SYMBOL servoE = B.4 'pin SYMBOL servoF = B.5 'pin SYMBOL feelR = pinB.6 SYMBOL feelL = pinB.7 SYMBOL IRpin = C.2 SYMBOL inIRpin = pinC.2 ' bit0-31 b0-27 w0-13 SYMBOL f_allmoved = bit0 SYMBOL f_standing = bit1 SYMBOL f_autowalk = bit2 SYMBOL f_Rforward = bit3 '1=front Right foot is forward SYMBOL speed = B1 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 atE = B10 SYMBOL toE = B11 SYMBOL atF = B12 SYMBOL toF = B13 SYMBOL atX = B14 SYMBOL toX = B15 SYMBOL cmnd = B16 SYMBOL IRcmnd = B17 SYMBOL Wpulse = W9 SYMBOL true = 1 SYMBOL false = 0 SYMBOL touched = 0 'feeler state for touched SYMBOL pace = 25 SYMBOL down = 45 SYMBOL walkclear = down -20 SYMBOL upAsit = 165 '158 163 SYMBOL upAwalk = upAsit -walkclear SYMBOL downA = upAsit -down SYMBOL upBsit = 105 '106 112 SYMBOL upBwalk = upBsit +walkclear SYMBOL downB = upBsit +down SYMBOL upEsit = 100 '101 SYMBOL upEwalk = upEsit +walkclear SYMBOL downE = upEsit +down SYMBOL upFsit = 175 '164 SYMBOL upFwalk = upFsit -walkclear SYMBOL downF = upFsit -down SYMBOL midswingC = 135 '134 135 SYMBOL clockC = midswingC +pace SYMBOL CRF = clockC 'C Right Forward SYMBOL anticlockC = midswingC -pace SYMBOL CRB = anticlockC 'C Right Back SYMBOL midswingD = 130 '129 124 SYMBOL clockD = midswingD +pace SYMBOL DRF = clockD 'D Right Forward SYMBOL anticlockD = midswingD -pace SYMBOL DRB = anticlockD 'D Right Back 'stand 45 from sit 'walk 30 from sit 'stride 30 from mid 'L1C mid 135 R1C mid 135 'L1A sit 165 R1B sit 105 'L2D mid 130 R2D mid 130 'L2E sit 100 R2F sit 175 'L3C mid 135 R3C mid 135 'L3A sit 165 R3B sit 105 ' I7---\ _ /---I6 ' | | ' L1 --A C | |C B-- R1 ' R Br| |BrR ' | | ' L2 --E D | |D F-- R2 ' Y Or| |OrY ' | | ' L3 --A C |_|C B-- R3 ' BlGr GrBl '================================================================= 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 atD =midswingD toD =atD 'middle legs straight out, see Note atC =midswingC toC =atC 'corner legs straight out atA =upAsit atB =upBsit atE =upAsit atF =upAsit speed =2 GOSUB sit 'wait: PAUSE 1000 GOSUB stand f_Rforward =1 IF feelL<>touched AND feelR<>touched THEN walk Commander: SERTXD(">") f_autowalk =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 GOSUB mid ELSE GOSUB stand ENDIF CASE "0" GOTO walk CASE "1" speed =1 CASE "2" speed =2 CASE "3" speed =4 CASE "4" speed =6 CASE "5" speed =8 CASE "6" speed =10 ENDSELECT GOTO Commander ' I7---\ _ /---I6 ' | | ' L1 --A C | |C B-- R1 ' R Br| |BrR ' | | ' L2 --E D | |D F-- R2 ' Y Or| |OrY ' | | ' L3 --A C |_|C B-- R3 ' BlGr GrBl ' servos ' A L1LR L3LBl ' B R3LBl R1LR ' C L1HBr L3HGn R3HGn R1HBr ' D L2HOr R2HOr ' E L2LY ' F R2LY walk: IF feelL=touched OR feelR=touched THEN turn f_autowalk =true GOSUB paceF GOTO walk 'AE, now anticlockwise, B clockwise turn: sertxd("t") GOSUB stand 'BS1 too many GOSUBs to directly RT / LT IF feelR=touched OR cmnd="L" THEN LT 'if not feelL must be feelR, so RT RT: IF f_Rforward=1 THEN RTRF RTLF: toE =upEwalk toF =upFwalk toD =DRB GOSUB move GOSUB stand toA=upAwalk toB =upBwalk GOSUB move toD =DRF GOSUB move GOSUB stand GOTO feeler_test RTRF: toA =upAwalk toB =upBwalk toC =CRB toD =DRF GOSUB move f_Rforward=0 GOSUB stand GOTO feeler_test LT: IF f_Rforward=0 THEN LTLF LTRF: toE =upEwalk toF =upFwalk toD =DRF GOSUB move GOSUB stand toA=upAwalk toB =upBwalk GOSUB move toD =DRB GOSUB move GOSUB stand GOTO feeler_test LTLF: toA =upAwalk toB =upBwalk toC =CRF toD =DRB GOSUB move f_Rforward=1 GOSUB stand feeler_test: IF feelL=touched OR feelR=touched THEN turn IF f_autowalk=true THEN walk GOTO Commander paceF: IF f_Rforward=1 THEN paceFL paceFR: GOSUB stand sertxd("fr") toB =upBwalk toE =upEwalk 'GOSUB move 'lift right front toC =CRF toD =DRB GOSUB move f_Rforward =1 GOTO stand paceFL: GOSUB stand sertxd("fl") toA =upAwalk toF =upFwalk 'GOSUB move 'lift left front toC =CRB toD =DRF GOSUB move f_Rforward =0 GOTO stand mid: toC =midswingC toD =midswingD GOTO Move paceB: IF f_Rforward=0 THEN paceBL paceBR: f_standing =true GOSUB stand sertxd("br") toB =upBwalk toE =upEwalk GOSUB move 'lift right front toC =CRB toD =DRF GOSUB move f_Rforward =0 GOTO stand paceBL: f_standing =true GOSUB stand sertxd("bl") toA =upAwalk toF =upFwalk GOSUB move 'lift left front toC =CRF toD =DRB GOSUB move f_Rforward =1 ' fall through to stand, move and RETURN stand: sertxd("S")'DEBUG "stand",cr f_standing =true toA =downA toB =downB toE =downE toF =downF GOTO move sit: sertxd("s") f_standing =false toA =upAsit toB=upBsit toE =upEsit toF=upFsit '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 atX =atE toX =toE GOSUB calcnewat atE =atX atX =atF toX =toF GOSUB calcnewat atF =atX anymore: IF f_allmoved=true THEN donemove pulse: IF f_autowalk=1 AND inIRpin=0 THEN Commander 'frame rate ~14ms Wpulse =atA *pulsescale PULSOUT servoA,Wpulse Wpulse =atB *pulsescale PULSOUT servoB,Wpulse Wpulse =atC *pulsescale PULSOUT servoC,Wpulse Wpulse =atD *pulsescale PULSOUT servoD,Wpulse Wpulse =atE *pulsescale PULSOUT servoE,Wpulse Wpulse =atF *pulsescale PULSOUT servoF,Wpulse PAUSE 80 '5ms @32MHz frame rate without this pause is ~16ms 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="0" THEN PAUSE 2000 ENDIF 'finger off time for walk IF cmnd<>"z" THEN GotCmnd 'if bad IR then carry on ENDIF 'refresh servos here IF f_standing=true THEN Wpulse =atA *pulsescale PULSOUT servoA,Wpulse Wpulse =atB *pulsescale PULSOUT servoB,Wpulse Wpulse =atC *pulsescale PULSOUT servoC,Wpulse Wpulse =atD *pulsescale PULSOUT servoD,Wpulse Wpulse =atE *pulsescale PULSOUT servoE,Wpulse Wpulse =atF *pulsescale PULSOUT servoF,Wpulse PAUSE 80 '5ms @32MHz ENDIF GOTO GetCmnd GotCmnd: SERTXD(cmnd) RETURN