Derivative of quaternion


When I was searching for uses of quaternions in orientation algorithms, there was always one equation that was shown with no explanation: 

(1)q˙(t)=12ωq(t)

but sometimes it was:

(2)q˙(t)=12ωq(t)

or

(3)q˙(t)=12q(t)ω

Moreover, when I was looking for any derivation of these formulas I found out that all resources were several pages - not very encouraging for me or derivations were not complete in their own calculations, which was even more frustrating when you were thinking that finally, you would understand this. 

So, I decided to do it myself in 2 ways: first more based on quaternion interpretation and the second old-fashion derivative from the definition. Also, I will discuss frames of reference in which all of the elements are presented. I will provide some transformations of an equation in which everything will be well described and you will be able to better understand equations used in many other resources. I highly recommend reading an Introduction to quaternions and Quaternions as rotations because although derivates are based on knowledge from basic calculus some of the properties of quaternions and their interpretation are needed to fully understand these calculations.

Let's start with the traditional derivate from the definition of derivative:

(4)q˙(t)=limΔt0q(t+Δt)q(t)Δt(5)q(t)=cos(ω2t)+vsin(ω2t)=cos(θ(t)2)+vsin(θ(t)2)(6)q(t+Δt)=q(Δt)q(t)=[cos(ω2Δt)+vsin(ω2Δt)][cos(ω2t)+vsin(ω2t)](7)q˙(t)=limΔt0(q(Δt)1)q(t)Δt

by using the approximations:    limΔx0cos(Δx)=1, limΔx0sin(Δx)=Δx:

(8)q˙(t)=limΔt0(1+vω2Δt1)q(t)Δt=limΔt0vω2ΔtΔtq(t)=12ωq(t)


Now, let's see a derivate which is for me really nice because it is based on the interpretation of quaternions as rotations. 

The quaternion describing the rotation from the initial position to the current position can be written as:

(9)q(t)=qωtq0

Next, assuming constancy of angular velocity ω=const. we can use an exponential form of quaternion and write:

 (10)qω=cosω2+vsinω2(11)qωt=evω2t(12)q˙(t)=ddt(qωtq0)=ddt(qωt)q0+qωtddtq0=evω2tvω2q0

from direct calculations it can be shown that     evω2tvω2=vω2evω2t ; additionally vω = ω so:

(13)q˙(t)=ω2evω2tq0=12ωq(t)

in general multiplication is not commutative. See end of this post for explenation. 

The above formulas for the derivative of the quaternion of rotation use the quaternion q which is the quaternion transforming from the drone-related system to the global frame. However, the quaternion describing the transformation from the global system to the local system is more commonly used. We know that:

(14)gbq=bgq1=bgq

analogically derivative:

(15)gbq˙=bgq˙

using a formula for conjugation of quaternions multiplication:

 (16)gbq˙=(12ωbgq(t))=12bgq(t)ω=12gbq(t)ω

Note, that the ω which was used in the above formulas is a vector in the global system. We were considering quaternions which were describing global rotation from default orientation to end one. The measurements of the gyroscope are taken in the local frame. Taking this into account, it can be written:

(17)gbq˙=12gbq(t)ω(g)=12gbq(t)(bgq(t)ω(b)bgq(t))==12gbq(t)bgq(t)ω(b)gbq(t)=12ω(b)gbq(t)

So, this is the final equation:

(18)gbq˙=12ω(b)gbq(t)

It takes gyroscope measurements in the local frame (drone frame) and quaternion that is describing transformation from global frame to local frame. 

If you want use the same quaternion but measurements are in the global frame you need to use:

(19)gbq˙=12gbq(t)ω(g)

If you have the measurements in global frame and quaternion describing the rotation from global to local frame you can use:

(20)bgq˙=12ω(g)bgq(t)

So, as you can see it is important to know what reference frame you're using and which quaternion is used but now you should be able to transform these equations if necessary, at least it is my hope.



Why evω2tvω2=vω2evω2t is correct?

So, if we decompose the formulas to the same forms:
(21)L: evω2tvω2=(cosω2t+vsinω2t)(0+vω2)(22)R: vω2evω2t=(0+vω2)(cosω2t+vsinω2t)
it is important that only vector v has imaginary symbols and rest of the components can be written as some scalars:
(23)L: (α1+vβ1)(α2+vβ2)(24)R: (α2+vβ2)(α1+vβ1)
now we can perform multiplication:
(25)L: α1α2+α1vβ2+vβ1α2+vβ1vβ2(26)R: α2α1+α2vβ1+vβ2α1+vβ2vβ1
rearranging components we can show that L=R:

(27)L: α1α2+v(α1β2+β1α2)+vvβ1β2(28)R: α2α1+v(α2β1+β2α1)+vvβ2β1




Comments

Popular posts from this blog

Hardware - how to start?

LERP, NLERP and SLERP