Replacement rules for computing the shortest distance of a maze with the boe-bot
kingbp
Posts: 22
Hello I have a project with the Boe-bot where i want to make it drive through an entire line following maze with dead ends and continue until it reaches the end of the maze on the first run. Then It will make a 2nd run this time memorizing the entire maze and taking the shortest route to the end of the maze avoiding dead ends. I am using parallax's QTI sensors . I'm working on computing the shortest distance and storing the paths in memory but my code isn't working, I want to represent Left turn as L, Right turn as R, etc. but I get errors. Also I'm trying to use push and pop methods for replace path directions but there not working can you guys take a look at my code and give me some advice thanks.
' {$STAMP BS2}
' {$PBASIC 2.5}
myarray VAR Byte
GOSUB Turn_Right
GOSUB U_Turn
GOSUB Turn_Left
GOSUB Straight
L = GOSUB Turn_Left
R = GOSUB Turn_Right
S = GOSUB Straight
U = GOSUB U_Turn
IF (myarray = LUL)
THEN
POP LUL
PUSH S
IF (myarray = LUR)
THEN
POP LUR
PUSH U
IF (myarray = RUL)
THEN
POP RUL
PUSH U
IF (myarray = RUR)
THEN
POP RUL
PUSH S
IF (myarray = RUS)
THEN
POP RUL
PUSH L
IF (myarray = SUL)
THEN
POP SUL
PUSH R
IF (myarray = SUR)
THEN
POP SUR
PUSH L
IF (myarray = SUS)
THEN
POP SUS
PUSH U
' {$STAMP BS2}
' {$PBASIC 2.5}
myarray VAR Byte
GOSUB Turn_Right
GOSUB U_Turn
GOSUB Turn_Left
GOSUB Straight
L = GOSUB Turn_Left
R = GOSUB Turn_Right
S = GOSUB Straight
U = GOSUB U_Turn
IF (myarray = LUL)
THEN
POP LUL
PUSH S
IF (myarray = LUR)
THEN
POP LUR
PUSH U
IF (myarray = RUL)
THEN
POP RUL
PUSH U
IF (myarray = RUR)
THEN
POP RUL
PUSH S
IF (myarray = RUS)
THEN
POP RUL
PUSH L
IF (myarray = SUL)
THEN
POP SUL
PUSH R
IF (myarray = SUR)
THEN
POP SUR
PUSH L
IF (myarray = SUS)
THEN
POP SUS
PUSH U
Comments
Next, I'm not completely sure (you can do some weird things in PBASIC...) but I don't think you can assign a GOSUB to a variable. You'd have to use an IF block to test instead.
Finally, I don't think you've posted your full code. Please remember to always do so in the future.
The book is a free pdf download, from the book section. You will need to add your PBasic code for the logic you want to implement..... Have Fun out there.