'>KasTom_IR_earP08m2v2.bas 'from Loki SETFREQ m32 'serrxd,sertxd @38400 SERTXD("KasTom_IRearP08m2-v2.bas",CR) 'report program number #PicAxe 08m2 'Memory used = 810 bytes out of 2048 #no_data 'Slot 0 DATA (16,16,16,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' F F F . 'Slot 1 DATA (17,17,17,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' B B B . 'Slot 2 DATA (18,18,18,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' R R R . 'Slot 3 DATA (19,19,19,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' L L L 'Slot 4 DATA (16,16,61,17,17,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' F F, Alitalk B B . 'Slot 5 DATA (100,104,16,16,18,18,101,16,16,19,19,102,17,17,105,100,16,16,105,17,102,17,17,17,255,0,0,0,0,0,0,0) ' ss, vn, F, F, R, R, sm, F, F, L, L, sf, B, B, vh, ss, F, F, vh, B, sf, B, B, B, . 'Slot 6 DATA (16,16,18,18,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' F F R R. 'Slot 7 DATA (16,16,19,19,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) ' F F L L . '================================================================= Bugs: 'waitBS2: ' at the moment interupting an Act is very difficult ' not sure why '----------------------------------------------------------------- Rationale: '================================================================= Modified_and_New: Modified: New: '================================================================= Note: '================================================================= ProgramOverview: 'Modified_and_New: 'ProgramOverview: 'BambinoCommands: 'TVR010_PicAxe_IR_controller: 'CommandMapping: 'CommandMapping2: this is the version used 'VARIABLES_and_CONSTANTS: 'Movement commands 'EEPROM Acts, start addresses '------------------------------------------ 'INITIALISE: initialise Bambino 'defaultMIND 'initMIND: '------------------------------------------ 'ACTIVITIES: 'NewCmnd: 'Docmnd: ' select action on cmnd ' includes all cmnds listed under [KEY_xxx] ' Play and Record set playing and recording flags ' some actions alter cmnd and goto Docmnd to reprocess cmnd ' key Acts: could just drop through to IRcmnd but does a goto instead, ' saves testing the Play and Record flags ' 'RecordAct: ' if recording then ' if end of slot ' cmnd=end ' goto Docmnd to execute it ' write cmnd to selected act in eeprom ' 'PlayAct: ' if playing then ' read cmnd of selected act from eeprom ' if cmnd <> end of list ' goto Docmnd to execute it ' else drop through to IRcmnd: ' 'IRcmnd: ' wait for IR cmnd ' beep to acknowlede IR ' goto Docmnd ' '------------------------------------------ '================================================================= 'BEHAVIOURS: all done in BS2 'B_fast: 'B_medium: 'B_slow: 'B_USbold: 'B_USnormal: 'B_UStimid: '================================================================= 'REACTIONS: '================================================================= 'PROGRAM_ACTS: 'RockADo: '================================================================= '----------------------------------------- '================================================================= 'COMMUNICATION: 'HMI - Human Machine Interface 'getIR: 'badkey: 'beep50: 'squak: 'because that is what it sounds like 'beep255: '================================================================= 'cmndBS2: 'tellBS2: 'waitBS2: '================================================================= 'UTILITIES: 'IRgetKey1to8: 'IRgetAct_cmnd: 'nokey: 'Z: 'do nothing '================================================================= 'SENSE: '================================================================= LokiCommands: 'using TVR010_PicAxe_IR_controller #rem [KEY_POWER] stops a learned Act AND enters Command mode. ends modify mode, ends learning it can't stop a subroutine Act Direction Keys -------------- [KEY_UP] ie [Fd] STEP Forward [KEY_DOWN] ie [Bk] STEP Backward [KEY_RIGHT] ie [Rt] STEP Right [KEY_LEFT] ie [Lt] STEP Left Function Keys ------------- [KEY_BAR] ie [f|] enters learn mode TO record key presses has TO be followed by a number key 1-8 = the Act TO be remembered up TO 8 Acts can be learned learned Acts can call subroutine Acts Acts can chain TO other Acts, eg Fd,Bk,2 - chain TO Act2 A learned Act which chains itself repeats forever, eg [f|][1][Fd][1][POWER] Act1 will DO Fd forever [KEY_TENT] ie [f^] selects subroutine Acts = SAct, has TO be followed by a number key 1-8 plays SActs, SActs play UNTIL the END. [KEY_1] is RockAdo [KEY_VCROSS] ie [f+] [mode+] BS2Do has TO be followed by a number key 1-8 selects BS2Do [KEY_XCROSS] ie [fX] Dump EEPROM Acts DATA TO PC, including Config DATA Act Keys -------- [1] TO [8] Play an Act [f^][1] TO [f^][8] Play a subroutine Act When Recording an Act, [1]-[8] record a jump TO a new Act IF [1],[2],[3],[4],[5],[6],[7].[8],[0] are used TO jump TO another Act there is no point in recording more moves because they will never be replayed since control is transfered TO the new Act, just press [KEY_POWER] TO END the recording; [f^] THEN [1]-[8] TO DO AND include a Subroutine Act (SAct); when the memory slot is full Bambino will beep AND recording will END. {Act8 Autoruns ON PowerOn - won't work properly} Behaviour Key ------------- [9] Behaviour mode eg [9][1] set speed slow [1] set speed slow [2] set speed medium [3] set speed fast [4] set vitality TO LOW [5] set vitality TO normal [6] set vitality TO HIGH [-] disable Ground test ' [+] disable Tip test ' [9] set US behaviour to User values set by handset ' [KEY_UP] B_faster: - increase speed ' [KEY_0] B_normal: - normal speed ' [KEY_DOWN] B_slower: - decrease speed Sensor Keys ----------- [-] enable Ground sensors [+] enable Tip test Activity Key ------------ [0] RETURN control TO BS2 Tasker Quirks ------ IF you are recording Act1 AND press [f|][2] THEN you will start TO record Act2 AND Act1 will be left without placing an END marker. IF Act1 is THEN played the new moves will be played THEN whatever moves remained there from before. IF you enter record mode but press [POWER] before pressing a valid Act key [1] - [8] THEN UNTIL you press [POWER] a second time any commands will be recorded in Act #6. There is no room left TO correct this! [KEY_POWER]=21 @32bytes per slot =>$2A0 =>$A0 =160 =slot #6 ================================================================= 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). #endrem '------------------------------------------- '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]=speed up SYMBOL KEY_DOWN = 17 '[Bk] Step Backward [9][Bk]=speed down SYMBOL KEY_RIGHT = 18 '[Rt] Step Right SYMBOL KEY_LEFT = 19 '[Lt] Step Left SYMBOL KEY_BAR = 96-60 '[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+] BS2Do ' [f+][1]=>AliTalk ' [f+][2]=>rockNroll SYMBOL KEY_DIAG_CROSS = 20 'use synonym for easier coding SYMBOL KEY_XCROSS = 20 '[fX] transfer EEPROM to PC for including in programs ' -- Commands -- options -- BS2Do -- SYMBOL KEY_1 = 0 '[1] [9][1]=set speed slow ([f+][1]=>AliTalk) SYMBOL KEY_2 = 1 '[2] [9][2]=set speed medium ([f+][2]=>rockNroll) SYMBOL KEY_3 = 2 '[3] [9][3]=set speed fast SYMBOL KEY_4 = 3 '[4] [9][4]=(set vitality to low) SYMBOL KEY_5 = 4 '[5] [9][5]=(set vitality to normal) SYMBOL KEY_6 = 5 '[6] [9][6]=(set vitality to high) SYMBOL KEY_7 = 6 '[7] [9][7] SYMBOL KEY_8 = 7 '[8] [9][8] SYMBOL KEY_9 = 8 '[9] set Behaviour modes [9][9] SYMBOL KEY_MINUS = 98-60 '[-] enable foot sensors [9][-]=disable foot test SYMBOL KEY_0 = 9 '[0] Halt [9][0]=B_normal: - normal speed SYMBOL KEY_PLUS = 11 '[+] enable whisker sensors[9][+]=disable Whiskers test '================================================================= 'CommandMapping100: 'not used '0-98 IR controller 'cmnd =cmnd +108 subroutine Acts and other '[9] Behaviour +200 bad keys 98- 96| ' 0 1 2 3 4 5 6 7 8 9 11 16 17 18 19 20 21 37 54 96 98 'SHIFT100 subroutine Acts '100 101 102 103 104 105 106 107 108 109 111 116 117 118 119 120 121 137 154 196 198 'SHIFT200 behaviours '200 201 202 203 204 205 206 207 208 209 211 216 217 218 219 220 221 237 254 CommandMapping60: 'key//60 ' this is the Loki version - Pop is different 'if -60 on IRIN then '{>50 then -50 =0 1 2 3 4 5 6 7 8 9 11 16 17 18 19 20 21 37 46 48 54} possible but not used ' >60 then -60 =0 1 2 3 4 5 6 7 8 9 11 16 17 18 19 20 21 36 37 38 54 'allows 4+ sets of key mappings 0-59 60-119 120-179 180-239 and 240-255 =0 1 2 3 4 5 6 7 8 9 + SYMBOL shiftSAct200 =200 '[f^][x] SYMBOL shiftBehave100 =100 '[9][x] SYMBOL shiftDo60 =60 '[f+][x] '================================================================= PIN_MAPPING: 'C.0 serin 'Loki symbol SerFromBS2 =C.1 '10K pulldown, on reset BS2 sets Rdy highZ symbol EarRdy_ =C.1 symbol SerToBS2 =C.1 symbol BS2Rdypin =pin2 symbol BS2Rdy =C.2 symbol inIR =C.3 symbol inIRpin =pin3 symbol earLED =C.4 'C.5 sertxd ' _ _ ' +V | V | 0v ' sertxd C.5 | | C.0 serin ' earLED C.4 | | C.1 EarRdy_/SertoBS2 BSe15 idle is LOW ' inIR C.3 |___| C.2 BS2Rdy BSe14 ' '----------------------------------------- VARIABLES_and_CONSTANTS: SYMBOL tempW0 =W0 SYMBOL temp0 =B0 'initialise: walk: SYMBOL tempLo =B0 'SYMBOL eyelit =B0 'QEwhiskerX 'SYMBOL whisklit =B0 'QGwhiskerX SYMBOL temp1 =B1 SYMBOL tempHi =B1 'SYMBOL tempW1 =W1 SYMBOL M_flags =B2 'Mind flags 'SYMBOL f_mapR =bit22 'obstacle/hole map R 'SYMBOL f_mapL =bit23 'obstacle/hole map L SYMBOL B_flags =B3 'Behaviour flags SYMBOL f_dowhiskers =bit24 '0=ignore Eye and Ground Whiskers SYMBOL f_doUS =bit25 '0=ignore US SYMBOL f_memturn =bit26 '1=turned Left, 0= turned Right 'SYMBOL f_hole =bit27 '1=a hole SYMBOL f_play =bit28 '1=playing SYMBOL f_record =bit29 '1=recording 'SYMBOL f_direction =bit30 'currrent direction Fd=1, Bk=0 SYMBOL f_Bfast =bit31 'speed Behaviour 1=use B_fast: 'SYMBOL Scentre =W2 'SYMBOL maxkey =B4 'maxkey for IRgetKey 'SYMBOL paceC =B5 '100 is left foot back, 200 left foot forward 'SYMBOL Sat =W3 'current servo positions 'SYMBOL rollat =B6 'SYMBOL paceat =B7 'SYMBOL Sto =W4 'desired servo positions 'SYMBOL rollto =B8 'SYMBOL paceto =B9 SYMBOL Sspeed =W5 SYMBOL rollspeed =B10 '4 is too fast, 0 won't move SYMBOL pacespeed =B11 '6 is about max for servos to keep up 'SYMBOL Smoveby =W6 'SYMBOL rollby =B12 '+ve right 15 good for walking 'SYMBOL paceby =B13 '+ve Left foot forward 20@speed 3; 25@speed 1 'SYMBOL Light =W7 'SYMBOL lightR =B14 'light level Right 'SYMBOL lightL =B15 'light level Left 'SYMBOL counters =W8 'SYMBOL i =B16 '_iStand: 'SYMBOL spulse =B16 'FOR NEXT counter for servo pulses SYMBOL iA =B17 'counter for Acts SYMBOL SAct =B17 'W9 SYMBOL Ado =B18 'parameter for Acts 'SYMBOL bitmap_obs =B19 '%11 bitmap of obstacles %LeftRight 'w10 SYMBOL Act =B20 SYMBOL BeHave =B20 SYMBOL Apend =B21 'Penultimate end of record slot 'w11 SYMBOL eptr =B22 'pointer to EEPROM SYMBOL BS2prompt =B23 ' SYMBOL cmnd =B24 SYMBOL param =B24 SYMBOL BS2cmnd =B25 'b26 - b27 SYMBOL slot7E =255 'slot 7 End, don't overwrite Config Data '================================= 'EEPROM Acts, start addresses SYMBOL act0s =0 ' 0-31 SYMBOL act1s =32 '32-63 SYMBOL act2s =32 *2 '64-95 SYMBOL act3s =32 *3 '96-127 SYMBOL act4s =32 *4 '128-159 SYMBOL act5s =32 *5 '160-191 SYMBOL act6s =32 *6 '192-223 SYMBOL act7s =32 *7 '224-255 '----------------------------------------- '================================================================= INITIALISE: SERTXD("INITIALISE",CR) HIGH EarRdy_ 'nothing to send LOW earLED 'in case we get here from timeout in cmndBS2: initMIND: f_record =0 Ado =4 'for RockAdo ' cmnd =KEY_8 'Autorun 8 ' GOTO NewCmnd '================================================================= ACTIVITIES: WaitIRcmnd: LOW earLED SERTXD(CR,">") IF f_record=1 THEN HIGH earLED 'mouth lit ENDIF GOSUB getIR NewCmnd: TOGGLE earLED 'GOSUB beep50 'so we know IR received PAUSE 50 TOGGLE earLED DoCmnd: ' SERTXD(CR,"DoCmnd:") SERTXD("!",#cmnd,",",#f_record,CR) GOSUB nokey SELECT cmnd '[POWER],[UP],[DOWN],[RIGHT],[LEFT],[0] CASE KEY_POWER IF f_record=0 AND f_play=0 THEN BS2cmnd =5 GOSUB tellBS2 '5=Halt GOTO WaitIRcmnd: ELSE f_play =0 IF f_record=1 THEN f_record =0 WRITE eptr,255 'end marker LOW earLED ENDIF ENDIF CASE KEY_UP BS2cmnd =1 GOSUB tellBS2 CASE KEY_DOWN BS2cmnd =2 GOSUB tellBS2 CASE KEY_RIGHT BS2cmnd =3 GOSUB tellBS2 CASE KEY_LEFT BS2cmnd =4 GOSUB tellBS2 CASE KEY_0 BS2cmnd =9 GOSUB tellBS2 '[1]-[8] Acts CASE cmnd 0-7 Acts 1-8 IF f_record<>1 THEN f_play=1 'play eptr =32 *cmnd 'set to start SERTXD(CR,"p@",#eptr) ENDIF '[9] Behaviour CASE KEY_9 GOSUB getIR cmnd =cmnd +shiftBehave100 GOTO NewCmnd '[+] CASE KEY_PLUS ' GOSUB tellBS2 '[-] CASE KEY_MINUS BS2cmnd =22 GOSUB tellBS2' StbOn CON 22 '[f|] record CASE KEY_BAR f_play =0 SERTXD(CR) GOSUB IRgetAct_cmnd IF cmnd=KEY_POWER THEN WaitIRcmnd '[POWER] pressed so quit f_record =1 eptr =32 *cmnd Apend =eptr +31 MAX slot7E 'to avoid overwriting EEPROM config DATA HIGH earLED 'mouth lit for record SERTXD("r@",#eptr,CR) GOSUB nokey GOTO WaitIRcmnd 'get cmnds '[f^] subroutine Acts CASE KEY_TENT 'subroutine acts GOSUB IRgetAct_cmnd cmnd =cmnd +shiftSAct200 '[POWER]+shiftSAct200 will still execute as [POWER] SERTXD(" S",#cmnd,CR) GOTO DoCmnd 'already beeped '[f+] BS2Do CASE KEY_VCROSS GOSUB IRgetKey0to9 cmnd =cmnd +shiftDo60 SERTXD(" D",#cmnd,CR) GOTO DoCmnd 'already beeped '[fX] Dump 'Remember internal Slots/Acts are 0-7 keys [1]-[8] CASE KEY_XCROSS 'Dump sends DATA to PC, include Config Data FOR Act=0 TO 7 SERTXD(CR,"'Slot ",#Act,CR,"DATA (") FOR eptr=0 TO 30 temp0 =Act *32 +eptr READ temp0,cmnd SERTXD(#cmnd,",") NEXT eptr temp0 =Act *32 +31 READ temp0,cmnd SERTXD(#cmnd,")") NEXT Act SERTXD(CR) BS2cmnd =$2A GOSUB tellBS2 'dump BSe Acts in decimal 'do subroutine Acts 'non for Loki CASE >=shiftSAct200 SAct =cmnd -shiftSAct200 SERTXD("S",#cmnd,CR) ON SAct GOSUB RockADo 'empty 'do Behaviours CASE >=shiftBehave100 param =cmnd -100 SELECT CASE cmnd CASE 0 BS2cmnd =$22 param =$11 GOSUB tellBS2 '42=s $rp =$11 speed CASE 1 BS2cmnd =$22 param =$33 GOSUB tellBS2 '42=s $rp =$33 speed CASE 2 BS2cmnd =$22 param =$55 GOSUB tellBS2 '42=s $rp =$55 speed CASE 3 BS2cmnd =$1B GOSUB tellBS2 'be UStimid CASE 4 BS2cmnd =$1C GOSUB tellBS2 'be USnormal CASE 5 BS2cmnd =$1D GOSUB tellBS2 'be USbold CASE 16 BS2cmnd =$10 GOSUB tellBS2 'Su=$10 'increase speed(+1) MAX potspeed CASE 17 BS2cmnd =$11 GOSUB tellBS2 'Sd=$11 'reduce speed(/2) MIN minpacespeed CASE 38 BS2cmnd =$13 GOSUB tellBS2 'StbOff=98-60 [9][-]=disable foot test ENDSELECT 'behave =cmnd -shiftBehave100 'cmnd 0 1 2 'keys [1] [2] [3] 'do BS2Do CASE >=shiftDo60 SERTXD("D",#cmnd,CR) param =cmnd -60 BS2cmnd =$2F GOSUB tellBS2 ;$2F =c, jump TO Act number in NEXT Byte END SELECT '------------- recordAct: IF f_record=1 THEN IF eptrbreak _playon: SERTXD("@",#eptr) READ eptr,cmnd Eptr =eptr +1 IF cmnd<>255 THEN DoCmnd '255=end f_play =0 ENDIF '------------- GOTO WaitIRcmnd: '================================================================= BEHAVIOURS: 'all done in BS2 '---------- 'B_faster: 'vitality Behaviour ' RETURN 'B_normal: 'vitality Behaviour ' RETURN 'B_slower: 'vitality Behaviour ' RETURN 'B_fast: 'speed Behaviour ' RETURN 'B_medium: 'speed Behaviour ' RETURN 'B_slow: 'speed Behaviour ' RETURN 'B_noWhiskers: f_doWhiskers =0 RETURN 'B_noUS: f_doUS =0 RETURN '================================================================= PROGRAMMED_ACTS: '--------------- RockADo: BS2cmnd =2 '@ GOSUB tellBS2 RETURN '================================================================= COMMUNICATION: 'HMI - Human Machine Interface '------------- getIR: 'sertxd("getIR") IRIN inIR,cmnd 'Get cmnd cmnd =cmnd//60 RETURN badkey: TOGGLE earLed PAUSE 800 '100ms TOGGLE earLed PAUSE 800 '100ms TOGGLE earLed PAUSE 800 '100ms TOGGLE earLed RETURN beep50: SETFREQ m4 SOUND earLed,(50,20) SETFREQ m32 RETURN squak: 'because that is what it sounds like beep255: ' SOUND earLed,(255,80) '(255,10ms) @32MHz 'HIGH VoiceLed RETURN '================================================================= tellBS2: TOGGLE earLED LOW EarRdy_ 'tell BS2 got ircmnd ' = LOW SerToBS2 'idle is LOW waitBS2: sertxd("'") IF inIRpin=0 THEN GOSUB getIR IF BS2Rdypin=0 THEN waitBS2 PAUSE 5 'wait for BSe to get ready, pause 1 is too short. SEROUT SerToBS2,N9600_32,(BS2cmnd,param) sertxd(#BS2cmnd,",",#param) HIGH EarRdy_ 'tell BS2 nothing to send GOSUB nokey 'wait for finger off button TOGGLE earLED RETURN '================================================================= UTILITIES: '--------- IRgetKey0to9: IRIN inIR,cmnd 'key1 - key8 => 0-7 IF cmnd=9 THEN :cmnd =0 :ENDIF IF cmnd<9 THEN :cmnd =cmnd+1 :GOTO _IRget0to9End :ENDIF IF cmnd=KEY_POWER THEN RETURN ENDIF 'quit GOSUB badkey GOTO IRgetKey0to9 'repeat until valid act _IRget0to9End: GOSUB beep50 RETURN IRgetKey1to8: IRgetAct_cmnd: IRIN inIR,cmnd 'key1 - key8 => 0-7 IF cmnd<8 THEN _IRgetActEnd IF cmnd=KEY_POWER THEN RETURN ENDIF 'quit GOSUB badkey GOTO IRgetAct_cmnd 'repeat until valid act _IRgetActEnd: GOSUB beep50 RETURN nokey: IRIN [50,_nokeyend],inIR,temp0 'IRIN timeout =>reurn GOTO nokey _nokeyend: Z: RETURN '=================================================================