BAMBINO 20m2 User Manual ======================== 12 October 2013 Bambino has been designed as a low cost, user programmable, autonomous biped robot kit. To get the best out of Bambino it is recommended that you learn to program the PicAxe20m2 microcontroller brain in the Basic programming language built into the PicAxe system. There is a complete suite of programs which start with flashing an LED and end with a complete robot program which allows Bambino to be controlled and taught from the PicAxe TVR010 infra-red remote-control. Loading each of these programs in turn into Bambino and studying how they are written together with making the suggested program modifications and noting the results will show you how you to develop the complete control program by building it up in simple steps. Overview ======== Bambino has - two motors called servos, one makes Bambino lean to the left, right, or stand upright and the other servo moves the legs forwards and backwards. By doing this in the right sequence Bambino will walk or turn; - one forward facing ultrasonic distance sensor for detecting objects in front; - two downward facing orange lights (LEDs) and two downward facing light sensors (photo-transistors) for detecting the edges of tables etc; - two forward facing orange lights (LEDs) and two forward facing light sensors (photo-transistors) for detecting objects in front; - one speaker; - one red LED; - one infra-red sensor for detecting commands from the TVR010 infra-red remote control or other controller using Sony codes; - one infra-red light (LED) to send commands to another Bambino. The battery consists of three AA cells housed in the black box on the top of Bambino. There is an on/off switch at the top right hand corner of the circuit-board. The connector at the top of the circuit-board is for programming Bambino and for accepting commands from a PC or other computer. Bambino's Optical Sensors ------------------------- Bambino senses the presence or absence of objects by measuring the difference in reflected light with the Orange LEDs On and Off. There are two forward facing phototransistor sensors shielded with black tubing. There are two downward facing phototransistor sensors shielded with black tubing. For the forward facing sensors if more light is falling on them when the LEDs are lit then there is probably an obstacle there. It may be that the obstacle doesn't reflect much light in that case Bambino will not see it! For the downward facing sensors if there is less light falling on them when the LEDs are lit than when they last self calibrated when Bambino is switched on or at the start of Wander then there is probably a hole such as at a table edge. If Bambino calibrates the hole sensors while on a black surface then it probably won't see holes. Bambino's Ultrasonic Sensor --------------------------- The sensor works by making a high frequency sound and timing how long it takes to hear the echo, a simple calculation then allows Bambino to know the distance to the object. Bambino's Servos ---------------- A Servo is a motor, gearbox and electronics combined in one unit. The position of the output shaft can be set by sending command pulses to the servo where the angular position of the shaft depends on the length of the pulse. The angle can vary over +-45 degrees as the pulse varies from 1ms to 2ms long and the pulse should be repeated every 20ms. The PicAxe20m2 can easily be programmed to do that. TVR010 infra-red remote-control ------------------------------- Before use, the transmitter must be programmed with the ‘Sony’ transmit code. 1. Insert 2 AAA size batteries, preferably alkaline. 2. Press ‘S’ and ‘B’ at the same time. S is in the centre of the arrows. The top left red LED should light. 3. Press ‘0’. The LED should flash. 4. Press ‘1’. The LED should flash. 5. Press ‘3’. The LED should go out. 6. Press the red power button (top right). The red button is [POWER]; buttons [A] [B] [C] [D] [E] [F] [G] change the Mode, Bambino only works with mode [B], if Bambino stops responding then press [B]; the direction buttons are [KEY_UP] or [Fd] Step Forward [KEY_DOWN] or [Bk] Step Backward [KEY_RIGHT] or [Rt] Step Right [KEY_LEFT] or [Lt] Step Left; [Key_S] is in the centre of the arrows (only used to setup the controller); below are the four function keys [KEY_BAR] or [f|] learn an Act, next [key] selects an Act [KEY_TENT] or [f^] next [key] selects a Subroutine-Act [KEY_VERT_CROSS] or [f+] Modify Mode [KEY_DIAG_CROSS] or [fX] transfer EEPROM to PC for including in programs; then below are the number keys [1] to [9], and [-], [0], [+]; the six keys at the bottom do nothing at all. ------------------------------------------------------------------ Getting started with Bambino ============================ Bambino comes either as a kit of parts including the fully built circuit board with the PicAxe20m2 brain, or as a fully assembled robot. If you have the kit then after you have assembled Bambino you should work your way through the supplied programs loading each one into Bambino in turn. Even if you only want to use the full robot control program you will first have to setup the servos before loading it. See Appendix 1 - seting the serovs with Bambino-08+.bas. This rest of this manual will show what Bambino is capable of with its full robot control program. USing Bambino ============= Using the full robot-control program Bambino can be taught up to eight Acts, each of up to 32 moves. The program records the moves into EEPROM memory so Bambino remembers the moves even when switched off. These Acts are selected by the buttons [1] to [8]. Act [8] is special in that it starts to play as soon as Bambino is switched on. Any of the Acts can chain to any other Act and even to itself so Bambino can repeat moves forever. An Act can also invoke or call a Subroutine Act (SAct) written in the Basic program. After an SAct finishes the original Act will carry on playing. Bambino can also Wander about autonomously using the Optical and Ultrasonic sensors to avoid obstacles and table edges. No sensors give perfect readings and Bambino only has a little brain so not every obstacle or edge will be seen, even humans walk into things or fall down a step so do not be surprised if and when Bambino doesn't see some obstacle or walks off the edge of a table. Contents -------- - Operating Bambino - To Record a simple Act - To Record a repeating Act - To chain to another Act at the end of a recording - To Record repeating Acts - To include a Subroutine act, SAct, in an Act - To tell Bambino what to do when it is switched on - Bambino's sensor behaviour - Testing for obstacle/holes - Setting Bambino's behaviour - Setting User values for the Ultrasonic behaviour - Advanced behaviour - vitality - Other Operating Bambino ----------------- [POWER] stop buttons [1] to [8] and [0] play an Act or Wander To stop Bambino press the [POWER] button on the TVR010. When stopped and waiting for a command Bambino's eyes will be dim. To play an Act press the relevant number button [1] to [8]. To get Bambino to Wander press button [0] When Bambino is stopped pressing button [Fd] will cause Bambino to take a step forward. When Bambino is stopped pressing button [Bk] will cause Bambino to take a step back. When Bambino is stopped pressing button [Lt] will cause Bambino to turn left one step. When Bambino is stopped pressing button [Rt] will cause Bambino to turn right one step. Note that Bambino turns by sliding its feet, sometimes it has to take a step before its feet are in the right position to turn. To play an SAct press the function button [f^] then the number button [1] to [8] for the desired SAct. currently there is only one in the supplied control program, SAct #1 - RockADo To Record a simple Act ---------------------- [f|] press function button [f|] to enter Record mode; press a number button [1] to [8] for the Act you wish to record. If you press any other button Bambinos down sensors will blink to indicate an incorrect button. While Bambino is waiting for a button to be pressed the mouth LED will light. To just quit without recording any moves press [POWER] twice, the first time the mouth LED will go out and the second time the eyes will glow dim indicating Bambino is stopped. To recap, to record press [f|] then a number button [1] to [8] Bambino's eyes will go out and the mouth LED will light. Press [Fd],[Bk],[Rt],[Lt] as desired. Bambino will beep when a command is received and the mouth LED will go out while the command is being done. When it is finished the mouth LED will light indicating Bambino is waiting for the next command. When you have finished press [POWER] to end recording. If you try and enter too many moves Bambino will beep and the recording will end automatically. When recording has ended Bambino's will glow dim. The Act can be played by pressing the number button for the Act. To Record a repeating Act ------------------------- Record as for a simple Act but before pressing [POWER] press the number button for the Act you are recording then press [POWER]. eg [f|] [2] [Fd] [2] [POWER] Will select recording of Act 2, record a Forward one step command [Fd], record a command to play Act 2 then [POWER] ends recording. So if you press [2] to play Act 2 Bambino will take a step forward and then play Act 2 again, so Bambino will walk forwards forever or until you press [POWER] or turn it off To chain to another Act at the end of a recording ------------------------------------------------- As before but instead of pressing the button for the Act you are recording, press the number button for the Act you wish to do next. eg [f|] [3] [Rt] [Rt] [2] [POWER] Now Act 3 when played will cause Bambino to turn right twice then play Act 2. To Record repeating Acts ------------------------ Make a new recording [f|] [2] [Fd] [Fd] [Fd] [3] [POWER] Now when you press [2] to play Act 2, Bambino will step forward three times then play Act 3. If Act 3 is still [f|] [3] [Rt] [Rt] [2] [POWER] Act 3 will make Bambino turn right twice then play Act 2. So Bambino will continually take three steps forward and two steps right, again until you press [POWER]. To include a Subroutine act, SAct, in an Act -------------------------------------------- Note There is only the one SAct included in the program, SAct #1 - RockADo. Lets record Act 4 to do Forward one step then include RockADo and repeat, remember [f^] from above selects Subroutine acts [f|] [4] [Fd] [f^] [1] [4] [POWER] press [4] to play the act. To tell Bambino what to do when it is switched on ------------------------------------------------- By now you should have gathered that programming Bambino from the TVR010 remote-control is quite easy. Any button press can be recorded into an Act. We mentioned before that Act [8] is special in that it starts to play as soon as Bambino is switched on so if you want Bambino to Wander when it is switched on then simply record Act 8 as [f|] [8] [0] [POWER] Act 8 will then immediately start Wander. If you record [f|] [8] [f^] [1] [0] [POWER] when switched on Bambino will do RockADo and then Wander. Bambino's sensor behaviour -------------------------- When an obstacle or hole is detected by the optical sensors Bambino will try and avoid it by turning and or stepping back and remember whether the obstacle/hole was to the front or right or left. If another obstacle/hole is now seen then Bambino will remember two obstacles/holes, if there are more than two obstacles/holes then Bambino will step back before turning. At each step Bambino forgets a bit about the obstacles/holes and will go back to just turning away from them. When an obstacle is detected by the Ultrasonic sensor if it is further away than some distance, lets call it US-AwareAt, then the obstacle is ignored. If the obstacle is nearer, but not too close then Bambino just turns. If the obstacle is closer than some distance, lets call it US-TooNear, then Bambino will make a 'squak' noise and step back and turn away. Testing for obstacle/holes -------------------------- [-] enable the Optical sensors and run tests for obstacles and holes [+] enable the Ultrasonic sensor and run the test for obstacles pressing [-] will enable the Optical sensors and run tests for obstacles and holes, pressing [+] will enable the Ultrasonic sensor and run the test for obstacles, these commands can be recorded in Acts. When the Act is run if when those commands are executed the sensor tests show there is an obstacle or hole then the appropriate action will be done before Bambino carries on with the rest of the commands in the Act. Setting Bambino's behaviour --------------------------- [9][1] slow [9][2] medium [9][3] fast [9][4] timid [9][5] normal [9][6] bold [9][7] disable optical sensors [9][8] disable ultrasonic sensor [9][9] use USER ultrasonic settings [9][0] default vitality [9][Fd] increase vitality [9][Bk] decrease vitality Bambino can walk slowly, or medium, or fast. To set slow press [9] then [1] To set medium press [9] then [2] To set fast press [9] then [3] Bambino can be timid, normal or bold in response to the Ultrasonic distance readings. If Bambino is timid then US-TooNear =15 cm US-AwareAt =30 cm If Bambino is normal then US-TooNear =10 cm US-AwareAt =20 cm If Bambino is bold then US-TooNear =5 cm US-AwareAt =10 cm To set timid press [9] then [4] To set normal press [9] then [5] To set bold press [9] then [6] We said that no sensor was perfect and Bambino's optical sensors can be affected by Halogen lights or bright sunlight and the readings can be affected by the colour of the obstacles or floor or table. If when Wandering Bambino is avoiding things which are not there then the optical sensors can be turned off To turn off the Optical sensors press [9] then [7] When the battery is running down the Ultrasonic sensor can give false reading and when Wandering Bambino can think there is an obstacle when there isn't one. If this happens the Ultrasonic sensor can be turned off. To turn off the Ultrasonic sensors press [9] then [8] In addition US-TooNear and US-AwareAt can be set by the user (see below) To use those values press [9] then [9] Again all these commands can be recorded in Acts. eg [f|] [1] [9] [1] [Fd] [Fd] [9] [2] [Fd] [Fd] [9] [3] [Fd] [Fd] [1] [POWER] Will create an Act 1 where Bambino is set to slow then takes two steps forward, is set to medium and takes two steps forward, is set to fast and takes another two steps forward, then repeats that forever. Setting User values for the Ultrasonic behaviour ------------------------------------------------ [f+] then do [-] set US-TooNear, [+] set US-AwareAt as required [POWER] to quit place an obstacle in front of Bambino press [f+] to enter modify mode press [-] to set US-TooNear press [+] to set US-AwareAt press [POWER] to end Advanced behaviour - vitality ----------------------------- [9][Fd] increases vitality [9][Bk] decreases vitality [9][0] default vitality It is possible to alter the vitality of Bambino over something like a +30% to -50% range. Pressing [9] then [Fd] increases the vitality by about 10% each time up to the maximum of +30%. Pressing [9] then [Bk] decreases the vitality by about 10% each time to a minimum of -50%. Pressing [9] then [0] restores the vitality to the default setting. The changed vitality is not remembered when Bambino is turned off Again these commands can be recorded in Acts. Other ----- [fX] send the contents of the EEPROM memory to a PC over the programming link at 38400 baud More for those programming Bambino in Basic using the PicAxe IDE. Pressing [fX] will send the contents of the EEPROM memory to a PC over the programming link at 38400 baud in a format suitable for pasting into another Basic program. It is best not to use the Serial Terminal in the PicAxe IDE for this. I use Br@ys Terminal or preferably Parallax's Serial Terminal. ======================================================================== Appendix 1 - seting the serovs with Bambino-08+.bas ==================================================== Switch on Bambino and load Bambino-08+.bas using the PicAxe Programming Editor. This allows you to set the mid positions of both servos. Because of the way each servo is made and the horns can only be put on about every 15 degrees the feet may not be exactly side by side or flat on the ground. Adjust the Roll servo so Bambino stands up straight and doesn't lean to the left or right. Adjust the Pace servo so Bambino stands with both feet side by side. Using the TVR010 infra-red remote-control - press either the [KEY_LEFT] or [KEY_RIGHT] button to adjust the Roll servo, press either the [KEY_UP] or [KEY_DOWN] button to adjust the Pace servo, for the Roll servo the right down LED will light, for the Pace servo the left down LED will light. The [-] and [+] buttons are by button [0]. Press either the [+] or [-] buttons to adjust the servo position when it is right press the [POWER] key, the down LEDs will go out and the mouth LED will light, if you press other keys then the eyes will say no, adjust both servos. The calibrated values are stored in EEPROM for further programs. You can Open a serial terminal @4800 baud to see the values. ======================================================================== Appendix 2 - BambinoCommands: using TVR010_PicAxe_IR_controller =============================================================== The following synopsis of key usage, from Bambino-46.bas, may be useful. BambinoCommands: 'using TVR010_PicAxe_IR_controller '-------------------------------------------------- ' '[KEY_POWER] stops a learned Act and enters Command mode. ' ends modify mode, ends learning ' it can't stop a subroutine Act ' 'Direction Keys '-------------- '[KEY_UP] ie [Fd] Step Forward '[KEY_DOWN] ie [Bk] Step Backward '[KEY_RIGHT] ie [Rt] Step Right '[KEY_LEFT] ie [Lt] Step Left ' 'Function Keys '------------- '[KEY_BAR] ie [f|] enters learn mode to record key presses ' has to be followed by a number key 1-8 ' = the Act to be remembered ' up to 8 Acts can be learned ' learned Acts can call subroutine Acts 'Acts can chain to other Acts, eg Fd,Bk,2 - chain to Act2 'A learned Act which chains itself repeats forever, 'eg [f|][1][Fd][1][POWER] Act1 will do Fd forever '[KEY_TENT] ie [f^] selects subroutine Acts = SAct, ' has to be followed by a number key 1-8 ' plays SActs, SActs play until the end. ' [KEY_1] is RockAdo '[KEY_VCROSS] ie [f+] modify USawareAt, UStoonear ' [+] set USAwareAt in EEPROM DUSawareAt ' [-] set UStoonear in EEPROM DUStoonear ' [Key_POWER] to quit '[KEY_XCROSS] ie [fX] Dump EEPROM Acts DATA to PC, including Config Data ' 'Act Keys '-------- '[1] to [8] Play an Act '[f^][1] to [f^][8] Play a subroutine Act 'When Recording an Act, ' [1]-[8] record a jump to a new Act ' if [1],[2],[3],[4],[5],[6],[7].[8],[0] are used to jump to ' another Act there is no point in recording more moves because they ' will never be replayed since control is transfered to the new Act, ' just press [KEY_POWER] to end the recording; ' [f^] then [1]-[8] to do and include a Subroutine Act (SAct); ' when the memory slot is full Bambino will beep and recording will end. 'Act8 Autoruns on PowerOn ' On poweron to WANDER do [f|][8][0][Power] ' enter command mode do [f|][8][Power] ' WANDER B_slow do [f|][8][9][1][0][Power] ' run Act1 do [f|][8][1][Power] ' do SAct1 then Act1 do [f|][8][f^][1][1][Power] ' etc 'Act0 is WANDER and cannot be changed ' 'Behaviour Key '------------- '[9] Behaviour mode eg [9][1] set speed slow ' [1] set speed slow ' [2] set speed medium ' [3] set speed fast ' [4] set US behaviour to timid ' [5] set US behaviour to normal ' [6] set US behaviour to bold ' [7] disable Whiskers test ' [8] disable Ultrasonic test ' [9] set US behaviour to User values set by handset ' [KEY_UP] B_faster: - increase speed ' [KEY_0] B_normal: - normal speed ' [KEY_DOWN] B_slower: - decrease speed ' 'Sensor Keys '----------- '[-] enable and test Whisker sensors and re-act, R_Whiskers: '[+] enable and test Ping sensor and re-act, R_Ping: ' 'Activity Key '------------ '[0] WANDER ' ' 'Quirks '------ ' If you are recording Act1 and press [f|][2] then you will start 'to record Act2 and Act1 will be left without placing an end marker. 'If Act1 is then played the new moves will be played then whatever 'moves remained there from before. 'If you enter record mode but press [POWER] before pressing a valid 'Act key [1] - [8] then until you press [POWER] a second time and 'Bambino's eyes glow dim any commands will be recorded in Act #6. 'There is no room left to correct this! ======================================================================== Appendix 3 ========== Bambino_Suite: 'Bambino-00 all off, no activity so can probe board for voltages 'Bambino-01 Test eyeLEDs, whiskerLEDs and speaker 'Bambino-02 Test PWM of eyeLEDs 'Bambino-03 Test InfraRed input 'Bambino-04 Test Eye light values 'Bambino-05 Test Whisker light values 'Bambino-06 Play the inbuilt tunes using keys 1 to 4 and beep on 5 'Bambino-07 Set servos to mid position 'Bambino-08 Calibrate servo mid positions and put in EEPROM. 'Bambino-08+ Adjust servo mid positions from Handset and put in EEPROM. 'Bambino-09 Introduce _iStand:- initialise with feet in mid position 'Bambino-10 Set rollby, rollbymax for Roll Right 'Bambino-11 Check rollby, rollbymax for Roll Left 'Bambino-12 Check rollby and rollbymax for rollR, rollL 'Bambino-13 Introduction of _Stand 'Bambino-14 Investigate effect of rollspeed; ' watch roll for all three speeds 'Bambino-15 Investigate effect of rollspeed; ' watch Roll and Stand for all three speeds 'Bambino-16 Check paceFL paceFR; Investigate effect of pacespeed ' Introduction of pulseservos: 'Bambino-17 Check Fd 'Bambino-18 Test Rt, Lt 'Bambino-19 Test Bk 'Bambino-20 Test T2l: TurntoLight: T2d: TurntoDark: Wl: Wd: 'Bambino-21 Creaton of sections ACTIONS, BEHAVIOURS, ACTS; ' Introduction of ACT parameter 'Ado' 'Bambino-22 Demo routine + example use of Start1: to flash eyes 'Bambino-23 Walk Fd with obstacles avoidance using eyes from 04, ' introduction of Default behaviour 'Bambino-24 Walk Fd with obstacles avoidance as 23, with Act BT 'Bambino-25 Walk Fd with drop-off avoidance using whiskers from 05 ' obstacle map extended to include holes 'Bambino-26 rewritten with reading of whiskers as subroutines 'Bambino-27 rewritten with autocalibration of down whiskers 'Bambino-28 Test maximum PWM and hence minimum brightness of eyeLEDs, ' needed in Bambino-29 'Bambino-29 Wait for IR command then do it otherwise WANDER as B24 'Bambino-30 rewrite to clearer code 'Bambino-31 remember a sequence of key presses on IR-controller 'Bambino-32 remember up to 7 sequences of key presses in RAM, ' forgotten on power off 'Bambino-33 remember up to 8 sequence of key presses in EEPROM, ' now not forgotten. 'Bambino-34 obstacles memory made deeper for better obstacle avoidance, ' and put in RAM, Mfrus_obs introduced 'Bambino-35 key [0] can now be learned 'Bambino-36 incorporate drop-off avoidance from B25, ' remember holes and obstacles 'Bambino-37 PicAxe SRF05 Ultrasonic sensor added ' and facility to adjust ' USawareAt and UStoonear from IR-handset 'Bambino-38 Added code to use either PicAxe SRF05 or an HC-SR04 ' Ultrasonic sensor with #defines for sensor type, ' cm or inches, and testUS. 'Bambino-39 added KEY_PLUS to test Ping sensor and act on result, ' can be put in learned routines. ' added poweron test of US, if <10 then disable US 'Bambino-40 revised use of LEDs for indicating holes/obstacles ' Separated Whisker and Ultrasonic actions in Walk: 'Bambino-41 added CASE KEY_9 '[9] Behaviour to select behaviours ' B_slow,B_medium,B_fast, ' B_UStimid,B_USnormal,B_USbold, ' B_noWhiskers,B_noUS ' B_USxxx now write to RAM 'Bambino-42 moved whisker testing and reaction to R_Whiskers ' added KEY_MINUS to test Whiskers and act on result ' removed test of US in INITIALISE:, not needed now on keys[9][8] 'Bambino-43 Act#8 made autorun ' On poweron to WANDER do [|][8][0][Power] ' command mode do [|][8][Power] ' WANDER B_slow do [|][8][9][1][0][Power] ' run Act1 do [|][8][1][Power] ' do CAct1 then Act1 do [|][8][^][1][1][Power] ' etc 'Bambino-44 updating of RAMobstaclesX ' removed from Whisker sense routines, put in R_whiskers: ' moved testing of DUSvalues and updating of RAMUS to B_USuser: ' [9][9] runs B_USuser: to get USuser distance values from EEPROM 'Bambino-45 program now runs @32MHz except when pulsing Servos and Beeping ' Beeping didn't sound right @32MHz ' Servos pulsed @4MHz to keep 10us resolution which fits in a byte 'Bambino-46 adjusment of sframe to fine adjust speed '=================================================================