Engee documentation
Notebook

Pressure regulation in the pipeline

The example demonstrates the Engee model of pipeline pressure regulation and the subsequent execution of the code generated from the model on an Arduino microcontroller.

Introduction

This example is the next stage in the development of the example "Modelling of pipeline pressure control". At the previous stage the technological part of the object was considered and debugging of the regulator for stabilisation of the set pressure was made, at the current stage the control system is extended by automatic setting of the changing pressure in the pipeline and blocks C Function for interaction of the control algorithm with the periphery of the microcontroller.

Control system model

The technology part of the model has the same representation as in the model of the previous project phase.

truboprovod_mai.png

The pipeline control system is integrated into the Controller subsystem for subsequent code generation.
The following main functional parts can be distinguished in this subsystem:

  • blocks C Function of interaction with the microcontroller periphery,
  • block Chart of formation of the set pressure in the pipeline,
  • PI-regulator subsystem.

truboprovod_subsystem.png

Peripheral interaction blocks have the following purpose:

  • ADC_A0 - reading and scaling of analogue signal from A0 output of Arduino microcontroller,
  • PWM - scaling of the control signal and transferring it to the PWM channel of the microcontroller to regulate the gate valve position,
  • Serial - to output to serial port an array of values: set and measured pressure, control signal.

The PI controller is represented in discrete elements and has the following coefficients: $k_П = 0.375 \cdot10^{-6}, 1/T_И = 0.875 \cdot10^{-6}$. The pressure setpoint block Chart represents a diagram with one parent and three child states, each of which forms its own pressure setpoint value. Switching between them is performed by the internal counter Cnt.

truboprovod_chart.png

Pressure control modelling

To simulate the operation of the control system, let's load and run the model arduino_pressure_regulator.engee:

In [ ]:
if "arduino_pressure_regulator" in [m.name for m in engee.get_all_models()]
    m = engee.open( "arduino_pressure_regulator" );
else
    m = engee.load( "$(@__DIR__)/arduino_pressure_regulator.engee" );
end

data = engee.run(m);

From the obtained modelling data we will plot the signals:

  • Chart.RefPress - set pressure in the pipeline,
  • Датчик давления.1 - measured pressure in the pipeline.
In [ ]:
using Plots
plotlyjs()
plot(data["Chart.RefPress"].time,
     data["Chart.RefPress"].value,
     label="Заданное давление",
     lw=2, size=(900,300), legend=:topright)
plot!(data["Датчик давления.1"].time,
     data["Датчик давления.1"].value,
     label="Измеренное давление", 
     lw=2)
Out[0]:

As can be seen in the graphs, the control system automatically generates a changing pressure set point and regulates the current pressure in the pipeline.

Code generation

Let's generate the code from the subsystem Controller for further loading the control algorithm into the microcontroller:

In [ ]:
engee.generate_code( "$(@__DIR__)/arduino_pressure_regulator.engee",
                     "$(@__DIR__)/Controller_code";
                     subsystem_name="Controller" )
[ Info: Generated code and artifacts: /user/start/examples/codegen/arduino_pressure_regulator/Controller_code

The files obtained in the directory Controller_code - arduino_pressure_regulator_Controller.h and arduino_pressure_regulator_Controller.c further we will use when connecting in the sketch pressure_controller.ino. Let's proceed to the execution of this sketch on the microcontroller.

Execution on the target device

To test the algorithm before debugging the Engee model for a real object in this example, we will use the Arduino MEGA2560 debug board. In the Arduino IDE environment we will compile and load the sketch with the C files generated from the model into the microcontroller. After loading, the following graphs can be observed in the serial port of the PC:

truboprovod_1080.gif

The graphs show how the control signal of the PI controller (third graph) changes when the current pressure in the pipeline changes (second graph, simulated signal).

Conclusion

In this demo, we have considered the development of a pipeline control model by automatically generating a given pressure using the Engee library of Engee automata followed by code generation and testing the execution of the developed control model on a target device.