> For the complete documentation index, see [llms.txt](https://kraksat.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kraksat.gitbook.io/documentation/software/payload-software.md).

# Satellite state machine

Nine modes can be distinguished in the logic of the satellite’s payload operation. Five of them, that is the default logic, are shown in the diagram below.

![KRAKsat state machine](https://304735622-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_OaaGq_sXQV0Tmp9Pu%2F-LoGP1gi2X70e_khbnfr%2F-LoGP4QVgOT6CoIc5sgj%2Fstate_machine_kraksat%20\(9\).png?alt=media\&token=2ebe1a14-5e86-4f84-ba4f-48ed0f193755)

| Mode name            | Mode ID |
| -------------------- | ------- |
| IDLE                 | 0       |
| DETUMBLING           | 1       |
| DETUMBLING\_F        | 2       |
| EXPERIMENT           | 3       |
| EXPERIMENT\_F        | 4       |
| MANUAL               | 5       |
| DIAGNOSTIC           | 6       |
| DIAGNOSTIC\_F        | 7       |
| IDLE\_FOR\_TIME      | 8       |
| CURRENT\_MODE        | 9       |
| DETUMBLING\_SR\_MODE | 10      |

## Mode structure definition

| Property             | Description                                                                                         |
| -------------------- | --------------------------------------------------------------------------------------------------- |
| mode\_id             | The id of the mode.                                                                                 |
| init\_function       | The function that is executed within initialization of the mode.                                    |
| exit\_function       | The function that is executed immediately on the exit of the mode.                                  |
| condition\_exit      | The function that returns state enum when at least one of stop conditions of the mode is fulfilled. |
| condition\_entry     | The function that returns state enum when all of begin conditions of the mode are fulfilled.        |
| do\_custom\_function | The function that contains logic that is executed not in 1min/1s/200ms timer exception.             |
| do\_1min\_cycle      | The function that contains logic that is executed in 1min timer exception.                          |
| do\_1000ms\_cycle    | The function that contains logic that is executed not in 1s timer exception.                        |
| do\_200ms\_cycle     | The function that contains logic that is executed not in 200ms timer exception.                     |
| timer\_1s            | The default value that determines the maximum time of the mode duration \[s].                       |
| timer\_prescaler     | The value that is prescaler for property timer\_1s.                                                 |
| is\_timer\_active    | The property that determines if timer timer\_1s is active.                                          |
| next\_mode           | The mode that will be set as a following mode if condition\_entry equals SUCCESS.                   |
| failure\_mode        | The mode that will be set as a following mode if condition\_entry equals FAIL.                      |

{% tabs %}
{% tab title="IDLE" %}
IDLE mode is a low power consumption mode that is set as a middle mode in which the state machine waits for the fulfilment of the next mode’s begin conditions.

| Property             | Description                                                         |
| -------------------- | ------------------------------------------------------------------- |
| mode\_id             | 0                                                                   |
| init\_function       | None                                                                |
| exit\_function       | None                                                                |
| condition\_exit      | The stop condition is equal to the begin condition of the next mode |
| condition\_entry     | None                                                                |
| do\_custom\_function | None                                                                |
| do\_1min\_cycle      | IMU magnetometer sensor refresh                                     |
| do\_1000ms\_cycle    | None                                                                |
| do\_200ms\_cycle     | None                                                                |
| timer\_1s            | n/a                                                                 |
| timer\_prescaler     | 1                                                                   |
| is\_timer\_active    | False                                                               |
| next\_mode           | Diagnostic                                                          |
| failure\_mode        | Diagnostic                                                          |
| {% endtab %}         |                                                                     |

{% tab title="Diagnostic" %}
Diagnostic mode’s goal is to make measurements and control the actuator in such order in time to allow an observer to determine if all sensors and actuators are working correctly. The table bellow shows how measurement and actuator control is performed in time.

| Property             | Description                                                                                                                       |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| mode\_id             | 6                                                                                                                                 |
| init\_function       | Initialization of all actuators.                                                                                                  |
| exit\_function       | Stop of all actuators.                                                                                                            |
| condition\_exit      | <p>If power voltage < 9.5 then WAIT IN IDLE;<br>If temp F.R.W. temperature > 90 then FAIL;<br>If timer\_1s <= 0 then SUCCESS;</p> |
| condition\_entry     | If power voltage > 10 then SUCCESS.                                                                                               |
| do\_custom\_function | None                                                                                                                              |
| do\_1min\_cycle      | None                                                                                                                              |
| do\_1000ms\_cycle    | The function is described in section "Diagnostic algorithm"                                                                       |
| do\_200ms\_cycle     | None                                                                                                                              |
| timer\_1s            | 100                                                                                                                               |
| timer\_prescaler     | 1                                                                                                                                 |
| is\_timer\_active    | True                                                                                                                              |
| next\_mode           | Detumbling                                                                                                                        |
| failure\_mode        | Detumbling                                                                                                                        |
| {% endtab %}         |                                                                                                                                   |

{% tab title="Diagnostic Force" %}
Diagnostic force mode has the same function as Diagnostic mode. Only the entry and exit conditions differ.

| Property             | Description                                                                       |
| -------------------- | --------------------------------------------------------------------------------- |
| mode\_id             | 7                                                                                 |
| init\_function       | Initialization of all actuators.                                                  |
| exit\_function       | Stop of all actuators.                                                            |
| condition\_exit      | <p>If power voltage < 9 then WAIT IN IDLE;<br>If timer\_1s <= 0 then SUCCESS;</p> |
| condition\_entry     | If power voltage > 10 then SUCCESS.                                               |
| do\_custom\_function | None                                                                              |
| do\_1min\_cycle      | None                                                                              |
| do\_1000ms\_cycle    | The function is described in section "Diagnostic algorithm"                       |
| do\_200ms\_cycle     | None                                                                              |
| timer\_1s            | 100                                                                               |
| timer\_prescaler     | 1                                                                                 |
| is\_timer\_active    | True                                                                              |
| next\_mode           | Detumbling                                                                        |
| failure\_mode        | Detumbling                                                                        |
| {% endtab %}         |                                                                                   |

{% tab title="F.R.W. Experiment" %}
F.R.W. experiment mode’s goal is to control electromagnets in order to conduct acceleration of the ferrofluid. Its custom function is turned on by interrupts from timer 5.

| Property             | Description                                                                                                                        |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| mode\_id             | 3                                                                                                                                  |
| init\_function       | Initialization of PWM timers for F.R.W. magnetorquers.                                                                             |
| exit\_function       | Stop of PWM timers for F.R.W. magnetorquers.                                                                                       |
| condition\_exit      | <p>If power voltage < 9.5 then WAIT IN IDLE; <br>if temp F.R.W. temperature > 90 then FAIL;<br>if timer\_1s <= 0 then SUCCESS;</p> |
| condition\_entry     | If power voltage > 10 and temp F.R.W. temperature > 0 and temp F.R.W. temperature < 50 then SUCCESS;                               |
| do\_custom\_function | The function logic is described in section "F.R.W. control algorithm".                                                             |
| do\_1min\_cycle      | None                                                                                                                               |
| do\_1000ms\_cycle    | None                                                                                                                               |
| do\_200ms\_cycle     | None                                                                                                                               |
| timer\_1s            | 180                                                                                                                                |
| timer\_prescaler     | 1                                                                                                                                  |
| is\_timer\_active    | True                                                                                                                               |
| next\_mode           | IDLE time                                                                                                                          |
| failure\_mode        | IDLE time                                                                                                                          |
| {% endtab %}         |                                                                                                                                    |

{% tab title="F.R.W. Experiment Force" %}
F.R.W. experiment force mode has the same function as F.R.W. experiment mode. Only the entry and exit conditions differ.

| Property             | Description                                                                        |
| -------------------- | ---------------------------------------------------------------------------------- |
| mode\_id             | 3                                                                                  |
| init\_function       | Initialization of PWM timers for F.R.W. magnetorquers.                             |
| exit\_function       | Stop of PWM timers for F.R.W. magnetorquers.                                       |
| condition\_exit      | <p>If power voltage < 9 then WAIT IN IDLE; <br>if timer\_1s <= 0 then SUCCESS.</p> |
| condition\_entry     | If power voltage > 10 then SUCCESS.                                                |
| do\_custom\_function | The function logic is described in section "F.R.W. control algorithm".             |
| do\_1min\_cycle      | None                                                                               |
| do\_1000ms\_cycle    | None                                                                               |
| do\_200ms\_cycle     | None                                                                               |
| timer\_1s            | 180                                                                                |
| timer\_prescaler     | 1                                                                                  |
| is\_timer\_active    | True                                                                               |
| next\_mode           | IDLE time                                                                          |
| failure\_mode        | IDLE time                                                                          |
| {% endtab %}         |                                                                                    |

{% tab title="Detumbling" %}
Detumbling mode’s goal is to reduce the angular velocity of the satellite. The implemented algorithm calculates and adjusts a control on 3 magnetorquers based on IMU sensor data. If detumbling doesn't succeed, the payload will go to Detumbling SR mode and trigger the algorithm embedded in the ADCS module.

| Property             | Description                                                                                                                                                                       |
| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| mode\_id             | 1                                                                                                                                                                                 |
| init\_function       | Initialization of PWM timer for ADCS magnetorquers.                                                                                                                               |
| exit\_function       | Stop of PWM timer for ADCS magnetorquers.                                                                                                                                         |
| condition\_exit      | <p>If power voltage < 9.5 or temp F.R.W. temperature > 80 then WAIT IN IDLE;<br>If timer\_1s <= 0 then FAIL;</p><p>If average angular speed in all axes <  5°/s then SUCCESS;</p> |
| condition\_entry     | If power voltage > 10 and temp F.R.W. temperature < 60  then SUCCESS.                                                                                                             |
| do\_custom\_function | None                                                                                                                                                                              |
| do\_1min\_cycle      | None                                                                                                                                                                              |
| do\_1000ms\_cycle    | None                                                                                                                                                                              |
| do\_200ms\_cycle     | The function logic is described in section "Detumbling algorithm".                                                                                                                |
| timer\_1s            | 10800                                                                                                                                                                             |
| timer\_prescaler     | 1                                                                                                                                                                                 |
| is\_timer\_active    | True                                                                                                                                                                              |
| next\_mode           | F.R.W. experiment                                                                                                                                                                 |
| failure\_mode        | Detumbling SR                                                                                                                                                                     |
| {% endtab %}         |                                                                                                                                                                                   |

{% tab title="Detumbling force" %}
Detumbling force mode has the same function as Detumbling mode. Only the entry and exit conditions differ.

| Property             | Description                                                                                                                                     |
| -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| mode\_id             | 2                                                                                                                                               |
| init\_function       | Initialization of PWM timer for ADCS magnetorquers.                                                                                             |
| exit\_function       | Stop of PWM timer for ADCS magnetorquers.                                                                                                       |
| condition\_exit      | <p>If power voltage < 9 then WAIT IN IDLE;<br>If timer\_1s <= 0 then FAIL;</p><p>If average angular speed in all axes <  5°/s then SUCCESS.</p> |
| condition\_entry     | If power voltage > 10 then SUCCESS.                                                                                                             |
| do\_custom\_function | None                                                                                                                                            |
| do\_1min\_cycle      | None                                                                                                                                            |
| do\_1000ms\_cycle    | None                                                                                                                                            |
| do\_200ms\_cycle     | The function logic is described in section "Detumbling algorithm".                                                                              |
| timer\_1s            | 10800                                                                                                                                           |
| timer\_prescaler     | 1                                                                                                                                               |
| is\_timer\_active    | True                                                                                                                                            |
| next\_mode           | F.R.W. experiment                                                                                                                               |
| failure\_mode        | F.R.W. experiment                                                                                                                               |
| {% endtab %}         |                                                                                                                                                 |

{% tab title="Detumbling SR" %}
Detumbling SR mode triggers detumbling algorithm embedded in the OBC board. No action is performed by the microcontroller in the Payload module.

| Property             | Description                                                                  |
| -------------------- | ---------------------------------------------------------------------------- |
| mode\_id             | 10                                                                           |
| init\_function       | Initialization of detumbling algorithm embedded in the OBC board.            |
| exit\_function       | Stop of detumbling algorithm embedded in the OBC board.                      |
| condition\_exit      | <p>If OBC transmit SUCCESS then SUCCESS;<br>If timer\_1s <= 0 then FAIL.</p> |
| condition\_entry     | None                                                                         |
| do\_custom\_function | None                                                                         |
| do\_1min\_cycle      | Check register table if OBC transmit SUCCESS.                                |
| do\_1000ms\_cycle    | None                                                                         |
| do\_200ms\_cycle     | None                                                                         |
| timer\_1s            | 2700                                                                         |
| timer\_prescaler     | 1                                                                            |
| is\_timer\_active    | True                                                                         |
| next\_mode           | F.R.W. experiment                                                            |
| failure\_mode        | F.R.W. experiment                                                            |
| {% endtab %}         |                                                                              |

{% tab title="Manual" %}
Manual mode is a mode that controls ADCS magnetorquers based on commands from the ground station.

| Property             | Description                                                                   |
| -------------------- | ----------------------------------------------------------------------------- |
| mode\_id             | 5                                                                             |
| init\_function       | Initialization of PWM timer for ADCS magnetorquers.                           |
| exit\_function       | Stop of PWM timer for ADCS magnetorquers.                                     |
| condition\_exit      | <p>If timer\_1s <= 0 then SUCCESS;</p><p>If battery\_volt<9 then FAILURE.</p> |
| condition\_entry     | If battery\_volt>10 then SUCCESS.                                             |
| do\_custom\_function | None                                                                          |
| do\_1min\_cycle      | None                                                                          |
| do\_1000ms\_cycle    | ADCS magnetorquers control and IMU magnetometer sensor refresh.               |
| do\_200ms\_cycle     | None                                                                          |
| timer\_1s            | 10800\* timer\_prescaler                                                      |
| timer\_prescaler     | 1                                                                             |
| is\_timer\_active    | True                                                                          |
| next\_mode           | IDLE                                                                          |
| failure\_mode        | IDLE                                                                          |
| {% endtab %}         |                                                                               |

{% tab title="IDLE time " %}
IDLE TIME mode is a low power consumption mode that is set to wait for a long period of time for recharging batteries and cooling coils. IDLE TIME mode lasts for 48h or while special log buffer is not full and the battery is charged above 10V.

| Property             | Description                                                                              |
| -------------------- | ---------------------------------------------------------------------------------------- |
| mode\_id             | 8                                                                                        |
| init\_function       | None                                                                                     |
| exit\_function       | None                                                                                     |
| condition\_exit      | If timer\_1s <= 0 or (battery\_volt>10 and special log buffer is not full) then SUCCESS; |
| condition\_entry     | None                                                                                     |
| do\_custom\_function | None                                                                                     |
| do\_1min\_cycle      | IMU magnetometer sensor refresh                                                          |
| do\_1000ms\_cycle    | None                                                                                     |
| do\_200ms\_cycle     | None                                                                                     |
| timer\_1s            | 2880 \* timer\_prescaler                                                                 |
| timer\_prescaler     | 60                                                                                       |
| is\_timer\_active    | True                                                                                     |
| next\_mode           | Diagnostic mode                                                                          |
| failure\_mode        | Diagnostic mode                                                                          |
| {% endtab %}         |                                                                                          |
| {% endtabs %}        |                                                                                          |

## Diagnostic algorithm

The diagnostic algorithm is used to validate proper functioning of satellite's hardware. This procedure toggles certain actuators in predefined intervals. Simultaneously, measurements from the IMU and the temperature sensor that is attached to the payload container are taken.

| Timeline | Step                          |
| -------- | ----------------------------- |
| 15 s     | Only measurements             |
| 10 s     | ADCS magnetorquer X           |
| 10 s     | ADCS magnetorquer Y           |
| 10 s     | ADCS magnetorquer Z           |
| 15 s     | Only measurements             |
| 10 s     | F.R.W. electromagnets phase 0 |
| 10 s     | F.R.W. electromagnets phase 1 |
| 10 s     | F.R.W. electromagnets phase 2 |
| 10 s     | F.R.W. electromagnets phase 3 |

## F.R.W. control algorithms

F.R.W. control algorithms are designed to control electromagnets in order to accelerate the ferrofluid. Its custom function is turned on by interruption from timer 5. F.R.W. can work in 9 different modes which are listed in the table below. More information about control system of the Ferrofluid Reactio Wheel can be found in: Jan Życzkowski, "Ferrofluid reaction wheel for nanosatellites orientation control", Master Thesis, AGH University of Science and Technology, Cracow 2019, supervisor: Adam Piłat.&#x20;

| Control mode               | mode ID |
| -------------------------- | ------- |
| FRW\_BAISIC\_CLOCKWISE     | 0       |
| FRW\_BAISIC\_ANTICLOCKWISE | 1       |
| FRW\_ACC\_CLOCKWISE        | 2       |
| FRW\_ACC\_ANTICLOCKWISE    | 3       |
| FRW\_STEP\_CLOCKWISE       | 4       |
| FRW\_STEP\_ANTICLOCKWISE   | 5       |
| FRW\_PID\_DUTY             | 6       |
| FRW\_PID\_FREQ             | 7       |
| FRW\_LIST\_MODE            | 8       |

####

{% tabs %}
{% tab title="FRW\_ControlBasicClockwise:" %}
FRW\_ControlBasicClockwise works as a universal control. It is possible to change its parameters:

| Parameter    | Details                                                                                                             |
| ------------ | ------------------------------------------------------------------------------------------------------------------- |
| pwm\_duty    | duty of coils PWM                                                                                                   |
| period       | period with which 4 coils are working, in ms. Period of the is F.R.W. two times larger                              |
| pwm\_direct  | direction of the current going through coils (it is not the direction for F.R.W.)                                   |
| control duty | percentage of time every phase is tuned on during cycle (e.g. 25 - one-step, 37 - one and half-step, 50 - two-step) |

To control F.R.W. in opposite direction use function: FRW\_ControlBasicAntiClockwiseFunction.

![FRW Baisic control diagram](https://304735622-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_OaaGq_sXQV0Tmp9Pu%2F-L_s--hRe98LgdzDvZWa%2F-L_s1aAEHCZTHJ9cKw15%2Fcontrol_baisic%20-%20Copy.PNG?alt=media\&token=85995423-eb45-4cc5-aea6-ef3583a58680)

|              |
| ------------ |
| {% endtab %} |

{% tab title="FRW\_ControlAcceleratingClockwise:" %}
FRW\_ControlAcceleratingClockwise works like the basic mode, with changing frequency over time. It has some additional parameters:

| Parameter          | Details                                                                                      |
| ------------------ | -------------------------------------------------------------------------------------------- |
| start\_period      | Starting period for 4 coils                                                                  |
| stop\_period       | ending period for 4 coils                                                                    |
| acceleration\_time | Time of acceleration in seconds. After this time, F.R.W\.will work with period: stop\_period |

To control F.R.W. in opposite direction use function: FRW\_ControlAcceleratingAntiClockwise.

![FRW acceleration control diagram](https://304735622-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_OaaGq_sXQV0Tmp9Pu%2F-L_s--hRe98LgdzDvZWa%2F-L_s1aA9WKE1aq7eEcUJ%2Fcontrol_acc%20-%20Copy.PNG?alt=media\&token=bfbf74bb-26bc-4cab-b2b3-3633f50e9da4)
{% endtab %}

{% tab title="Algorithm FRW\_ControlStepClockwise:" %}
FRW\_ControlStepAntiClockwise is an experimental asymetric control with the following parameters:

| Parameter       | Details                                                                           |
| --------------- | --------------------------------------------------------------------------------- |
| period          | period with which 4 coils are working, in ms                                      |
| coils\_on\_time | Time of one phase turned on, in ms                                                |
| phase\_delay    | delay in turning on phases, in ms                                                 |
| pwm\_direct     | direction of the current going through coils (it is not the direction for F.R.W.) |
| pwm\_duty       | duty of coils PWM                                                                 |

The function works when:

* period>3∗phase\_delay+coils\_on\_time
* coils\_on\_time>2∗phase\_delay

To control F.R.W. in the opposite direction use function: Algorithm FRW\_ControlStepAntiClockwise.

![FRW Step control diagram](https://304735622-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_OaaGq_sXQV0Tmp9Pu%2F-L_s--hRe98LgdzDvZWa%2F-L_s1aACA0b2nuAvzEU9%2Fcontrol_step%20-%20Copy.PNG?alt=media\&token=82b83b99-9278-4485-b0a6-4f75aeb0202e)
{% endtab %}

{% tab title="FRW\_ControlPID\_duty:" %}
FRW\_ControlPID\_duty aim is to stabilize satellite rotation according to Z axis to value given in INIT\_FRW\_MODE\_DUTY (degrees/s). It uses mesurements done by gyroscope. There are 3 constants: Ki\_duty, Kp\_duty and Kd\_duty - which can be changed from Earth using IMU paramconfig.
{% endtab %}

{% tab title="FRW\_ControlPID\_frequency:" %}
The purpose of FRW\_ControlPID\_frequency is to stabilize satellite rotation according to Z axis to value given in INIT\_FRW\_MODE\_FREQ (degrees/s). It uses mesurements done by gyroscope. There are 3 constants: Ki\_freq, Kp\_freq and Kd\_freq - which can be changed from the Earth using IMU paramconfig.
{% endtab %}

{% tab title="FRW\_Control\_list:" %}
FRW\_Control\_list enables the user to create their own control. It is done by performing all instructions from the control list. To add an instruction to the list, use command 240 which consists of:&#x20;

| Parameter     | Details                                                              |
| ------------- | -------------------------------------------------------------------- |
| coil          | phase which should be changed                                        |
| time          | time till next action \[ms]                                          |
| dir           | direction of current in phase - 0 for clockwise, 1 for anticlockwise |
| duty          | duty for changed phase                                               |
| reset         | 1- for cleaning all data on the list, 0 - to add instruction         |
| {% endtab %}  |                                                                      |
| {% endtabs %} |                                                                      |

## Detumbling algorithm

### Detumbling modes high level logic

![Detumbling high level logic](https://304735622-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_OaaGq_sXQV0Tmp9Pu%2F-L_chZpe9OsiVPc_GNxy%2F-L_csIyoBI6yTESnnpaq%2Fadcs_workflow.png?alt=media\&token=40b648c6-78ef-4f38-976c-003819e43e19)

### Detumbling algorithm

The payload detumbling algorithm uses magnetorquers in all three satellite axes. A magnetorquer is an electromagnet which due to current flow creates a magnetic moment which interfaces with the Earth'a magnetic field. This creates a torque acting on the satellite. Thus, being able to control the current flowing through the coil (the words coil and electromagnet will be used interchangeably)  enables controling the angular velocity of the satellite. The equation used to calculate the torque created by the electromagnet is shown below:

$$
\vec{M}=\vec{\mu} \times \vec{B}
$$

Where $$\vec{M}$$is the created torque, $$\vec{\mu}$$is the magnetic moment and $$\vec{B}$$ is the Earth's magnetic field's induction.

![The operation of a magnetorquer](https://304735622-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_OaaGq_sXQV0Tmp9Pu%2F-Lv1LXj7vLm_fhNVtASi%2F-Lv1S1hLfsYsxjbuPhXQ%2Fmagnetorquer.jpg?alt=media\&token=da0a7d07-e093-44a3-90cf-fc8e22edd8e5)

The algorithm is based on the so-called Angular Rate Feedback algorithm. The equation used to calculate the needed current in each of the coils is shown below (the current in each coil is one of the components of the current vector):

​

$$
\dot{\vec{B}} = \vec{B}\times\omega
$$

$$
\vec{i} = -k \frac{\dot{\vec{B}}}{ \left\lVert B  \right\rVert ^2}
$$

The optimal value of *k* was chosen after conducting simulations on a model of the satellite. An appropriate PWM signal is passed on the inputs of H-bridges, which control the current of the magnetorquers.

One cycle of the algorithm consists of five steps; the time interval between those steps is 200 ms (so the whole algorithm cycle is 1s).&#x20;

* Step 1: At the beginning of this step, the current in all coils is always zero. The magnetic field induction (B) is measured (because no current flows through the magnetorquers, their magnetic field has no influence on the measurement). Also the angular velocity of the satellite is acquired. The output current of the coils is calculated using the above equation and the current of the coils is changed.
* Step 2, 3, 4: In each of these steps the magnetic field induction in the satellite-oriented reference frame is estimated and the angular velocity is measured. Apart from that, the operations are the same as in step 1
* Step 5: The current of the coils is set to 0, so that the magnetic field induction can be measured in step 1. Return to step 1.

The estimation of the magnetic field induction in the satellite-oriented reference frame is conducted as follows: it is assumed that it is constant in the Earth-oriented frame and it changes because of the non-zero angular velocity of the satellite (which is measured). So, the magnetic field induction can be estimated as:

$$
\vec{B}(t+\Delta t) \approx \vec{B}(t) + \dot{\vec{B}}\Delta t,
$$

where:

$$
\Delta t = 200 ms.
$$

More information about detumbling system can be found in: Artur Hadasz, "Simulation of stabilization algorithms and building a prototype of a stabilization system for picosatellites using magnetorquers", BSc Thesis, AGH University of Science and Technology, Cracow 2018, supervisor: Paweł Zagórski and in the work: Piotr Mikołajek, "Design and simulation of a picosatellite low Earth orbit magnetic field based attitude determination system", BSc Thesis, AGH University of Science and Technology, Cracow 2018, supervisor: Paweł Zagórski.&#x20;
