I have an accelerometer located in an arbitrary position on a car. As the accelerometer already has a coordinate system by default, I want to find some method that allows transforming the data I have from the sensor and aligning them with the coordinate system of the car. I have read several papers but I have not found the solution. I know that one of the first steps is to have the vector with the car stopped and then running and obtain a rotation matrix, a hand would be of great help to solve my case.
-
$\begingroup$ Is this a model car that you could pick up and manipulate? Or one big enough to drive around? I should have asked for clarification before my earlier answer. If it's a big one, I have some more practical ideas. $\endgroup$– r-bryanCommented Dec 5, 2021 at 21:03
-
$\begingroup$ Hi @r-bryan It is a large vehicle, the kind we use every day to get around. Maybe because of my bad English it was understood a little badly. Your ideas that you have would be of great help. $\endgroup$– José Vicente RCommented Dec 6, 2021 at 23:05
-
$\begingroup$ No, no, your English is fine! I'll apply another answer. $\endgroup$– r-bryanCommented Dec 7, 2021 at 0:22
-
$\begingroup$ @r-bryan Great, good to know that. I hope for your help. $\endgroup$– José Vicente RCommented Dec 7, 2021 at 13:39
2 Answers
Edited after a clarifying comment: this was a pretty good answer, except it assumed the question was about an RC car!
Gravity is your friend here. It always points straight down, exactly 1 G. Orient your car with its +X axis straight down, and capture the accelerometer reading, all three of its axes. That gives one row of your matrix. (You could double-check by measuring with the car's -X straight down, but when you measure something twice, you have to explain why the measurements are different :-))
Do the same thing with the car's Y and Z axes for the other two matrix rows. The resulting matrix will transform car coords to accelerometer coords. In the likely case of wanting to transform the other way, invert the matrix.
First let's define a right-handed coordinate system for the car. Let X point to the right, Y straight ahead, and Z straight up. Next we'll measure where the car's axes are in the accelerometer coordinate system. (Assume the accelerometer calibration units/G are the same in its X, Y, Z.)
Measuring car -Z is easy -- that's 1 G, straight down, as long as the car is parked on level ground not too far from sea level. The magnitude of the measurement vector calibrates its units/G.
To find car +Y, accelerate the car straight forward. Capture the accelerometer measurement, and subtract the reading that it showed for -Z. The difference points in the car's +Y direction. Its magnitude isn't important; normalize its magnitude to match the 1 G calibration from -Z.
The car +X direction is the cross product of the normalized (car +Y) and (car +Z). Note the Z sign change.
Stack up those X,Y,Z measurement vectors by rows into a matrix, and you have a way to transform car coordinates to accelerometer readings.
Finally, the inverse of that matrix gives a way to transform what the accelerometer reports to what the car is doing.
What if the road was unavoidably bumpy while driving for the +Y measurement? If the bumps were strictly up and down, I think you can subtract some multiple of the Z measurement to make the net Z projection zero. But I haven't worked through those details. If the car is bouncing in X and/or Y directions, or if you can't accelerate it straight ahead, I guess move the project to Bonneville Salt Flats :-)
I haven't tested this procedure, so I hope it works for you. Good luck!