Activities
We have now built our robot, it can :
We now need to combine these in order to solve various problems. Writing sets of rules in order to solve problems we commonly refer to as Algorithms. We will discuss a few simple algorithms here for you to experiment with.
Beyond the simple test routines that we ran int he assembly stages, this is perhaps one of the simplest algorithms to write. We will use what we learned from Motor section on how to move, and from the Line Sensors on detecting light and dark.
Here we can look at the 4 digital inputs from the line sensors to find the dark (low) line that we are following, and move accordingly. We will assume they are numbered 1 to 4 from left to right.
if (all sensor light) { we have lost it, turn on the spot a little and try again set one motor forward, and one backward, run for a short while. stop and try again } else if ( left side dark) { run right motor only to turn left } else if ( right side dark) { run left side motor only to turn right } else { run both motors the same to go forward }
This gives a very simplistic method of following a line, constantly trying to adjust to keep the line in the middle, and if its lost turning around until it is found again.
A more advanced version of this algorithm would be to not just turn when adjusting, but to go forward with one wheel faster than the other so that you both turn and go forward at the same time.
Using the motors, the servo and the ultrasonic sensors for this one, the robot can proceed forwards until its movement is blocked by an object, then it will look around and choose a direction to turn.
if ( no, or far off object ahead) { keep going forward } else { look right if ( no object in that direction ) { turn right } else { look left if ( no object in that direction ) { turn left } } }
These are similar rules to those used for line following, only this time we have the option to turn our 'head' to look in different directions and choose a direction.
More advanced algorithms may try to plan ahead, knowing that an object is approaching and turning early to avoid it. Also a strategy for when the route ahead seems completely blocked, perhaps by reversing until there is a clear path available.
Maze solving is a favourite of robot builders, and many competitions are held around the world on the subject. One of the simplest algorithms is the 'Left Hand Rule', where you follow the maze such that your left hand is always touching the wall. Simple algorithms like this are easy to implement and will get you there, but can take a long time.
One such very simplistic algorithm might be :-
if ( path to left ) { turn left } else if ( path ahead ) { move forwards } else { turn right }
A quick guide to a number of alternative approaches to maze solving can be found on Wikipedia each with its own strengths and weaknesses.
Good luck !
If you are not comfortable with programming in the Arduino environment one easy way to get started is by using the Blockly graphical programming system. This allows you to write software for your arduino by dragging around blocks in a fashion similar to Scratch. Then copy and paste the code it generates into the Arduino IDE to send to your robott.
Save the example files to disk and use the 'Load XML' button within Blockly.