Step 13: The Program

codesnip.tiff
I had fun writing this program. Basically there are a few functions that take care of the whole maze solving process. The left hand on the wall function holds the logic to read the sensors and navigate the maze following those rules I outlined earlier. The turning functions are programmed in a fashion so that the robot continues to turn until it sees the black line in which case it then drives forward. There is also a function programmed with a little line following capabilities. It is no PID line following, but does allow the robot to stay on course. This function also controls the robot's speed. 

The more detailed function is that of shortening the path.  A letter is stored at every intersection that indicates the direction the robot took. If the previous letter was a "B", indicating a wrong turn, the function that shortens the path is run to substitute letters in place of those 3 letter sequences outlined earlier.

Finally there is a function that replays the shortest path that the robot calculated when the robot is picked up and then placed back down on the black line. The robot can detect when it is placed back down and then runs the shortest calculated path.

You can view the code here or of course download it on this page. 


 
Remove these adsRemove these ads by Signing Up
pingpongkid5 says: Feb 22, 2012. 7:40 PM
A couple questions.
1. What happens when you plug it in? Should some kind of software or something pop up? Does it need to be a mac or windows or can in be both?
2. does the arduino need power when it is connected for the program to be put on it?
3. Is there alternate software I need to read this code or put it on the arduino?
patrickmccb (author) in reply to pingpongkid5Feb 22, 2012. 10:43 PM
1. Nothing happens when you plug it in. Operating system does not matter.
2. The programming cable supplies power for you.
3. You need to install the Arduino IDE (http://arduino.cc/en/Main/Software) to view the code, edit it, and upload it.
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!