How to make a plane rotating with roll, pitch and yaw?
조회 수: 36 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (2개)
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.
댓글 수: 0
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
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 Exchange에서 3-D Scene Control에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!