Hi, all. This is my initial post on this great forum, thanks Lynxmotion!
I’m having a problem with the BasicMicro compiler that I can’t figure out. The scenario is this:
ATOM Pro 28
Bot Board II
Atom-Pro IDE 8.0.1.11
I’m converting code from a BS2p to a BAP28 MCU. I believe I’ve accounted for all the syntactical differences between the two MCUs BASIC languages. However, when I compile the code, the following line:
The variable Hex_Count is defined earlier in the program (Hex_Count VAR Byte). If I comment out the offending line, or just make it a simple assignment (Hex_Count = 1) rather than a binary assignment as intended, the program will successfully compile and run (albeit, with somewhat unintended logic). Below is the offending line in place with some nearby code (I can supply the entire program, if it will help).
I can’t see a problem. What am I missing???
Thanks,
Kevin
IF Hex_Mode = 0 THEN
Hex_Dir = "w"
IF FRange < FRONT_OBSTACLE_DISTANCE THEN
Hex_Mode = 10
Hex_Count = 0
GOSUB Hex_Stop
ELSEIF RRange < RIGHT_OBSTACLE_DISTANCE
Hex_Mode = 20
GOSUB Hex_Stop
ELSEIF LRange < LEFT_OBSTACLE_DISTANCE
Hex_mode = 30
GOSUB Hex_Stop
ENDIF
; BACKWARDS UNTIL DISTANCE > 20 OR COUNT > 3
ELSEIF Hex_Mode = 10
Hex_Count = Hex_Count + 1 ; <-- THIS IS THE LINE
Hex_Dir = "s"
IF FRange > RETREAT_DISTANCE THEN
GOSUB Hex_Stop
IF( RRange < LRange ) THEN
Hex_Dir = "a"
ELSE
Hex_Dir = "d"
ENDIF
Hex_Mode = 11
Hex_Count = 6
ENDIF
IF Hex_Count > 3 THEN
GOSUB Hex_Stop
IF( RRange < LRange ) THEN
Hex_Dir = "a"
ELSE
Hex_Dir = "d"
ENDIF
Hex_Mode = 11
Hex_Count = 5
ENDIF
; TURN
ELSEIF Hex_Mode = 11
Hex_Count = Hex_Count - 1
IF Hex_Count = 0 THEN
Hex_Mode = 0
GOSUB Hex_Stop
ENDIF
The variable is properly defined and I get the same error without the white space. Interestingly enough, binary assignment statements which decrement this variable (Hex_Count = Hex_Count - 1) elsewhere in the program compile without error. But the program logic requires that I be able to increment the variable when required. I’m baffled. Compiler bug?
strange but im experiencing the same thing to that effect. i can decrement the variable but no increment in a code iv been using.
Have you tried adding a sound to see if command is being used?
its not a bug, maybe try:
IF Hex_Count<6 THEN ;NOT SURE HOW MUCH INCREMENT YOU ARE USING 3,4,5?
Sound P9,[50\4000] ;ADD SOUND TO SEE IF ITS WORKING
Hex_Count = Hex_Count + 1
ELSE
Sound P9,[50\4000, 50\4500] ;ADD SOUND TO SEE IF ITS WORKING
Hex_Count = 0
ENDIF
ENDIF
; =========================================================================
; File: SRF04_OBSTACLE_AVOIDANCE.BAS
; Purpose: Basic Obstacle Avoidance Using SFR04 to control HexEngine via BasicATOM Pro 28
; Author: Matt Denton (for BS2P and SRF08 connected to SMB)
; Ported: 20/08/09 for BasicATOM Pro 28 and SRF04 Ultrasonic Sensor connected to BotBoardII
; Kevin Lincoln
; =========================================================================
; ----- Program Description ]---------------------------------------------
; This program demonstrates two way serial comunications between the
; HexEngine and a BasicATOM Pro 28 device using the SERIN and SEROUT
; commands. In order to get this to work when using SERIN, the maximum
; baud rate is 9600, and a delay is needed from when the HexEngine receives
; a packet request to when it returns it. This is because we are not using
; hardware uarts on the BAP28. There is a setting on the HexEngine
; that will transmit a number of 0xff bytes to form a transmision delay
; before the actual reply packet. This setting also sets the UART STOP
; bits to two, which also helps slow down the comms data rate.
; Also, it is much easier to receive PIP packets in mode 0, with
; no Escape code checking, Therefore, before running this test, set the
; following in the HexEngine configuration menu:
; CBR=3
; TXD=3
; PIP=0
; This sets the baud rate to 9600, transmission delay on and PIP mode 0
; Don't forget to exit config mode when you are done!
; Only 3 wires are needed for communication with the BAP28, which can be
; found on the p.Brain-SMB connector CN17.
; Pin 2 = U1RX
; Pin 4 = U1TX,
; Pin 6 = GROUND
; U1RX needs to be connecteed to the BAP28 SER_OUT pin, U1TX to BAP28 SER_IN
; and GROUND to the BAP28 ground. If you are using the 5V regulator on the
; p.Brain-SMB, You can also take a fourth wire from Pin 9 on CN17 to
; supply the 5V power for the BAP28 device.
; HexEngine ] BAP28
; U1TX ]----TX----> SER_IN
; U1RX ]<---RX----- SER_OUT
; GROUND ]----GND---- GROUND
; 5V ]- - 5V- - - 5V
; ----- Revision History ]------------------------------------------------
; ----- Compilation Switches ]--------------------------------------------
PIP_MODE_1 CON 0 ; PIP MODE 1 FOR MORE ROBUST COMMS, 0 FOR SIMPLER COMMS
; ----- I/O Definitions ]-------------------------------------------------
Echo CON P0 ; echo input from SRF04
Trigger CON P1 ; trigger out to SRF04
SER_OUT CON P4 ; serial out to SMB/Hexengine U1RX
SER_IN CON P5 ; serial in from SMB/Hexengine U1TX
; ----- Constants ]-------------------------------------------------------
Trig10 CON 20 ; 10uS pulse in BAP 0.5uS units
ToCm CON 58 ; convert SRF04 raw reading (in uS) to CM
CMD_PIP_ESCAPE CON $7d
CMD_PIP_HEADER CON $7e
CMD_PIP_XOR CON $20
HEAD_LOOK_SPEED CON 16
HEAD_LEFT CON 1900 ; P/T head sometimes hits left anterior femur at 2000uS
HEAD_RIGHT CON 1100 ; P/T head sometimes hits right anterior femur at 1000uS
HEAD_MID CON 1528 ; mid position of my pan servo
HEAD_OFFSET CON 30
FRONT_OBSTACLE_DISTANCE CON 20 ; CM
RIGHT_OBSTACLE_DISTANCE CON 28 ; CM
LEFT_OBSTACLE_DISTANCE CON 28 ; CM
RETREAT_DISTANCE CON 19 ; CM
Baud CON I9600 ; match SMB/Hexengine CBR
; ----- Variables ]-------------------------------------------------------
samples VAR Nib ; sensor loop counter
pWidth VAR Word ; pulse width from sensor
rawDist VAR Word ; filtered measurment
Dist_CM VAR Word ; Distance in centimeters
PIP_Byte VAR Byte
PIP_Len VAR Byte
PIP_Temp VAR Byte
PIP_Cs VAR Byte
PIP_Buff VAR Byte(17)
W_Temp VAR Word
Temp VAR Byte
RRange VAR Byte
FRange VAR Byte
LRange VAR Byte
Hex_Count VAR Byte
Hex_Dir VAR Byte
Hex_Mode VAR Byte
; ----- Initialization ]--------------------------------------------------
Setup:
HIGH SER_OUT
LOW Trigger
; ----- Program Code ]----------------------------------------------------
Main:
; ALLOW THE HEXENGINE TO POWER UP
PAUSE 1500
; WAKE HEXAPOD
PIP_Buff(0) = "+"
PIP_len = 1
GOSUB Send_PIP_Packet
; RESET LEGS IF ALREADY POWERED UP
PIP_Buff(0) = "r"
PIP_len = 1
GOSUB Send_PIP_Packet
; SET GAIT TO WAVE 3
PIP_Buff(0) = "3"
PIP_len = 1
GOSUB Send_PIP_Packet
Hex_Dir = "w"
DO
; MOVE HEAD LEFT
W_Temp = HEAD_LEFT + HEAD_OFFSET
GOSUB Move_Head_Position
GOSUB Get_Distance
LRange = Dist_CM
; MOVE HEAD CENTRE
W_Temp = HEAD_MID + HEAD_OFFSET
GOSUB Move_Head_Position
GOSUB Get_Distance
FRange = Dist_CM
; SEND WALK COMMAND
PIP_Buff(0) = "w" ;Hex_Dir
PIP_len = 1
GOSUB Send_PIP_Packet
; MOVE HEAD RIGHT
W_Temp = HEAD_RIGHT + HEAD_OFFSET
GOSUB Move_Head_Position
GOSUB Get_Distance
RRange = Dist_CM
; MOVE HEAD CENTRE
W_Temp = HEAD_MID + HEAD_OFFSET
GOSUB Move_Head_Position
GOSUB Get_Distance
FRange = Dist_CM
PIP_Buff(0) = "w" ;Hex_Dir
PIP_len = 1
GOSUB Send_PIP_Packet
IF Hex_Mode = 0 THEN
Hex_Dir = "w"
IF FRange < FRONT_OBSTACLE_DISTANCE THEN
Hex_Mode = 10
Hex_Count = 0
GOSUB Hex_Stop
ELSEIF RRange < RIGHT_OBSTACLE_DISTANCE
Hex_Mode = 20
GOSUB Hex_Stop
ELSEIF LRange < LEFT_OBSTACLE_DISTANCE
Hex_mode = 30
GOSUB Hex_Stop
ENDIF
; BACKWARDS UNTIL DISTANCE > 20 OR COUNT > 3
ELSEIF Hex_Mode = 10
Hex_Count = Hex_Count + 1
Hex_Dir = "s"
IF FRange > RETREAT_DISTANCE THEN
GOSUB Hex_Stop
IF( RRange < LRange ) THEN
Hex_Dir = "a"
ELSE
Hex_Dir = "d"
ENDIF
Hex_Mode = 11
Hex_Count = 6
ENDIF
IF Hex_Count > 3 THEN
GOSUB Hex_Stop
IF( RRange < LRange ) THEN
Hex_Dir = "a"
ELSE
Hex_Dir = "d"
ENDIF
Hex_Mode = 11
Hex_Count = 5
ENDIF
; TURN
ELSEIF Hex_Mode = 11
Hex_Count = Hex_Count - 1
IF Hex_Count = 0 THEN
Hex_Mode = 0
GOSUB Hex_Stop
ENDIF
; STOP & PAUSE
ELSEIF Hex_Mode = 20
Hex_Mode = 21
Hex_Count = 2
Hex_Dir = "a"
; TURN LEFT
ELSEIF Hex_Mode = 21
Hex_Count = Hex_Count - 1
IF Hex_Count = 0 THEN
Hex_Mode = 0
GOSUB Hex_Stop
ENDIF
; STOP & PAUSE
ELSEIF Hex_Mode = 30
Hex_Mode = 31
Hex_Count = 2
Hex_Dir = "d"
; TURN LEFT
ElseIF Hex_Mode = 31
Hex_Count = Hex_Count - 1
IF Hex_Count = 0 THEN
Hex_Mode = 0
GOSUB Hex_Stop
ENDIF
ENDIF
WHILE 1
END
; ----- SLEEP ]----------------------------------------------------
Hex_Sleep:
PIP_Buff(0) = "-"
PIP_Len = 1
GOSUB Send_PIP_Packet
DO
PAUSE 500
GOSUB Get_Distance
IF (Dist_CM < 10) THEN
PIP_Buff(0) = "+"
PIP_Len = 1
GOSUB Send_PIP_Packet
EXIT
ENDIF
WHILE 1
RETURN
; ----- STOP ]----------------------------------------------------
Hex_Stop:
Hex_Dir = " "
PIP_Buff(0) = " "
PIP_len = 1
GOSUB Send_PIP_Packet
RETURN
; ----- ECHO ]----------------------------------------------------
Get_Distance:
rawDist = 0 ; clear measurement
FOR samples = 1 TO 5 ; take five samples
PULSOUT Trigger, Trig10 ; 10 uS trigger pulse
PULSIN Echo, 0, pWidth ; measure pulse
rawDist = rawDist + (pWidth / 5) ; simple digital filter
PAUSE 10 ; minimum period between
NEXT
Dist_CM = rawDist / ToCM ; convert raw to centimeters
; Uncomment line below to confirm sensor function in IDE Terminal1 @ 9600 N81
; SEROUT s_out, i9600, "Raw Value: ", sdec pWidth, " Distance: ", sdec Dist_CM," Centimeters", 13, 10] ;display result in terminal
RETURN
; ----- SERVO POS ]----------------------------------------------------
Move_Head_Position:
PIP_Buff(0) = "N"
PIP_Buff(1) = W_Temp >> 8
PIP_Buff(2) = W_Temp & $ff
PIP_Buff(3) = $5
PIP_Buff(4) = $dc
PIP_Buff(5) = $5
PIP_Buff(6) = $dc
PIP_Buff(7) = $5
PIP_Buff(8) = $dc
PIP_Buff(9) = $5
PIP_Buff(10) = $dc
PIP_Buff(11) = $5
PIP_Buff(12) = $dc
PIP_Buff(13) = $0 ; HI BYTE FRAMES FOR MOVE TO COMPLETE
PIP_Buff(14) = HEAD_LOOK_SPEED ; LO BYTE FRAMES FOR MOVE TO COMPLETE
PIP_len = 15
GOSUB Send_PIP_Packet
; WAIT FOR MOVE TO COMPLETE
; SEND THE POLL SERVO MOVE COMMAND, AND WAIT FOR
; ACK RESPONSE "k"
PIP_Buff(0) = "n"
PIP_Len = 1
DO
PAUSE 20
GOSUB Send_PIP_Packet
SERIN SER_IN, Baud , 300, End_Head_Move, [WAIT($7E), PIP_Len, Temp]
IF Temp = "k" THEN EXIT
WHILE 1
End_Head_Move:
RETURN
; ----- 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 LENGTH
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=1
; 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=1
ENDIF
#ENDIF
RETURN
Is the “_” causing the problem? I know Kurt said Hcount works but I wonder if the underscore is somehow causing the compile error? Perhaps try “hexCount” without the underscore and see if it will compile. If it does then it must be something to do with the underscore.
The fun part of these type issues, is sometimes it is not the name at all, but maybe the alignment of where the name started in the program, or maybe he has a hashing algorithm that stores names that hit some weird collision, or… Should be fun to debug!!!
Kurt
EDIT: I forgot to mention, that I have emailed Nathan and Ken of Basic Micro. The latest response from Ken is:
My gut feeling is it’s something along those “aligns”, as none of the other numerous variable names with underscores cause problems. Maybe I overwhelmed it with underscores and sent it home to mama .
Just a note. This problem was because the hex modifier parser was puking on the “HEX_” part of the name in this particular situation. I fixed the parser in Basic Micro Studio 1.0.0.10 which is now available for download on Basicmicro.com.