How can I solve a maze using stack or queue?

1.1k views Asked by At

I'm using a scribbler robot to navigate a self made maze (which I will improve once I get the functionality working, the one I have in a video is just for testing purposes.)

Maze

I initially was trying to make the robot move left and right solely on the getObstacle sensors. I had trouble tho.. It wouldn't turn left or right as I desired. So I'm thinking of using stack or a queue.

I would like to just tell the robot

if(getObstacle(1) <=6000): # once sensor reaches 6000, it will stop doing the command
   forward(1,0) # will move forward as long as getObstacle(1) is less than 6000

Then, once it detects the first obstacle, turn left and go forward

Then once it detects another obstacle, turn right.

I essentially want to map out the left and right turns of the maze and tell the scribbler when to turn beforehand.

So when it senses a wall for the first time = turn left.. then go forward

When it senses a wall for the second time = turn right.. then go forward.

How can I implement this code into a stack or queue?

The code I have now is based purely on the sensors, and it's unreliable.

Here's an example of what I'm working with:

def main():
    setIRPower(135)
    while True:
        left = getObstacle(0)
        center = getObstacle(1)
        right = getObstacle(2)
        # 2 feet per 1 second at 1 speed
        if (center <= 6000):
            forward(0.5, 0.3)       
        elif (center >= 6000 and right > left): #if right sensor detects value higher than left
            turnLeft(1, .55) #left turn
        else:
            turnRight(1, .55) #otherwise, turn right

I'm working with different variations of the code above. I just would like to implement the turns in a queue or stack, and I'm not sure how to do it.

Thanks

0

There are 0 answers