LightHub 4.6.0
Open-source smart home controller firmware
Loading...
Searching...
No Matches
out_pid Class Reference

PID controller output driver (CH_PID = 13). More...

#include <out_pid.h>

Inheritance diagram for out_pid:

Public Member Functions

 out_pid ()
 Default constructor.
void link (Item *_item)
 Attach to an item and grab its persistent PID state.
int Setup () override
 Allocate persistent state, load JSON config, initialize the PID controller.
int Poll (short cause) override
 Run the PID loop: compute output, apply it to the output item, watch the input-failure timer.
int Stop () override
 De-initialize and free the PID controller and persistent state.
int isActive () override
 True when the item command is not CMD_OFF.
int getChanType () override
 Channel type of the driver.
int Ctrl (itemCmd cmd, char *subItem=NULL, bool toExecute=true, bool authorized=false) override
 Handle /val (input), /set (setpoint) and /cmd|/ctrl (ON/OFF/ENABLE/DISABLE/RESET) commands.
void alarm (bool)
 Enter (state=true) or leave (state=false) the input-failure alarm; forces the alarmVal output on entry.
Public Member Functions inherited from abstractOut
 abstractOut ()
virtual bool isAllowed (itemCmd cmd)
virtual itemCmd getDefaultOnVal ()
virtual int Status () override
virtual void setStatus (uint8_t status) override
Item * getItem ()
Public Member Functions inherited from abstractCh
 abstractCh ()
virtual ~abstractCh ()

Protected Member Functions

bool getConfig ()
 Parse the item argument array, fill store and create the PID controller.
float getAlarmVal ()
 Get the forced output value used on alarm (alarmVal, or 0/255 by control direction).
Protected Member Functions inherited from abstractOut
int pubAction (bool state)
Protected Member Functions inherited from abstractCh
int publishTopic (const char *topic, long value, const char *subtopic=NULL)
int publishTopic (const char *topic, float value, const char *subtopic=NULL)
int publishTopic (const char *topic, const char *value, const char *subtopic=NULL, const char *suffix=NULL)

Protected Attributes

pidPersistent * store
Protected Attributes inherited from abstractOut
Item * item
 Item currently linked to this driver.

Detailed Description

PID controller output driver (CH_PID = 13).

Runs a classic PID loop (PID_v1) and steers an external output item (e.g. a dimmer) with the computed control value.

JSON config (item argument array):

[13,
[kP, kI, kD, dT, alarmTO, alarmVal, outMin, outMax], // PID params, 1..8 elems, or 6 elems
outputExecObj, // command object applied to the controlled output
cascadeExecObj] // optional: object receiving the setpoint (cascade)
  • PID params array, trailing elements are optional: kP, kI, kD, dT (sample time, sec), alarmTO (input-failure timeout, sec, default 600 s), alarmVal (forced output value applied on alarm), outMin, outMax (output limits, default 0..255). A negative kP selects REVERSE direction.
  • The initial setpoint is taken from the item "val" entry (default 20.0).

Control (Ctrl) suffixes:

  • /val - measured input value fed to the controller (also disarms the input-failure alarm);
  • /set - setpoint, additionally forwarded to cascadeExecObj;
  • /cmd - AUTO / HEAT / COOL / ON / OFF / ENABLE / DISABLE / RESET;
  • /ctrl - ENABLE / DISABLE (freeze the control action).

If no /val is received for alarmTO seconds the driver enters the alarm state and forces the output to alarmVal.

Constructor & Destructor Documentation

◆ out_pid()

out_pid::out_pid ( )
inline

Default constructor.

Member Function Documentation

◆ alarm()

void out_pid::alarm ( bool state)

Enter (state=true) or leave (state=false) the input-failure alarm; forces the alarmVal output on entry.

◆ Ctrl()

int out_pid::Ctrl ( itemCmd cmd,
char * subItem = NULL,
bool toExecute = true,
bool authorized = false )
overridevirtual

Handle /val (input), /set (setpoint) and /cmd|/ctrl (ON/OFF/ENABLE/DISABLE/RESET) commands.

Control unified PID controller item.

Implements abstractOut.

◆ getAlarmVal()

float out_pid::getAlarmVal ( )
protected

Get the forced output value used on alarm (alarmVal, or 0/255 by control direction).

◆ getChanType()

int out_pid::getChanType ( )
overridevirtual

Channel type of the driver.

Reimplemented from abstractOut.

◆ getConfig()

bool out_pid::getConfig ( )
protected

Parse the item argument array, fill store and create the PID controller.

◆ isActive()

int out_pid::isActive ( )
overridevirtual

True when the item command is not CMD_OFF.

Reimplemented from abstractOut.

◆ link()

void out_pid::link ( Item * _item)
inlinevirtual

Attach to an item and grab its persistent PID state.

Reimplemented from abstractOut.

◆ Poll()

int out_pid::Poll ( short cause)
overridevirtual

Run the PID loop: compute output, apply it to the output item, watch the input-failure timer.

Reimplemented from abstractCh.

◆ Setup()

int out_pid::Setup ( )
overridevirtual

Allocate persistent state, load JSON config, initialize the PID controller.

Reimplemented from abstractOut.

◆ Stop()

int out_pid::Stop ( )
overridevirtual

De-initialize and free the PID controller and persistent state.

Reimplemented from abstractCh.

Member Data Documentation

◆ store

pidPersistent* out_pid::store
protected

The documentation for this class was generated from the following files: