'******************************* ; ***** Sample Header File ***** ; ******************************* ; Filename: Mad Dog Robot.bas ; Date: May 24, 2011 ; File Version: 1 ; Written by: PGR ; Function: Operate Minute to Win it Mad Dog Game Playing Robot ; Target PICAXE: 18M2 ; ******************************* ' intial setup ' define meaningful names for output pins symbol Neck = b.6 ' controls rotation of robot neck [drill motor] symbol Grip = b.5 ' controls robot gripper motor symbol DPDT = b.7 ' controls DPDT relay which determines grip motor rotation direction symbol Platform = b.4 ' controls back and forth movement of robot platform [wiper motor] symbol LED = c.1 ' time out error LED symbol PwmDty = w10 ' setup memory location b0 to store PwmDty value ' pin b.0 is rear microswitch to detect table at rear position ' pin b.1 is front switch (embedded in wiper motor) to detect platform at front position ' pin b.2 is switch to detect robot neck at center position as is required to pick up ruler ' pin b.3 is IR sensor to read signals from IR remote control 'define storage varable locations 'symbol b2 = infra ' variable storage location b2 stores data as received by the IR sensor main: irin b.3,infra 'wait for new signal sertxd ("IR value is ",#infra,cr,lf) ' only used for debugging pause 200 ; short delay if infra = 18 then gosub Forwrd ' volume up button if infra = 19 then gosub Rearwrd ' volume down button if infra = 16 then gosub OpenGrip ' channel up button if infra = 17 then gosub CloseGrip ' channel down button if infra = 20 then gosub CenterNeck ' Mute Button if infra = 0 then gosub SlowNeck ' one key on remote if infra = 1 then gosub FastNeck ' two key on remote if infra = 2 then gosub Ready ' three key on remote if infra = 3 then gosub Compete ' four key on remote goto main Forwrd: let time =0 'reset timer to 0, the time variable name (in seconds) is a new feature of picaxe M2 chips Do high Platform ' start platform motor loop until time => 10 or pinb.1 = 1 'that is run platform motor unitl front sensing switch is tripped or times out after 10 seconds low Platform ' stop platform motor if time => 10 then goto TimeOutError return Rearwrd: let time =0 'reset timer to 0, the time variable name (in seconds) is a new feature of picaxe M2 chips Do high Platform ' start platform motor loop until time => 10 or pinb.0 = 1 'that is run neck motor unitl rear sensing switch is tripped or times out after 10 seconds low Platform ' stop platform motor if time => 10 then goto TimeOutError return CenterNeck: gosub Rearwrd ' always make sure platform is in back postion before operating neck let time =0 'reset timer to 0, the time variable name (in seconds) is a new feature of picaxe M2 chips let PwmDty =60 ' set intial value for pwmout ReTry: pwmout B.6, 99, PwmDty ' run neck motor at about 10 percent duty Do loop until time => 15 or pinb.2 = 1 'that is run platform motor unitl neck center sensing switch is tripped or times out after 15 seconds pwmout B.6, OFF ' stop neck motor pause 300 if time => 15 then goto TimeOutError if pinb.2 <> 1 then PwmDty = PwmDty - 5 ' if centering did not pass test, then reduce pwmduty by 5 & try again goto Retry end if return FastNeck: gosub Rearwrd ' always make usre platform is in back postion before operating neck let PwmDty =100 ' set intial value for pwmout pwmout B.6, 99, PwmDty ' run neck motor at 20 percent duty pause 1000 ' run for 1 second for b0 = 1 to 2 do pwmduty B.6, PwmDty ' run neck motor at 40 percent duty pause 40 ' pause for 0.04 seconds inc PwmDty 'debug PwmDty loop until PwmDty > 140 pause 5000 pwmout B.6, OFF pause 500 pwmout B.6, 99, 280 pause 4000 next do pwmduty B.6, PwmDty ' run neck motor at 40 percent duty pause 2 ' pause for 0.002 seconds dec PwmDty 'debug PwmDty loop until PwmDty < 80 pwmout B.6, OFF ' stop neck motor return SlowNeck: gosub Rearwrd ' always make usre platform is in back postion before operating neck pwmout B.6, 99, 60 ' run neck motor at 10 percent duty pause 1000 ' run for 0.10 seconds pwmout B.6, OFF ' stop neck motor return CloseGrip: low DPDT 'de-energize DPPT relay pause 100 ' let relay settle high Grip ' grip will close - NC microswitch breaks motor circuit at forward travel limit Return OpenGrip: high DPDT ' energize DPDT relay pause 100 ' let relay settle high Grip ' grip will open - NC microswitch breaks motor circuit at rearward travel limit Return Ready: gosub Rearwrd gosub CenterNeck gosub OpenGrip Return Compete: gosub Forwrd gosub CloseGrip Pause 4000 gosub Rearwrd gosub FastNeck gosub CenterNeck gosub Forwrd gosub OpenGrip Pause 4000 gosub Rearwrd Return TimeOutError: high LED pause 1000 low Led pause LED goto TimeOutError end