I've got an initial quaternion , q0. And I get angular velocity measurments, I integrate the the velocities so I got 3 angles at 50Hz or so. How can make a quaternion based on the 3 angles? I can't just make 3 quaternions, can I?
So to make it clear.
Q.new=Q.new*Q.update(alfa,beta,gamma)
Q.new represents my current orientation in a quaternion, I want to update it by multiplying with a Q.update quaternion. How can I make the Q.update with the angles?
Thanks!
The easiest way to update the quaternions is by integrating the differential equation for a local rotation rate [Sola]. In a kinematic system, the angular velocity ω of a rigid body at any instantaneous time is described with respect to a fixed frame coinciding instantaneously with its body frame.
To rotate anything by quaternion q you just do q*p*q. inverse() . If p is a vector then you first convert it to "fake" quaternion by setting w=0 and x,y,z same as vector. If p is quaternion then you are good to go.
Quaternions provide an interesting alternative for representing the rotation of rigid bodies and have great advantages compared to Euler angles, i.e., lack of discontinuities and gimbal lock, and provision of mathematical simplicity.
Aircraft and rockets. Quaternions are vital for the control systems that guide aircraft and rockets. Let us think of an aircraft in flight. Changes in its orientation can be given by three rotations known as pitch, roll and yaw, represented by three arrays of numbers called matrices.
Forgive me thread necromancing, but the answers all seem to complicated and some, like me, may prefer this more 'convenient' approach:
Say omega=(alpha,beta,gamma) is the measured angular velocity vector of the gyros. Then we rotate
theta = ||omega||*dt; //length of angular velocity vector
many units (deg or rad dependent on gyro) around
v = omega / ( ||omega|| ); // normalized orientation of angular velocity vector
Thus, we can construct the rotation quaternion as:
Q.update = (cos(theta/2),v_x * sin(theta/2), v_y * sin(theta/2), v_z * sin(theta/2));
All that is left now is to rotate our current rotation by Q.update
. This is trivial:
Q.new = multiply_quaternions(Q.update,Q.new);
// note that Q.update * Q.new != Q.new * Q.update for quaternions
Done. Quaternions are beautiful, aren't they?
Some slides on gyros and quaternions that may be useful: http://stanford.edu/class/ee267/lectures/lecture10.pdf
I presume you are integrating euler angles because you like to make your life difficult. First and foremost the gyro does not directly integrate into your euler angles. If you are asking this question I'm going to assume you also don't know how to properly find rate of change euler angles from your gyro measurements. You need a transformation matrix for that to work. I highly recommend picking up a copy of Farrell's "Aided navagition" On page 57 he explains how to calculate the transformation matrix to change your gyro rates into Euler rates. But why bother when you can get your rate of change quaternion directly from the quaternion and your gyro data:
rate of change quaternion = qdot
quaternion = q
gyro quaternion = w = [0,gyrox,gyroy,gyroz]
so
qdot = 0.5 * q Ⓧ w
where Ⓧ represents the quaternion product. Be careful with your frames here. The gyro represents the angular rate of sensor frame with respect to the inertial frame represented in the sensor frame. That means your quaternion needs to represent a similar rotation from the sensor to the inertial frame. In this case it should represent a rotation from the inertial frame to the gyro frame. If we disregard things like the rotation of the earth the preceding equation is valid.
Be aware about "Aided Navigation." In my opinion his treatment of quaternions is very confusing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With