Meta-Sensing (How to get out of a Jam)
One of things you may have noticed in completing last week's exercise is that at times, the robot tends to get stuck into corners. Now, you were warned about the situation, and most of you may have used some randomization during back-up and turn situations to get rid of this situation. This strategy works in most situations. In real life, bugs use it to get out of tight spaces.
There is a way in which you can make the robot "self-aware", recognize that it is in some kind of a jam (stuck in a corner), and then it try and rectify the situation by temporarily suppressing the normal behavior, carrying out some corrective action, and then resuming the normal behavior. This is especially easy to do in IC, since you can create parallel tasks, you can dynamically kill them, and dynamically restsrt them.
Suppose you have an avoid proces that implements the avoid obstacle behavior (the kind of process that would be used to detect and avoid bumps). When you create the process, save its process_id (start_process returns this number) in a global variable. Also, in your program, write another process, lets call it (jam_solver) that does the following:
jam_solver initialize the last time a jam was corrected to current time initialize bump count to 0 do forever wait until a bump is detected when a bump is detected, record the time of bump if the time elapsed since the last bump is less than, say 2 seconds then update bump count else set bump count to 0 if too many rapid bumps (say > 5 or 6) then kill the avoid process do some drastic manuevering start the avoid process set bump count to 0 set last bump corrected to current time
You can say that the process above is doing a kind of meta-sensing. It keeps track of the number of rapid bumps. And if the number exceeds some preset limit (5 or 6 is a good limit), it can indicate that the robot is in a jam. It takes over for a while and then resumes normal behavior.
Exercises for this week
For next lab, you may try and expriment with this meta-sensing routine. Add it to the robot you created for this week. Does it improve the robot's behavior? Put the robot in a corner and observe how it behaves.
Next week, we will watch some video demos of robots from various research labs around the world.