All,
I am attempting to use a three axis accelerometer to detect when my robot runs into something. My problem is that it only sort of works...with the code I wrote for it. The accelerometer works fine, but my algorithm and/or placement of the accelerometer doesn't do it. I saw Oddbot do this with one of his little robots, and it seemed to work fine. Oddbot is way (well way, way, way) beyond my skill level with this stuff, but if he can get it to work, I should too theoretically.
My robot is fairly heavy for a hobby robot (about 5#) which would affect how the accelerometer works because it has more momentum so changes in direction might not register as well. I put the accelerometer in the very center of the robot, attached the sensor with electric tape and watch the X and Y axis(es). If I see a > .4 g change and then another > .4 change very soon after, I assume I ran into something. Based on whether it was a negative g or positive G in the Y axis defines whether I back up and then turn left or right. Pretty simple, straightforward, 15 lines of code to implement - should work?
Without the motors running, all changes to the robot are picked up with the accelerometer. I can slap the robot, see the numbers change and a good jolt will give a > .4 g change and it will attempt to back up and turn etc. The problem is that when I am running this on our wood floors, across tile and grout lines etc, that is enough to register sporadically as a > .4 g change, so it will back up, turn etc even though it hasn't run into anything. Even looking for a .4 g change, it sometimes doesn't register when I run into something and it will grind and grind until I kick it (giving it a > .4 g jolt) which makes it back up and turn one way or the other. What is frustrating too, is with fresh batteries, just starting the robot in a straight line is enough to register a > .4 g change so it will go 6" back up turn, go 6" back up turn, rinse and repeat. I have tried all kinds of different numbers, put in many hours of stumbling behind it in my dining room and .4 g gives the best, albeit not acceptable performance. A lower number and all it does is back up and turn, a bigger number and it doesn't register anything.
One thing I had thought of was to put the accelerometer on a piece of plywood or plastic that had 4 small rubber bands pulling gently from all corners. This would increase the movement and therefore the g numbers when I hit something which might be enough for me to filter out background readings from going straight across uneven floors, etc. Maybe if I placed the sensor closer to the front of the robot where it is going to hit things I could get more reliable readings?
I would like to believe that defeat is not in my lexicon. But I am feeling like the San Francisco 49ers this past Monday. I have probably spent too hours so far on this (embarassingly high amount of time), and although I have learned a lot, I am nowhere near having something that can reliably detect collisions. Any one else do this successfully? Anyone have any suggestions?
Regards,
Bill