/* Control of Bambino 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 Bambino does. The following 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 Bambino 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. Bambino 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. Bambino alternately enables or disables the servos after a reset or power on. The whiskerLEDs glowing dim indicate Bambino is ready for a command. The redLED on indicate Bambino is recording commands. The '>' prompt in the Serial Monitor indicates Bambino is ready for a command. Primary command letters used - .!?# 0123456789 ABEFGHLRSUVWX bcglrstvw The commands are 'Q',[Esc] - quit all '.' - quit current operation - recording, playing, input 'S' - Stop/Start '!' - use page3 Reacts for the next record, load, replay, or print '(' - 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 become the current Do and the old Do will be fogotten. ')' - end of a Do will show its location in EEPROM when played '0' - use page0 for the next Act '1'-'8' the routine or Act to record or replay, any Act 1-8 can be set to autorun on poweron or reset. '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 avoidUObjects() behaviour rules 'W' - read Whisker sensors and avoid obstacles (if any) using avoidObstacles() behaviour rules 'G' - read Beard sensors and avoid holes (if any) using avoidHoles() behaviour rules 'A' - beAlive() until '.' or reset // the loop() from B_M22_BeAlive 'X' - Xplore() until '.' or reset // Wander() 'E' - Experiment - user routine until '.' or reset 'v', 'b','e','o' voice choose sound: 'b' bip, 'e' whee, 'o' whoa 'w','1'-'9' - wait 1 - 9 seconds 'g0' - (go 0) turn off walking 'g1' - (go 1) turn on walking 'su' - speedup, speed up/down enabled, speed is increased by 1 up to max 'sd' - speed down, speed up/down enabled, speed is divided by 2 down to 1 's', '1'-'9' set speed, both roll and pace speeds set to the same 'sr','1'-'9' set roll speed units of servo degrees change per frame 'sp','1'-'9' set pace speed units of servo degrees change per frame 'sm' - set rollspeedmax to current rollspeed, set pacespeedmax to current pacespeed 'srm' - set rollspeedmax to current rollspeed 'spm' - set pacespeedmax to current pacespeed 'mr+','0'-'9' - alter rollC in current behaviour in RAM - +ve offset from rollC in current behaviour in EEPROM 'mr-','0'-'9' - alter rollC in current behaviour in RAM - -ve offset from rollC in current behaviour in EEPROM 'mp+','0'-'9' - alter paceC in current behaviour in RAM - +ve offset from paceC in current behaviour in EEPROM 'mp-','0'-'9' - alter paceC in current behaviour in RAM - -ve offset from paceC in current behaviour in EEPROM (b=behaviour) 'b','1'-'8' - set current default behaviour and copy to RAM BeHaves 's','1'-'8' - save current RAM BeHaviour to EEPROM Behaviour 1-8 'l','1'-'8' - load behaviour slot 1-8, eg blx30,85. load slot x position 30 with 85 and quit loading '#','A-Z','a-z' - robot name A-Z,a-z '1'-'9' - robot group 1 - 9 'a','0'-'8' = set Autorun Act, '0' means no autorun '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 'p','1'-'9' - set paceby - step length units of 2 servo degrees 't','1'-'9' - set turnby - step length in turns units of 2 servo degrees 'r','1'-'9' - set rollby - roll amount when stepping units of 2 servo degrees 'q' - Quiet - turn off status messages, ## disables Quiet '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'-'9' - automatic sense Ground, 0=off, 1=on 'W','0'-'9' - automatic sense Whiskers, 0=off, 1=on 'U','0'-'9' - automatic sense Ultrasonic, 0=off, 1=on '@' - Adjust Servos - start routine to incrementally adjust servo positions [I] to display instructions [*] to display current EEPROM values [-] adjust Servo position -ve [+] adjust Servo position +ve [/] to change servo. [C] to set Centre angles RollC and PaceC [R] to set the default Roll amount [P] to set the default Pace length [S] to set the servos at RollC and PaceC ([L] to set Low=Minimum angle - future use ) ([H] to set High=Maximum angle - future use ) '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 '@l' - turn until @ light '@d' - turn until @ dark 'r',('0'),'1'-'8' - Record moves into selected Act in EEPROM 'c',('0'),'1'-'8','1'-'8' - copy one Act to another Act slot 'l',('0'),'1'-'8' - load Act, like 'r' but records commands into EEPROM without playing them '?','h' - print Help instructions '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 'm' - print Mind - all Acts, Behaviour '!' - print ReActs 'B' - print all Behaviours in EEPROM '#','0' - message for all robots, robots silent '1-9' - message for robot group 1 - 9, robots silent 'A-Z,a-z' - message for robot name A-Z,a-z, 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 '<' - do Default Act '>' - resume Act '?' - all robots reply with their name and group - delayed according to name If other keys are pressed, including lower case keys, then the Whisker LEDs will flash badkey(). Upper-case is used for single letter commands and Lower-case will 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 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 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.'. If an Act is playing or auto-running then enter '.' first until you get the '>' prompt. The command 'l','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 Bambino 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 Bambino. Load with 'l' then '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 Beard sensors detect a hole Reaction-7 - Reaction if Left Beard sensor detects a hole Reaction-8 - Reaction if Right Beard sensor detects a hole Example of ?! - print all ReActs >?! ReAct1 vbtm. - 4 moves ReAct2 vosdBtatmtm. - 11 moves ReAct3 sdBtotmtmtmtm. - 13 moves ReAct4 sdBRRRR. - 7 moves ReAct5 sdBLLLL. - 7 moves ReAct6 sdBtotmtmtmtm. - 13 moves ReAct7 sdBRRRR. - 7 moves ReAct8 sdBLLLL. - 7 moves > ============================================================= 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 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 1 0 0 0 0 0 0 0=false, 1=true 30 rollC 85 85 85 85 85 85 85 85 servo degrees 29 paceC 89 89 89 89 89 89 89 89 servo degrees 28 rollby 15 15 15 15 15 15 15 15 servo degrees 27 paceby 15 15 15 15 15 15 15 15 servo degrees 22 rname a a a a a a a a A-Z,a-z 21 rgroup 1 1 1 1 1 1 1 1 0-9 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 4 4 4 4 4 4 4 4 1-9 15 pacespeedmax 6 6 6 6 6 6 6 6 1-9 14 rollspeed 1 1 1 1 1 1 1 1 1-9 13 pacespeed 1 1 1 1 1 1 1 1 1-9 12 autosenseG 0 0 0 0 0 0 0 0 0,1 11 autosenseW 0 0 0 0 0 0 0 0 0,1 10 autosenseU 0 0 0 0 0 0 0 0 0,1 -- @Behaviour . . @ . . . . . > ============================================================= Example of ?b - print current behaviour in RAM >?b BA46_Aware robot a1 MsgForMe=1 BeQuiet=0 3 Behaviour 0 walking 1 autoAct 0 autorun 1 rollspeed 1 pacespeed 4 rollspeedmax 6 pacespeedmax 15 rollby 15 paceby 15 turnby 85 rollC 89 paceC 5 SonarAwareAt 2 SonarTooNear 0 autosenseG 0 autosenseW 0 autosenseU > ============================================================= Acts are stored in EEPROM pages 1 and 2 Example of ?? - print all Acts >?? Act1 GFVBR1. - 6 moves Act2 B2. - 2 moves Act3 Fsu3. - 4 moves Act4 w2V4. - 4 moves Act5 BBB. - 3 moves Act6 WFsu6. - 5 moves Act7 VVw2VV. - 6 moves Act8 veFvoFvbF8. - 10 moves Act01 FFF. - 3 moves Act02 BBB. - 3 moves Act03 RRR. - 3 moves Act04 GWUFsu04. - 8 moves Act05 VV05. - 4 moves Act06 FBBFVevo05. - 10 moves Act07 FBBFVevo05. - 10 moves Act08 FFFBBB. - 6 moves > ============================================================= //== SECTIONS =============================================== //== NEW //== CHANGED //== INCLUDES // pins20.h - pin usage // varsCons47.h - EEPROM addresses, general, Ultrasonic module HC-SR04 // EEPROM.h - the Arduino EEPROM library // avr/pgmspace.h - to allow the printHelp() text to be in ProgramSpace //== VARIABLES and CONSTANTS //== HELP TEXT // PROGMEM //== SETUP // init46.h - Initialise various things //== LOOP //== FUNCTIONS // GetCcmnd() //reads Serial or playing Act until Ccmnd != 0, prints Ccmnd // RecordCcmnd() // Experiment() //until Quit // Xplore() //Wander() until Quit // makeCcmndDigit() ensure 1-9 // waitCcmndSecs() //read delay time from Act and wait // printMind() // PrintReActs() // loadBehaviour() // get1char() // getnum() // printBehaviour() // PrintBehaviours() // DumpActs() //Dump Acts, Print without names and length // loadAct() // copyAct() // Ccmnd <- PlayAct() // PrintAllActs() // printAct() // Act <- getAct() //called when recording, loading, printing and copying Acts // setEEPROMindexes(char Act) // changes EEPROMindex, ActEnd // badkey() // indicate invalid key // printHelp() // USreact() // read Ultrasonic sensor and react to objectRange using avoidUObjects() behaviour rules // WhiskerReact() // read Whisker sensors and avoid holes (if any) using avoidObstacles() behaviour rules // BeardReact() // read Beard sensors and avoid obstacles (if any) using avoidHoles() behaviour rules // beAlive() // the loop() from BA22_BeAlive // redLEDdim() - BambinoMM only // redLEDon() // redLEDoff() // bip() // make a bip sound // whiskerLEDsDim() - not BambinoMM // whiskerLEDsOff() - not BambinoMM //TAB FILES // AdjustServos45.ino // AdjustServos(), printEEPROMvalues(), printAdjustInstructions() // PROGMEM adjust_instructions // acts23.ino // ACTS - WanderSteps(steps), Wander() // RightStep(steps), LeftStep(steps) // rock(repeats), shuffle(repeats) // SOUND - whee(), whoa() // behaviour44.ino // BEHAVIOUR MODIFIERS - speeddown(), speedup() // BEHAVIOUR RULES - reactUObjects(), reactObstaclesLR(), reactHolesLR() // - avoidUObjects(), avoidObstaclesLR(), avoidHolesLR() // sense44.ino // SENSE - dist_HC_SR04() / - readWhiskers(), QueryObstacle(), showWhiskerLightLevels(), showObstacles() // - readBeard(), QueryEdge(), showBeardLightLevels(), void showHoles() // - readLight() // movement34.ino // MOVEMENT - forward(), backward(), turnRight(), turnLeft(), // halt(), // rollCentre(), rollLeft(), rollRight(), // paceCentre(), paceLeftForward(), paceRightForward(), // paceLeftBackward(), paceRightBackward(), // turnLeftForward(), turnRightForward(), // turnLeftBackward(), turnRightBackward(), // rollmove(), pacemove() // skills41.ino // SKILLS - turnLight(), turnDark(), turnAtLight(), turnAtDark() // META MOVEMENT - turnAway(), turnMemory(), turnOther() // servos23.ino // SERVOS - enableServos(), disableServos(), ServosInitC() // hardware20.ino // HARDWARE - ServoPulse(byte Spin, int Spulse), beep(byte beeppin,int beepfreqHz,long beeptime) // system45.ino // SYSTEM - disable_walking(), enable_walking(), toggle_f_walking(), // initialiseEEPROM(), initialiseEEPROMbehaviours() //=========================================================== */