0

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

user3577397
  • 453
  • 3
  • 12
  • 27
  • Basic Depth-first-search, and very close to [programming-theory-solve-a-maze](http://stackoverflow.com/questions/3097556/programming-theory-solve-a-maze) – kdopen Dec 12 '14 at 20:47
  • I don't know how to go about programming the A* algorithm in Python and gear it toward my scribbler robot. I'm looking at it now and trying to figure it out. It's over my head so far. – user3577397 Dec 12 '14 at 20:56
  • How about http://stackoverflow.com/questions/27432813/how-to-make-a-robot-navigate-a-maze? – kdopen Dec 12 '14 at 21:03
  • @kdopen What about it? That's my question. I've been struggling with this for countless hours. I'm still trying to figure it out. – user3577397 Dec 12 '14 at 21:07
  • Sorry, didn't check the author. But rather than ask two related questions, build on just one of them – kdopen Dec 12 '14 at 21:17
  • Okay, then [this question](http://stackoverflow.com/questions/18279775/implementing-stack-with-python) might help you with the stack implementation, but for a simple stack (last in first out) just append to a list and pop from the end. Whenever you change direction, push the current location and the directions remaining. When you hit a dead end, reverse to the last known location and pop it – kdopen Dec 12 '14 at 21:22
  • Does that mean I have to pop the commands in real time? I'd like to pre-program when scribbler can turnLeft and turnRight. I'm trying to write code for it now. – user3577397 Dec 12 '14 at 21:35
  • I can't lie, I have no idea how to implement the commands into a queue or stack. I'm reading examples and I'm royally confused. – user3577397 Dec 12 '14 at 21:39
  • IF you can model the maze as a digraph, the you can implement a DFS to find the quickest way (shortest path) through the maze. Then just program scribbler to follow the route. But that's hardly dynamic. There's no easy answer to this question – kdopen Dec 12 '14 at 23:25
  • Any ideas how to implements a DFS? Can you provide pseudocode to get me started? I never done this before. Not sure how to do DFS using scribbler commands in python – user3577397 Dec 13 '14 at 00:00
  • Google Dijkstra's Shortest Path algorithm, that's precisely what this is for. But it's not simple to implement in Python. I did it recently but don't have access to the source (had my laptop stolen) – kdopen Dec 13 '14 at 00:37

0 Answers0