Bamduino
--------

Bamduino is a small Biped Robot driven by two servos, powered by four AAA cells, controlled by a custom Arduino Uno circuit board. 
It has -
  one ultrasonic sensor module for detecting obstacles;
  two forward facing optical sensors (whiskers) for detecting obstacles;
  two downward pointing optical sensors (Beard) for detecting table edges etc.;
  one sounder;
  one red LED to indicate when recording commands;
  one expansion connector;
  a reset switch to toggle Bamduino's mode;
  one programming/communication connector. 
  
The two LEDs of the forward facing optical sensors glow dim when waiting for a command.
Any particular one of the four sensor LEDs will stay on when avoiding a seen obstacle or table edge.


Control of Bamduino 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 Bamduino 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 Bamduino remembers them even when turned off.
The sequences of commands can then be replayed.

THE SPELLS
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. See command bax.

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.

Bamduino 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.
  
Bamduino alternately enables or disables the servos after a reset or power on.

The whiskerLEDs glowing dim indicate Bamduino is ready for a command.
The redLED on indicate Bamduino is recording commands.
The '>' prompt in the Serial Monitor indicates Bamduino is ready for a command.


Control of Bamduino from a Sony IRcontroller
--------------------------------------------
A subset of commands can be sent by IR which are listed below.

=============================================================
165 commands
=============================================================

IR-COMMANDS
=========== 
[^] Forward one step
[v] Backwards one step
[>] turn Right one step
[<] turn Left one step
[power] Stop/Halt with both feet together
[1]-[8] the routine or Act to record or replay
[0] page0
[9]
  [1]-[3] speed slow,medium,fast
  [4]-[6] timid,normal,bold USsensing
  [7]/[-] disable Hole reacts
  [8]/[+] disable Obstacle reacts
  [^] faster
  [0] normal
  [v] slower
[-] enable and test Ground sensors
[+] enable and test whiskers and Ultrasonic sensors
[f|] record
[f^]
  [0] - Xplore
  [1] - bip
  [2] - whee
  [3] - whoa
  [4] - chatter
  [5]{[1]-[9] - rock
  [6]{[1]-[9] - shuffle
  [9] - beAlive - not PM
  [+] - turn to open space
  [-] - turn to object
[f+] (adjust) 
[fx] #


Primary commands used
012345678 !?#.* ABEFGHLRSUVWX bclrstvw
   
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
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
-  enable and test Ground sensors and react
+  enable and test forward Whiskers and Ultrasonic sensors and react
U  read Ultrasonic sensor and if enabled react to objectRange using reactUObjects()  and ReActs in EEPROM
W  read Whisker sensors   and if enabled avoid holes (if any) using reactObstacles() and ReActs in EEPROM
G  read Beard sensors     and if enabled 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
T <char>  Transmit by IR one [key] of an IR command, 
          'TF' transmit [^], 'TaT4' transmit [f^][4], 'TaT6T3' transmit [f^][6][3]
a0  Xplore
 1,b  bip
 2,e  whee
 3,o  whoa
 4,c  chatter
 5,r 1-9  rock
 6,s 1-9  shuffle
 9  beAlive - not PM
  [-] turnUSnear
  [+] turnUSfar
iw 0-3 Whisker LEDS  
 b 0-3 Beard LEDS    
vb  bip
 e  whee
 o  whoa
 c  chatter
n 1-9  wait 1 - 9 1/10 seconds 
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 servo degrees change per frame
  p 1-9  set pace speed - units of servo degrees change per frame
  m   set rollspeedmax to current rollspeed, set pacespeedmax to current pacespeed
  rm  set rollspeedmax to current rollspeed
  pm  set pacespeedmax to current pacespeed
ta  turn Away from leading foot,        used in ReActs
 m  turn Memory (same way as last turn, used in ReActs
 o  turn Other way from last time,      used in ReActs
 l  turn to light
 d  turn to dark
 -  turnUnear - using Ultrasonic distance
 +  turnUfar  - using Ultrasonic distance   
 @l  turn until @ light
 @d  turn until @ dark
m 1-9  set probability level of following commands being executed
  }    end of a mind.
BEHAVES
( #$@ 012345678 aglpqrstu  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, ## disables Quiet
  v 0,1  verbose, light level reporting of sensors, 0=off, 1=on
  w0  turn off walking 
  w1  turn on walking
  p 0-9  set paceby - step length                units of 2 servo degrees
  t 0-9  set turnby - step length in turns       units of 2 servo degrees
  r 0-9  set rollby - roll amount when stepping  units of 2 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
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
 U  print US range
 E  print Eyes light
 W  print Whiskers
 G  print Beard
 O  print Obstacles
#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
*iB  initialise EEPROM behaves, ignored if recording
//*r and *w allow a higher processor to access the whole of the EEPROM behaves  - no ProMini help
*r<EEadress>,  read EERPOM behave address 0-255
*w<EEadress>,<behaveValue>,  write EERPOM behave address 0-255, behaveValue

The whiskerLEDs glowing dim indicate Bambino is ready for a command.
If other keys are pressed, including lower case keys, then the Whisker LEDs will flash badkey().
(MM - mouth glows dim while ready and Beard LEDs used for badkey().) 

RESPONSES
void IRin(byte pin)
  xIR if IR timeout
sense44.ino - readLight()  // read ambient Light levels   0 - 1023
  [a<LeyeLight>|<ReyeLight>]
sense44.ino - readWhiskers()
  [W<LwhiskerLight>,<LwhiskerDark>,<LwhiskerLight -LwhiskerDark>|<RwhiskerLight>,<RwhiskerDark>,<RwhiskerLight -RwhiskerDark>]
sense44.ino - readBeard()
  [B<LbeardLight>,<LbeardDark>,<LbeardLight -LbeardDark>|<RbeardLight>,<RbeardDark>,<RbeardLight -RbeardDark>]
sense44.ino - showObstacles()
  [o%<f_obstacleLeft><f_obstacleRight>]
sense44.ino - showHoles()
  [h%<f_holeLeft><f_holeRight>]
=============================================================  
