PID controller with 3 input

What would be the best way to implement a cooking program like the following.
The following temperatures are used and got - ambient, surface and core.

  1. Set the values ​​(e.g. sous vide cooking) to an ambient temperature of 80 °C, a surface temperature of 62 °C and an core temperature of 60 °C.
  2. The ambient temperature is gradually lowered from 80 °C --> 60 °C as the surface temperature rises closer to x °C --> 60 °C.
  3. When the surface temperature 60 °C is reached, the surface temperature is kept at 60.5 °C, until the internal temperature reaches 60 °C and this state is maintained for the given time, after which cooling to a certain internal temperature x °C can be started or not depended on cooking process..

I suggest you think more about it.

Sorry.

I am not understanding what it is you want to do.
Though you have said it above..... I am not getting it.

Think how you would do it but strip it to pieces.

You need an.... OUTPUT (or something to happen) with given conditions.

What I am reading above is a basic description of what happens if you leave what ever it is alone and do pretty much nothing.

How can YOU gradually lower the surface temperature? Other than just leaving it to acquire the ambient temperature. Ok, you said 60 Deg (C).....
Yeah, so....?

Oh, yeah, you are LOWERING the Ambient temperature from 80 to 60. So yeah, my question still stands.

It may be easier if you could better explain the inter workings of the three things you are sensing and what should happen in what conditions.

You have said that you can measure ambient, surface and core temperatures, but you have not said what heating systems you have. In other words which of those do you have any control over?

OK
It certainly boggles the mind when I talked about the ambient temperature.
In my example I mentioned sous vide...
i.e. then the ambient is water and the temperature of the water is to be monitored
So initially, the target temperatures are set
ambient 80 °C
surface 62 °C
core 60 °C
At first, the outermost loop adjusts the water temperature to 80 °C and when the target temperature is reached, the vacuumed proteins are placed in the environment (so in the water :wink: ).
After that, you should use another loop to monitor the rise of the surface temperature of the protein while dropping the target temperature of the environment closer to the target temperature of surface, so that the protein is not overcooked.
So here you should adjust 2 things: ambient (water) 80 °C --> 60 °C and surface x °C --> 60 °C, preferably 1-2 °C below the surface target, i.e. 58 °C, for example.
When the surface temperature has reached the target temperature (58 °C), the ambient target is then set to the core temperature target of 60 °C + 0.5 = 60.5 °C
This loop lasts until the core has reached the target temperature or the required degree of tender time or not.
The continuation depends on whether the product is eaten immediately or later, and based on that, cooling is done if necessary.
An additional option could be check also the time needed for pasteurization.
A water heater and a peltier cooler are used
1,2 or more loops?
Ramp PID?

Could you draw a sketch showing what the system is like physically, including where the heater and cooler are please? It is still not clear to me what you can actually control.

You can paste an image here directly.

Hopely this help...

Not really.
Draw a sketch showing what the box shown consists of, where the heater/cooler are, and exactly what is being measured. Remember we know nothing about your industry or the kit you use.

Is the cooker capable of maintaining a given water temperature, 60° say, without further input or must you continually turn the heater on and off to maintain the temperature?

Simplifying things
we have big enough water container

water heating coil

peltier water circulation cooler

meat probe
we get ambient, surface and core temperatures

In pic we see
Ambient temperature 60.5 C (sensor is in yellow part near 60.0 C)
Surface temperature 60.0 C (red ball)
Core temperature 59.9 C ( blue ball)
This was some sous vide cooking targeting core 60 C.
Sensors from red ball to right are inside meat

Those 3 values are inputs for PID
PID outputs are heater and cooler.
Using 2 relays.
Arduino scan probe and send MQTT data into Node red
Node red send MQTT data to control Arduino pins which are connected to relays (on/off)
Outer loop is controlling ambient temperature and 2 inner loops controlling surface and core or...???
Possibility to using heater and cooler same time or separately.
Heater for example 1500 W and cooler 100-200 W

As the only thing you can actually control directly is the heat going into or out of the water, it is not possible to control all three temperatures at once. At any moment you can only control one of them, or some function of more than one of them.

Do you have to heat up the water so that it gets to 80 and stays there for a while, or ramp it up at a controlled rate, or something similar, or is it just a matter of whacking on the heater and waiting till it gets to the right temperature?

If you need to bring it up in a controlled manner then this is simple enough. A node-red-contrib-pid node measuring the water temperature and controlling the heater. You say that the heater is controlled using a relay, so presumably you want a time proportioned output. For this you can use a node-red-contrib-timeprop, which was designed for use with the PID node. Don't worry about the fact that it has not been updated for 7 years, it is a simple node and has not needed any updates. If it did need updating for the latest node-red or nodejs then the maintainer (me) would sort it.

To help me understand fully could you post a chart showing what the three temperatures might look like during the three phases of the process? Just a rough graph to give an idea of what happens.

Of course, there are sous vide circulators with PID control and several models with WIFI/Bluetooth control and a timer, but if you want customized cooking, you can only do this manually by changing the temperatures and controlling the process based on experience.
Many sous vide circulators also do not restart after a power outage and lose set temperatures and return to default settings...
In sous vide, the environment is water, and keeping its temperature constant is easy compared to an oven or grill.
The smaller the temperature difference between the surface and the core, the slower the product reaches the core goal. If you initially "boost" the ambient temperature above the surface target by 10-20 °C (e.g. 80 °C/60 °C), the faster the core also reaches its target. Taking care of the surface temperature ensures that the product does not overcook the surface.
I have been manually grilling sous vide style so far, monitoring the surface temperature and adding carbon and turning the product cuople times against the indirect heat source. I got less than 1 C difference in product temperatures manually.

All the ways you mentioned can come into question in the example case.
Ramp the internal temperatures to 39 C and 45 C and hold for 1.5 h at those temperatures and then 80 C, but the clearest way to start is to quickly 80 C and monitor the development of the surface heat and then start reduce the ambient temperature accordingly

I'm making a few sous vide cooking charts and later some bbq charts, but I think those are not so helpful at he moment, maybe?

Ok, let us assume for the moment that at various times you need to be able to control the water temperature, the surface temperature and the core temperature.

The process is what is known as a cascade process. You can heat and cool the water. The temperature of the water over time then feeds through and determines the surface temperature, and the surface temperature over time then affects the core temperature.

The best way to control processes like this is with cascade control. You can use your favourite search engine to find more about what that means.
Meanwhile I need to go away and draw a sketch of how to do that, but I have things to do. Will get back when I can.

If I understand this correctly, you only have one temperature control and that is the water bath temperature. In all probability you would get away with proportional control (output = error * Kp). You might add a slow integral but you may only want to enable this after initial warm up or you will over integrate, overshoot, over integrate, undershoot etc. As for the other parts of your question, you need to figure out mathematically how you expect those other measurments to affect the water temperature setpoint and, as @Colin says, these need to be cascaded as an algorithm to manipulate your temperature setpoint.

Edit,

A couple of other things to bear in mind. 1) Use your outputs in proportional mode over a time period i.e. a time period might be 5 seconds, if your control loop output is 50% then the output is on for 2.5 seconds. 2)Use an SCR rather than a relay (less likely to fail). 3) You have asymetric heating and cooling so you may need asymetric gains to make a stable system. 4) The size of any piece of protein and it's thermal mass will have an influence over the algotithm - maybe considder delta T/Time (rate of change) as a significant factor.

Good luck with your project.

Nick

Sorry for the delay.

This is a representation of your process

The heat and cool inputs over time determine the water temperature via the process transfer function. Then the water temperature over time determine the surface temperature via another transfer function, and the surface temperature then determines the core temperature via another transfer function.

When you want to control the water temperature directly then you can use a pid node like this:

Where the setpoint is determined by whatever profile you want for that phase of the process.
I think I have got an example flow somewhere showing how to do heat/cool control with node-
red-contrib-pid. I can look that out when you get that far.

When you then move on to the next phase of the process and want to control the surface temperature then you can use two pid nodes in cascade as follows:

Here the output of the surface temperature pid node controls (via appropriate scaling) the setpoint of the water pid, and the surface temperture setpoint is determined by your profile.

Finally, when you want to control the core temperature then you need a third pid node:

Where now the core temperature comes from your required profile.

You will need to get the first version, with just one pid node active, going and tuned first. Once that is working you can add the second and tune that loop, then the third.

Here is a flow that you can use for heat/cool control with node-red-contrib-pid. Instructions on configuring it are in the Function node.

[{"id":"d06813fe.a657d","type":"inject","z":"9b808c99.ccb9c","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"0.25","payloadType":"num","x":135,"y":97,"wires":[["5685aea6.42f268"]]},{"id":"aef6c072.927a7","type":"inject","z":"9b808c99.ccb9c","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"0.5","payloadType":"num","x":136.5,"y":132,"wires":[["5685aea6.42f268"]]},{"id":"e09ee366.fdac08","type":"inject","z":"9b808c99.ccb9c","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"0.75","payloadType":"num","x":137.5,"y":169,"wires":[["5685aea6.42f268"]]},{"id":"7a93c7f8.a116e","type":"inject","z":"9b808c99.ccb9c","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"0.0","payloadType":"num","x":134.5,"y":61,"wires":[["5685aea6.42f268"]]},{"id":"d48c3837.cad168","type":"inject","z":"9b808c99.ccb9c","name":"","repeat":"","crontab":"","once":false,"topic":"","payload":"1.0","payloadType":"num","x":137.5,"y":206,"wires":[["5685aea6.42f268"]]},{"id":"5685aea6.42f268","type":"function","z":"9b808c99.ccb9c","name":"Split Heat/Cool","func":"/* A function designed to be used with node-red-contrib-pid in applications where both\n * heating and cooling are available to control the system.\n * The node is given a power value in msg.payload in the range 0 to 1, such as is produced by \n * node-red-contrib-pid and splits this into a heat power (o/p 1) and cool power (o/p 2) where\n * each is in the range 0 to 1.  These can then be fed directly into an output device, if this\n * is continuously variable, or they may be passed to node-red-contrib-timeprop nodes to generate\n * time proportioned on/off outputs.\n * There are two particular issues to be dealt with in a heat/cool application. Firstly is the fact\n * that the cooling device may be more or less powerful than the heating device. It is necessary\n * therefore to be able to adjust the gain of the system separately for heating and cooling. Secondly\n * is the highly non-linear response of some devices, notably refrigerant systems, that can have a\n * large effect initially, then this tails off. To compensate for this it is useful to have an \n * overlap range where both heat and cool are slightly on.\n *\n * To allow for these requirements two variables can be set below. The value of the power input value\n * where the heating starts to come on is determined by the variable heatMin.  Above this value the\n * heating will rise till it is fully on with an input of 1.\n * The cooling is fully on when value of the power input is 0, and falls till the cooling is fully\n * off at an input of coolMin.\n *\n * If the heating and cooling systems are of similar power then set heatMin and coolMin both to 0.5\n * in which case input values of 0.5 to 1.0 will map to heating outputs of 0.0 to 1.0,\n * and 0.5 down to 0.0 will map to cooling 0.0 to 1.0.\n * If, for example, the cooling system is more powerful than heating then they can both be set\n * to something like 0.7 which increases the gain in the heating region and reduces it\n * in the cooling region, to compensate for the different powers in the heating/cooling systems.\n * If some overlap is desired (so that both heat and cool are on slightly near the crossover\n * point) then overlap the two settings so that, for example, heatMin might be 0.45 and coolMin\n * might be 0.55\n */\n\n// set these as described above\nvar heatMin = 0.5;          // the value of input corresponding to 0 heat o/p\nvar coolMin = 0.5;          // the value of input corresponding to 0 cool o/p\n    \nvar power = msg.payload;\nvar heat = (power - heatMin)/(1 - heatMin);\n// limit to range 0 to 1\nheat = Math.min(Math.max(heat, 0), 1);\nvar cool = (coolMin - power) / coolMin;\n// limit to range 0 to 1\ncool = Math.min(Math.max(cool, 0), 1);\nreturn [{payload: heat}, {payload: cool}];\n","outputs":"2","noerr":0,"x":400,"y":250,"wires":[["2b64cd9e.3e398a"],["268a1179.f064f6"]]},{"id":"268a1179.f064f6","type":"debug","z":"9b808c99.ccb9c","name":"Cool","active":true,"console":"false","complete":"payload","x":604.5,"y":264,"wires":[]},{"id":"2b64cd9e.3e398a","type":"debug","z":"9b808c99.ccb9c","name":"Heat","active":true,"console":"false","complete":"payload","x":604,"y":220,"wires":[]},{"id":"bef43ce5.5970c","type":"comment","z":"9b808c99.ccb9c","name":"Feed node-red-contrib-pid in here","info":"","x":169,"y":273,"wires":[]},{"id":"4263d000.5c697","type":"comment","z":"9b808c99.ccb9c","name":"To heater","info":"","x":580,"y":185,"wires":[]},{"id":"18516842.115a1","type":"comment","z":"9b808c99.ccb9c","name":"To Cooler","info":"","x":579,"y":302,"wires":[]}]

Thanks !
I start to setup my system and next weekend try to cook something...
Tomorrow send some cooking data

I suggest starting by just having the water bath and get the first PID loop tuned and controlling the water temperature.
This blog post suggests how you can do the loop tuning.