solving a variable width, odd angles maze

Hi everyone.

I got a small arduino-driven tank to solve a simple maze using a line follower method.

However, the maze was simple (simplistic?) in that all angles were 90 degrees and the corridor widths were constant.

Now, I'm trying to generalize this to a variable width corridors and obtuse|acute angles. I'm still assuming a simply connected maze (no loops).

The problem I'm running into is mainly due to variable width. Some walls are so far apart that the robot thinks there's nothing to its right and it moves right (thinking it's an empty space) but in reality, it's just far enough from the wall.

So, it ends up just bouncing around, going in circles between the maze walls.

I need it to somehow hug the wall if it's close but move to a wall if it's far (and then hug it.)

p.s. I've looked into SLAM but I don't think it does what I need.

What sensors do you currently have to detect the distance to a wall?

MorganS:
What sensors do you currently have to detect the distance to a wall?

VL53L0X Time-of-Flight ToF Ranging Sensor.

Thanks!

lobstermama:
So, it ends up just bouncing around, going in circles between the maze walls.

Would it be a solution to make it stay beside one wall?

...R

Robin2:
Would it be a solution to make it stay beside one wall?

...R

Yeah, that's what I'm struggling with.

It's like in the image below

it's very position dependent. If the robot is too far from the right wall and I'm trying to follow the right wall, then it thinks it needs to turn right. It thinks that's an empty corridor and turns right, hits that wall, turns right again and ends up totally lost.

However, if I move it to the right like here:

then it's ok and it's following the wall.

Obviously, your program logic isn't working. Post that, using code tags, and people can make informed suggestions.

See the "How to use this forum" post.

lobstermama:
it's very position dependent. If the robot is too far from the right wall and I'm trying to follow the right wall, then it thinks it needs to turn right. It thinks that's an empty corridor and turns right, hits that wall, turns right again and ends up totally lost.

I spent some time a while back writing a Python program to follow the "wall" of an image to create a pattern like mowing a lawn which would become the path for a milling cutter. It took a while to figure out the quirks, but, in essence, there needed to be hierarchy of decisions aimed at making it adopt a preference for the left-hand side if it was working clockwise round the image.

My guess is that your code is missing something that causes the robot to have a preference for the right-hand wall. Maybe think about this question - "how did it manage to get away from the right-hand wall in the first place?"

By the way it will be much better to think about the logic of the problem quite separately from the code needed to implement it. When you know what you want to do writing the code will be straightforward.

...R

Robin2:
....

By the way it will be much better to think about the logic of the problem quite separately from the code needed to implement it. When you know what you want to do writing the code will be straightforward.

...R

agree a 100%. Hence me asking for help :slight_smile:

Essentially, the code I had for solving a simple maze is not suited for complex mazes.

So, I don't have any code that works, nor am I looking for code suggestions, I'm asking for help with LOGIC itself. Sorry, probably should've been more clear.

Having said that, I've been doing more research and it appears that this is a highly non-trivial problem; way beyond a simple forum post.

Off I go to Coursera :slight_smile:

it appears that this is a highly non-trivial problem; way beyond a simple forum post.

Given distance sensors, maintaining a distance to a wall, or centering between two walls of arbitrary separation is a very straightforward problem. It has been solved many times.

jremington:
Given distance sensors, maintaining a distance to a wall, or centering between two walls of arbitrary separation is a very straightforward problem. It has been solved many times.

Unless I'm missing something, it's only straightforward if certain assumptions about the robot's initial placement are made.

If robot is placed at an angle, let's say 45 degrees to the walls, then it considers a side wall to be an obstacle in front, and the wall behind it to be its "right" wall.

It all quickly becomes a giant mess.

Again, I might be overcomplicating it but the cursory research done thus far suggests this is actually a fairly complex problem. And probably SLAM is unavoidable.

lobstermama:
Unless I'm missing something, it's only straightforward if certain assumptions about the robot's initial placement are made.

That sounds as if you need an initialisation routine that makes it go somewhere from which to start. For example move close to the closest wall.

...R

Some time ago I had to find objects on an image, and used the "marching squares" method with good results. Dunno how it could be adopted to a marching tank...

Essentially a signal "close to wall" is required in forward and one side direction. In a "search wall" state the tank should try to get close to a wall, by e.g. moving in a straight line till contact. The "follow wall" state should not be hard to implement. Critical is the "turn" state, where the tank looses contact to the wall and cannot know in advance how far to turn. I'd try to use the last point-of-contact as the center of a circle, and let the tank follow the circumference until it again hits the bent off wall. Good luck :slight_smile:

Robin2:
That sounds as if you need an initialisation routine that makes it go somewhere from which to start. For example move close to the closest wall.

...R

this is actually a good idea! Thank you.

it's only straightforward if certain assumptions about the robot's initial placement are made.

Correct. Hence my use of the work "maintaining", which you seem to have overlooked.

The problem you are now considering, where the robot is starting from an arbitrary orientation, is a different problem and has nothing to do with the subject of my reply, the images you posted in reply #4.

So why not take a few minutes to describe what you are really trying to do? If it is to navigate a specific robot maze, then there will be rules that can be helpful for robot navigation. Initial robot placement is one of them. Navigating an arbitrary environment is a different problem.

How many distance sensors do you have and how are they arranged on the tank?

The sensor you pointed to is supposed to have a range of about two meters. How wide are these corridors?!?

johnwasser:
How many distance sensors do you have and how are they arranged on the tank?

The sensor you pointed to is supposed to have a range of about two meters. How wide are these corridors?!?

Not wide at all. 4-5 feet max. I have one up front and one on the right.

I also have an alternative solution where a sensor is mounted on a servo and the servo sweeps left to right, taking sample distances 0 to 180 degrees every 10 degrees. This does not work at all because the robot moves while the servo sweeps and by the time I detect an opening, the robot has moved on. (I don't want to stop to take readings).

Anyway. A large reading to the right could mean this:

or it could mean this:

so even though the distance reading to the right is the same, the behavior would be different.

GO_STRAIGHT in the upper image, TURN_RIGHT in the lower one.

OK. This seems to be a problem only on startup. Once you have acquired a wall to follow you just need to maintain distance.

On startup, rotate 360 degrees, taking readings periodically. You could save time by using the front sensor for the first 90 degrees so a rotation of 270 would be enough. Then rotate until the nearest point is on your right. Treat that as a wall and start following.

If the distance to the wall is a little too low, steer a little left.
If the distance to the wall is a little too high, steer a little right.
If the front distance drops to the point where you have to turn or hit the wall, rotate left at least 90 degrees and continue until the distance on the right starts rising.
If the distance on the right is suddenly high, drive in a circle around the last near point on the right until you are the desired distance from the wall around the corner.

That's my best guess on what to do.

johnwasser:
OK. This seems to be a problem only on startup. Once you have acquired a wall to follow you just need to maintain distance.

On startup, rotate 360 degrees, taking readings periodically. You could save time by using the front sensor for the first 90 degrees so a rotation of 270 would be enough. Then rotate until the nearest point is on your right. Treat that as a wall and start following.

If the distance to the wall is a little too low, steer a little left.
If the distance to the wall is a little too high, steer a little right.
If the front distance drops to the point where you have to turn or hit the wall, rotate left at least 90 degrees and continue until the distance on the right starts rising.
If the distance on the right is suddenly high, drive in a circle around the last near point on the right until you are the desired distance from the wall around the corner.

That's my best guess on what to do.

OK.. Thanks!

I'll be honest, this doesn't seem all that robust.

I tried something similar, trying slowly to get to a right wall if it's too far AND there's nothing in front me.

But.. There's another wrinkle in this--without PID control it starts swinging widely, trying to correct and over-correcting.

So. Definitely non-trivial. :slight_smile:

lobstermama:
But.. There's another wrinkle in this--without PID control it starts swinging widely, trying to correct and over-correcting.

Walls don't move so after making a decision to move there seems no reason to reconsider that decision until enough time has elapsed to get close to the wall.

Alternatively, having decided to move in a particular direction only take notice of distances in that direction until you are close enough.

That should eliminate swinging.

What is the max distance the robot might have to go to encounter the nearest wall? (Facts always make problems easier to solve)

...R