Posts

Filters - Theory

Image
 Filters  In this post, I want to present the theory needed for digital filter design. Firstly, a quick description of mainly used filters in the continuous domain - I want to give you some intuition in interpreting the transform functions. Next, I will present practical discretization from the '$s$' domain into the '$z$' (discrete time). Finally, a difference equation will be provided which can be directly programmed on any microprocessor. In a future post, I will show the possible implementation of described filters. In essence, the filter should block undesirable frequencies and let others pass through without distortion. For our applications, we can divide filters into 4 main categories: Low-pass filters High-pass filters Band-pass filters Notch filters Low-pass filter As the name suggests this filter allows low frequencies to pass and suppress high ones. The simplest LPF is a system with one pole: \begin{gather}H(s)=\frac{\omega_{0}}{s+\omega_{0}}\end{gather} A typ

Hardware - how to start?

Image
Introduction The first problem when it comes to programming robots is what hardware should I use and how to set up everything? The easiest solution is to use Arduino which is pretty user-friendly and on the Internet, there are thousands of tutorials about it. However, sometimes Arduino is not powerful enough (usually is more than enough). But you need to use something with more capabilities? Or you just want to be more "professional" than using a simple Arduino. The commonly-known and willingly chosen solutions are STM32 microchips and boards. With HAL library and STM32 Cube IDE gives tons of possibilities without being too overwhelming (nevertheless, this is a significant step-up of complexity referring to the Arduino). Fortunately, there are many resources and guides on this topic - in my opinion, this is the way to start. But if you want to step deeper and don't want to use functions that you don't understand, here comes STM32 and programming on registers. This is

Derivative of quaternion

Image
When I was searching for uses of quaternions in orientation algorithms, there was always one equation that was shown with no explanation:  \begin{gather}\dot{\mathbf{q}}(t)=\frac{1}{2}\boldsymbol{\omega}\mathbf{q}(t) \end{gather} but sometimes it was: \begin{gather}\dot{\mathbf{q}}(t)=-\frac{1}{2}\boldsymbol{\omega}\mathbf{q}(t) \end{gather} or \begin{gather}\dot{\mathbf{q}}(t)=-\frac{1}{2}\mathbf{q}(t) \boldsymbol{\omega}\end{gather} 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 transfo

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