This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Underfloor Water heating - Night lowering
#3
You can modify PID library compute function like this. Then you need to specify night_mode (boolean, true = night mode) and setpoint_night (float16 or similar) addresses in PID init. After that restart your script via enable/disable so new library and parameters are loaded.

Code:
function PID:compute()
  local params, current, setpoint, deltasc, deltain, output

  params = self.params

  -- get input values
  current = grp.getvalue(params.current)
  setpoint = grp.getvalue(params.setpoint)

  if params.night_mode and grp.getvalue(params.night_mode) then
    setpoint = grp.getvalue(params.setpoint_night)
  end

  -- delta between setpoint and current
  deltasc = setpoint - current

  -- calculate new iterm
  self.iterm = self.iterm + params.ki * self.deltatime * deltasc
  self:clampiterm()

  -- delta between current and previous value
  deltain = current - self.previous

  -- calculate output value
  self.output = params.kp * deltasc + self.iterm
  self.output = self.output - params.kd / self.deltatime * deltain

  -- write to output
  self:setoutput()

  -- save previous value
  self.previous = current

  return self.output
end
Reply


Messages In This Thread
RE: Underfloor Water heating - Night lowering - by admin - 11.09.2018, 07:05

Forum Jump: