How to make a plane rotating with roll, pitch and yaw?

32 ビュー (過去 30 日間)
Alex
Alex 2016 年 3 月 20 日
コメント済み: Ced 2016 年 3 月 21 日
Hello!
Firstly, I want to thank to anyone who posted here, I really used some of the advices.
Secondly, I want to create a plan is rotating from an origin (lets say Center(0,0,0)) using angles in the three rotation axes.
So far, i have created a plane with fill3, resulting a parallelipiped shape (matchbox) (for the record, a 2d place could work also, using fill3 with 4 points).
The problem is that i do not know ho to rotate it. So far I have tried something with arrow3 which has as it input parameters the angles, but is not so suggestive and it " jumps" sometimes, for a group of angles.
Any thoughts?
Thank you!

回答 (2 件)

Chad Greene
Chad Greene 2016 年 3 月 20 日
I wrote a function to do this, it's called xyz2rpy. You can download it and check out the documentation here.

Ced
Ced 2016 年 3 月 20 日
編集済み: Ced 2016 年 3 月 20 日
Hi
you can use hgtransform objects. Andrew Gibiansky has a simple quadrotor simulator which uses them, you could have a look at his file on how he does it. The basic concept is the following ( I copied the sections out of his code, see link below):
1. combine all your patches, fill3 etc to be Children of an hgtransform object, something like this:
for i = 1:size(faces, 1)
h(i) = fill3(X(faces(i, :)), Y(faces(i, :)), Z(faces(i, :)), 'r');
hold on;
end
% Conjoin all prism faces into one object.
t = hgtransform;
set(h, 'Parent', t);
h = t;
2. Then, you can apply rotations are translations using the methods from the hgtransform class, e.g.
% Compute translation to correct linear position coordinates.
dx = data.x(:, t); % select translation of CoM at timestep t
move = makehgtform('translate', dx);
% Compute rotation to correct angles. Then, turn this rotation
% into a 4x4 matrix represting this affine transformation.
angles = data.theta(:, t);
rotate = rotation(angles); % Creates rotation matrix
rotate = [rotate zeros(3, 1); zeros(1, 3) 1];
% Move the quadcopter to the right place, after putting it in the correct orientation.
set(model,'Matrix', move * rotate);
Again, this is not my code (apart from 1-2 comments), but I have found it helpful before to start building visualizations. Here is the link to his github code:
One major flaw in the code (in my opinion) is that he regenerates the plot in each timestep. In my experience, this made it impossible for me to visualize something at "actual speed". To do so, only generate a plot in the first iteration, and then update the Data using
set(h_plot,'XData',new_x_data,'YData',new_y_data,'ZData',new_z_data);
in the following iterations.
  2 件のコメント
Alex
Alex 2016 年 3 月 21 日
編集済み: Alex 2016 年 3 月 21 日
Thank you for your answer!
I tried to just copy/paste the Gibiansky commands and used my plane to see if it works but I did not understood where that data structure is coming from.
Here, first save the rotation function:
% Compute rotation matrix for a set of angles. function data = rotation(angles) omega = angles(3); phi = angles(2); kappa = angles(1);
data = zeros(3);
data(:, 1) = [
cos(omega) * cos(phi)
cos(phi) * sin(omega)
- sin(phi)
];
data(:, 2) = [
cos(omega) * sin(phi) * sin(kappa) - cos(kappa) * sin(omega)
cos(omega) * cos(kappa) + sin(omega) * sin(phi) * sin(kappa)
cos(phi) * sin(kappa)
];
data(:, 3) = [
sin(omega) * sin(kappa) + cos(omega) * cos(kappa) * sin(phi)
cos(kappa) * sin(omega) * sin(phi) - cos(omega) * sin(kappa)
cos(phi) * cos(kappa)
];
end
% Then the script :
angles=[3, 40, 5]; p1 = [5 2 0.5 ]; p2 = [5 4 0.5 ]; p3 = [1 4 0.5 ]; p4 = [1 2 0.5 ];
x = [p1(1) p2(1) p3(1) p4(1) ]; y = [p1(2) p2(2) p3(2) p4(2) ]; z = [p1(3) p2(3) p3(3) p4(3) ];
h=fill3(x, y, z,1);
axis([-3 6 -1 6 -1 3]); axis vis3d; grid rotate3d on
xlabel('x'); ylabel('y'); zlabel('z'); t=hgtransform; set(h,'Parent',t); h=t;
% Compute translation to correct linear position coordinates.
dx = data.x(:, t); % select translation of CoM at timestep t
move = makehgtform('translate', dx);
% Compute rotation to correct angles. Then, turn this rotation
% into a 4x4 matrix represting this affine transformation.
angles = data.phi(:, t);
rotate = rotation_took(angles); % Creates rotation matrix
rotate = [rotate zeros(3, 1); zeros(1, 3) 1];
% Move the quadcopter to the right place, after putting it in the correct orientation.
set(model,'Matrix', move * rotate);
Could you please throw an eye?
I am still struggling to understand some parts of Matlab.
Thank you!
Ced
Ced 2016 年 3 月 21 日
No worries, rotations always end up confusing, no matter how much you use them...
So, the "rotation" function takes the 3 angles of rotation for roll-pitch-yaw (Tait-Bryan angles to be precise) and forms the rotation matrix. Are you familiar with rotation matrices? Note that there are many possible formulations of this, so if your plane seems to be turning the wrong direction, you have most likely selected the wrong one. If you are using roll-pitch-yaw as angles though, it should be ok.
Sorry, I must be blind... in which file is the "angles=[3, 40, 5] ... " part?
For the last bit:
The position and orientation of your plane are described by a translation vector (i.e. the position in space) and the rotation matrix (the orientation).
- dx is your translation vector
- The first rotate is the rotation matrix
The 4x4 result would be a way of combining both translation and rotation into a single object. You can pretty much ignore this, just plug your translation and rotation separately in there as Gibiansky did it.

サインインしてコメントする。

カテゴリ

Help Center および File Exchange3-D Scene Control についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by