'Bambino-27 SERTXD("B27",CR) 'report program number '728 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 'Bambino-24 Walk Fd with obstacles avoidance as 23, with Act BT 'Bambino-25 Walk Fd with drop-off avoidance using whiskers from 05 'Bambino-26 rewritten with reading of whiskers as subroutines 'Bambino-27 rewritten with autocalibration of down whiskers '----------------------------------------------------------------- Rationale: 'Walk Fd with drop-off avoidance '------------------------------- 'Optical sensor are tricky to get working 100% of the time. 'Sunlight tends to blind them and the high frequency flickering of 'artificial light, which we can't see, confuses them. 'Here a new routine calibrateholewhiskers: is introduced which 'uses the QGwhiskerX routines to determine the reflectance of the 'the ground, ie table or wherever Bambino is walking. and sets 'the hole thresholds at 60%. 'At each step Bambino then compares that value to the light from the 'ground to see if the value is less and if so the ground has probably 'gone away and there is a hole. 'This also means Bambino will tend not to stray from a white paper 'on a dark table. '================================================================= 'modified '-------- 'QGwhiskerL: Query whisker Left 'QGwhiskerR: Query whisker Right 'New '--- 'SYMBOL RAMtemp0 =28 'first non variable RAM location 'SYMBOL RAMtemp1 =29 'SYMBOL RAMholedetectR =30 'holds % light level difference for hole 'SYMBOL RAMholedetectL =31 'holds % light level difference for hole 'calibrateholewhiskers: '================================================================= 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 GwhiskerLedL_=c.3 'low =>Ground whisker LED on SYMBOL GwhiskerLedR_=b.3 'low =>Ground whisker LED on SYMBOL eyeR =c.7 'adc SYMBOL eyeL =c.1 'adc SYMBOL GwhiskerL =b.5 'adc Ground whisker Down Left SYMBOL GwhiskerR =b.0 'adc Ground whisker Down Right SYMBOL inIR =c.6 SYMBOL outIR =b.2 SYMBOL tempW0 =W0 SYMBOL temp0 =B0 'initialise,calibrateholewhiskers,QGwhiskerX SYMBOL temp0dark =B0 'QGwhiskerX SYMBOL temp1 =B1 'initialise,QGwhiskerX SYMBOL temp1lit =B1 'QGwhiskerX 'W1 SYMBOL temp2 =B2 SYMBOL temp2diff =B2 SYMBOL B_flags =B3 SYMBOL f_Bfast =bit31 'speed Behaviour 1=use B_fast: 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 =B10 '4 is too fast, 0 won't move SYMBOL pacespeed =B11 '6 is about max for servos to keep up 'SYMBOL Smoveby =W6 'SYMBOL rollby =B12 '+ve right 15 good for walking 'SYMBOL paceby =B13 '+ve Left foot forward 20@speed 3; 25@speed 1 SYMBOL Light =W7 SYMBOL lightL =B14 'ambient light level Left, eye or whisker SYMBOL lightR =B15 'ambient light level Right, eye or whisker SYMBOL i =B16 '_iStand: SYMBOL spulse =B16 'FOR NEXT counter for servo pulses SYMBOL Ado =B17 'parameter for Acts SYMBOL iA =B18 'counter for Acts SYMBOL obstacles =B17 '%1111 bitmap of obstacles '%Lefthole,Righthole,Leftobstacle,Rightobstacle, '=== 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 '================================= 'RAM DATA 28 - 511 SYMBOL RAMtemp0 =28 'first non variable RAM location SYMBOL RAMtemp1 =29 SYMBOL RAMholedetectR =30 'holds % light level difference for hole SYMBOL RAMholedetectL =31 'holds % light level difference for hole 'If there is close tungsten light then Bambino may need an eye shade 'or a neb to shield the ground from the tungsten light. 'depending on the sensors obsdetectL and obsdetectR may need to be different SYMBOL obsdetectL =10 '% light level difference for obstacle SYMBOL obsdetectR =10 '% light level difference for obstacle 'whisker LEDs on, 82R 1.414v =>17.2mA @4.02V '================================================================= 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 GOSUB calibrateholewhiskers START: SERTXD(CR,"S") obstacles =0 GOSUB QGwhiskerL 'and update obstacle map GOSUB QGwhiskerR 'and update obstacle map Walk: HIGH eyeLedR_ 'eye OFF HIGH eyeLedL_ 'eye OFF temp0 =obstacles 'to use bits IF BIT2=1 THEN LOW GwhiskerLedR_ ENDIF IF BIT3=1 THEN LOW GwhiskerLedL_ ENDIF SERTXD(cr," map",#bit3,#bit2,#bit1,#bit0) 'combine holes and obstacles bit1 =bit3 OR bit1 bit0 =bit2 OR bit0 obstacles =temp0 AND %11 'delete top two bits SERTXD(" ",#bit1,#bit0) ON obstacles GOSUB Fd,Lt,Rt,BT GOTO START: 'loop back to start '----------------------------------------- 'Acts '---- RockAdo: FOR i=1 TO Ado GOSUB _rollR GOSUB _rollL NEXT i RETURN FdAdo: FOR i=1 TO Ado GOSUB Fd NEXT i RETURN BkAdo: FOR i=1 TO Ado GOSUB Bk NEXT i RETURN BT: GOSUB Bk GOSUB Bk GOSUB Rt GOSUB Rt RETURN '----------------------------------------- 'Behaviours '---------- B_fast: pacespeed =6 '6 is about max for servos to keep up rollspeed =3 'half of pacespeed is about right for walking f_Bfast =1 RETURN 'B_medium: ' rollspeed =2 ' pacespeed =3 ' RETURN 'B_slow: ' rollspeed =1 ' pacespeed =1 ' RETURN B_turn: rollspeed =1 'slow so foot doesn't bounce pacespeed =5 RETURN '----------------------------------------- 'Actions '------- beep150: SOUND VoiceLed_,(150,10) RETURN LedsOFF: HIGH eyeLedR_ HIGH eyeLedL_ HIGH GwhiskerLedR_ HIGH GwhiskerLedL_ RETURN ELedsON: LOW eyeLedR_ LOW eyeLedL_ RETURN Fd: SERTXD (" Fd") IF paceatpaceC THEN GOSUB Fd 'need right foot forward IF f_Bfast=1 THEN GOSUB beep150 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