Skip to content

Getting started

Control library has been written in c++, the library is a set of object you can instanciate.

Each Controller is in a different file (pid.cpp, rst.cpp, pr.cpp).

It has mainly been developped to be used with The OwnTech Power API based on Zephyr and integrated with PlatformIO.


Control library has been designed to be integrated as a PlatformIO library.

To use it, you need to add the line below in the platformio.ini file.


    control_lib =

Using the Pid() Controller.

To introduce the control library, we propose to implement a PID regulator.

The use of the Pid is based on 3 steps.

  1. Object instanciation (declaration).
  2. Initialisation.
  3. Execution.

For each Controller like (Pid, Rst, Pr) we have to define a parameter structure.

We define constants used to initialize the parameter structure.

#include "pid.h"

static float32_t Ti = 7.5175e-5F;
static float32_t Td = 0.0F;
static float32_t N = 0.0F;
static float32_t upper_bound = 1.0F;
static float32_t lower_bound = 0.0F;
static float32_t Ts = 100.0e-6F;

We define the parameter structure. Each parameter is defined here.

static PidParams pid_params(Ts, kp, Ti, Td, N, lower_bound, upper_bound);

We define the variable pid which is a Pid object.

static Pid pid;

In the setup_routine() of the OwnTech Power API, you must initialize the Pid with its parameters.


In the loop_critical_task() you can call the method calculateWithReturn() which have two arguments:

  1. the reference
  2. the measure.
new_command = pid.calculateWithReturn(reference, measurement);

new_command is the result of the pid calculation for one step.


Remind that the loop_critical_task() is called at the sampling time you define and must be equal to \(T_s\).