Important --------- ------------------------------------------------------------------------------------------------------ //== VARIABLES and CONSTANTS ================================ //BA48_Do.ino boolean f_recording =false; //recording an Act boolean f_recordC =false; //record current Command boolean f_play =false; //Play current Act boolean f_reacting =false; //Play current ReAct boolean f_inDo =false; boolean f_doDefault =true; //true for the first loop and #< only boolean f_runDefault =false; //run Default when nothing else to do boolean f_bG =0; //auto sense Ground control boolean f_bW =0; //auto sense Whiskers control boolean f_bU =0; //auto sense Ultrasonic control const byte NL =10; //NewLine value const byte LF =10; //LineFeed value const byte CR =13; //Carriage Return value const byte Esc =27; //Esc key value char Act; //***NotInitialised*** - current Act as '1' - '8' byte actIndex =0; //current Act number, set to default int EEPROMindex =-1; //index to moves in an Act in EEPROM, -1 => nothing to continue with #> int hashhashAt; //copy of EEPROMindex at hashhashSTOP int ReactAt; //copy of EEPROMindex at React int ActEnd; //setEEPROMindexes(char Act) - end address of current recording Act in EEPROM int moves =0; //current move char Ccmnd =0; //current Character command, default null command byte epage; //setup() =1 - the Act page for the current Act, default page =1 for Acts 1-8 and page =2 for 01-08 char Behaviour; //read from EEPROM in init, current behaviour 1-8 in epage 0 byte BehaviourEbase =224; //base address of current behaviour 0,32,64,96,128,160,192,(224) byte slotbase; //working slotbase byte behaveNum; //BeHave address in Behaviour slot byte behaveValue; String numString =""; //temporary string in loadBehaviour(), getnum() varsCons47.h //EEPROM addresses const byte E8f_walking =255; //31 - 0,1 init -> f_walking const byte E8rollC =254; //30 - init -> rollC const byte E8paceC =253; //29 - init -> paceC const byte E8rollby =252; //28 - init -> rollby const byte E8paceby =251; //27 - init -> paceby, turnby const byte E8rollmin =250; //26 - nominal minimum roll value, not used at present const byte E8rollmax =249; //25 - nominal maximum roll value, not used at present const byte E8pacemin =248; //24 - nominal minimum roll value, not used at present const byte E8pacemax =247; //23 - nominal maximum roll value, not used at present const byte E8rname =246; //22 - 'A-Z a-z' init(A) -> rname const byte E8rgroup =245; //21 - '0-9' init(0) -> rgroup const byte E8autoAct =244; //20 - '0-8' const byte E8SonarAwareAt =243; //19 - 1-9 init(5) -> SonarAwareAt const byte E8SonarTooNear =242; //18 - 1-9 init(2) -> SonarTooNear const byte E8f_cm =241; //17 - true, false init const byte E8rollspeedmax =240; //16 - init const byte E8pacespeedmax =239; //15 - init const byte E8rollspeed =238; //14 - 1-9 init const byte E8pacespeed =237; //13 - 1-9 init const byte E8senseG =236; //12 - 0,1 auto sense Ground const byte E8senseW =235; //11 - 0,1 auto sense Whiskers const byte E8senseU =234; //10 - 0,1 auto sense Ultrasonic // 224 is default behaviour marker //addresses within a slot const byte Ef_walking =31; const byte ErollC =30; const byte EpaceC =29; const byte Erollby =28; const byte Epaceby =27; const byte Erollmin =26; const byte Erollmax =25; const byte Epacemin =24; const byte Epacemax =23; const byte Ername =22; const byte Ergroup =21; const byte EautoAct =20; const byte ESonarAwareAt =19; const byte ESonarTooNear =18; const byte Ef_cm =17; const byte Erollspeedmax =16; const byte Epacespeedmax =15; const byte Erollspeed =14; const byte Epacespeed =13; const byte EsenseG =12; const byte EsenseW =11; const byte EsenseU =10; // 0 is default behaviour marker //BEHAVIOUR char autoAct ='0' ; byte SonarTooNear ; // init =EEPROM(2), 'bu(m)-', units 50mm/2inch, objects nearer will be considered as Too Near and avoided byte SonarAwareAt ; // init =EEPROM(5), 'bu(m)+', units 50mm/2inch, objects nearer will avoided, objects farther away will be ignored //MIND boolean f_walking ; //init =toggle - 1=> walking enabled , 0=> walking disabled boolean f_BeQuiet ; //init =0 - 1-> status messages off boolean f_MsgForMe ; //init =1 - 0-> messages are for other robots boolean f_hashcmnd =0 ; // processing a hash command boolean f_hashhashSTOP ; //init =0 - ##Stop from external commander boolean f_TurnedRight ; //***NotInitialised*** - 1=> last turn was Right, 0=> last turn was Left boolean f_forwards =1; //setup() =1 - current direction, 1=>forwards, 0=>backwards, controls step direction in turns boolean f_turning =0 ; // controls pace in paceRightForward() and paceRightBackwards() when turning, f_turning =1 =>turning boolean f_AtLight ; //turnLight() - true if facing Light boolean f_AtDark ; //turnDark() - true if facing Dark boolean f_holeRight ; //***NotInitialised*** - queryEdgeLR() - 0=> no hole, 1=> hole eg a table edge, boolean f_holeLeft ; //***NotInitialised*** - queryEdgeLR() - 0=> no hole, 1=> hole eg a table edge boolean f_obstacleRight ; //***NotInitialised*** - queryObstaclesLR() - 0=> no obstacle, 1=> obstacle boolean f_obstacleLeft ; //***NotInitialised*** - queryObstaclesLR() - 0=> no obstacle, 1=> obstacle byte cmnd =0 ; // current command char rname ; //init =EEPROM(A) - robot name char rgroup ; //init =EEPROM(0) - robot group //SERVOS //Servo values are in units of 1 degree, 0 - 180, centre at 90" byte rollC =90; // default, AdjustServos39.ino, roll centre = 90 degrees (ie 1500us) => upright byte paceC =90; // default, AdjustServos39.ino, pace centre = 90 degrees (ie 1500us) => feet together byte Servoframe =20; // never changed, Servo frame rate millisecs byte maxroll =18; // physically max roll byte rollat ; //init,ServosInitC() - Roll servo position, +ve roll to right byte paceat ; //init,ServosInitC() - Pace servo position, +ve left foot forwards byte rollby ; //init =EEPROM - roll angles about rollC byte paceby ; //init =EEPROM - pace angles about paceC byte turnby; //init =paceby - servo turn angles about paceC byte rollspeed ; //setup() =1 roll servo speed byte pacespeed ; //setup() =1 pace servo speed byte rollspeedmax ; //setup() =4 max speed for speedup() byte pacespeedmax ; //setup() =6 max speed for speedup() byte rollto ; //movement34 - roll servo value to move to byte paceto ; //movement34 - pace servo value to move to byte Srollat ; //init =rollat - remember rollat when walking disabled byte Spaceat ; //init =paceat - remember paceat when walking disabled //== SENSORS ================================================ //Eyes int ReyeLight ; // light level read from R whisker light sensors, integer values between 0 and 1023 int LeyeLight ; // light level read from L whisker light sensors, integer values between 0 and 1023 const byte LeftRightLightTurnThreshold =10 ; // difference% between LeyeLight and ReyeLight for a Light turn //=========================================================== //Whiskers int RwhiskerLight; // reading from Right whisker sensor, LED on, integer values between 0 and 1023 int LwhiskerLight ; // reading from Left whisker sensor, LED on, integer values between 0 and 1023 int RwhiskerDark ; // reading from Right whisker sensor, LED off, integer values between 0 and 1023 int LwhiskerDark ; // reading from Left whisker sensor, LED off, integer values between 0 and 1023 int RwhiskerDifference ; // difference between RwhiskerLight and RwhiskerDark int LwhiskerDifference ; // difference between LwhiskerLight and LwhiskerDark const byte obstacleThresholdRight =20 ; // difference between RwhiskerLight and RwhiskerDark for an obstacle const byte obstacleThresholdLeft =20 ; // difference between LwhiskerLight and LwhiskerDark for an obstacle //=========================================================== //Beard int RbeardLight ; // reading from Right beard sensor, LED on, integer values between 0 and 1023 int LbeardLight ; // reading from Left beard sensor, LED on, integer values between 0 and 1023 int RbeardDark ; // reading from Right beard sensor, LED off, integer values between 0 and 1023 int LbeardDark ; // reading from Left beard sensor, LED off, integer values between 0 and 1023 int RbeardDifference ; // difference between RbeardLight and RbeardDark int LbeardDifference ; // difference between LbeardLight and LbeardDark const byte holeThresholdRight =10 ; // difference between RbeardLight and RbeardDark for a hole const byte holeThresholdLeft =10 ; // difference between LbeardLight and LbeardDark for a hole //=========================================================== // Ultrasonic module HC-SR04 // According to Parallax's datasheet for the PING))), // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf // sound travels at 1130 feet per second, i.e. 73.746 microseconds per inch // (or the speed of sound is 340 m/s or 29 microseconds per centimeter). // This gives the distance travelled by the ping, outbound and return, // so we divide by 2 to get the distance of the obstacle // and then divide by 29 to get cm or divide by 73.746 to get inches, // i.e. divide by 2*29=58 to get cm, // or divide by 2*73.746=147.492 =>147 to get inches. // Note the output of the HC_SR04 never goes LOW unless an echo is received. // The default time-out for pulseIn() is 1 second (Arduino language reference). // so if there is no obstacle to return an echo then unless a timeout is set // pulseIn() will return 0 after its timer times out and this routine // will hang for 1 second. // The HC-SR04 has a range of about 10 feet, then since the speed of sound // is about 1 foot per milli-second it will take 20ms at maximum range. // so UStimeout is set to 20000 =20ms const int UStimeout =20000; //20ms const byte uscm =58; const byte usinch =147; boolean f_cm =true; // US distance in cm byte objectRange ; // distance to object detected by HC-SR04 sensor //===========================================================