'>Hxtr0-0.BSx debug "prog0" '============================================================== 'Milford Instruments http://www.milinst.com 'Hextor Design, Bug Commander - Behavioural Operating System 'and the Behavioural Controller programs by David Buckley '================================================================ '{$stamp BS2sx,Hxtr0-1,Hxtr0-2,Hxtr0-3,Hxtr0-4,Hxtr0-5,Hxtr0-6,Hxtr0-7} 'Unfortunately that was a long line, ask Parallax. '============================================================== 'Hxtr0-0.BSx - main 'Hxtr1-x.BSx - Activity sequencer 'Hxtr2-x.BSx - US Behaviour 'Hxtr3-x.BSx - Direct Control 'Hxtr4-x.BSx - Prog4 'Hxtr5-x.BSx - Prog5 'Hxtr6-x.BSx - Prog6 'Hxtr7-x.BSx - Utils- LCD menu and IR remote 'HxtrDoc-x.BSx - Meta Commands and Program Headers '============================================================== 'Parallax bug fix for Windoz Editor ver1.1 'must have a debug stmnt as first executable stmnt in page0 'otherwise editor will not always load some higher pages. 'debug cls '============================================================== 'New '--- 'Initialisation of the CommonRAM stack pointer at init1 'test of CommonRam 0 at init ' 'The menu system now no longer responds to IR commands, all IR 'control is in Prog7 ' 'Required knowledge: ' 'Meta command: 'BOS Commands: 'Common RAM: 'Constants: lcdoptions not used now 'Variables: dmbase,btnc now menc 'Routine: set1, set2 renamed as Qs4r170, Ts0r200 'Subroutine:default irin in irget was 15 now set to 0 'Labels: 'Sequence: A_setting1, A_setting2 now A_Qs4r170, A_Ts0r200 'usRules: 'Behaviour: 'LCD text: all messages altered '============================================================== 'Experiment with '============================================================== 'Direct Control 'turns on servo power and exits with servo power on 'BOSbusy goes low immediately, doesn't wait for move to finish '$speed;$servo - high nibble and low nibble respectively ' BOScmnd,arg1.arg2 ' 0,$speed;$servo,position ' 1,$XX,$servo,X ->P actual servo position ' 2,$XX,$servo,X ->S servo status, bit1-on bit0-done ' 3,X,X ->hiF,then loF two bytes all servo moved status ' 4,X,X ->hiR,then loR two bytes all servo on/off status ' 5,$XX;$servo,X stop pulsing servo ' '-------- Legs & Logical-Servos -------- ' ' Plan view of Hextor S - Servo(0 - 13) L - Legs(1 - 6) ' S L L S ' ( ) gripper 13 ' | | lift 12 ' L---F---R LEG NUMBERS ' 1,0 | 1 2 | 6,7 1=LF 2=RF ,L - left, R - Right ' 3,2 | 3 4 | 8,9 3=LM 4=RM ,M - mid, F - Front ' 5,4 | 5 6 | 10,11 5=LB 6=RB ,B - Back ' \-------/ ' '-------- Servo values and leg positions ------- ' f - forward m - middle b - backward 'Left Lf=255 Lm=127 Lb=0 'Right Rf=0 Rm=127 Rb=255 ' ' d - Down u - Up 'Left Ld=0 Lu=255 'Right Rd=255 Ru=0 ' '-------- Arm and Gripper positions ------- 'Arm up 255 'Arm down 0 'Gripper open 255 'Gripper closed 0 '-------------------------------------------------------------- 'Activities name-table program1 '------------------------------ A_null con 0 A_chirp1 con 1 A_beep2 con 2 A_wiggle1 con 3 A_wiggle2 con 4 A_wiggle3 con 5 A_Qs4r170 con 6 A_Ts0r200 con 7 A_tround con 8 A_beg con 9 A_Rface con 10 A_Lface con 11 A_F5 con 12 A_R5 con 13 A_L5 con 14 A_BR con 15 A_BL con 16 A_L3 con 17 A_R3 con 18 A_L2 con 19 A_R2 con 20 A_user1 con 21 A_user2 con 22 A_user3 con 23 A_user4 con 24 'Ultrasonic-behaviour name-table program2 '---------------------------------------- US_null con 0 US_sitcorner con 1 US_beg con 2 US_hello con 3 US_wander con 4 US_user1 con 5 US_user2 con 6 US_user3 con 7 US_user4 con 8 'Utilities name-table '--------------------- U_KirCon con 0 U_KlcdCon con 1 '-------------------------------------------------------------- 'common RAM '0 program to return to - all '1 Activity to do - Sequencer '2 USrules to do - US-behaviour '3 usyawn0 - US-behaviour '4 usyawn1 - US-behaviour '5 irin - current IR value on change of pgm '6 incS - include level for activities prog1 '7 menc - last menu code '8 mopt - menu option OAUIP '9 irwatch - 0=>ignore IR signal, 1=>act on it '10 program to run - all 'Note there is no test for the stack being too big, beware of 'the stack growing down through 4! '61 down sequence stack '62 sequence stack pointer '-------------------------------------------------------------- 'LCD commands. 'For more detailed information see the ILM-216 User Manual. 'Function ASCII '-------- ----- 'Null 0 'Cursor home 1 'Hide cursor 4 'Show underline cursor 5 'Show blinking-block cursor 6 'Bell (not implemented with Hextor LCD) 7 'Backspace 8 'Horezontal tab (4 columns) 9 'Smart linefeed (cursor down one line) 10 'Vertical tab (cursor up one line) 11 'Formfeed (clear screen) 12 'Carriage return 13 'Backlight on 14 'Backlight off 15 'Accept cursor position entry 16 ' 64 is the start of the first line ' 80 is the start of the second line 'Format right aligned text 18 'Escape (ESC; start multipart instruction) 27 '--------- LCD messages - finish each message with Null ------- dbtxt data 12,4,16,80,"back < > do ",0 dOK data 16,78,"ok",0 dfree data 16,78," ",0 dnoir data 16,64,"IR watch is OFF ",0 dir data 16,64,"IR watch is ON ",0 'keep all following text 12 bytes long or addressing is wrong 'end each list with 0 '1=homecursor,"",0=null=>end of list dmo0 data 1,"OPTIONS v.0",0 '0 data 1,"Activities ",0 '1 data 1,"US behaviour",0 '2 data 1,"Programs ",0 '3 data 1,"Settings ",0 '4 data 0 dma0 data 1,"ACTIVITIES ",0 '0 data 1,"A_chirp1 ",0 '1 data 1,"A_beep2 ",0 '2 data 1,"A_wiggle1 ",0 '3 data 1,"A_wiggle2 ",0 '4 data 1,"A_wiggle3 ",0 '5 data 1,"A_Qs4r170 ",0 '6 data 1,"A_Ts0r200 ",0 '7 data 1,"A_tround ",0 '8 data 1,"A_beg ",0 '9 data 1,"A_Rface ",0 '10 data 1,"A_Lface ",0 '11 data 1,"A_F5 ",0 '12 data 1,"A_R5 ",0 '13 data 1,"A_L5 ",0 '14 data 1,"A_BR ",0 '15 data 1,"A_BL ",0 '16 data 1,"A_L3 ",0 '17 data 1,"A_R3 ",0 '18 data 1,"A_L2 ",0 '19 data 1,"A_R2 ",0 '20 data 1,"A_Iflash ",0 '21 data 1,"A_user1 ",0 '22 data 1,"A_user2 ",0 '23 data 1,"A_user3 ",0 '24 data 1,"A_user4 ",0 '25 data 0 dmu0 data 1,"US BEHAVIOUR",0 '0 data 1,"US_sitcorner",0 '1 data 1,"US_beg ",0 '2 data 1,"US_hello ",0 '3 data 1,"US_wander ",0 '4 data 1,"US_user1 ",0 '5 data 1,"US_user2 ",0 '6 data 1,"US_user3 ",0 '7 data 1,"US_user4 ",0 '8 data 0 dmp0 data 1,"PROGRAMS ",0 '0 data 1,"Do LCD Keys ",0 '1 data 1,"Do IR Keys ",0 '2 data 1,"RUN BOScon ",0 '3 data 1,"RUN Prog4 ",0 '4 data 1,"RUN Prog5 ",0 '5 data 1,"RUN Prog6 ",0 '6 data 0 dms0 data 1,"SETTINGS ",0 '0 data 1,"BacklightON ",0 '1 data 1,"BacklightOFF",0 '2 data 1,"IR watch ON ",0 '3 data 1,"IR watch OFF",0 '4 data 0 '-------------------------------------------------------------- BOStx con 0 'pin serial to BOS processor BOSrx con 1 'pin serial from BOS processor epower con 2 'pin high turns on power to electronics BOShalt con 3 'pin high halts current BOS move BOSbusy var in4 'pin BOS processor busy => high irrx con 5 'pin infra red comms in, i96n lcdtx con 6 'pin to send to LCD lcdrx con 7 'pin to receive from LCD Rled con 8 'pin high turns on right green led Lled con 9 'pin high turns on left red led outRled var out8 'pin high turns on right green led outLled var out9 'pin high turns on left red led ustx con 14 'pin ultrasonic commands, i96n usrx con 15 'pin ultrasonic data in, i96n i96n con 16624 '9600 baud, 8 bit, no parity, inverted poweruptime con 1500 'pause before powering up electronics nocmnd con 15 'Kir - no command pending BOScmnd var byte 'byte to send to BOS processor arg var word arg1 var arg.lowbyte 'command argument arg2 var arg.highbyte 'command argument irin var byte 'infra-red command oldirin var byte 'old infra-red command lcdbtns var byte 'button states are in lower nibble btn1state var lcdbtns.bit0 btn2state var lcdbtns.bit1 btn3state var lcdbtns.bit2 btn4state var lcdbtns.bit3 btn var lcdbtns.lownib '0 - 4 current button state oldbtn var nib '0 - 4 last button state lcdmsg var word 'pointer to current char in text lcdchar var byte 'character to send to LCD menc var byte 'current menu Choice mopt var byte 'Menu option set mendo var byte 'selection chosen by OK name var byte retprog var name stkp var byte 'point to top of CommonRam stack dmbase var word 'pointer to entry 0 of current menu cmndpage var nib 'Kir command page cmnd var nib 'Kir command irwatch var bit 'inverted flag, 0=>watch for IR 'during downloading the power to the electronics is turned off, 'if it is turned back on again too soon the electronics do not 'power up properly,so wait 1 second before turning power on. init: output Rled output Lled high Rled high Lled get 9,irwatch '0=>watch get 62,stkp 'get stack pointer if stkp<>0 then init1 'if 0 then poweron run0 'else omit stack initialisation 'and poweron wait put 62,62 'initialise stack pointer pause poweruptime ' init1:high epower 'turn on electronics BOScmnd ="V" 'beep gosub tellBOSc 'once pause 200 gosub tellBOSc 'and again COOLSTART: pause 50 'min pause 50 otherwise BOS 'misses first command - why? @? get 7,menc 'so we return to old menu option get 8,mopt lcdmsg =dbtxt :gosub lcd 'write button text '---- Main Behaviour Controller --- start:toggle Rled pause 50 gosub lcdmenu 'returns mopt,menc,mendo<>0 bmopt:branch mopt,[start,mopt1,mopt2,mopt3,mopt4] goto start mopt1:'Activities name =mendo goto dosequence mopt2:'US behaviours name =mendo goto dousbehave mopt3:'Programs if mendo=1 then doKlcdCon if mendo=2 then doKirCon if mendo=3 then runBOScon goto RunProgX mopt4:'Settings if mendo=1 then lightON if mendo=2 then lightOFF if mendo=3 then IRON if mendo=4 then IROFF goto start '------------- RUN leaves ---------------------- doKirCon: if irwatch=1 then irOFF put 1,U_KirCon name =7 goto RUNprogName '---------------------------------- doKlcdCon: 'Keys lcd Control put 1,U_KlcdCon name =7 goto RUNprogName '------------------------------- dosequence: put 1,name name =1 goto RUNprogName '------------------------------- dousbehave: put 2,name name =2 goto RUNprogName '------------------------------- runBOScon: name =3 'run Direct BOS Control pgm goto RUNprogName '------------------------------- RunProgX: 'mendo=4 => run 4 'mendo=5 => run 5 'mendo=6 => run 6 'mendo=7 => run 7 name =mendo goto RUNprogName '------------------------------- RUNprogName put 0,0 put 5,irin put 7,menc put 8,mopt run name 'run pgm '------------- leaves -------------------------- irON: irwatch =0 lcdmsg =dir :gosub lcd pause 2000 put 7,menc put 8,mopt put 9,irwatch goto coolstart '---------------------------------- irOFF:irwatch =1 lcdmsg =dnoir :gosub lcd pause 2000 put 7,menc put 8,mopt put 9,irwatch goto coolstart '---------------------------------- lightON:serout lcdtx,i96n,[14] goto start '---------------------------------- lightOFF:serout lcdtx,i96n,[15] goto start run 7 '------------- subroutines --------------------- lcdmenu: 'returns mopt = active menu ' menc = active menu displayed choice ' mendo = selected choice mendo =0 oldbtn =0 lcdmsg =dbtxt :gosub lcd 'write button text lcdit:lookup mopt,[dmo0,dma0,dmu0,dmp0,dms0],dmbase lcdmsg =dmbase +(menc *14) gosub lcd lcdb: toggle Lled gosub btns 'returns btn 0 - 4 if btn=oldbtn then lcdb oldbtn =btn if btn=1 then lcd1 'back' if btn=2 then lcd2 '<' if btn=3 then lcd3 '>' if btn=4 then lcd4 'do' - we can use btns '<' '>' as well goto lcdb lcd1: if menc<>0 then lcd10 'else go up to top level menc =mopt :mopt =0 goto lcdit lcd10:menc =0 goto lcdit lcd2: menc =1 +menc -1 min 1 -1 'can't wrap don't know end '+1 -1 => don't go through 0 goto lcdit lcd3: menc =menc +1 read (dmbase +(14*menc)),lcdchar if lcdchar=0 then lcd3a 'are we past last msg? goto lcdit lcd3a:menc =menc -1 'go back to end msg goto lcdit lcd4: if menc=0 then lcd1 'back up if mopt<>0 then lcd4x 'else goto next menu start mopt =menc :menc =0 :goto lcdit lcd4x:mendo =menc 'do it lcdmsg =dOK :gosub lcd 'tell us being done lcd4x0:gosub btns if btn<>0 then lcd4x0 'wait until finger off button return 'RETURN mendo '-------------------- lcd: read lcdmsg,lcdchar if lcdchar=0 then lcdret 'if 0 then end of msg serout lcdtx,i96n,[lcdchar] lcdmsg =lcdmsg +1 'point to next character goto lcd lcdret:return '-------------------- btns: lcdbtns =0 'set a default value serout lcdtx,i96n,[27,"K0"] 'ask LCD for button status serin lcdrx,i96n,200,nolcd,[lcdbtns] 'get byte nolcd:btn =NCD lcdbtns.lownib '0 - 4 return '-------------------- tellBOSc: 'used for the initialisation beeps & KeyCon pause 10 'give the BOS time to go into receive mode if BOSbusy=1 then tellBOSc 'wait until BOS not busy serout BOStx,i96n,[BOScmnd] return '------------------------ end program -------------------------