'Bambino-23 SERTXD("B23",CR) 'report program number @4800baud '596 bytes #PicAxe 20M2 #no_data '================================================================= 'PICAXE IC Memory ext I/O Outputs Inputs ADC Memory Starts Polled Resonator ' £ Type pins bytes slot pins Vars. RAM Spad Data Table* Int. def. opt. '2.28 PICAXE-20M2 20 2k 18 1-16 1-17 4 28 512 256 512 8 Yes 4 -32 'PICAXE-20M2 circuit board with LEDs off takes 1mA 'PICAXE-20M2 circuit board with LEDs off and servos connected takes 10mA '================================================================= '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 rollL, rollR '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 Creation 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 '----------------------------------------------------------------- Rationale: 'Walk Fd with obstacles avoidance using eyes from 04 '--------------------------------------------------- 'Now we can start to make Bambino come alive. 'Bambino reads the two eyes and 'if there are obstacles sets the bits in the variable obstacles. 'If there is an obstacle to the left it turns on the left eyeLED 'If there is an obstacle to the right it turns on the right eyeLED 'Then does Fd,Lt,Rt,Bk depending on the value of obstacles. ' 'If in fast mode then when turning the feet bounce and turning is not 'too good so we introduce B_turn which sets the parameters for turning.. ' 'The eye routines measure the ambient light level and then measure 'the light level with the LED turned on. When it is dark and the 'measured light level is low the LED makes a big difference but 'very little difference when it is bright so measuring the difference 'in levels is not really useful when it is bright. A better way is to 'calculate the change as a percentage of the possible change then the 'percentage change doesn't drop off at high light levels as the 'photo-transistors saturate. '================================================================= 'modified '-------- 'all variable moved up by 2 bytes to leave all the bit variables spare for flags, etc 'start 'Rt for B_turn 'Lt for B_turn 'New '--- 'EyesON: 'EyesOFF: 'f_Bfast 'if 1 then B_fast 'B_turn 'set behaviour variables for turning 'lightL 'lightR 'eyelit 'obsdetectL 'obsdetectR 'QEwhiskerL: Query Eye whisker Left 'QEwhiskerR: Query Eye whisker Right '================================================================= SYMBOL servopace =c.0 'left connector SYMBOL servoroll =c.4 'right connector SYMBOL VoiceLed_ =c.5 'low =>LED on SYMBOL eyeLedL_ =c.2 'low =>LED on SYMBOL eyeLedR_ =b.1 'low =>LED on SYMBOL whiskerLedL_ =c.3 'low =>whisker LED on SYMBOL whiskerLedR_ =b.3 'low =>whisker LED on SYMBOL eyeR =c.7 SYMBOL eyeL =c.1 SYMBOL inIR =c.6 SYMBOL outIR =b.2 SYMBOL temp0 =B0 SYMBOL eyelit =B0 SYMBOL temp1 =B1 'B2 SYMBOL B_flags =B3 SYMBOL f_Bfast =bit31 'defaultBehaviour 1=use default SYMBOL Scentre =W2 SYMBOL rollC =B4 '100 is roll to the left, 200 to the right SYMBOL paceC =B5 '100 is left foot back, 200 left foot forward SYMBOL Sat =W3 'current servo positions SYMBOL rollat =B6 SYMBOL paceat =B7 SYMBOL Sto =W4 'desired servo positions SYMBOL rollto =B8 SYMBOL paceto =B9 SYMBOL Sspeed =W5 SYMBOL rollspeed =B11 '4 is too fast, 0 won't move SYMBOL pacespeed =B12 '6 is about max for servos to keep up SYMBOL i =B13 '_iStand: Acts: SYMBOL spulse =b14 SYMBOL lightL =B15 'ambient light level Left SYMBOL lightR =B16 'ambient light level Right SYMBOL eyediff =B17 SYMBOL obstacles =B18 '%11 bitmap of obstacles %LeftRight SYMBOL Ado =B19 'parameter for Acts '=== Your Bambino ================ SYMBOL rollby =15 '15 good for walking, edit to value in program11 SYMBOL paceby =25 '+ve Left foot forward 20@speed 3; 25@speed 1 SYMBOL sframe =20 'time between servo pulses SYMBOL rollbymax =20 '@speed 3; 25@speed 1 'rollmax absolute max is 40, above that the tilt rods hit the body SYMBOL pacebymax =30 'pacebymax absolute max is 30, above that the tilt rods hit the rear femur 'and the horn screws hit the leg body 'EEPROM DATA SYMBOL DrollC =254 'holds rollC, 100 is roll to the left, 150 is nominal centre SYMBOL DpaceC =255 'holds paceC, 100 is left foot back, 150 is nominal centre '================================= 'depending on the sensors obsdetectL and obsdetectR may need to be different SYMBOL obsdetectL =10 '% light level difference for obstacles SYMBOL obsdetectR =10 '% light level difference for obstacles '================================================================= initialise: 'get values from EEPROM set by program #8 or #8+ READ DrollC,rollC READ DpaceC,paceC SERTXD("rollC=",#rollC," paceC=",#paceC,CR) LOW eyeLedR_ 'make output HIGH eyeLedL_ 'make output GOSUB _iStand 'stand and initialise rollat, paceat initspeed: GOSUB B_fast START: obstacles =0 GOSUB EyesOFF QEwhiskerL: READADC eyeL,lightL LOW eyeLedL_ 'eyeL on PAUSE 1 READADC eyeL,eyelit HIGH eyeLedL_ 'eyeL off temp1 =255 -lightL 'possible change 'find difference as % of possible change eyediff =eyelit MIN lightL -lightL *100 /temp1 SERTXD(" L%=",#eyediff," ") IF eyediffpaceC THEN GOSUB Fd 'need right foot forward IF f_Bfast=1 THEN GOSUB B_turn GOSUB _LF IF f_Bfast=1 THEN GOSUB B_fast RETURN _RF: 'SERTXD ("_RF") paceto =paceC -paceby FOR spulse=paceat TO paceto STEP -pacespeed paceat =spulse GOSUB pulseservos NEXT spulse RETURN _LF: 'SERTXD ("_LF") paceto =paceC +paceby FOR spulse=paceat TO paceto STEP pacespeed paceat =spulse GOSUB pulseservos NEXT spulse RETURN Stand: 'stand with both feet flat SERTXD (" Sd") IF rollat