How to code floodfill in arduino?

Hi guys.i wnt to make a maze solving robot.i want it to use the shortest path.i know i must use floodfil alghoritm for this but dont know how to code it in arduino. Please help me

Here's how I did in for a micro mouse robot.

Declare a 2D array of structs representing the cells of the maze. Each cell knows which of the cardinal points have walls and how many steps they are from the maze target - this last is initially unknown.

Set the maze goal to zero steps.

For each cell next to the goal that you can move to (i.e. no wall), if it doesn't already have a step value, set it to the step value of the cell you're on plus one.

Do the same thing recursively to the cell you just set steps for until you can't find cells with no steps set.

Done.

I was using a computer with plenty of memory. For an arduino solution, you might have to replace the obvious recursive solution with an iterative approach. Similarly, storing wall data in every cell is inefficient use of RAM - may be necessary to find a cleverer solution.

Should be "...if it doesn't already have a lower step value...".

Johan_Ha:
Should be "...if it doesn't already have a lower step value...".

Very true. Good catch :slight_smile:

Pacman36:
I know i must use floodfil alghoritm for this

No, there are other algorithms, and some are better than flood fill. I think one of the best ones is called A*. But they are all quite memory intensive and not suitable for Arduinos with limited ram such as Uno and others based on atmega328, unless the maze is quite small.

Pacman36:
i think floodfill is suitable for arduino nano... but dont know programming in arduino

If you don't know programming in Arduino, how can you know that floodfill is suitable? I don't think you can know. Also you don't yet know that the maze algorithm is not even the most difficult part of the project.

Start learning Arduino code by following tutorials and examples in the IDE. When you have started your flood fill code and need help to make it work, post it here and we will be pleased to help.