{{ RemoteHex.spin }} ' ============================================================================== ' ' File...... RemoteHex.spin ' Purpose... Remote control application for the Hexcrawler HDATS ' Author.... (C) 2007 Steven R. Norris -- All Rights Reserved ' E-mail.... steve@norrislabs.com ' Started... 02/21/2007 ' Updated... 02/28/2007 ' ' ============================================================================== ' ------------------------------------------------------------------------------ ' Program Description ' ------------------------------------------------------------------------------ {{ This is a simple remote control application for the Hexcrawler HDATS. It uses the GaitHexHDATS object for leg sequencing. It uses a Parallax RF Receiver to receive characters from a remote keyboard. The protocol is simple. The keyboard sends a "!" and then the ASCII character pressed. The RF Receiver connects to the Propeller through a 10K resistor to the pin designated by the constant Pin_LinkRx. This applications uses a total of 4 Cogs. One for this code, one for the GaitHexHDATS, one for the serial comm to the Parallax Servo Controller, and one for the serial comm to the RF Receiver. }} ' ------------------------------------------------------------------------------ ' Revision History ' ------------------------------------------------------------------------------ {{ 0709a - first version }} CON ' ------------------------------------------------------------------------------ ' Constants ' ------------------------------------------------------------------------------ _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 Pin_LinkRx = 0 Pin_LinkTx = 1 ' not used - dummy value Pin_Lcd = 5 Pin_PscTx = 7 ' Gait types Gait_None = 0 Gait_Home = 1 Gait_HomeAB = 2 Gait_Walk = 3 Gait_Spin = 4 Gait_Crab = 5 ' S3 servos S3_Vert = 14 S3_Horz = 15 VAR ' ------------------------------------------------------------------------------ ' Variables ' ------------------------------------------------------------------------------ byte m_Gait byte m_Speed byte m_Direction long m_Turn byte m_HiStep OBJ Gait : "GaitHexHDATS" ' This is the Hexcrawler HDATS Gait object Link : "FullDuplexSerial" ' Serial communications from the RF receiver Lcd : "Debug_Lcd" ' Optional debug display Keybd : "Keyboard" ' Optional PS/2 keyboard PUB Main | char, valid ' ------------------------------------------------------------------------------ ' Main ' ------------------------------------------------------------------------------ ' Initialize the LCD Lcd.start(Pin_Lcd, 19200, 4) ' Start lcd Lcd.cursor(0) ' Cursor off Lcd.cls ' Clear lcd Lcd.backLight(TRUE) ' Backlight on Lcd.clrln(0) Lcd.gotoxy(0, 0) Lcd.str(string("Remote HexDATS")) ' Initialize the keyboard Keybd.start(26, 27) ' Start the Gait object in its own Cog Gait.Start(Pin_PscTx) ' Start the serial communications for the RF receiver Link.Start(Pin_LinkRx, Pin_linkTx, 1, 9600) ' Setup "Busy" LED dira[16]~~ outa[16]~~ ' Wait a bit Pause_ms(1000) ' Home the legs Gait.Home Gait.Wait ' Home the S3 Gait.MoveServo(S3_Vert, 7, 550) Gait.MoveServo(S3_Horz, 7, 730) ' Busy LED off outa[16]~ ' Defaults m_Gait := Gait_None m_Speed := 1 m_Direction := 0 m_Turn := 0 m_HiStep := FALSE repeat valid := FALSE char := Link.rxcheck if char == "!" char := Link.rxtime(10) case char "2": m_Gait := Gait_Walk m_Direction := 0 m_Turn := 0 valid := TRUE "5": m_Gait := Gait_Walk m_Direction := 1 m_Turn := 0 valid := TRUE "1": if m_Gait == Gait_Walk if m_Turn > 0 m_Turn := -1 else m_Turn -= 1 if m_Turn < -3 m_Turn := -3 outa[16]~~ Gait.SetTurn(m_Turn) Pause_ms(100) outa[16]~ "3": m_Gait := Gait_Walk if m_Gait == Gait_Walk if m_Turn < 0 m_Turn := 1 else m_Turn += 1 if m_Turn > 3 m_Turn := 3 outa[16]~~ Gait.SetTurn(m_Turn) Pause_ms(100) outa[16]~ "4": m_Gait := Gait_Crab m_Direction := 1 valid := TRUE "6": m_Gait := Gait_Crab m_Direction := 0 valid := TRUE "7": m_Gait := Gait_Spin m_Direction := 1 valid := TRUE "9": m_Gait := Gait_Spin m_Direction := 0 valid := TRUE "A": m_Speed := 0 m_HiStep := FALSE valid := TRUE "B": m_Speed := 1 m_HiStep := FALSE valid := TRUE "C": m_Speed := 2 m_HiStep := FALSE valid := TRUE "D": m_Speed := 3 m_HiStep := TRUE valid := TRUE "*": outa[16]~~ m_Gait := Gait_None Gait.Halt m_HiStep := FALSE valid := TRUE "#": outa[16]~~ m_Gait := Gait_None Gait.HomeAB Gait.Wait m_HiStep := FALSE valid := TRUE if valid outa[16]~~ case m_Gait Gait_Walk: m_HiStep := FALSE Gait.Walk(m_Direction, m_Speed, m_Turn, -1) Gait_Spin: Gait.Spin(m_Direction, m_HiStep, -1) Gait_Crab: m_HiStep := FALSE Gait.Crab(m_Direction, m_Speed, -1) Pause_ms(100) outa[16]~ PRI Pause_ms(msDelay) waitcnt(cnt + ((clkfreq / 1000) * msDelay))