Assistance with Fine Tuning


#1

Hey, I recently ran into some problems with my set up and ended up resetting my brew pi.

I’m pretty much all back up and running now, however with a fermenter full of water as a test run, it seems that my beer temperature ends up sitting about 0.5 to 0.6 degrees above the set temperature (currently running in beer constant) see graphs below.

I noticed that the heater was kicking quite a lot in so I tried adjusting the dead time between actuators (image 3). but this didn’t change much.

Currently I have the advanced settings as follows:

Beer-to-Fridge proportional gain (Kp) = 2
Beer-to-Fridge integral time constant (Ti) = 7200
Beer-to-Fridge derivative time constant (Td) = 1200
Maximum difference between fridge and beer set point (= output of PID) = 10
Beer-to-Fridge Input filter delay time = 18 seconds
Beer-to-Fridge Derivative filter delay time = 159 seconds

Cooler proportional gain (Kp) = 5
Cooler integral time constant (Ti) = 2400
Cooler derivative time constant (Td) = 60
Cooler PWM period (seconds) = 1200
Cooler minimum OFF time = 180
Cooler minimum ON time = 120
Cooler Input filter delay time = 18 seconds
Cooler Derivative filter delay time = 159 seconds

Heater 1 proportional gain (Kp) = 5
Heater 1 integral time constant (Ti) = 2400
Heater 1 derivative time constant (Td) = 60
Heater 1 PWM period (seconds) = 4
Heater 1 Input filter delay time = 18 seconds
Heater 1 Derivative filter delay time = 159 seconds

I don’t have a second heater but this is what its set at anyway.

Heater 2 proportional gain (Kp) = 10
Heater 2 integral time constant (Ti) = 600
Heater 2 derivative time constant (Td) = 60
Heater 2 PWM period (seconds) = 4
Heater 2 Input filter delay time = 18 seconds
Heater 2Derivative filter delay time = 159 seconds

Dead time when switching between actuators = 360

My set up is:

Spark photon V2 running 0.5.2 with a Rpi 2B
120L bar fridge, 25 watt heat matt, fridge temp sensor, beer temp sensor installed in a thermowell.

Controll Algorithm as follows:

{
  "kind": "Control",
  "pids": [
    {
      "kind": "Pid",
      "name": "heater1pid",
      "enabled": true,
      "input": {
        "kind": "SensorSetPointPair",
        "sensor": {
          "kind": "TempSensorFallback",
          "onBackupSensor": false,
          "sensor": {
            "kind": "TempSensorDelegate",
            "name": "fridge",
            "delegate": {
              "kind": "OneWireTempSensor",
              "value": 23.5625,
              "connected": true,
              "address": "286471360700009A",
              "calibrationOffset": 0
            }
          }
        },
        "setPoint": {
          "kind": "SetPointSimple",
          "name": "fridgeset",
          "value": 23.293
        }
      },
      "output": {
        "kind": "ActuatorPwm",
        "dutySetting": 0,
        "period": 4,
        "minVal": 0,
        "maxVal": 100,
        "target": {
          "kind": "ActuatorMutexDriver",
          "mutexGroup": {
            "kind": "ActuatorMutexGroup",
            "deadTime": 360000,
            "waitTime": 308736
          },
          "target": {
            "kind": "ActuatorDigitalDelegate",
            "name": "heater1",
            "delegate": {
              "kind": "ActuatorPin",
              "state": false,
              "pin": 16,
              "invert": true
            }
          }
        }
      },
      "inputError": 0.1094,
      "Kp": 5,
      "Ti": 2400,
      "Td": 60,
      "p": -0.5469,
      "i": 0.5313,
      "d": -1.9336,
      "actuatorIsNegative": false
    },
    {
      "kind": "Pid",
      "name": "heater2pid",
      "enabled": true,
      "input": {
        "kind": "SensorSetPointPair",
        "sensor": {
          "kind": "TempSensorDelegate",
          "name": "beer2",
          "delegate": {
            "kind": "TempSensorDisconnected",
            "value": null,
            "connected": false
          }
        },
        "setPoint": {
          "kind": "SetPointSimple",
          "name": "beer2set",
          "value": null
        }
      },
      "output": {
        "kind": "ActuatorPwm",
        "dutySetting": 0,
        "period": 4,
        "minVal": 0,
        "maxVal": 100,
        "target": {
          "kind": "ActuatorMutexDriver",
          "mutexGroup": {
            "kind": "ActuatorMutexGroup",
            "deadTime": 360000,
            "waitTime": 308733
          },
          "target": {
            "kind": "ActuatorDigitalDelegate",
            "name": "heater2",
            "delegate": {
              "kind": "ActuatorNop",
              "state": false
            }
          }
        }
      },
      "inputError": null,
      "Kp": 10,
      "Ti": 600,
      "Td": 60,
      "p": 0,
      "i": 0,
      "d": 0,
      "actuatorIsNegative": false
    },
    {
      "kind": "Pid",
      "name": "coolerpid",
      "enabled": true,
      "input": {
        "kind": "SensorSetPointPair",
        "sensor": {
          "kind": "TempSensorFallback",
          "onBackupSensor": false,
          "sensor": {
            "kind": "TempSensorDelegate",
            "name": "fridge",
            "delegate": {
              "kind": "OneWireTempSensor",
              "value": 23.5625,
              "connected": true,
              "address": "286471360700009A",
              "calibrationOffset": 0
            }
          }
        },
        "setPoint": {
          "kind": "SetPointSimple",
          "name": "fridgeset",
          "value": 23.293
        }
      },
      "output": {
        "kind": "ActuatorPwm",
        "dutySetting": 15.9883,
        "period": 1200,
        "minVal": 0,
        "maxVal": 100,
        "target": {
          "kind": "ActuatorMutexDriver",
          "mutexGroup": {
            "kind": "ActuatorMutexGroup",
            "deadTime": 360000,
            "waitTime": 308730
          },
          "target": {
            "kind": "ActuatorTimeLimited",
            "minOnTime": 120,
            "minOffTime": 180,
            "maxOnTime": 65535,
            "state": false,
            "target": {
              "kind": "ActuatorDigitalDelegate",
              "name": "cooler",
              "delegate": {
                "kind": "ActuatorPin",
                "state": false,
                "pin": 17,
                "invert": false
              }
            }
          }
        }
      },
      "inputError": 0.1094,
      "Kp": 5,
      "Ti": 2400,
      "Td": 60,
      "p": -0.5469,
      "i": -13.5078,
      "d": -1.9336,
      "actuatorIsNegative": true
    },
    {
      "kind": "Pid",
      "name": "beer2fridgepid",
      "enabled": true,
      "input": {
        "kind": "SensorSetPointPair",
        "sensor": {
          "kind": "TempSensorDelegate",
          "name": "beer1",
          "delegate": {
            "kind": "OneWireTempSensor",
            "value": 26.3125,
            "connected": true,
            "address": "287D093607000004",
            "calibrationOffset": 0
          }
        },
        "setPoint": {
          "kind": "SetPointSimple",
          "name": "beer1set",
          "value": 26
        }
      },
      "output": {
        "kind": "ActuatorOffset",
        "target": {
          "kind": "SensorSetPointPair",
          "sensor": {
            "kind": "TempSensorFallback",
            "onBackupSensor": false,
            "sensor": {
              "kind": "TempSensorDelegate",
              "name": "fridge",
              "delegate": {
                "kind": "OneWireTempSensor",
                "value": 23.5625,
                "connected": true,
                "address": "286471360700009A",
                "calibrationOffset": 0
              }
            }
          },
          "setPoint": {
            "kind": "SetPointSimple",
            "name": "fridgeset",
            "value": 23.293
          }
        },
        "reference": {
          "kind": "SensorSetPointPair",
          "sensor": {
            "kind": "TempSensorDelegate",
            "name": "beer1",
            "delegate": {
              "kind": "OneWireTempSensor",
              "value": 26.3125,
              "connected": true,
              "address": "287D093607000004",
              "calibrationOffset": 0
            }
          },
          "setPoint": {
            "kind": "SetPointSimple",
            "name": "beer1set",
            "value": 26
          }
        },
        "useReferenceValue": false,
        "setting": -2.707,
        "achieved": -2.4375,
        "minimum": -10,
        "maximum": 10
      },
      "inputError": 0.3125,
      "Kp": 2,
      "Ti": 7200,
      "Td": 1200,
      "p": -0.625,
      "i": -2.2461,
      "d": 0.1641,
      "actuatorIsNegative": false
    }
  ]
}

Connected devices as below:

Any help/advice would be most appreciated.

Cheers
Coop.


#2

Thanks for the detailed description!
I have surrounded your control algorithm JSON with 3 backticks so it renders as scrollable code.

You reduced your dead time to 6 minutes, which allows frequent switching between heating and cooling. I think it will work better if you set it to 30 minutes or one hour (3600), so only one of the two will be active.

I think most of the overshoot is because of the low beer-to-fridge Kp. Because of the low proportional gain, reaching setpoint takes longer and in the meantime, the integrator increases. Instead of only correct long term errors, the integrator is helping to reach the setpoint from a temperature step and causes overshoot.

Also, as long as the beer-to-fridge is clipping to the maximum difference the integrator is disabled.

So Increase beer-to-fridge Kp to 5, make the integrator slower (for example 6 hours, 21600) and set minimum dead time back to 30 minutes or even 1 hour. You want to free-rise between cooling cycles, not actively heat.


#3

Thanks for the advice Elco, I’ll give it a shot.

Cheers


#4

So much better, last temperature drop is with the adjusted settings. No more overshoot and now sitting between 22.1 and 22.2. :sunglasses:

Greatly appreciate the help Elco :beers: