Posts

Quaternions as rotations in 3D

Just as a unit circle in the complex plane can be used to describe a rotation in one axis, quaternions using 3 imaginary numbers describe a rotation in 3 dimensions. According to Euler's rotation theorem , any complex rotation of any vector $\mathbf{p}\in \mathbb{R}^3$ about any axes can be replaced by a single rotation about the $\mathbf{v}=[v_x,v_y,v_z] $ by an angle $\theta$. Using quaternions, the rotation of a vector $\mathbf{p}$ can be represented by multiplication: \begin{equation}\mathbf{p}'=\mathbf{q}\mathbf{p}\mathbf{q}^{-1}=\mathbf{q}\mathbf{p}\mathbf{q}^*\label{eq:rotation}\end{equation} where vector $\mathbf{p}$ is treated as a pure quaternion - $\mathbf{p}= [0,p_x,p_y,p_z]$, and quaternion $\mathbf{q}$ in trygonmetric form is: \begin{equation}    \mathbf{q}=\cos{\frac{\theta}{2}}+[v_xi,v_yj,v_zk]\sin{\frac{\theta}{2}}\label{eq:trigonometric form written out}\end{equation} It can now be seen that the imaginary part of the quaternion can be treated as the vector def

Quaternions introduction

 Why quaternions? The quaternion notation is the least intuitive solution, but it has several advantages that make it very commonly used in many fields that deal with orientation in 3D space. First, however, the basic operations in the domain of quaternions as well as the assumptions made in the following chapters will be described. The main advantages will be seen in the next chapters, but this part is to give some awareness about quaternions properties used in the next operations. Although it is not necessary to understand quaternions up smallest detail, in my opinion, it is really pleasant to know how some mathematics, used in projects works. Also, I hope that this presentation of quaternions (of course not complete and probably fully correct in math rigor) will be more approachable for non-mathematicians. What are quaternions? Quaternions are just extensions of complex numbers.They have Real part - $Re(\mathbf{q})$ and Imaginary part - $Im(\mathbf{q})$ but instead of 1, there are 3

Transformation matrix

Image
The transformation matrix is a much wider concept but for purpose of orientation in 3D space, we will restrict it into a rotation matrix. So transformation matrix transform (wow) any vector from one reference frame in the other: \begin{gather} \mathbf{v}^{(0)}=\mathbf{R}_{1}^{0}\mathbf{v}^{(1)} \end{gather} Rotation matrix rotate any vector about a specific axis and about a set angle (in this example rotation of vector $\mathbf{v}=\left[\begin{array}{ccc} 1,1,1\end{array}\right]^T$ about $90^{\circ}$  in Z-axis): \begin{gather}\mathbf{v'=\mathbf{R}_z(90^{\circ})\mathbf{v}}=\left[\begin{array}{ccc} 0 & -1 & 0\\ 1 & 0 & 0\\    0 & 0 & 1   \end{array}\right]    \left[\begin{array}{c}1\\1\\1    \end{array}\right]=     \left[\begin{array}{c}      -1\\    1\\    1    \end{array}\right]\end{gather} It is important to see the difference between the transformation of a vector between references frames and the rotation of a vector. These two are related to each other

Euler angles or Tait-Bryan angles or yaw-pitch-roll?

Image
The most intuitive way to describe orientation is through Euler angles. The 3 angles tell about successive rotations about fixed axes. In these free rotations, you can achieve any orientation from every other. There are 12 possible combinations of these rotations. In 6 of them the first and third rotation is performed about the same axis (x-z-x, x-y-x, y-x-y, y-z-y, z-y-z, z-x-z) this convention was introduced by Leonhard Euler and these angles are called Euler angles. The other 6 possible combinations of rotations are about 3 different axes (x-y-z, x-z-y, y-x-z, y-z-x, z-y-x, z-x-y), called Tait-Bryan angles after their creators (these are also sometimes called Euler angles and to make it simpler will be included in this name). Note that each of these rotations can be performed in the system associated with the object (extrinsic rotations) or in an external, static system (intrinsic rotations). The mutual equivalences are as follows (left - rotations about the internal axes, right - r

LERP, NLERP and SLERP

Image
WHAT IS THAT AND WHY DO YOU NEED THIS? Whenever you've got 2 numbers and you want something between them, you want some kind of interpolation. And the same in quaternions - you have to quaternions that describe the same no one is 100% correct but 100% incorrect either, so you want a quaternion that is a combination of these two. So you can use the simplest idea of combining two numbers: \[\mathbf{q}_{3}=\alpha \mathbf{q}_{1} +(1-\alpha)\mathbf{q}_{2} \label{eq:LERP}\] this is LERP ( linear interpolation ) but since, for orientation porpuse quaternion need to have norm of 1, after this interpolation you need to normalize result: \[\mathbf{q}_{3}=norm(\alpha \mathbf{q}_{1} +(1-\alpha)\mathbf{q}_{2}) \label{eq:NLERP}\] and that is NLERP ( normalized linear interpolation ) . Now, how these methods could be interpreted, and what are the consequences in real applications?  If we imagine a circle with a radius of 1 which is going across quaternions that we want to interpolat

Introduction to my drone

Image
So the idea of this project was to create my own control system for UAV. I wanted to learn how to program robots and use in practical applications, stuff that I was studying at university.  I became from the FPV world so my drone is more or less created based on existing software such as Betaflight or Inav . Although I've known some basics about programming and drones it was hard to even start.  This drone (you can see it above) is the third iteration of this idea, so it has some more complex ideas behind it. But I would like to step back and write up some basics such as connecting into Flight Controller, configuring MCU, IMU. Also, I want to describe math behind the scene which is not so complex as every article suggest. I want to introduce Euler angles, matrix of rotation and quaternions which are in my opinion the most powerful and overall not so hard to understand.