Using scipy package, which sequence to choose for Rotation.as_euler() - scipy

I'm trying to convert from quaternion to row pitch yaw using the as_euler() function, but I don't know which sequence to choose as the parameter "zyx", "xyz", "zyz", etc
Also what is the order of the output euler angles? Is it going to be [roll, pitch yaw] or [yaw, pitch, roll]?
Much thanks!

Yaw, pitch, roll axes are used for rotation around its principal axis sequentially. there exist twelve possible sequences which are;
Proper Euler Angles "z-x-z, x-y-x, y-z-y, z-y-z, x-z-x, y-x-y"
Tait–Bryan angles "x-y-z, y-z-x, z-x-y, x-z-y, z-y-x, y-x-z"
Most common usages is z-y-x in Tait-Bryan angles. "yaw" means rotate around z axis, "pitch" means rotate around y axis, "roll" means rotate around x axis.
If you use z-y-x order the euler-angles order is [yaw, pitch, roll]. You must choose the order depending on what field you work in.

Related

Computing Euler angles from rotation matrix: boundary cases

I want to compute the Euler angles from a rotation matrix in order to find out the orientation associated to that rotation. For that purpose, I am using MATLAB and the function rotm2eul that gives me the rotation first about x-axis, then about y-axis and finally the z-axis.
I am using a signal with 1000 frames and for each frame a rotation matrix is computed, as well, the three Euler angles. However, when I am going to see the Euler angles' curve, there is some "jumps" as I shown on the figures below.
On Technique 1, I think it jumps from -180º to 180º which should be the same. In fact, the upper portion of the plot seems a continuation of the lower portion. So in this case I thought I could subtract 360º to the upper portion to get the plot. But I am not sure if I do this I am falsifying the results.
On Technique 2, it makes a jump with a different reason of the previous one. I think it must be because the angle associated with the y-axis reaches 90º which should be a boundary case. But in this case I don't know how should I correct the data or , like previously, if I want to correct the plot is falsifying the euler angle result.
Technique 2: This is a Gimbal lock, known feature of Euler angles. You can't avoid it completely. You can change the rotation order, but it will appear in another position.

MATLAB flip definition of angles (or alternative angular metric)

I am doing work on symmetric images where I would like to define a symmetric (polar) coordinate space. Basically for the left image, I want 0 degrees to be defined along the right horizontal axis (as is the default). However, for the right image, I want 0 degrees to be defined along the left horizontal axis.
I know a phase shift of pi would do the trick. However, for comparison purposes, I am trying to keep the range of angles the same, [-pi : pi).
In the above color plot of the rotations in an object, note that they are both defined in the same direction. Ideally I'd like to see the colors of the right object flipped across its vertical axis.
I should note that these angles are calculated by taking the arctan(y/x) of the perimeter coordinates when measured from the centroid. Is there a different trig function that may result in the proper symmetry? I couldn't seem to come up with one while still claiming it was representative of direction.

How to calculate yxy rotation sequence given the quaternion transformation and how to interpret data

Still need the math: I am trying to calculate the yxy rotation sequence given a quaternion transformation. I can easily do this using Matlab's quat2angle function. However, I need to calculate this by hand using a python script.
This part solved: Please look at this awesome presentation which helped me resolve these issues below:
https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&uact=8&ved=0CCoQFjAC&url=http%3A%2F%2Fwww.udel.edu%2Fbiology%2Frosewc%2Fkaap686%2Freserve%2Fshoulder%2Fshoulder%2FBluePresentation.ppt&ei=jgRAVLHfOsSrogTJiYHABQ&usg=AFQjCNGFmwh11jEZen80jc3tM4f7HUQcNw&sig2=Dlr8_7TIFPLyUfJy6-pSJA&bvm=bv.77648437,d.cGU
Also, with Matlab, I am seeing strange results with the way they calculate yxy. I have a quaternion transformation of [1.0000 -0.0002 -0.0011 -0.0006] and I get y = 112.4291 x = -0.0719 y1 = -112.5506 (in degrees).
I don't expect to see any rotations here (my sensors aren't rotating). Why is Matlab showing me rotation? And when I try to just move in the x rotation, I see y and y1 also rotate, however, I don't expect y or y1 to be rotating. Any thoughts?
UPDATE:
When I add y + y1 I seem to get the value for the first y (when doing simple rotation around the first y), and this smooths out the data. However, when I combine the three rotations of the shoulder, the data doesn't make sense. I am trying to define shoulder movement based on plane of elevation, elevation and rotation (yxy) in a way that's easy to interpret. When I rotate around x, then the second y, I get "clipping" (data goes to 180 then -180 following positive trend for y1 and opposite happens for y), even though I start my sensors at the zero position. Also, If I try to rotate only around the second y, I see rotation in the x. That doesn't make any sense either. Any additional thoughts?
Note:
I am using 2 IMU sensors, taring them in the same orientation, holding one constant and rotating the other, calculating the relative rotation between them using quaternions, and then calculating the yxy rotation sequence angles.
In case anyone is interested in quaternion calculations and transformations. I solved it using this transformations library:
http://www.lfd.uci.edu/~gohlke/code/transformations.py.html
There are several functions in here using matrices, quaternions, and Euler rotations. And you can convert quaternions to several different Euler rotation sequences. Give thanks to the person who created this script.

Using the iPhone accelerometer in a car

I want to use the iPhones's accelerometer to detect motions while driving. I'm a bit confused what the accelerometer actually measures, especially when driving a curve.
As you can see in the picture, a car driving a curve causes two forces. One is the centripetal force and one is the velocity. Imagine the iPhone is placed on the dashboard with +y-axis is pointing to the front, +x-axis to the right and +z-axis to the top.
My Question is now what acceleration will be measured when the car drives this curve. Will it measure g-force on the -x-axis or will the g-force appear on the +y axis?
Thanks for helping!
UPDATE!
For thoses interested, as one of the answers suggested it measures both. The accelerometer is effected by centrifugal force and velocity resulting in an acceleration vector that is a combination of these two.
I think it will measure both. But don't forget that the sensor will measure gravity as well. So when your car is not moving, you will still get accelerometer readings. A nice talk on sensors in smartphones http://www.youtube.com/watch?v=C7JQ7Rpwn2k&feature=results_main&playnext=1&list=PL29AD66D8C4372129 (it's on android, but the same type of sensors are used in iphone).
Accelerometer measures acceleration of resultant force applied to it (velocity is not a force by the way). In this case force is F = g + w + c i.e. vector sum of gravity, centrifugal force (reaction to steering centripetal force, points from the center of the turn) and car acceleration force (a force changing absolute value of instantaneous velocity, points along the velocity vector). Providing Z axis of accelerometer always points along the gravity vector (which is rare case for actual car) values of g, w and c accelerations can be accessed in Z, X and Y coordinates respectively.
Unless you are in free fall the g-force (gravity) is always measured. If I understand your setup correctly, the g-force will appear on the z axis, the axis that is vertical in the Earth frame of reference. I cannot tell whether it will be +z or -z, it is partly convention so you will have to check it for yourself.
UPDATE: If the car is also going up/downhill then you have to take the rotation into account. In other words, there are two frames of reference: the iPhone's frame of reference and the Earth frame of reference. If you would like to deal with this situation, then please ask a new question.

Quaternions vs Axis + angle

I have been trying to find the difference between the 2 but to no luck minus this
The primary diff erence between
the two representations is that a quaternion’s axis of rotation is scaled
by the sine of the half angle of rotation, and instead of storing the angle in the
fourth component of the vector, we store the cosine of the half angle.
I have no idea what
sine of the half angle of rotation
or
cosine of the half angle
means?
Quaternios and Axis-angle are both 4D representations of 3D rotations/orientations and both have pro's and cons.
Axis-angle: represents the rotation by its angle a and the rotation axis n. For example, a rotation of 180 degrees around the Y-Axis would be represented as a = 180, n= {0,1,0}. The representation is very intuitive, but for actually applying the rotation, another representation is required, such as a quaternion or rotation matrix.
Quaternion: represents a rotation by a 4D vector. Requires more math and is less intuitive, but is a much more powerful representation. Quaternions are easily interpolated (blending) and it is easy to apply them on 3D point. These formula's can easily be found on the web. Given a rotation of a radians about a normalized axis n, the quaternion 4D vector will be {cos a/2, (sin a/2) n_x, (sin a/2) n_y, (sin a/2) n_z}. That's where the sine and cosine of the half angle come from.
It means that if you, for example, want to make a 180deg rotation around the Z axis (0,0,1), then the quaternion's real part will be cos(180deg/2)=0, and its imaginary part will be sin(180deg/2)*(0,0,1)=(0,0,1). That's q=0+0i+0j+1k. 90-degree rotation will give you q=cos(90deg/2)+sin(90deg/2)*(0i+0j+1k)=sqrt(2)/2+0i+0j+sqrt(2)/2*k, and so on.
OTOH, if you're asking what sine and cosine are, check if your languange provides sin() and cos() functions (their arguments will probably be in radians, though), and check out http://en.wikipedia.org/wiki/Sine.