'>LokiIRcmnderP08m2-2 setfreq m8 'serrxd,sertxd @9600 'SETFREQ m32 SERTXD("LokiIRcmnderP08m2-2.bas",CR) 'report program number '782 bytes, takes 38 seconds to download #PicAxe 08m2 #no_data 'Memory used = 810 bytes out of 2048 '================================================================= Bugs: 'waitBS2: needs to be rewritten so it doesn't block IRin, at the moment interupting an Act is very difficult '----------------------------------------------------------------- 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 ' '[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 '* [7] disable Whiskers test '* [8] disable Ultrasonic 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 and test Whisker sensors and re-act, R_Whiskers: '*[+] enable and test Ping sensor and re-act, R_Ping: ' 'Activity Key '------------ '*[0] Return control to BS2 Do ' ' '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). '------------------------------------------- '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-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+] 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-60 '[-] 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: '================================================================= '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: ' this is the version used 'if -60 on IRIN then '{>60 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 shiftSAct60 =60 '[f^][x] SYMBOL shiftDo120 =120 '[f+][x] SYMBOL shiftBehave180 =180 '[9][x] '================================================================= PIN_MAPPING: 'C.0 serin symbol SerFromBS2 =C.1 '10K pulldown, on reset BS2 sets Rdy highZ symbol BS2Rdy =C.1 symbol BS2Rdypin =pin1 symbol voiceLED =C.2 symbol inIR =C.3 symbol SerToBS2 =C.4 symbol EarRdy =C.4 'C.5 sertxd ' _ _ ' +V | V | 0v ' sertxd C.5 | | C.0 serin ' EarRdy C.4 | | C.1 SerFromBS2/BS2Rdy ' inIR C.3 |___| C.2 voiceLED ' '----------------------------------------- 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 rollC =B4 '100 is roll to the left, 200 to the right '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 IRcmnd =B24 'cmnd from IRremote 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) LOW EarRdy 'nothing to send LOW voiceLED '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: SERTXD("k") IF f_record=1 THEN HIGH VoiceLED ENDIF 'mouth lit GOSUB getIR SERTXD(#cmnd) NewCmnd: GOSUB beep50 'so we know IR received DoCmnd: SERTXD(CR,"DoCmnd") SERTXD(CR,#cmnd) SELECT cmnd '[POWER],[UP],[DOWN],[RIGHT],[LEFT],[0] CASE KEY_POWER IF f_record=0 AND f_play=0 THEN GOSUB cmndBS2 GOTO WaitIRcmnd: ELSE f_play =0 IF f_record=1 THEN f_record =0 WRITE eptr,255 'end marker ENDIF 'GOSUB dump 'debug ENDIF CASE KEY_UP GOSUB cmndBS2 CASE KEY_DOWN GOSUB cmndBS2 CASE KEY_RIGHT GOSUB cmndBS2 CASE KEY_LEFT GOSUB cmndBS2 CASE KEY_0 GOSUB cmndBS2 '[1]-[8] Acts CASE cmnd 0-7 Acts 1-8 IF f_record<>1 THEN f_play=1 'play BS2cmnd =KEY_POWER 'tell BS2 to wait for cmnds GOSUB tellBS2 eptr =32 *cmnd 'set to start SERTXD("p@",#eptr,CR) ENDIF '[9] Behaviour CASE KEY_9 GOSUB nokey GOSUB getIR cmnd =cmnd +shiftBehave180 GOSUB beep50 GOTO DoCmnd '[+] CASE KEY_PLUS '[-] CASE KEY_MINUS GOSUB cmndBS2 '[mode|] record CASE KEY_BAR f_play =0 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 VoiceLED 'mouth lit for record BS2cmnd =KEY_POWER 'tell BS2 to wait for cmnds GOSUB tellBS2 GOSUB nokey SERTXD("r@",#eptr,CR) GOTO WaitIRcmnd 'get cmnds '[mode^] subroutine Acts CASE KEY_TENT 'subroutine acts GOSUB IRgetAct_cmnd cmnd =cmnd +shiftSAct60 '[POWER]+shiftSAct60 will still execute as [POWER] SERTXD(" S",#cmnd,CR) GOTO DoCmnd 'already beeped '[mode+] BS2Do CASE KEY_VCROSS GOSUB IRgetAct_cmnd cmnd =cmnd +shiftDo120 SERTXD(" D",#cmnd,CR) GOTO DoCmnd 'already beeped '[modeX] 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) 'do Behaviours CASE >=shiftBehave180 BS2cmnd =cmnd '-shiftBehave180 this is done by BS2 GOSUB tellBS2 'behave =cmnd -shiftBehave180 'cmnd 0 1 2 'keys [1] [2] [3] ' ON behave GOSUB B_slow,B_medium,B_fast ' IF behave=KEY_UP THEN GOSUB B_faster ' IF behave=KEY_0 THEN GOSUB B_normal ' IF behave=KEY_DOWN THEN GOSUB B_slower 'ignore other values 'do BS2Do CASE >=shiftDo120 SERTXD("D",#cmnd,CR) BS2cmnd =cmnd -shiftDo120 GOSUB tellBS2 'do subroutine Acts CASE >=shiftSAct60 SAct =cmnd -shiftSAct60 SERTXD("S",#cmnd,CR) ON SAct GOSUB RockADo 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 IF cmnd>60 THEN cmnd =cmnd -60 ENDIF RETURN badkey: LOW voiceLed PAUSE 800 '100ms HIGH voiceLed PAUSE 800 '100ms LOW voiceLed PAUSE 800 '100ms HIGH voiceLed RETURN beep50: ' SETFREQ m4 SOUND VoiceLed,(50,20) SOUND VoiceLed,(50,20) ' SETFREQ m8 'HIGH VoiceLed RETURN squak: 'because that is what it sounds like beep255: SOUND VoiceLed,(255,80) '(255,10ms) @32MHz 'HIGH VoiceLed RETURN '================================================================= cmndBS2: BS2cmnd =cmnd tellBS2: HIGH voiceLED HIGH EarRdy 'tell BS2 got ircmnd waitBS2: sertxd("wC") SERIN [30000,INITIALISE],SerFromBS2,N9600_8,BS2prompt 'get cmnd 'long timeout to give BS2 time to complete behaviours IF BS2prompt<>"C" THEN waitBS2 'not for us LOW EarRdy 'idle ready for SEROUT SEROUT SerToBS2,N9600_8,(BS2cmnd) LOW voiceLED GOSUB nokey 'wait for finger off button RETURN '================================================================= UTILITIES: '--------- 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,cmnd'IRIN timeout =>reurn GOTO nokey _nokeyend: Z: RETURN '=================================================================