CYBERTRONICS

Advanced Cybernetics Solutions

sym2code knowledge base

Sym2Code Example

Speed Projection using Roll Pitch Yaw

Let us consider the attitude of a body through a classic Euler angle representation, using roll, pitch and yaw angles \Theta = \begin{pmatrix}\phi,\theta,\psi\end{pmatrix}^T \in \mathbb{R}^3: R^n_b(\Theta) = \begin{pmatrix} \cos(\psi) &-\sin(\psi) &0\\ \sin(\psi) &\cos(\psi) &0\\ 0 &0 &1 \end{pmatrix} \begin{pmatrix} \cos(\theta) &0, &\sin(\theta)\\ 0 &1 &0\\ -\sin(\theta) &0, &\cos(\theta) \end{pmatrix} \begin{pmatrix} 1 &0 &0\\ 0 &\cos(\phi) &-\sin(\phi)\\ 0 &\sin(\phi) &\cos(\phi) \end{pmatrix} The body speed with surge sway and heave components v^b = \begin{pmatrix} u, v, w\end{pmatrix}^T \in \mathbb{R}^3 can be projected into the navigation frame as follows: v^n = R^n_b(\Theta) v^b Let us now create a piece of code to automatically compute the rotation matrix R^n_b and the navigation speed v^n.
% Roll Pitch Yaw Angles
syms roll pitch yaw q real

% Direction Cosine Matrices
Rx = [ 1, 0 0;
0, cos(roll), -sin(roll);
0, sin(roll), cos(roll)];

Ry = [ cos(pitch), 0, sin(pitch);
0, 1, 0;
-sin(pitch), 0, cos(pitch)];

Rz = [ cos(yaw), -sin(yaw), 0;
sin(yaw), cos(yaw) , 0;
0, 0, 1 ];

% Input Parameterization
RPY= Sym('RPY',[roll; pitch; yaw],'Roll Pitch Yaw');
Vb = SymVectorCol('Vb',{'surge','sway','heave'}, 'Body Speed');

% Output Variables
Rnb= Sym('Rnb',simplify(Rz*Ry*Rx),'Attitude');
Vn = Sym('Vn',simplify(Rnb*Vb),'Navigation Speed');

% Generate Code!
Sym2Code({Vn, Rnb}, 'SpeedMap', {RPY, Vb});

Get in Touch

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close