Align smartphone and vehicle using Acceleration and Orientation from Matlab Mobile
3 ビュー (過去 30 日間)
古いコメントを表示
Dear,
I acquired data during driving with a car. The data I collected was:
- Acceleration (X,Y,Z)
- Orientation (Azimuth, Pitch, Roll)
I placed my phone in an arbitrary position within my car, hoping to later align the acceleration using the acceleration. I'm aware that I need to use Euler angles of some kind, but not sure of the exact implementation. The main question is, what rotation matrix do I need to make and how I should multiply this with my unaligned accelerations and aligned accelerations. One of the main difficulties for me is that I think I would need Yaw instead of Azimuth, but I'm not sure.
In stationary position, my aligned accelerations should be (0,0,9.81). Whilst momentarily, the accelerations are more as (2,2,4.81)
Many thanks for any help.
David
0 件のコメント
回答 (2 件)
William Rose
2022 年 8 月 7 日
編集済み: William Rose
2022 年 8 月 7 日
The information provided is not sufficient to determine the rotation matrix.
Also, the data you gave is not consistent with a simple rotation. Rotations preserve length. Therefore the length of your rotated acceleration vector should be 9.81. But vector v1=[2,2,4.81] has magnitude 5.58.
Let us multiply v1 by a constant so that it has length 9.81: v1=[3.52,3.52,8.46].
This is still not sufficient to determine R. You can think of it this way: The rotation matrix R describes the orientation of the phone relative to the car. We know that R*w1=v1, where w1=[0,0,9.81]. w is in car coordinates, v is in phone coordinates. You need at least one more independent vector in both coordinate systems. With that information, you can compute R as follows:
R*[w1,w2,cross(w1,w2)]=[v1,v2,cross(v1,v2)].
Therefore R= [v1,v2,cross(v1,v2)]*inv([w1,w2,cross(w1,w2)])
Because of measurement errors, the R computed above will not be exactly a rotation matrix - in other words, its columns will not be three vectors which are exactly orthogonal and have length=1. Another way of putting it is that it will not be exactly true that R*R'=I, where R'=transpose of R and I=identity matrix. You deal with that by a singular value decomposition approach. Once you have R, you use inv(R) to convert your measured vectors from phone coordinate system to car coordinate system:
w=inv(R) * v
1 件のコメント
William Rose
2022 年 8 月 8 日
William Rose
2022 年 8 月 8 日
Try the following for the rotation matrix R=
:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1091055/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1091060/image.jpeg)
where
[0.375561 -0.385512 0.023676].
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1091065/image.png)
The matrix Rxyz is derived in the attached notes, equaiton 37. I realized that, since [0;0;9.81] gets transformed to [3.5161; 3.5161; 8.4563], then it must also be the case that [0;0;1] gets transformed to [0.3584; 0.3584; 0.8620], by simple scaling. And that means the last column of Rxyz must be [0.3584; 0.3584; 0.8620]. So we have three equaitons and three unknowns - where the unknowns are the angles
. Then we must find the values of
that will make the last column of Rxyz, shown above, have those values. I solve this system of 3 equtions and 3 unknowns using Matlab's solve(). I called the angles x,y,z for simplicity.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1091070/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1091075/image.png)
x=optimvar('x');
y=optimvar('y');
z=optimvar('z');
eq1 = -cos(x)*sin(y)*cos(z)+sin(x)*sin(z)==0.3584;
eq2 = cos(x)*sin(y)*sin(z)+sin(x)*cos(z)==0.3584;
eq3 = cos(x)*cos(y)==0.8620;
prob = eqnproblem;
prob.Equations.eq1 = eq1;
prob.Equations.eq2 = eq2;
prob.Equations.eq3 = eq3;
x0.x = 0; x0.y=0; x0.z=0; %initial guess
sol = solve(prob,x0) %solve the system of equations
Use the values of x,y,z above for the angles, when evaluating the formulas for the elements of the rotation matrix Rxyz, using the formulas in the image above.
The matrix Rxyz describes how the phone is rotated relative to the car. Matrix Rxyz times a vector w1, in car coordinates, gives the vector v1, in phone coordinates. To convert acceleration v2, measured in phone coordinates, to w2 (car coordinates), do w2=inv(Rxyz)*v2.
I said earlier that the information provided was insufficient. I was wrong.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!