Rotation sequences and different MATLAB interpretation issue: MATLAB seems to interpret rotation sequences in a quite different mode with respect to scientific literature

2 views (last 30 days)
Hi all,
I wrote some code to understand how MATLAB interprets rotations. I have an aircraft with nose pointing NORTH (x axis), right wing pointing EAST (y axis) and the bottom of the fuselage pointing DOWN (z axis).
1) How can I plot according to my coordinate system instead of MATLAB default???
2) Why does the rotation sequence 1) yaw 2) pitch 3) roll seem to be wrong into MATLAB?
I tried using different terns of angles but the final orientation of my aircraft doesn't correspond to that I suppose to be.
E.g. let's take yaw=20*pi/180 pitch=45*pi/180 and roll=0: I'm expecting my aircraft to rotate first around DOWN of 20° and then nose UP of 45° with wings lying on NORTH-EAST plane...NO!!! IT DOESN'T!!! Why?
It seems to be a strange interpretation of aircraft convention of angle rotation.
Please help me! Thanks a lot. Luca.
Here is the code:
..............................................................
clear all
close all
clc
f=linspace(-10,10,50);
a=linspace(-5,5,50);
c=linspace(-3,0,50);
fuselage=[f; zeros(1,size(f,2)); zeros(1,size(f,2))];
wings=[zeros(1,size(f,2)); a; zeros(1,size(f,2))];
tail=[min(f)*ones(1,size(f,2)); zeros(1,size(f,2)); c];
%%Coordinates definition
% Using right-hand coordinate system:
% NORTH (positive x pointing the nose of the fuselage)
% EAST(positive y through right wing)
% DOWN (positive z pointing under the fuselage)
D=[zeros(1,size(f,2)); zeros(1,size(f,2)); linspace(0,2,50)]; % Coordinate DOWN
E=[zeros(1,size(f,2)); linspace(0,7,50); zeros(1,size(f,2))]; % Coordinate EAST
N=[linspace(0,20,50); zeros(1,size(f,2)); zeros(1,size(f,2))]; % Coordinate NORTH
%%Angles definition
% Yaw is positive rotating around the DOWN axis clockwise according to right-hand rule
% Pitch is positive rotating around the EAST axis clockwise according to right-hand
% rule
% Roll is positive rotating around the NORTH axis clockwise according to right-hand
% rule
yaw=45*pi/180;
pitch=45*pi/180;
roll=0*pi/180;
attitude_aircraft(D, N, E, fuselage, wings, tail, yaw, pitch,roll);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function attitude_aircraft(D, N, E, fuselage, wings, tail, yaw, pitch,roll)
% Rotation according to MATLAB
R = angle2dcm(yaw, pitch, roll );
% Rotation with separates matrices
R_x = @(x) [ 1 0 0;...
0 cos(x) sin(x);...
0 -sin(x) cos(x)];
R_y = @(y) [cos(y) 0 -sin(y);...
0 1 0;...
sin(y) 0 cos(y)];
R_z = @(z) [ cos(z) sin(z) 0;...
-sin(z) cos(z) 0;...
0 0 1];
% Rotation according to the SEQUENCE1 1)Yaw, 2)Pitch, 3)Roll
R_corr = R_x(roll) * R_y(pitch) * R_z(yaw);
% Rotation according to the SEQUENCE2 1)Roll, 2)Pitch, 3)Yaw
R_fissa = R_z(yaw) * R_y(pitch) * R_x(roll);
% Aircraft rotated according to MATLAB
fuso=R*fuselage;
wingsi=R*wings;
taila=R*tail;
% Aircraft rotated according to SEQUENCE1
FUSO=R_corr*fuselage;
wingsI=R_corr*wings;
tailA=R_corr*tail;
% Aircraft rotated according to SEQUENCE2
FUSOo=R_fissa*fuselage;
wingsIi=R_fissa*wings;
tailAa=R_fissa*tail;
figure (1)
hold on
xlabel('asse x');
ylabel('asse y');
zlabel('asse z');
axis equal
axis vis3d
grid on
plot3(N(1,:),N(2,:),N(3,:),'.k');
h2=plot3(E(1,:),E(2,:),E(3,:),'.k');
h3=plot3(D(1,:),D(2,:),D(3,:),'.k');
plot3(fuso(1,:),fuso(2,:),fuso(3,:),'.y');
h5=plot3(wingsi(1,:),wingsi(2,:),wingsi(3,:),'.y');
h6=plot3(taila(1,:),taila(2,:),taila(3,:),'.y');
plot3(FUSO(1,:),FUSO(2,:),FUSO(3,:),'.c');
h8=plot3(wingsI(1,:),wingsI(2,:),wingsI(3,:),'.c');
h9=plot3(tailA(1,:),tailA(2,:),tailA(3,:),'.c');
plot3(FUSOo(1,:),FUSOo(2,:),FUSOo(3,:),'.r');
h11=plot3(wingsIi(1,:),wingsIi(2,:),wingsIi(3,:),'.r');
h12=plot3(tailAa(1,:),tailAa(2,:),tailAa(3,:),'.r');
set(get(get(h2,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h3,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h5,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h6,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h8,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h9,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h11,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h12,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
legend('fixed coordinate system','angle2dcm',...
'SEQUENCE1',...
'SEQUENCE2')
hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Rotation around DOWN(yaw) only
fuso1=R_z(yaw)*fuselage;
wings1=R_z(yaw)*wings;
tail1=R_z(yaw)*tail;
% Rotation around DOWN(yaw) then EAST(pitch)
fuso2=R_y(-pitch)*fuso1;
wings2=R_y(-pitch)*wings1;
tail2=R_y(-pitch)*tail1;
% Rotation around DOWN(yaw) then EAST(pitch) then NORTH(roll)
fuso3=R_x(-roll)*fuso2;
wings3=R_x(-roll)*wings2;
tail3=R_x(-roll)*tail2;
figure (2)
hold on
xlabel('asse x');
ylabel('asse y');
zlabel('asse z');
axis equal
axis vis3d
grid on
plot3(N(1,:),N(2,:),N(3,:),'.k');
h14=plot3(E(1,:),E(2,:),E(3,:),'.k');
h15=plot3(D(1,:),D(2,:),D(3,:),'.k');
%%Ruotato lungo z di yaw
plot3(fuso1(1,:),fuso1(2,:),fuso1(3,:),'.b');
h17=plot3(wings1(1,:),wings1(2,:),wings1(3,:),'.b');
h18=plot3(tail1(1,:),tail1(2,:),tail1(3,:),'.b');
%%Ruotato lungo z di yaw e lungo y di pitch
plot3(fuso2(1,:),fuso2(2,:),fuso2(3,:),'.g');
h20=plot3(wings2(1,:),wings2(2,:),wings2(3,:),'.g');
h21=plot3(tail2(1,:),tail2(2,:),tail2(3,:),'.g');
%%Ruotato lungo z di yaw, lungo y di pitch e infine di roll lungo x
plot3(fuso3(1,:),fuso3(2,:),fuso3(3,:),'.m');
h23=plot3(wings3(1,:),wings3(2,:),wings3(3,:),'.m');
h24=plot3(tail3(1,:),tail3(2,:),tail3(3,:),'.m');
%%Ruotato lungo z di yaw, lungo y di pitch e di roll lungo x
plot3(FUSOo(1,:),FUSOo(2,:),FUSOo(3,:),'xr');
h26=plot3(wingsIi(1,:),wingsIi(2,:),wingsIi(3,:),'xr');
h27=plot3(tailAa(1,:),tailAa(2,:),tailAa(3,:),'xr');
% mi aspetto che la x rossa coincida con . il magenta
set(get(get(h14,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h15,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h17,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h18,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h20,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h21,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h23,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h24,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h26,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
set(get(get(h27,'Annotation'),'LegendInformation'),...
'IconDisplayStyle','off');
legend('fixed coordinate system','DOWN(yaw)',...
'DOWN(yaw)+EAST(pitch)',...
'DOWN(yaw)+EAST(pitch)+NORTH(roll)',...
'SEQUENCE2')
hold off

Answers (1)

Simulink Dude
Simulink Dude on 6 May 2011
You will have to map the meaning of your coordinate frame in the real world to that of the animation environment.
I used it in this example:

Categories

Find more on Automotive in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!