Boe Bot Escapes a maze Questions from school!
Hi,
Our tech teacher can't really teach us anything about robot, so i came here to ask some questions.
The program looks like this:
' {$STAMP BS2}
' {$PBASIC 2.5}
' 5.2
' Henry Zhu
' May 16
counter VAR Byte
FREQOUT 4, 2000, 3000
main:
DO
IF (IN5=0)AND(IN7=0) THEN ' Both whiskers detect obstacle
GOSUB Back_Up ' Back up & U-turn
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5=0) THEN ' Left whisker contacts
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (IN7=0) THEN ' Right whisker contacts
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both whiskers 1, no contacts
GOSUB Forward_pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
' Functions
Forward_pulse:
PULSOUT 13, 850 ' Go Forward
PULSOUT 12, 650
PAUSE 20
RETURN
Turn_Left:
FOR counter = 0 TO 20 ' Left turn 90 degrees
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right: ' Right turn 90 degrees
FOR counter = 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Go Backward
FOR counter = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
END
Now the problems arise :
1.how to make the robot to turn around when it get struck in a corner? I know you have to do a nest if-then statement but how?
2. What are the values (ex.24?) to make the robot turn 30, 45 degrees? My strategy is to program the robot intelligently so it can escape the maze byitself rather the hard-coded way of doing it, which is also more time-consumpting.
Our tech teacher can't really teach us anything about robot, so i came here to ask some questions.
The program looks like this:
' {$STAMP BS2}
' {$PBASIC 2.5}
' 5.2
' Henry Zhu
' May 16
counter VAR Byte
FREQOUT 4, 2000, 3000
main:
DO
IF (IN5=0)AND(IN7=0) THEN ' Both whiskers detect obstacle
GOSUB Back_Up ' Back up & U-turn
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5=0) THEN ' Left whisker contacts
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (IN7=0) THEN ' Right whisker contacts
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both whiskers 1, no contacts
GOSUB Forward_pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
' Functions
Forward_pulse:
PULSOUT 13, 850 ' Go Forward
PULSOUT 12, 650
PAUSE 20
RETURN
Turn_Left:
FOR counter = 0 TO 20 ' Left turn 90 degrees
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right: ' Right turn 90 degrees
FOR counter = 0 TO 20
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Go Backward
FOR counter = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
END
Now the problems arise :
1.how to make the robot to turn around when it get struck in a corner? I know you have to do a nest if-then statement but how?
2. What are the values (ex.24?) to make the robot turn 30, 45 degrees? My strategy is to program the robot intelligently so it can escape the maze byitself rather the hard-coded way of doing it, which is also more time-consumpting.
Comments
2) You should be able to approximate how to make the robot turn 30 or 45 degrees. You may have to experiment with exact values since servo motors are not exact things. They're sensitive to power supply voltage and there's some variation in manufacture in terms of friction mostly.
I don't have the boebot now to experiment, but...
1)Time lteration and pulsewidth, but how do you determine the time in seconds using a for loop?
2)Approximately 24 for 45 degrees turn?