Created
October 5, 2018 14:01
-
-
Save sroettgermann/e480f4507d1aa9ff826e7ebdf516c5bd to your computer and use it in GitHub Desktop.
matlab function to convert quaternion to euler angles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [phi_,theta_,psi_] = quat2euler(measurement_) | |
qw = measurement_.quat_w; | |
qx = measurement_.quat_x; | |
qy = measurement_.quat_y; | |
qz = measurement_.quat_z; | |
% roll - phi | |
sinr = 2 * (qw .* qx + qy .* qz); | |
cosr = 1 - 2 * (qx.^2 + qy.^2); | |
phi_ = atan2(sinr,cosr); | |
% pitch - theta | |
sinp = asin(2 * (qw .* qy - qz .* qx)); | |
%if (sinp > 1.0) | |
% sinp = 1.0; | |
%elseif (sinp < -1.0) | |
% sinp = -1.0; | |
%end | |
theta_ = asin(sinp); | |
% yaw - psi | |
siny = 2 * (qw .* qz + qx .* qy); | |
cosy = 1 - 2 * (qy.^2 + qz.^2); | |
psi_ = atan2(siny,cosy); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment