Obstacle Avoidance Algorithm

5/6/2010

We use a hard-coded turning sequence to deal with obstacles when they are detected on the rising edge of the IR distance sensor (an interrupt is triggered for this purpose).  The program breaks away and executes the turns that we tell it, and then it goes back to the ordinary line-following routine to attempt to re-find the line afterwards.

To figure out what the car had to do to turn to avoid the obstacle, we used a similar scheme to what we did in the slollum project; we measured out the dimension of the object and the distance at which the IR sensor was normally triggered (about 30 inches) and then used these dimensions to manually controlled the car with as few turns as possible (so that the info could fit on the board*). We controlled the car through serial and recorded the dutyCycle for the turns at every hall tick so that we could in essence “replay” this sequence.  We were then able to use a Java program to compress this data since it will often be turning in the same direction for many hall ticks in a row.  Here’s the code our Java program generated to put on the board:

double dutyFracs[6] = {0.108,0.126,0.144,0.125,0.107,0.126};

byte dutyIndex[6] = {0,23,37,69,84,85};

dutyFracs says what the turning fractions ought to be, and dutyIndex says on which hall tick to go to the next dutyFrac.  Here’s a plot of the turns we made it do:

We turn to the left around the obstacle instead of to the right since there is no possibility to hit the wall if we turn to the left going counter-clockwise around the track.

*The board had a limited amount of memory for variables (960 bytes as described by the error) and so by the time we had gotten to obstacle avoidance we had taken up around 930 bytes. We actually did this same method but without limiting ourselves to making very few turns (trying to make the routine “prettier” than it turned out) and we then discovered that we could not compress the data enough we used fewer turns (the degree each turn was increased since we had to turn fewer times).