📄 quad_lcd_appmod.bs2
字号:
'----[Quad_LCD_Appmod.bs2]------------------------------------------------
'{$STAMP BS2}
'{$PBASIC 2.5}
'
' File....... Quad_LCD_Appmod.bs2
' Purpose.... Control the QuadCrawler using the Parallax LCD AppMod.
' Select gaits using the LCD AppMod's push buttons.
' Receive feedback through the LCD display
' Author..... CrustCrawler Inc. (Mike Gebhard)
' E-mail..... support@crustcrawler.com
' Started.... 19 November 2004
' Updated.... 05 December 2004
'
' Hardware
' (1) QuadCrawler Robotic Kit
' (1) Parallax BOE
' (1) Parallax Basic Stamp II
' (1) Parallax PSC
' (1) Parallax LCD AppMod
'
' This program is a combibation of QuadWalker_Engine_Select_Gait.bs2
' and several modified routines from Parallax's LCD Terminal AppMod
' documentation. Please refer to these programs for specific program
' operation.
'
'=========================================================================
' To use this program
' 1. Use leg centers found in HomeQuad.bs2
'=========================================================================
' Find the section of code below
'-----[ Horizontal Leg Constants ]----------------------------------------
' Center1 CON 750 ' Leg1 horizontal servo
' Center2 CON 750 ' Leg2 horizontal servo
' Center3 CON 750 ' Leg3 horizontal servo
' Center4 CON 750 ' Leg4 horizontal servo
'
' Replace these constants with the constants
' you found using the HomeQuad.bs2 program.
'
' Example Quad center constants yours will vary
'-----[ Horizontal Leg Constants ]----------------------------------------
'Center1 CON 725
'Center2 CON 800
'Center3 CON 785
'Center4 CON 750
'
'=========================================================================
' LCD Appmod Push Buttons
'=========================================================================
' Button A
' Hold down button A to enter selection mode. The robot will stop moving.
' The LCD will display the current gait on line 1 and a simple
' navigation element on line 2.
'
' |--------------|
' | Currunt Gait |
' | <B C> |
' |--------------|
' A B C D
'
' Button B and C
' Press buttons B and C to navigate through 15 gaits.
'
' Button D
' Press button D accept gait selection.
'=========================================================================
' gaitCode and gait text
'=========================================================================
' gaitCode
' $00 - Home
' $01 - Spin Left
' $02 - Spin Right
'
' gaitCode gaitCode
' $10 - Forward Fast $20 - Forward
' $11 - Fast Forward Left $21 - Forward Left
' $12 - Fast Forward Right $22 - Forward Right
'
' LED gaitCode gaitCode
' $30 - Backward $40 - Fast Backward
' $31 - Backward Left $41 - Fast Backward Left
' $32 - Backward Right $42 - Fast Backward Right
'
'-------------------------------------------------------------------------
' -----[ 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
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)
' -----[ PSC I/O Definitions ]-------------------------------------------------
PSC PIN 15 ' PSC module
Baud CON 33164 ' 2400 baud
'----- [Adjustable Ramp Values] -----------------------------------------------
'Off fast >>>>> slow
' 0 $1 >>>>> $3F(63)
LiftRamp CON $1 ' Vertical servo ramp
VeryFast CON $8 ' Walk very fast
Fast CON $A ' Walk fast
'-----[ Horizontal Leg Constants ]----------------------------------------
'Servo center
Center1 CON 750 ' Leg1 horizontal servo
Center2 CON 750 ' Leg2 horizontal servo
Center3 CON 750 ' Leg3 horizontal servo
Center4 CON 750 ' Leg4 horizontal servo
'-----[ Stride Calculations ]---------------------------------------------
Stride CON 150 ' Stride units
delay CON Stride/5 ' Allow leg servos time to
' complete movement
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
'----- [Adjustable vertical servo positions] --------------------------------
RaiseRight CON 300 ' Raised and lowered
LowerRight CON 1200 ' vertical servo values
RaiseLeft CON 1200
LowerLeft CON 300
' -----[ Variables ]-------------------------------------------------------
idx VAR Nib ' loop counter
char VAR Byte ' character sent to LCD
scan VAR Byte ' loop counter
gaitCode VAR Byte ' Walking mode
temp VAR Byte ' Temp pointer
ptrEEPROM VAR Word ' EEPROM Pointer
buttons VAR Nib
btnA VAR buttons.BIT0 ' left-most button
btnB VAR buttons.BIT1
btnC VAR buttons.BIT2
btnD VAR buttons.BIT3 ' right-most
'---- [Walking Variables] ------------------------------------------------
servoAddr VAR Byte ' Servo addresses
Index VAR Word ' Gait select
servoPosition VAR Word ' Servo Position
Ramp VAR Byte ' Ramp used in SEROUT
RightRamp VAR Byte ' Right side ramp values
LeftRamp VAR Byte ' Left side ramp values
'---- [EEPROM data] ------------------------------------------------------
Msg1 DATA "Crust",0
Msg2 DATA " Crawler",0
Msg3 DATA "Press ",0
Msg4 DATA " Reset ",0
Nav DATA "<B C>",0
Ir DATA " GO! ",0
GaitTable DATA $00,"Home ",0, $01,"L Spin ",0, $02,"R Spin ",0,
$10,"FForward",0, $11,"FF Left ",0, $12,"FF Right",0,
$20,"Forward ",0, $21,"F Left ",0, $22,"F Right ",0,
$30,"Backup ",0, $31,"B Left ",0, $32,"B Right ",0,
$40,"F Backup",0, $41,"FB Left ",0, $42,"FB Right",0
' Walk Forward
Forward DATA $01,Word RaiseRight, $07,Word RaiseLeft,
$00,Word Leg1Forward, $02,Word Leg2Back,
$04,Word Leg3Center, $06,Word Leg4Center,
$01,Word LowerRight, $07,Word LowerLeft,
$03,Word RaiseRight, $05,Word RaiseLeft,
$00,Word Leg1Center, $02,Word Leg2Center,
$04,Word Leg3Forward, $06,Word Leg4Back,
$03,Word LowerRight, $05,Word LowerLeft,
$FF ' end of forward
' Walk Backward
Back DATA $01,Word RaiseRight, $07,Word RaiseLeft,
$00,Word Leg1Center, $02,Word Leg2Center,
$04,Word Leg3Forward, $06,Word Leg4Back,
$01,Word LowerRight, $07,Word LowerLeft,
$03,Word RaiseRight, $05,Word RaiseLeft,
$00,Word Leg1Forward, $02,Word Leg2Back,
$04,Word Leg3Center, $06,Word Leg4Center,
$03,Word LowerRight, $05,Word LowerLeft,
$FF 'end of back
' Left Turn EEPROM values
LTurn DATA $01,Word RaiseRight, $07,Word RaiseLeft,
$00,Word Leg1Forward+Stride, $06,Word Leg4Back+Stride,
$04,Word Leg3Forward, $02,Word Leg2Back,
$01,Word LowerRight, $07,Word LowerLeft,
$03,Word RaiseRight, $05,Word RaiseLeft,
$00,Word Leg1Center+Stride, $06,Word Leg4Center+Stride,
$04,Word Leg3Forward, $02,Word Leg2Back,
$03,Word LowerRight, $05,Word LowerLeft,
$FF ' end of left turn
' Right turn EEPROM Values
RTurn DATA $01,Word RaiseRight, $07,Word RaiseLeft,
$00,Word Leg1Forward, $02,Word Leg2Center-Stride,
$04,Word Leg3Center-Stride, $06,Word Leg4Back,
$01,Word LowerRight, $07,Word LowerLeft,
$03,Word RaiseRight, $05,Word RaiseLeft,
$00,Word Leg1Forward, $02,Word Leg2Back-Stride,
$04,Word Leg3Forward-Stride, $06,Word Leg4Back,
$03,Word LowerRight, $05,Word LowerLeft,
$FF ' end of right turn
' Raise Center Lower
Adjust 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,
$FF ' end of adjust legs
'---- [End EEPROM Data] -----------------
'Set default mode to fast forward
gaitCode = $10
'Initialize LCD
GOSUB Initialize_LCD ' Initialize LCD
GOSUB CrustCrawler_Logo ' Display CrustCrawler
GOTO Initialize_Mode ' Wait for button press
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -