/* Control of Jet-Laser from the Serial Monitor -------------------------------------------- Just as with a washing machine controller where you wouldn't expect to have to write more microcontroller code just to get it to do a different wash cycle so neither is it desirable to have to continually write Arduino code to change what Jet does. The IR commands can be sent from a PicAxe Sony IR handset whilst the main commands can be entered from the Serial Monitor (or other Terminal) set to 9600 baud and sequences of commands can be recorded in the EEPROM so Jet remembers them even when turned off. The sequences of commands can then be replayed. If each sequence which we will call an Act takes less than 32 commands then 8 Acts will fit in the second 256 byte page of the EEPROM. A second set of eight Acts will fit in the third 256 byte page of the EEPROM. These are addressed as logical Page0 by prefixing with 0 the 1-8 Act number. So sixteen Acts can be remembered. 01,02,03,04,05,06,07,08,1,2,3,4,5,6,7,8 An Act can have up to 31 commands followed by '.' indicating end of the Act. Any of the first 8 Acts can be set to autorun on poweron or reset. depending on selected behaviour A further 8 ReActs which set the moves to make depending on Sensor values are held in EEPROM page3. These can be learned, loaded and played as the Acts, See the ReActs section below. Jet can have up to 8 different Behaviours holding the BeHave parameters, see ?B, b,1-8, and bs,1-8. These are held in EEPROM page0. Jet alternately enables or disables the servos after a reset or power on. If the servos are enabled then while waiting for a command the head LED will blink. If the servos are disabled then while waiting for a command the head LED will be off. The head LED on indicates Jet is recording commands. The '>' prompt in the Serial Monitor indicates Jet is ready for a command. ============================================================= IR commands ----------- 'function keys '[f|] [f^] [f+] [fx] 'ACTIONS: '[^] - F '[v] - B '[>] - R '[<] - L 'COMMANDS '[0]-[8] - "0"-"8" '[Power] - "." - end, stop '[Power][Power] - "H" - Halt '[Power][Power][Power] - "S" - toggle walking '[f|] - "r" - record '[f^][0] - Xplore '[f^][1] - bip '[f^][2] - whee '[f^][3] - whoa '[f^][4] - chatter '[f^][5][1-8] - rock '[f^][6][1-8] - shuffle '[f^][9] - beAlive '[f^][-] - turn to near '[f^][+] - turn to far '[fx][fx] - "##" - quit '[fx][<] - "#<" - do default '[fx][>] - "#>" - resume 'REACTIONS: '[+] - "U" - R_Ping: '[-] - "GW" - R_Whiskers 'BEHAVIOURS: '[9][1] - "s1" - B_slow: '[9][2] - "s3" - B_medium: '[9][3] - "s5" - B_fast: '[9][4] - "bu-1","bu+2" - B_UStimid: '[9][5] - "bu-2","bu+4" - B_USnormal: '[9][6] - "bu-3","bu+6" - B_USbold: ============================================================= Primary terminal commands used 012345678 !?#.* ABEFGHLRSUVWX bclrstvw The commands are COMMANDS ======== 'Q',[Esc] - quit all, go to command mode '.' - quit current operation - recording, playing, input 'S' - Stop/Start '(' - start of a Do, a jump to an Act will on . continue in the Do, will show its location in EEPROM when played. If a jump is made to an Act which contains another Do then that Do will not be implemented. ')' - end of a Do will show its location in EEPROM when played ')' - end of Do '0' - use page0 for the next Act or command '!' - use page3=Reacts for the next ReAct or command '1'-'8' the routine or Act to record, replay, load etc '9' - play Autorun act 'F' - Forwards one step 'B' - Backwards one step 'R' - turn Right one step 'L' - turn Left one step 'H' - Halt with both feet together 'V' - Voice, make a beep, whee 'U' - read Ultrasonic sensor and react to objectRange using reactUObjects() and ReActs in EEPROM 'W' - read Whisker sensors and avoid holes (if any) using reactObstacles() and ReActs in EEPROM 'G' - read Beard sensors and avoid obstacles (if any) using reactHoles() and ReActs in EEPROM 'A' - beAlive() until '.' or Esc or reset // the loop() from B_PM22_BeAlive 'X' - Xplore() until '.' or Esc or reset // Wander() 'E' - Experiment - user routine until '.' or Esc or reset 'a','0' - Xplore 0 for IR {'1','b' - bip 1 for IR {'2','e' - whee 2 for IR {'3','o' - whoa 3 for IR {'4','c' - chatter 4 for IR {'5','r'}{'1'-'9' rock {'6','s'}{'1'-'9' shuffle '9' beAlive 9 for IR '-' turnUSnear '+' turnUSfar 'v','b' - bip 'e' - whee 'o' - whoa 'c' - chatter 'w', '1'-'9' - wait 1 - 9 seconds 's','1'-'9' set speed, both roll and pace speeds set to the same 'u' - speedup, speed up/down enabled, speed is increased by 1 up to max 'd' - speed down, speed up/down enabled, speed is divided by 2 down to 1 'r','1'-'9' set roll speed units of 4 servo degrees 'p','1'-'9' set pace speed units of 4 servo degrees 'm' - set rollspeedmax to current rollspeed, 4 servo degrees 'rm' - set rollspeedmax to current rollspeed 'pm' - set pacespeedmax to current pacespeed 't','a' - turn Away from leading foot, will be used in avoid Acts 'm' - turn Memory (same way as last turn, will be used in avoid Acts 'o' - turn Other way from last time, will be used in avoid Acts 'l' - turn to light 'd' - turn to dark '-' - turnUSnear '+' - turnUSfar '@l' - turn until @ light '@d' - turn until @ dark 'm','0'-'9' - set probability level of following commands being executed 'u','<','0'-'9',cmnds'}' - do cmnds if ultrasonic objectRange < digit eg u<2FV} - do FV if closer than 2 'u','>','0'-'9',cmnds'}' - do cmnds if ultrasonic objectRange > digit '}' - end of a mind. BEHAVES ( #$@ 012345678 alpqrstuw GUW ) 'b0' - reload current behaviour to RAM BeHaves 'b','1'-'8' - set current default behaviour and copy to RAM BeHaves 's','1'-'8' - save current RAM BeHaviour to EEPROM Behaviour 'l','1'-'8' - load EEPROM behaviour 1-8, at prompt enter BeHave number and BeHave data eg bl4 prompt 30,85. load slot 4 position 30 with 85 and quit loading eg bl5 prompt 30,85,20,2. load slot 5 position 30 with 85 and position 20 with 2 and quit loading '9' - load entry in all behaviours eg bl9 prompt 22,B. load group 'B' to all Behaviours and quit loading eg bl9 prompt 22,B,21,2. load group 'B', name 2 to all Behaviours and quit loading '#','A'-'z' - robot name A-z '0'-'9' - robot group 0-9 'a','0'-'8' - set Autorun act '1' - '8', '0' no Autorun act 'a','9' - set Autorun act to run when there is nothing else to do, ## turns it off not remembered through reset/power-off - default off 'q' - Quiet - turn off status messages, ## restores 'v','0','1' - verbose, report sensor values when read, 0=off, 1=on 'w0' - turn off walking 'w1' - turn on walking 'wf' - forwards, set stepping direction in L and R, used in Reactions 'wb' - backwards, set stepping direction in L and R, used in Reactions 'p','1'-'9' - set paceby - step length units of 4 servo degrees 't','1'-'9' - set turnby - step length in turns units of 4 servo degrees 'r','1'-'9' - set rollby - roll amount when stepping units of 4 servo degrees 'p+','0'-'9' - alter paceC in current behaviour in RAM - +ve offset from paceC in current behaviour in EEPROM 'p-','0'-'9' - alter paceC in current behaviour in RAM - -ve offset from paceC in current behaviour in EEPROM 'r+','0'-'9' - alter rollC in current behaviour in RAM - +ve offset from rollC in current behaviour in EEPROM 'r-','0'-'9' - alter rollC in current behaviour in RAM - -ve offset from rollC in current behaviour in EEPROM 'um+' - set manually SonarAwareAt, units 50mm 'um-' - set manually SonarTooNear, units 50mm 'u+','0'-'9' - set SonarAwareAt, units 50mm 'u-','0'-'9' - set SonarTooNear, units 50mm 'uc0' - Sonar distance in inches 'uc1' - Sonar distance in centimetres 'us' - save current Sonar settings to EEPROM 'G','0','1' - react to Ground holes, 0=off, 1=on 'W','0','1' - react to Whisker obstacles, 0=off, 1=on 'U','0','1' - react to Ultrasonic ojects, 0=off, 1=on '$','0','1' - Automatically sense UWG before every command if reaction enabled, 0=off, 1=on '@' - Adjust Servos 'Q' or '.' or 'Esc' to quit adjusting 'I' to display instructions '*' to display current EEPROM values '-' adjust Servo position -ve '+' adjust Servo position +ve '/' to change servo 'C' save the Roll or Pace positions as default Centre angles RollC or PaceC to EEPROM 'R' save the Roll amount as default to EEPROM 'P' save the Pace length as default to EEPROM 'S' Stand with the servos at RollC and PaceC SYSTEM SYSTEM 'r',('0'),'1'-'8' - Record moves into selected Act in EEPROM 'c',('0'),'1'-'8','1'-'8' - copy one Act to another Act, xy,x0y,0xy,0x0y 'l',('0'),'1'-'8' - load Act, like 'r' but records commands into EEPROM without playing them '?','hh' - print all Help 'ha' - print Help Act 'hb' - print Help Behaviour 'hs' - print Help System '1'-'8' - Print moves in selected Act '1' - '8', for '01'-'08' enter '0' first 'p' - print current Page '?' - print current Page 'd' - Dump out all acts to the PC, same as 'p' but without the Act and moves numbers. 'b' - print Behaviour - behaviour variables in RAM 'B' - print all Behaviours in EEPROM 'm' - print Mind - all Acts, Behaviour '!' - print ReActs '$' - print Sensors - USsensor, IRsensors '#','0' - message for all robots, robots silent '1-9' - message for robot group 1-9, robots silent 'A-z' - message for robot name A-z in current group, other robots silent '#' - (default) robots stop, obey all commands and send messages useful to talk to an unknown robot or put all in the stopped state turns off AutoSense, b$1 turns it on '<' - do Default Act (enables walking, useful if using IR and behaviour default is walking off) '>' - resume Act (enables walking, useful if using IR and behaviour default is walking off) '?' - all robots reply with their name and group - delayed according to name '.' - end a # session '*','i','M' - initialise EEPROM Mind, ignored if recording *r and *w will allow a higher processor to access the whole of the EEPROM '*','r'',' - read EERPOM address '*','w'','',' - write EERPOM address, behaveValue If other keys are pressed, including lower case keys, then the speaker will sound badkey. Upper-case is used for single letter commands and Lower-case is be used for parameter commands. Until programming mode is entered any of the commands have immediate effect. In immediate mode keys 1 - 8 will play the corresponding Act, whatever has been recorded. If 'r' is entered then the next key must be {0} 1 - 8 to select the Act to be recorded. If '.' is entered instead then recording will not start. Any of the keys can be entered in recording mode including 'r' but that makes no sense and is blocked during recording as is 'p' by setting f_recordC to false. 'S','?' operate but are also blocked from being recorded by setting f_recordC to false. When recording has started keys {0} 1 - 8 will record a jump to the corresponding Act. However in record mode playback of that Act is suppressed, hence after entering an Act number it makes no sense to add more commands since they will never be done because control will jump to the new Act; so just enter '.' to quit recording. E.g. "r1FFRR1." records "FFRR1." in Act1 if in immediate mode '1' is entered then Act-1 will be played giving Forward, Forward, turnRight, turnRight, jump to Act 1 So Act 1 will play forever, Act 1 could also be invoked from another Act eg "r21." here Act 2 does nothing except jump to Act-1. '.' or Esc quits a playing Act. To autorun 'beAlive' or 'Xplore' or 'Experiment' enter 'l8A.' or 'l8X.' or 'l8E'. (l for load, not 1 one) Then set the Autorun Act to 8 by 'ba8'. If an Act is playing or auto-running then enter '.' first until you get the '>' prompt. The command 'l' (ie l.c. L),{0} 1 - 8 - loads an Act directly from the Serial Monitor without acting E.g. "l7VVVFFV." loads Act-7 with "VVVFFV." You can load command strings which either won't Play or do odd things , so beware. E.g. keys l7?pVV. will load "?pPVV." into Act-7, but after '?p' the "VV" will never be done. E.g. "l7VV?7VV." will load "VV?7VV." into Act-7 and when played Jet plays VV then does '?' which expects an Act number for the Act to print, when the Act is printed the EEPROMindex will point to the end of the printed Act so Play will end. However if '.' is entered instead of an Act number then the '7' after '?' will be read and Act-7 will be done again. '?d' dumps all Acts to the the PC without names or length information. The output from ?d can be copied from the Serial Monitor, saved to a file, edited and pasted back into the Serial Monitor and loaded into Jet. Load with 'l' (ie l.c. L) then {0} 1 - 8. If the Acts are short all can be pasted at once. Otherwise load one Act at a time to prevent overloading the Arduino serial buffer. */ /* ============================================================= ReActs ====== Reactions stored in EEPROM page 3 as 8 slots of 32 bytes, Reactions can have the same commands as Acts and ended with ".". When a sensor test is made in an Act and something is detected then the relevant Reaction is played then the Act continues. Reaction-1 - Reaction if Ultrasonic distance is less than 'aware at' value hence objects farther away than 'aware at' value are ignored Reaction-2 - Reaction if Ultrasonic distance is less than 'too close' value i.e. objects are too close Reaction-3 - Reaction if both Left and Right Whiskers sense an object Reaction-4 - Reaction if Left Whisker senses an object Reaction-5 - Reaction if Right Whisker senses an object Reaction-6 - Reaction if both Left and Right Toe sensors detect a hole Reaction-7 - Reaction if Left Toe sensor detects a hole Reaction-8 - Reaction if Right Toe sensor detects a hole If automatic Ground, Whisker, or Ultrasonic sensing are enabled then testing is done in GetCcmnd e.g. >?! W & G, 1 indicates object or hole sensed LR ReAct1 U<=5 vbtm. - 4 bytes ReAct2 U<=2 vosdBtatmtm. - 11 bytes ReAct3 W11 Btotmtm. - 7 bytes ReAct4 W10 RR. - 2 bytes ReAct5 W01 LL. - 2 bytes ReAct6 G11 bwbtotmtm. - 9 bytes ReAct7 G10 bwbRR. - 5 bytes ReAct8 G01 bwbLL. - 5 bytes ============================================================= BEHAVES - power-on defaults set from current default Behaviour in @EEPROM ======= sense behaves SonarAwareAt is @EEPROM value SonarTooNear is @EEPROM value speed behaves - set in void setup() rollspeed is @EEPROM value pacespeed is @EEPROM value rollspeedmax is @EEPROM value pacespeedmax is @EEPROM value move behaves - set in void setup() init42.h rollby is @EEPROM value, set by B_PM04_Servos or AdjustServos() paceby is @EEPROM value, set by B_PM04_Servos or AdjustServos() turnby is paceby rollC is @EEPROM value, set by B_PM04_Servos or AdjustServos() paceC is @EEPROM value, set by B_PM04_Servos or AdjustServos() react behaves bG is @EEPROM value bW is @EEPROM value bU is @EEPROM value b$ is @EEPROM value varsCons44.h rollC =90; default, AdjustServos39.ino, roll centre = 90 degrees (ie 1500us) => upright paceC =90; default, AdjustServos39.ino, pace centre = 90 degrees (ie 1500us) => feet together Servoframe =20; never changed, Servo frame rate millisecs ============================================================= Behaviour parameters are stored in EEPROM page 0, 8 sets 32 bytes For a new robot slots initialised and slot8 set as default behaviour Note 26 Erollmin - never altered, not used 25 Erollmax - never altered, not used 24 Epacemin - never altered, not used 23 Epacemax - never altered, not used Example of ?B - print all behaviours in EEPROM >?B BEHAVIOUR b1 b2 b3 b4 b5 b6 b7 b8 # BeHave -- -- -- -- -- -- -- -- 31 f_walking 1 0 1 0 0 0 0 0 0=false, 1=true 30 rollC 87 87 87 87 87 87 87 87 servo degrees 29 paceC 85 85 85 85 85 85 85 85 servo degrees 28 rollby 20 20 20 20 20 20 20 20 degrees =cmnd *4 27 paceby 32 32 32 32 32 32 32 32 degrees =cmnd *4 22 rgroup 2 2 2 2 2 2 2 2 1-9 21 rname i i i i i i i i A-z 20 autoAct 1 1 1 1 1 1 1 1 0-8 19 SonarAwareAt 5 5 5 5 5 5 5 5 0-9, units 5cm or 2inch 18 SonarTooNear 2 2 2 2 2 2 2 2 0-9, units 5cm or 2inch 17 Sonar use cm 1 1 1 1 1 1 1 1 0=false, 1=true 16 rollspeedmax 7 7 7 7 7 7 7 7 1-9 15 pacespeedmax 7 7 7 7 7 7 7 7 1-9 14 rollspeed 3 3 3 3 3 3 3 3 1-9 13 pacespeed 3 3 3 3 3 3 3 3 1-9 12 Greact 1 1 1 0 0 0 0 0 0,1 11 Wreact 0 0 1 0 0 0 0 0 0,1 10 Ureact 0 0 1 0 0 0 0 0 0,1 9 auto$ense 1 1 0 0 0 0 0 0 0,1 -- @Behaviour . . @ . . . . . > ============================================================= Example of ?b - print current behaviour in RAM >?b JA53_turnUS robot 2i MsgForMe=1 BeQuiet=0 b 3 Behaviour bw 1 walking ba 1 autoAct, rerun Off (default Off) sr 3,7 rollspeed,rollspeedmax sp 3,7 pacespeed,pacespeedmax br 5(20) rollby bp 8(32) paceby bt 8(32) turnby br+- 87 rollC bp+- 85 paceC bu+ 5 SonarAwareAt bu- 2 SonarTooNear bG 1 Greact bW 1 Wreact bU 1 Ureact b$ 0 auto$ense bv 0 verbose > ============================================================= Acts are stored in EEPROM pages 1 and 2 Example of ?? - print all Acts >?? Act1 FFF. - 3 bytes Act2 BBB. - 3 bytes Act3 RRR. - 3 bytes Act4 LLL. - 3 bytes Act5 RL. - 2 bytes Act6 F6. - 2 bytes Act7 ?$w17. - 5 bytes Act8 . - 0 bytes Act01 VVV. - 3 bytes Act02 (0104)VRVRVRV. - 13 bytes Act03 L(02)RRR. - 8 bytes Act04 RLRL. - 4 bytes Act05 HHHH. - 4 bytes Act06 b3. - 2 bytes Act07 m7F07}m4voR07}m8veL07}w1Vw1V07. - 30 bytes Act08 bw1b$1bG107. - 11 bytes > =============================================================