May 30, 2011

Journal Entry #9

And so comes the last entry into this journal. There are a few more posts still to come for this project, but this is the last that I consider a journal entry. My car has come a long way. It went from a car being controlled by radio waves to one being controlled by ultrasound. And it has gone a bit beyond that.

I had come to the conclusion that I shouldn't use my infrared sensors because they had a minimum range of eight inches. Well, necessity dictated that I change my mind. My last entry depicted my car being able to make turns. At that point I'd written code that I was satisfied with, that I was certain would accurately work. However, when I placed my car in my homegrown track, it didn't work. Why didn't it work? The car would occasionally stop for no reason, it would turn into walls, and it would just outright misbehave. I scoured my code, shocked that some flaw of logic prevented my car from functioning. However, I found no such bugs, and no logical missteps. So what was wrong? I decided to test my sonar sensor, panning it in front of the car. The setup was a container set three feet in front of the car, that was narrow enough that the sensor should certainly be able to distinguish it from its surroundings. However, it didn't seem to work. My readings were inconsistent, and seemingly illogical.

So I concluded that something was messing my sensor up. I didn't know, and I still don't truly know, what was wrong, except that it was wrong. Having no alternative, I grabbed one of my IR sensors and mounted it to the car. And guess what? It worked! Below is a clip of it working. More footage will have to wait until my presentation, though. Again, it's at 1pm this Friday, June 3rd, at my school.

I'll give an overview here of the logic that makes my car work. Two readings are taken, from the left and right side of where the car will be in three feet's time. If the sensor detects an object closer than three feet while pointing to the left, then it turns to the right. It stays turned until there is no longer an object on the left. The car will stop if it is going straight and there is an object within eighteen inches on both the left and right, or if it is turning and there is an object within eighteen inches of the side it is turning to. It is important to stop so that my car tries to not run into walls. With my IR sensors, it is even more important because any reading taken inside eight inches will provide a value of much more than eight inches, messing up my logic. So I need to be sure that I'm not taking readings from any object closer than eight inches.

One feature I added which turned out to be important is reverse mode. When the car gets too close to an object, it backs up straight and tries to go forward again. This helps for when the car can't quite make the turn - it backs up and tries again. Also, it means less interaction with the car starting and restarting it when it gets a bad reading. Below are a couple diagrams of how my car works:

So what's next? Well, I have a presentation to give. The presentation is going to be really cool, and afterwards I hope to have a demo of my full track to give. I've built three obstacles that can be placed around the track and, hopefully, the car will avoid. Is there any more work to be done on my car after I present? Unlikely, assuming it doesn't break. I'll probably shelve it for now, and maybe later try and design a better car. It will be easier to start from scratch after all I have learned. A few tidbits for next time: use two power supplies, the rechargeable one for the motors and a separate one for the microcontroller. This will help alleviate any power issues that could arise. Also, find a better way to scan for range data. One possibility I've been considering is using a continuous rotation servo, and mounting on it a sensor and a compass, so you know in what direction you're taking the reading, and you can spin it rapidly around. Software wise, I'd love to come up with a way to navigate moving obstacles. But that is all for another time.

So, 'til then.

Next: Senior Project Wrap-Up