I did a couple of quick changes to make it compile. First I got rid of the Basic stamp section of constants. I Defined Baud as N19200. There also is an incompatibility of if statements. So I broke the one line version into the proper syntax. Finally they had DO… LOOP which the atom does not have, so converted to: do … while 1 which should work. I did get it to compile, but I did not download it or verify it would work… Good Luck
Kurt
[code] ’ The main loop uses the I2C out command to start the PING on the SFR08,
’ waits 70mS and then reads back from the HexEngine I2C port to gather the
’ SFR08 echo. once it has the data, the light level is used to control the
’ height of the ehxapod and the distance from the ranger is used to contol
’ the y translate of the hexapod, if the SFR08 module is mounted on the
’ front of the hexapdo this gives the effect of the hexapod moving away from
’ an object in front of it, and cowering if a hand passes of the head.
’
’ ----- Revision History ]------------------------------------------------
’
’ ----- Compilation Switches ]--------------------------------------------
'#DEFINE FULL_DEBUG ’ COMPILE WITH PS2 DEBUG INFORMATION
'#DEFINE PIP_MODE_1 ’ PIP MODE 1 FOR MORE ROBUST COMMS, 0 FOR SIMPLER COMMS
’
’
’ ----- I/O Definitions ]-------------------------------------------------
LED con p0 ’ CHANGE TO SUIT YOUR CONFIGURATION
SER_OUT con p5 ’ CHANGE TO SUIT YOUR CONFIGURATION
SER_IN con p6 ’ CHANGE TO SUIT YOUR CONFIGURATION
’ ----- Constants ]-------------------------------------------------------
CMD_PIP_ESCAPE CON $7d
CMD_PIP_HEADER CON $7e
CMD_PIP_XOR CON $20
Baud CON N19200 ’ match DEBUG
’ ----- Variables ]-------------------------------------------------------
PIP_Byte VAR Byte
PIP_Len VAR Byte
PIP_Temp VAR Byte
PIP_Buff VAR Byte(17)
PIP_Cs VAR Byte
Range VAR Byte
Light VAR Byte
W_Temp VAR Word
Temp VAR Byte
’ ----- Initialization ]--------------------------------------------------
Setup:
HIGH SER_OUT
’ ----- Program Code ]----------------------------------------------------
Main:
’ ALLOW THE HEXENGINE TO POWER UP
PAUSE( 1500 )
’ RESET LEGS IF ALREADY POWERD UP
PIP_Buff(0) = “r”
PIP_len = 1
GOSUB Send_PIP_Packet
DEBUG CLS
DO
DEBUG HOME
’ WAKE HEXAPOD
PIP_Buff(0) = “+”
PIP_len = 1
GOSUB Send_PIP_Packet
' ----- I2C TEST Code ]----------------------------------------------------
' PINGS SRF08 MODULE CONNECTED TO I2C PORT, AND RETREIVES ECHO DATA.
' THIS ASSUMES THERE IS AN SRF08 MODULE CONNECTED, AND THAT IT HAS
' THE DEFAULT ADDRESS OF E0h
START_SFR08_PING:
HIGH LED
' SEND I2C DATA OUT OF I2C PORT
PIP_Buff(0) = "I"
PIP_Buff(1) = $e0 ' I2C ADDRESS
PIP_Buff(2) = 1 ' I2C SEND DATA COUNT
PIP_Buff(3) = 0 ' I2C REGISTER ADDRESS
PIP_Buff(4) = 82 ' I2C DATA (PING.. RETURN DATA IN uSECONDS)
PIP_len = 5
GOSUB Send_PIP_Packet
LOW LED
' WAIT FOR SFR08 ECHO MINIUMUM 65mS
PAUSE(70)
GET_SRF08_ECHO:
PIP_Buff(0) = "i"
PIP_Buff(1) = $e0 ' I2C ADDRESS
PIP_Buff(2) = 3 ' I2C DATA READ COUNT
PIP_Buff(3) = 1 ' I2C REGISTER START ADDRESS
PIP_len = 4
GOSUB Send_PIP_Packet
' GRAB RETURN PACKET
PIP_len = 4
' WAIT FOR HEADER, IGNORE PACKET LENGTH & CHECK SUM
SERIN SER_IN, Baud , 100, NO_I2C_DATA, [WAIT($7E), PIP_Len, STR PIP_Buff\PIP_Len]
' OUTPUT DATA TO DEBUG
#IF FULL_DEBUG #THEN
DEBUG "LEN: ", DEC2 PIP_Len, " TYPE: '" , PIP_Buff(0), "' "
#ENDIF
' STORE RANGE RESULT IN WORD
W_Temp = Pip_Buff(2) << 8
W_Temp = W_Temp | PIP_Buff(3)
Temp = PIP_Buff(1)
#IF FULL_DEBUG #THEN
DEBUG "LIGHT: ", DEC3 Temp, " RANGE: ", DEC4 W_Temp, " uS"
#ENDIF
' REDUCE AND CLAMP RANGE RESULT
W_Temp = W_Temp / 10
IF W_Temp < 20 THEN
W_Temp = 20
endif
IF W_Temp > 150 THEN
W_Temp = 150
endif
' INTERPOLATE RANGE RESULT
Range = ( ( W_Temp - 20 ) * ( 255 ) ) / ( 150 - 20 )
DEBUG CR, "RANGE: ", DEC3 Range
' CLAMP LIGHT RESULT
IF Temp > 150 THEN
Temp = 150
endif
' INTERPOLATE RANGE RESULT
Light = ( ( Temp ) * ( 255 ) ) / ( 150 )
DEBUG CR, "LIGHT: ", DEC3 Light
SEND_BODY_CMD:
PIP_Buff(0) = "B"
PIP_Buff(1) = 0 '
PIP_Buff(2) = 0 '
PIP_Buff(3) = 0 '
PIP_Buff(4) = 0 '
PIP_Buff(5) = (255-Range) -128 '
PIP_Buff(6) = Light -128 '
PIP_len = 7
GOSUB Send_PIP_Packet
GOTO CONTINUE
NO_I2C_DATA:
DEBUG CLREOL, "NO I2C DATA"
CONTINUE:
while 1
END
’ ----- PIP Packet ]----------------------------------------------------
’ SENDS PIP PACKET STORED IN PIP_BUFF OF PIP_LEN LENGTH
’ MODE 1 or MODE 0, DEPENDS ON COMPILATION SWITCH “PIP_MODE_1”
’ SENDS PIP PACKET STORED IN PIP_BUFF OF PIP_LEN LENGTH
’
Send_PIP_Packet:
’ SEND HEADER
SEROUT SER_OUT, Baud, [CMD_PIP_HEADER]
’ SEND PIP LENGHT
PIP_Byte = PIP_Len
GOSUB Send_Byte_Check_Codes
’ SETUP CHECK SUM
PIP_Cs = 0
’ SEND PACKET
FOR PIP_Temp = 0 TO PIP_Len-1
PIP_Byte = PIP_Buff( PIP_Temp )
PIP_Cs = PIP_Cs + PIP_Byte
GOSUB Send_Byte_Check_Codes
NEXT
’ SEND CHECK SUM
PIP_Byte = $ff - PIP_Cs
GOSUB Send_Byte_Check_Codes
RETURN
’ SENDS PIP BYTE TO SERIAL PORT AND CHECKS PIP CODES
’
Send_Byte_Check_Codes:
#IF PIP_MODE_1 #THEN
’ CHECK CODE AGAINST ILLEGAL CODES
IF( PIP_Byte = CMD_PIP_HEADER | PIP_Byte = CMD_PIP_ESCAPE ) THEN
’ SEND ESCAPED CODE
SEROUT SER_OUT, Baud, [CMD_PIP_ESCAPE, PIP_Byte ^ CMD_PIP_XOR]
ELSE
#ENDIF
’ SEND NORMAL CODE
SEROUT SER_OUT, Baud, [PIP_Byte]
#IF PIP_MODE_1 #THEN
ENDIF
#ENDIF
RETURN
[/code]