/* 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) 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 Act-8 autoruns on poweron or reset. 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. The commands are [Esc] - quit current operation - recording, playing, input 'Q' - quit current operation - recording, playing, input 'P' - Print moves in all Acts, and behaviour variables 'D' Dump out all acts to the PC, same as 'P' but without the Act and moves numbers. '0' - use page0 for the next Act '1'-'8' the routine or Act to record or replay, Act-8 autoruns 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 'U' - read Ultrasonic sensor and react to objectRange using avoidObjects() 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 'Q' or reset // the loop() from B_M22_BeAlive 'X' - Xplore() until 'Q' or reset // Wander() 'E' - Experiment - user routine until 'Q' or reset 'v' - sound: bip 'vb' - sound: bip 've' - sound: whee 'vo' - sound: whoa 'w','1'-'9' - wait 1 - 9 seconds. '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 within max 'sr','1'-'9' set roll speed 'sp','1'-'9' set pace speed 'srm' - set rollspeedmax to current rollspeed 'spm' - set pacespeedmax to current pacespeed 'm','p','1'-'9' set paceby - step length 't','1'-'9' set turnby - step length in turns 'r','1'-'9' set rollby - roll amount when stepping 't','a' - turn Away from leading foot, 'm' - turn Memory (same way as last turn, 'o' - turn Other way from last time these will be used in avoid Acts 'r','1'-'8' - Record moves into selected Act in EEPROM 'p','1'-'8' - Print moves in selected Act '1' - '8' 'c','1'-'8','1'-'8' - copy one Act to another Act slot 'l','1'-'8' - load Act, like 'r' but records commands into EEPROM without playing them '?' - print instructions 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. The Act slot has 32 bytes and can have up to 31 commands with the last entry set to 0 indicating end of Act. 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 'Q' 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 'Q' to quit recording. eg r,1,F,F,R,R,1,Q 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 r,2,1,Q here Act 2 does nothing except jump to Act-1. 'Q' or Esc quits a playing Act. To autorun 'beAlive' or 'Xplore' or 'Experiment' enter 'l8AQ' or l8XQ' or l8EQ'. If an Act is playing or auto-running then enter 'Q' first until you get the '>' prompt. The command 'l','1'-'8' - loads an Act directly from the Serial Monitor without acting E.g. "l7VVVFFVQ" loads Act-7 with "VVVFFV" You can load command strings which either won't Play or do odd things , so beware. E.g. keys l7PVVQ will load PVV into Act-7, but after P the VV will never be done. E.g. l7VVp7VVQ will load VVp7VV into Act-7 and when played Bambino plays VV then does 'p' 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 Q is entered instead of an Act number then the '7' after 'p' 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 Aduino serial buffer. */ /* Functions Variables and Constants --------------------------------- //== SECTIONS =============================================== //== NEW //== CHANGED //== INCLUDES // pinsPM20.h - pin usage // varsConsPM23.h - EEPROM addresses, general, Ultrasonic module HC-SR04 // EEPROM.h - the Arduino EEPROM library //== EEPROM //== SETUP // initPM20.h - Initialise various things //== LOOP //== FUNCTIONS // GetCcmnd() //reads Serial or playing Act until Ccmnd != 0 // RecordCCmnd() // speed(byte s) //set Roll and Pace speed with the same CCmnd value // makeCCmndDigit() //ensure 1-9 // waitCCmndSecs() //read delay time from Act and wait // DumpActs() //Dump Acts, Print without names and length // loadAct() // copyAct() // Ccmnd <- PlayAct() // PrintAllActs() // printAct() // Act <- getAct() // setEEPROMindexes(char Act) // changes EEPROMindex, ActEnd // printHelp() // badkey() // indicate invalid key // USreact() // read Ultrasonic sensor and react to objectRange using avoidObjects() 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 B_M22_BeAlive // redLEDon() // redLEDoff() // bip() // make a bip sound // whiskerLEDsDim() //TAB FILES // actsPM23.ino // ACTS - WanderSteps(steps), Wander() // RightStep(steps), LeftStep(steps) // rock(repeats), shuffle(repeats) // SOUND - whee(), whoa() // behaviourPM20.ino // BEHAVIOUR MODIFIERS - speeddown(), speedup() // BEHAVIOUR RULES - avoidObjects(), avoidObstacles(), avoidHoles() // sensePM25.ino // SENSE - dist_HC_SR04() // - readWhiskers(), QueryObstacle(), showWhiskerLightLevels() // - readBeard(), QueryEdge(), showBeardLightLevels() // movement23.ino // META MOVEMENT - turnAway(), turnMemory(), turnOther() // MOVEMENT - forward(), backward(), turnRight(), turnLeft(), // halt(), // rollCentre(), rollRight(), rollLeft(), // paceCentre(), paceRightForward(), paceLeftForward(), paceRightBackward(), paceLeftBackward(), // rollmove(), pacemove() // servos20.ino // SERVOS - enableServos(), disableServos(), ServosInitC() // hardware20.ino // HARDWARE - ServoPulse(byte Spin, int Spulse), beep(byte beeppin,int beepfreqHz,long beeptime) // system20.ino // SYSTEM - update_f_walking(), initialiseEEPROM() */