Tuesday, June 14, 2011

Trying To Tilt Compensate

I haven't been spending my 5 hours a week on this project, but I did spend a couple hours this week trying to put the compass and accelerometer readings together to get the tilt compensation working. I figured that I had the math down and the difficult part would be getting the microcontroller to talk to both the compass and the accelerometer at the same time. It turns out I was wrong on both accounts. It was surprisingly easy to merge my accelerometer and compass codes together, modify some variable names, and get both sensor readings to output to the computer screen. Unfortunately, the tilt compensation math didn't seem to work out, because the compensated outputs didn't make much sense.

Several weeks ago I had spent quite a bit of time trying to figure out the math for doing the tilt compensation. I believe its just a couple coordinate transformations, but it gets tricky when you start figuring out which axis to rotate about first and whether you use fixed axes or the transformed axes for the second rotation. I thought I figured all that out, reduced it to a couple simple equations, and verified it with a spreadsheet. Something isn't right, though.

It may be because I had mistakenly thought that when an axis is tilted downwards in the direction that gravity is pulling, it would read a positive value. It actually reads a negative value. I guess this makes sense if you think about accelerating the sensor along the postive x-direction. It would feel a force pulling it towards negative x, but it reads a positive value since it is accelerating in the positive x-direction. Just to try, I multiplied the inputs by -1 to see if that fixed it, but that didn't work. I don't think its a simple change like that. I might have to multiply the matrices in a different order or something. Unfortunately, I didn't really write out how I figured out the math last time, so I'll have to go through it again. When I have it figured out, I'll be sure to write a blog post on it.

No comments:

Post a Comment