LUA7: PID controller

This article shows how to implement a PID controller in LUA. For the XLogic implementation, please refer to XLogic4: PID controller.

Basics

A PID controller is a versatile control loop mechanism that compares an input reading with a set point and writes a control value based on the controller parameters and state.

Implementation

The required items and parameters are specified when creating the PID controller using the AddPidController() function. After that, the controller loop is automatically called every ta seconds.

Therefore it is sufficient to add the PID controller in the OnStartEvent() function. In this example we use the following parameters:

Name

Value

actualItemId"NETx\\VIRTUAL\\BuildingA\\Floor1\\RoomA\\Current"
setpointItemId"NETx\\VIRTUAL\\BuildingA\\Floor1\\RoomA\\Setpoint"
controlItemId"NETx\\VIRTUAL\\BuildingA\\Floor1\\RoomA\\Control"
ta10
Kp0.2
Ki0.0000222222
Kd0
minControlValue0
maxControlValue255
esumMin-2
esumMax65536
onChangetrue


Error rendering macro 'code': Invalid value specified for parameter 'lang'
function OnStartEvent()
	AddPidController("NETx\\VIRTUAL\\BuildingA\\Floor1\\RoomA\\Current", "NETx\\VIRTUAL\\BuildingA\\Floor1\\RoomA\\Setpoint", "NETx\\VIRTUAL\\BuildingA\\Floor1\\RoomA\\Control", 10, 0.2, 0.00002222222, 0, 0, 255, -2, 65536, true)
end

After the NETx Server has finished start-up, the PID controller is operational. Set a value for the set point. Vary the current value and watch how the control value changes accordingly.

Background information

Kp is the proportional factor which 1/P where P is the gain of the controller in K (Kelvin). Notable hardware vendors suggest for warm water heating a P of 5 K. Therefore, Kp for heating is 0.2.

Ki is calculated as Kp/Tr where Tr is the reset time in seconds of the controller. A typical value for warm water heating is 150 minutes . Thus, Ki = 0.2/150*60 = 0. 00002222222 for heating.

Article applies to the following products:

  • NETx BMS Platform R2 Build 1000+
  • NETx Multi Protocol Server R2 Build 1000+