' www.crustcrawler.com ' Copyright 2006 CrustCrawler Inc. ' '------- [ QuadRodPings3LCD.bs2 ] ---------------------------------------------- '{$STAMP BS2} '{$PBASIC 2.5} ' ' File....... QuadRodPings3LCD.bs2 ' Purpose.... ' Author..... CrustCrawler Inc. (Mike Gebhard) ' Help....... http://forum.crustcrawler.com/ ' Started.... 11/03/2005 ' Updated.... 03/28/2007 ' Version.... 2.0 ' ' Hardware ' (1) CrustCrawler QuadRod Robotic Kit ' (1) CrustCrawler S3 Tilt Pan ' (1) Parallax BOE ' (1) Parallax Basic Stamp II ' (1) Parallax PSC ' (1) Parallax PING))) Ultra Sonic Sensor ' '========================================================================= ' Updates 03/28/2007 '========================================================================= ' * Set delay to fire after reading each row in the EEPROM tables ' and NOT after reading each column. ' '========================================================================= ' Overview '========================================================================= ' Use the LCD AppMod to select gait parameters and display PING))) ' distance readings. Obstacle avoidance with an S3/PING system. ' '========================================================================= ' Getting Started '========================================================================= ' On first load, the CrustCrawler logo is displayed on the LCD AppMod. ' After 1/2 second the Velocity menu is displayed. If the LCD is blank, ' adjust the contrast POT. ' ' Use the LCD AppMod buttons to interface with the robot's gait ' parameters. ' ' BUTTONS ' A = Mode (set speed, direction, limiter) ' B = Increment ' C = Decrement ' D = Enter ' ' Press button A to setup the walking parameters. Pressing button A will ' toggle between the speed, direction, and limiter screens. Button B ' increments the speed or direction value displayed. Button C decrements ' the value. Press D to exit setup and display the CrustCrawler logo. ' ' The LCD will display distance reading from the PING))) ' ' PING Connections: ' PING BOE '------ ----- ' GND Vss ' 5V Vdd ' SIG Pin 14 ' '========================================================================= ' Program Operation Overview '========================================================================= ' Please read all documentation and review demo/base code for the ' QuadRod, PSC, BOE/BS2, and PING))). The code below is a combination ' the QuadRodLCD.bs2 and QuadRodPing.bs2. ' '========================================================================= ' Sub Routines '========================================================================= ' Please refer to QuadRodBase.bs2 and Ping_Demo.bs2 for details. ' '------------------------------------------------------------------------- ' -----[ I/O Definitions ]------------------------------------------------ PSC PIN 15 ' PSC module Ping PIN 14 ' PING))) ' ----[ Set baud for all STAMP versions ]--------------------------------- #SELECT $STAMP #CASE BS2SX, BS2P Baud CON 1021 + $8000 #CASE BS2PX Baud CON 1646 + $8000 #CASE #ELSE Baud CON 396 + $8000 #ENDSELECT ' -----[ LCD I/O Definitions ]-------------------------------------------- E PIN 1 ' LCD Enable (1 = enabled) RW PIN 2 ' Read/Write RS PIN 3 ' Reg Select (1 = char) LcdDirs VAR DIRB ' dirs for I/O redirection LcdBusOut VAR OUTB LcdBusIn VAR INB ' -----[ PING))) Constants ]---------------------------------------------- #SELECT $STAMP #CASE BS2, BS2E Trigger CON 5 ' trigger pulse = 10 uS Scale CON $200 ' raw x 2.00 = uS #CASE BS2SX, BS2P, BS2PX Trigger CON 13 Scale CON $0CD ' raw x 0.80 = uS #CASE BS2PE Trigger CON 5 Scale CON $1E1 ' raw x 1.88 = uS #ENDSELECT RawToIn CON 889 ' 65536 / 73.746 (with **) RawToCm CON 2257 ' 65536 / 29.034 (with **) IsHigh CON 1 ' for PULSOUT IsLow CON 0 RefreshConv CON 50 ' Pause = refresh*RefreshConv ' -----[ LCD Constants ]-------------------------------------------------- #DEFINE _lcdReady = ($stamp = BS2SX) OR ($stamp = BS2P) LcdCls CON $01 ' clear the LCD LcdHome CON $02 ' move cursor home LcdCrsrL CON $10 ' move cursor left LcdCrsrR CON $14 ' move cursor right LcdDispL CON $18 ' shift chars left LcdDispR CON $1C ' shift chars right LcdDDRam CON $80 ' Display Data RAM control LcdCGRam CON $40 ' Character Generator RAM LcdLine1 CON $80 ' DDRAM address of line 1 LcdLine2 CON $C0 ' DDRAM address of line 2 LcdScrollTm CON 250 ' LCD scroll timing (ms) '---- [Walking Variables] ------------------------------------------------ ptrEEPROM VAR Word ' Gait select servoPosition VAR Word ' Servo Position temp VAR Word ' Workspace servoAddr VAR Byte ' Servo addresses ramp VAR Byte ' Ramp used in SEROUT vel VAR Byte ' Value from speed screen rightRamp VAR Byte ' Right side ramp values leftRamp VAR Byte ' Left side ramp values limiter VAR Byte ' Reduce stride delay VAR Byte ' Wait steps VAR Nib ' Numbers of steps rowCounter VAR Nib ' Count EERROM rows ' -----[ Variables ]------------------------------------------------------- dist VAR Word ' distance measurement counter VAR Byte ' Loop counter char VAR Byte ' Character sent to LCD value VAR Byte ' Increment Decr. value dir VAR Nib ' Direction menu VAR Nib ' Current menu buttons VAR Nib btnA VAR buttons.BIT0 ' left-most button btnB VAR buttons.BIT1 btnC VAR buttons.BIT2 btnD VAR buttons.BIT3 ' right-most '-----[ Horizontal Leg Constants ]---------------------------------------- ' Adjustable leg centers ' Right Side - Increase value to move leg forward Center1 CON 900 'Front Center2 CON 700 'Back 'Left Side Center3 CON 600 'Front Center4 CON 800 'Back '-----[ Stride Calculations ]--------------------------------------------- '///////////////////////////////////////////////////////////////////////// ' The stride value determines the maximum value to move a horizontal ' servo from center. So a stride value of 200 means move 200 units ' plus servo center and 200 units minus servo center or 200 + 200 ' units. ' 5.5556 units = 1 degree ' a Stride of 200 = 72 degrees or ' (200*2)/5.556 = 72 '///////////////////////////////////////////////////////////////////////// Stride CON 200 Leg1Center CON Center1 Leg1Forward CON Center1+Stride ' Stride + Leg1 Center Leg1Back CON Center1-Stride Leg2Center CON Center2 Leg2Forward CON Center2+Stride Leg2Back CON Center2-Stride Leg3Center CON Center3 Leg3Forward CON Center3-Stride Leg3Back CON Center3+Stride Leg4Center CON Center4 Leg4Forward CON Center4-Stride Leg4Back CON Center4+Stride LiftRamp CON $1 ' Vertical servo ramp '----- [Adjustable vertical servo positions] -------------------------------- RaiseRight CON 550 ' Raised and lowered LowerRight CON 1200 ' vertical servo values RaiseLeft CON 950 LowerLeft CON 300 '---[S3 constants]-------------------------------------------------------- S3Y CON 8 S3X CON 9 S3Ramp CON $7 LookLeft90 CON 400 LookRight90 CON 1100 LookLeft45 CON 600 LookRight45 CON 900 TooClose CON 10 Far CON 50 NumOfSteps CON 2 '----- [Direction Constants] --------------------------------------------- Ahead CON 0 ForwardRight CON 1 RightSpin CON 2 BackRight CON 3 Backward CON 4 BackLeft CON 5 LeftSpin CON 6 ForwardLeft CON 7 '---- [ App Constants ]--------------------------------------------------- EOD CON $FF ' End of data block '----- [EEPROM DATA ] ---------------------------------------------------- ' Check out the excel file... ' http://www.crustcrawler.com/downloads/docs/LCDTerminalAppmodCharGen.xls ' to help create custom character graphics like the ones shown below. Smiley DATA $00, $0A, $0A, $00, $11, $0E, $06, $00 ' 0 smiley DownArrow DATA $04, $04, $04, $04, $1F, $0E, $04, $00 ' 1 Down Arrow UpArrow DATA $04, $0E, $1F, $04, $04, $04, $04, $00 ' 2 Up Arrow C_Gear DATA $06, $0F, $09, $18, $18, $09, $0F, $06 ' 3 char1 C Gear Enter DATA $01, $01, $01, $05, $0D, $1F, $0C, $04 ' 4 Enter Arrow EndCG DATA $00 Msg1 DATA "Crust ",0 Msg2 DATA " ",3,"rawler",0 Msg3 DATA "PING))) ",0 Msg4 DATA "RC ",0 Direction DATA "Dir: ",0 Speed DATA "Spd: ",0 Limit DATA "Lim: ",0 Distance DATA "Dist:",0 GUI DATA "m ", 2, " ",1," ", 4, 0 '_________________________________________________________________________ ' 'Right 'Left Forward DATA $01,Word RaiseRight, $07,Word RaiseLeft, $00,Word Leg1Forward, $06,Word Leg4Forward, 'Reset $02,Word Leg2Back, $04,Word Leg3Back, 'Thrust $01,Word LowerRight, $07,Word LowerLeft, $03,Word RaiseRight, $05,Word RaiseLeft, $00,Word Leg1Back, $06,Word Leg4Back, 'Thrust $02,Word Leg2Forward, $04,Word Leg3Forward, 'Reset $03,Word LowerRight, $05,Word LowerLeft, EOD ' end of Forward Back DATA $01,Word RaiseRight, $07,Word RaiseLeft, $00,Word Leg1Back, $06,Word Leg4Back, ' $02,Word Leg2Forward, $04,Word Leg3Forward, ' $01,Word LowerRight, $07,Word LowerLeft, $03,Word RaiseRight, $05,Word RaiseLeft, $00,Word Leg1Forward, $06,Word Leg4Forward, ' $02,Word Leg2Back, $04,Word Leg3Back, ' $03,Word LowerRight, $05,Word LowerLeft, EOD ' end of Back ' Left Turn EEPROM values LSpin DATA $01,Word RaiseRight, $07,Word RaiseLeft, $00,Word Leg1Forward, $06,Word Leg4Back, ' $02,Word Leg2Back, $04,Word Leg3Forward, ' $01,Word LowerRight, $07,Word LowerLeft, $03,Word RaiseRight, $05,Word RaiseLeft, $00,Word Leg1Back, $06,Word Leg4Forward, ' $02,Word Leg2Forward, $04,Word Leg3Back, ' $03,Word LowerRight, $05,Word LowerLeft, EOD ' end of LSpin ' Right turn EEPROM Values RSpin DATA $01,Word RaiseRight, $07,Word RaiseLeft, $00,Word Leg1Back, $06,Word Leg4Forward, ' $02,Word Leg2Forward, $04,Word Leg3Back, ' $01,Word LowerRight, $07,Word LowerLeft, $03,Word RaiseRight, $05,Word RaiseLeft, $00,Word Leg1Forward, $06,Word Leg4Back, ' $02,Word Leg2Back, $04,Word Leg3Forward, ' $03,Word LowerRight, $05,Word LowerLeft, EOD ' end of RSpin ' Raise Center Lower Neutral DATA $01,Word RaiseRight, $00,Word Center1, $01,Word LowerRight DATA $03,Word RaiseRight, $02,Word Center2, $03,Word LowerRight DATA $05,Word RaiseLeft, $04,Word Center3, $05,Word LowerLeft DATA $07,Word RaiseLeft, $06,Word Center4, $07,Word LowerLeft, EOD ' end of adjust legs '_________________________________________________________________________ ' 0 = normal mode ' 1 = debug mode #DEFINE debugMode = 0 Initialize: GOSUB Initialize_LCD ' Initialize LCD PAUSE 500 ' Wait 1/2 sec limiter = 0 ' Initialize limiter to 0 ramp = 0 ' Base ramp value dir = Ahead ' direction = forward vel = 3 ' Set vel to 3 ptrEEPROM = Neutral ' Center and lower all legs menu = 0 ' Show limiter menu GOTO Main ' Center legs ' Center legs '///////////////////////////////////////////////////////////////////////// 'Clear Screen ' Write UI ' Loop until button D is pressed ' Increment/Decrement value ' Convert value to ASCII by adding 48 ' 'Parameters () 'Return () '///////////////////////////////////////////////////////////////////////// Menus: char = LcdCls ' Clear command GOSUB LCD_Command ' Write clear screen command GOSUB Write_GUI ' Write Graphic Interface Get_Menu: char = LcdHome ' Cursor to home position GOSUB LCD_Command IF menu = 0 THEN GOTO Speed_Menu IF menu = 2 THEN GOTO Limiter_Menu Direction_Menu: ptrEEPROM = Direction ' Point to Direction string GOSUB LCD_Put_String ' Write String PAUSE 100 ' Wait value = dir ' Input param direction GOTO Incr_Decr ' Skip Speed_Menu: ptrEEPROM = Speed ' Point to Speed string GOSUB LCD_Put_String ' Write String PAUSE 100 ' Wait value = vel ' Input param ramp GOTO Incr_Decr ' Skip Limiter_Menu: ptrEEPROM = Limit ' Point to Speed string GOSUB LCD_Put_String ' Write String PAUSE 100 ' Wait value = Limiter ' Input param ramp Incr_Decr: DO WHILE btnD = 0 ' Do while D not pressed GOSUB LCD_Get_Buttons ' Check button pressed IF btnB THEN ' B pressed? SELECT menu CASE 0 value = (value + 1) // 16 CASE 1 value = (value + 1) // 8 CASE 2 value = (value + 1) // 256 ENDSELECT ENDIF IF btnC THEN ' C Pressed SELECT menu CASE 0 value = (value + 15) // 16 CASE 1 value = (value + 7) // 8 CASE 2 value = (value + 255) // 256 ENDSELECT ENDIF IF btnA = 1 THEN menu = (menu + 1) // 3 GOTO Get_Menu ENDIF GOSUB Set_Value ' Assign ramp or direction GOSUB Write_Num PAUSE 75 ' Write number to LCD LOOP GOSUB Write_Ping_Screen '________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Set delay ' Delay provides time for the servos to reach a position and is based ' on ramp (vel). ' This is an adjustable value. ' ' Parameters (vel) ' Return (delay) '///////////////////////////////////////////////////////////////////////// SetDelay: IF vel < 9 THEN delay = 30 ELSE delay = 10 ENDIF '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Set direction gait properties ' Set ptrEEPROM to EEPROM block ' Set left and right ramp values ' ' Parameters (dir) ' Return () '///////////////////////////////////////////////////////////////////////// Set_Direction: SELECT dir CASE Ahead ptrEEPROM = Forward GOSUB Equal CASE ForwardRight ptrEEPROM = Forward GOSUB SlowRight CASE RightSpin ptrEEPROM = RSpin GOSUB Equal CASE BackRight ptrEEPROM = Back GOSUB SlowRight CASE Backward ptrEEPROM = Back GOSUB Equal CASE BackLeft ptrEEPROM = Back GOSUB SlowLeft CASE LeftSpin ptrEEPROM = LSpin GOSUB Equal CASE ForwardLeft ptrEEPROM = Forward GOSUB SlowLeft ENDSELECT '_________________________________________________________________________ '#IF debugMode #THEN 'GOSUB Trace 'PAUSE 2000 '#ENDIF '///////////////////////////////////////////////////////////////////////// ' Main walking engine ' ' Parameters () ' Return () '///////////////////////////////////////////////////////////////////////// Main: 'Read 3 bytes from EEPROM READ ptrEEPROM, ServoAddr, servoPosition.LOWBYTE, servoPosition.HIGHBYTE DO WHILE servoAddr <> $FF 'Vertical servo are odd numbers IF (servoAddr // 2) = 1 THEN ramp = LiftRamp ELSE 'Set right side ramp (servo speed) IF (servoAddr = $00) OR (servoAddr = $02) THEN ramp = rightRamp ENDIF 'Set left side ramp IF(servoAddr = $04) OR (servoAddr = $06) THEN ramp = leftRamp ENDIF 'Limit horizontal swing if limiter variable has a ' value greater than zero IF (limiter > 0) THEN GOSUB Limit_Stride ENDIF ENDIF GOSUB Write_PSC 'Increment pointer and get the next 3 EEPROM values ptrEEPROM = ptrEEPROM + 3 READ ptrEEPROM, ServoAddr, servoPosition.LOWBYTE, servoPosition.HIGHBYTE #IF debugMode #THEN GOSUB Trace #ENDIF LOOP GOSUB LCD_Get_Buttons ' Check for button press IF btnA THEN ' Button A pressed? GOTO Menus ' Display menus ENDIF IF ptrEEPROM = Neutral + 36 THEN ' First run limiter = 75 ' Set limiter GOTO Menus ' first load ENDIF Get_Ping_Reading: GOSUB Get_Sonar ' Get raw PING reading GOSUB C_Centimeter ' Convert to centimeter value = dist GOSUB Write_Num GOSUB Determine_Direction GOTO Main 'Loop forever '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Walk backward if an object is within 10cm ' Spin left if an object is withing 10-15cm ' Make a gradual left turn if an object is detected between 15 and 30cm ' Walk forward if no object is detected within 30cm ' 'Parameters (distance reading) 'Return (dir) '///////////////////////////////////////////////////////////////////////// '///////////////////////////////////////////////////////////////////////// ' Determine which direction is most clear. ' ' Distance Action '---------- -------- ' < 15 cm Backup 3 steps ' 16 to 29 Look far left/Ping look far right/Ping ' 30 to 59 Look left/Ping look right/Ping ' ' When looking left and right, the PING is triggered and the distances ' are compared. The robot will turn in the direction of the largest ' distance reading. ' ' Parameters (dist) ' Return (dist) '///////////////////////////////////////////////////////////////////////// Determine_Direction: SELECT dist CASE < 15 ptrEEPROM = Back steps = NumOfSteps CASE < 30 servoPosition = LookLeft90 GOSUB Look temp = dist servoPosition = lookRight90 GOSUB Look IF temp > dist THEN ptrEEPROM = LSpin steps = NumOfSteps ELSE ptrEEPROM = RSpin steps = NumOfSteps ENDIF CASE < 60 servoPosition = LookLeft45 GOSUB Look temp = dist servoPosition = lookRight45 GOSUB Look IF temp > dist THEN ptrEEPROM = Forward steps = NumOfSteps GOSUB SlowLeft ELSE ptrEEPROM = Forward steps = NumOfSteps GOSUB SlowRight ENDIF CASE ELSE ptrEEPROM = Forward GOSUB Equal ENDSELECT GOSUB Center_S3 RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Turn the S3 left or right ' ' Parameters (servoPosition) ' Return () '///////////////////////////////////////////////////////////////////////// Look: SEROUT PSC,Baud,["!SC", S3X, S3Ramp, servoPosition.LOWBYTE, servoPosition.HIGHBYTE, CR] PAUSE 1000 GOSUB Get_Sonar RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Center the S3 but look slightly downward ' ' Parameters () ' Return () '///////////////////////////////////////////////////////////////////////// Center_S3: servoPosition = 650 SEROUT PSC,Baud,["!SC",S3Y, S3Ramp,servoPosition.LOWBYTE, servoPosition.HIGHBYTE, CR] servoPosition = 750 SEROUT PSC,Baud,["!SC",S3X, S3Ramp,servoPosition.LOWBYTE, servoPosition.HIGHBYTE, CR] RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Write position commands to the PSC ' ' Parameters (ServoAddr, servoPosition, delay) ' Return Nothing '///////////////////////////////////////////////////////////////////////// Write_PSC: SEROUT PSC,Baud,["!SC",ServoAddr, Ramp,servoPosition.LOWBYTE, servoPosition.HIGHBYTE, CR] IF rowCounter = 1 THEN PAUSE delay ENDIF RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' This subroutine triggers the Ping sonar sensor and measures ' the echo pulse. The raw value from the sensor is converted to ' microseconds based on the Stamp module in use. This value is ' divided by two to remove the return trip -- the result value is ' the distance from the sensor to the target in microseconds. ' --John Williams "Servo October 2005" '///////////////////////////////////////////////////////////////////////// Get_Sonar: Ping = IsLow ' make trigger 0-1-0 PULSOUT Ping, Trigger ' activate sensor PULSIN Ping, IsHigh, dist ' measure echo pulse dist = dist */ Scale ' convert to uS dist = dist / 2 ' remove return trip RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Convert distance reading to centimeter ' ' Parameters (dist) ' Return (dist) '///////////////////////////////////////////////////////////////////////// C_Centimeter: dist = dist ** RawToCm ' convert to centimeters RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Convert distance reading to inches ' 'Parameters (dist) 'Return (dist) '///////////////////////////////////////////////////////////////////////// 'C_Inches: 'dist = dist ** RawToIn ' convert to inches 'RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Position LCD cursor ' Conver the number in value to ASCII and write to the LCD AppMod ' ' Parameters () ' Return () '///////////////////////////////////////////////////////////////////////// Write_Num: char = LcdLine1 + 5 ' Goto line 1 position 4 GOSUB LCD_Command C_ASCII: ' convert to ASCII value char = (value / 100) ' Get 100s position value = (value //100) ' Get Mod char = char + 48 ' Convert to ASCII GOSUB Write_LCD_Char ' Write value char = (value / 10) ' Get 10s position value = (value // 10) ' Get Mod char = char + 48 ' Convert to ASCII GOSUB Write_LCD_Char ' Write value char = value + 48 ' Convert to ASCII GOSUB Write_LCD_Char ' Write value GOSUB Get_Value RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Write interface screen to LCD AppMod ' ' Parameters () ' Return () '///////////////////////////////////////////////////////////////////////// Write_GUI: ' Write GUI items on line 2 char = LcdLine2 ' Goto Line 2 GOSUB LCD_Command ' LCD Command ptrEEPROM = GUI ' Write CG chars (menu items) GOSUB LCD_Put_String ' Write characters RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Write PING))) screen to LCD AppMod ' ' Parameters () ' Return () '///////////////////////////////////////////////////////////////////////// Write_Ping_Screen: char = LcdCls ' Clear command GOSUB LCD_Command ' Write clear screen command ptrEEPROM = Distance ' Point to Direction string GOSUB LCD_Put_String ' Write String char = LcdLine2 ' Line 2 command GOSUB LCD_Command ' Write command ptrEEPROM = Msg3 ' Point to PING))) GOSUB LCD_Put_String ' Write PING))) RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Sets velocity, direction, and liniter values ' ' Parameters (ramp) ' Return (rightRamp, leftRamp) '///////////////////////////////////////////////////////////////////////// Set_Value: SELECT menu CASE 0 vel = value ' Assign ramp CASE 1 dir = value ' Assign direction CASE 2 limiter = value ' Assign limiter ENDSELECT RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Gets velocity, direction, and liniter values ' 'Parameters (menu) 'Return (vel, dir, limiter) '///////////////////////////////////////////////////////////////////////// Get_Value: SELECT menu CASE 0 value = vel ' Assign ramp CASE 1 value = dir ' Assign direction CASE 2 value = limiter ' Assign limiter ENDSELECT RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Equal ' ' Parameters (vel) ' Return (rightRamp, leftRamp) '///////////////////////////////////////////////////////////////////////// Equal: rightRamp = vel leftRamp = vel RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Slow right side ' ' Parameters (vel) ' Return (rightRamp, leftRamp) '///////////////////////////////////////////////////////////////////////// SlowLeft: rightRamp = vel leftRamp = vel + $5 RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Slow left side ' ' Parameters (vel) ' Return (rightRamp, leftRamp) '///////////////////////////////////////////////////////////////////////// SlowRight: rightRamp = vel + $5 leftRamp = vel RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Reduce leg travel by the value in limiter. This allows for run-time ' horizontal leg control. ' ' Parameters (ServoAddr, servoPosition) ' Return (servoPosition) '///////////////////////////////////////////////////////////////////////// Limit_Stride: 'Get joint center value and put it in temp SELECT ServoAddr CASE $00 temp = Center1 CASE $02 temp = Center2 CASE $04 temp = Center3 CASE $06 temp = Center4 CASE ELSE 'Do Noting ENDSELECT 'Reduce swing from center by the value in limiter IF servoPosition > temp THEN servoPosition = servoPosition - limiter ELSE servoPosition = servoPosition + limiter ENDIF RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Scan buttons ' ' Parameters () ' Return (buttons) '///////////////////////////////////////////////////////////////////////// LCD_Get_Buttons: LcdDirs = %0000 ' make LCD bus inputs buttons = %1111 ' assume all pressed FOR counter = 1 TO 10 buttons = buttons & LcdBusIn ' make sure button held PAUSE 5 ' debounce 10 x 5 ms NEXT LcdDirs = %1111 ' return bus to outputs RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Read EEPROM data and write it to the LCD ' ' Parameters (ptrEEPROM) ' Return () '///////////////////////////////////////////////////////////////////////// LCD_Put_String: DO READ ptrEEPROM, char ' Read data at EEPROM address IF (char = 0) THEN EXIT ' 0 = End of EEPROM String GOSUB Write_LCD_Char ' Write character to LCD ptrEEPROM = ptrEEPROM + 1 ' Increment EEPROM pointer LOOP RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Write LCD command/Write Character ' ' Parameters (char) ' Return () '///////////////////////////////////////////////////////////////////////// LCD_Command: ' write command to LCD #IF _LcdReady #THEN LCDCMD E, char RETURN #ELSE LOW RS GOTO Write_LCD_Char #ENDIF Write_LCD_Char: ' write character to LCD #IF _LcdReady #THEN LCDOUT E, 0, [char] #ELSE LcdBusOut = char.HIGHNIB ' output high nibble PULSOUT E, 3 ' strobe the Enable line LcdBusOut = char.LOWNIB ' output low nibble PULSOUT E, 3 HIGH RS ' return to character mode #ENDIF RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Initialize LCD ' Write custom cahracters to the LCD ' Write CrustCrawler Banner ' ' Parameters () ' Return () '///////////////////////////////////////////////////////////////////////// Initialize_LCD: #IF _LcdReady #THEN LCDCMD E, %00110000 : PAUSE 5 ' 8-bit mode LCDCMD E, %00110000 : PAUSE 0 LCDCMD E, %00110000 : PAUSE 0 LCDCMD E, %00100000 : PAUSE 0 ' 4-bit mode LCDCMD E, %00101000 : PAUSE 0 ' 2-line mode LCDCMD E, %00001100 : PAUSE 0 ' no crsr, no blink LCDCMD E, %00000110 ' inc crsr, no disp shift #ELSE NAP 5 ' let LCD self-initialize DIRL = %11111110 ' setup pins for LCD LcdBusOut = %0011 ' 8-bit mode PULSOUT E, 3 : PAUSE 5 PULSOUT E, 3 : PAUSE 0 PULSOUT E, 3 : PAUSE 0 LcdBusOut = %0010 ' 4-bit mode PULSOUT E, 3 char = %00101000 ' 2-line mode GOSUB LCD_Command char = %00001100 ' on, no crsr, no blink GOSUB LCD_Command char = %00000110 ' inc crsr, no disp shift #ENDIF ClearScreen: char = LcdCls ' Clear screen GOSUB LCD_Command Download_Chars: ' download custom chars char = LcdCGRam ' point to CG RAM GOSUB LCD_Command ' prepare to write CG data FOR counter = Smiley TO EndCG-1 ' build custom chars READ counter, char ' get byte from EEPROM GOSUB Write_LCD_Char ' put into LCD CG RAM NEXT CrustCrawler_Logo: ' Dispaly CC logo char = LcdLine1 ' Line 1 GOSUB LCD_Command ptrEEPROM = Msg1 ' Message 1 pointer GOSUB LCD_Put_String ' Write string char = LcdLine2 ' Go to Line 2 GOSUB LCD_Command ' Write command ptrEEPROM = Msg2 ' Point to message 2 GOSUB LCD_Put_String ' Write string RETURN '_________________________________________________________________________ '///////////////////////////////////////////////////////////////////////// ' Writes variables to the debug terminal when DebugMode = 1 ' ' Copy and paste the Debug tool to strategic location in the code. This ' allow you to see what is in each variable in the Trace sub. '///////////////////////////////////////////////////////////////////////// 'DEBUG Tool #IF debugMode #THEN GOSUB Trace #ENDIF ' Write trace information ' to debug terminal #IF debugMode #THEN Trace: DEBUG CLS, "Buttons: ", BIN buttons, CR, ?ramp, ?leftramp, ?rightramp, ?dir, ?vel, ?menu, ?limiter, ?ptrEEPROM, ?dist RETURN #ENDIF