Conditional Stateme...
 

Conditional Statements  

  RSS

jaco
 jaco
(@jaco)
Active Member
Joined: 6 months ago
Posts: 6
19/07/2019 9:06 pm  

I am building a boiler to steam sterilize my mushroom substrate at atmospheric pressure. My control will use a Pi Zero W and Atlas PT-1000.

I require a setup that will keep my boiler setpoint  (95C) for set period (12-24 hours). Bringing the boiler up to setpoint will take a few hours, hence need a method (PID or conditional) that can bring it up to setpoint and will maintain the setpoint for a certain minimum period (10min). Only once this condition has been satisfied, a countdown timer for a ser period (12-24hr) timer should start after which the system needs to shut down.

Any help with the best method of achieving this in Mycodo will be appreciated.

I think a conditional statement can achieve this, but after looking at it for a few hours can’t figure it out.


Quote
sam26k
(@sam26k)
Eminent Member
Joined: 7 months ago
Posts: 38
22/07/2019 12:27 am  

How are you controlling the boiler?  The conditional functions are a powerful tool.     The basics is  an input (eg: temp)   and an output (eg: a method to control the temp).  Learn the  Python function controllers.  Worth the effort.


ReplyQuote
jaco
 jaco
(@jaco)
Active Member
Joined: 6 months ago
Posts: 6
22/07/2019 7:50 pm  

I am using a Atlas PT-1000 high temp probe as input to a PID to control the temp. The PID will switch a SSR on/off coupled to my element.

The problem is I know nothing about python and although I want to learn, I was hoping to get the forum's help on code for the functionality described in my first post.

I am keen on customizing my entire setup using conditionals but for now urgently need the forums help to get past this bump.

 


ReplyQuote
sam26k
(@sam26k)
Eminent Member
Joined: 7 months ago
Posts: 38
22/07/2019 9:47 pm  

What do mean by PID controller? Are you using a raspberry pi or a dedicated controller?


ReplyQuote
sam26k
(@sam26k)
Eminent Member
Joined: 7 months ago
Posts: 38
22/07/2019 10:02 pm  

Can you draw a diagram of the setup?  Basically with a conditional you create a data input that can track the temperature then create an output that is wired to something that can control the temperature.  With that hardware in place then you can write code to cycle as you described above.


ReplyQuote
sam26k
(@sam26k)
Eminent Member
Joined: 7 months ago
Posts: 38
22/07/2019 11:45 pm  

BTW there is no shortcut to learning the basics of coding in Python, It took me more than a few hours to get that right the first time.


ReplyQuote
jaco
 jaco
(@jaco)
Active Member
Joined: 6 months ago
Posts: 6
25/07/2019 2:02 am  

I am using Mycodo on a Raspberry Pi Zero W. I only have one data input - the temperature reading from my temp probe and one output, my heating element controlled via a Solid State Relay coupled to the Raspberry Pi. Super simple setup.

With Mycodo there are various ways to approach the problem described in my first post. However, the only way I can think of is by combining a PID with timer and conditional to achieve what I want. It would be useful to have the functionality of a timer coded into the PID controller, in other words, start a countdown timer for the PID operation only once the setpoint has been reached and maintained for a certain period.


ReplyQuote
sam26k
(@sam26k)
Eminent Member
Joined: 7 months ago
Posts: 38
25/07/2019 8:42 pm  

Take a look at "Trigger: Timer (Duration)" on the function page.  Or one or more of the other timers.

edit: Would update to latest Mycodo rev if not up to date.

This post was modified 2 months ago by sam26k

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 5 years ago
Posts: 0
28/07/2019 11:17 pm  
Posted by: jaco

I am building a boiler to steam sterilize my mushroom substrate at atmospheric pressure. My control will use a Pi Zero W and Atlas PT-1000.

I require a setup that will keep my boiler setpoint  (95C) for set period (12-24 hours). Bringing the boiler up to setpoint will take a few hours, hence need a method (PID or conditional) that can bring it up to setpoint and will maintain the setpoint for a certain minimum period (10min). Only once this condition has been satisfied, a countdown timer for a ser period (12-24hr) timer should start after which the system needs to shut down.

Any help with the best method of achieving this in Mycodo will be appreciated.

I think a conditional statement can achieve this, but after looking at it for a few hours can’t figure it out.

I've been meaning to add this feature to PIDs for a while. However, this can still be achieved with what's currently available in Mycodo. There are a couple ways to accomplish what you're trying to do, but here is one simple way that came to mind that's relatively easy to program:

1. Create and tune a "PID Controller" Function that can raise your water to your target temperature.
2. Create a "Trigger: Timer (Duration)" Function.
3. Create a "Conditional" Function.
4. Create a "Execute Actions" Function.
5. For the "Execute Actions" Function: Add an "Activate Controller" Action and set it to the "PID Controller". Add an "Activate Controller" Action and set it to the "Conditional".
6. For the "Conditional": Add a "Measurement (Single)" as the condition and set it to your temperature sensor. Add an "Activate Controller" Action and set it to the "Trigger: Timer (Duration)". Add a "Deactivate Controller" and set it to the "Conditional".
7. Use the code below for the Conditional Statement (changing "asdf1234" to what your particular Condition ID is):

measurement = measure("{asdf1234}")
if measurement is not None:
   if measurement >= 95:
        run_all_actions(message=message)

8. For the "Trigger: Timer (Duration)", set the Period to 600 seconds (10 minutes). Add a "Deactivate Controller" Action and set it to the "PID Controller". Add a "Deactivate Controller" Action and set it to the "Trigger: Timer (Duration)".

This is how the whole system works:

Click "Execute All Actions" on the "Execute Actions" Function: It activates the PID and Conditional. The PID starts raising the temperature of the water. The Conditional monitors the temperature of the water. When the water reaches the desired temperature, the Conditional activates the "Trigger: Timer (Duration)" and deactivates itself. The "Trigger: Timer (Duration)" will wait 10 minutes, then deactivate the PID and itself.

This should effectively use the PID to raise the water to the desired temperature, keep it there for 10 minutes, then turn the PID off. This is all activated from only clicking the "Execute All Actions" button of the "Execute Actions" Function, then each function will trigger the next in the line of succession until everything has completed and all are in the off state again.

Hope this helps,

Kyle

This post was modified 2 months ago 10 times by Kyle Gabriel

ReplyQuote
jaco
 jaco
(@jaco)
Active Member
Joined: 6 months ago
Posts: 6
01/08/2019 8:00 pm  

Hi Kyle,

Thanks for your reply. This has definitely been of great help and a step in the right direction. I did a crummy job at explaining what I want to achieve initially so will give it another go. 

I require that the conditional monitors the temperature, but only to activate the "Trigger: Timer (Duration)" if this temperature has been maintained at the specified set point for a set period (in this case an arbitrary 10min was chosen). The "Trigger: Timer (Duration)" will be set for 12-24hr  - the required atmospheric steam sterilization period after which the system shuts down.

The reason for this is that when sterilizing the substrate in the steam drum, it will take some time for the substrate to reach the required temperature for sterilization. In this "warm up" period the temp probe might register false positive, i.e. periods where 95C is registered and then dips below this shortly after.  With the above method, this will result in the "Trigger: Timer (Duration)" being activated prematurely, resulting in incomplete sterilization. Example; a fully loaded drum can take up to 6 hours to reach 95C, after which it needs to be kept at this temp for 12 hours. So 18 hours total run time. During hour 1, the conditional registers momentary a spike in temp thereby triggering the countdown timer to start. However, the substrate will only reach set point temp in another 5 hours. This scenario results in the substrate only being kept at 95C for 7 hours, insufficient for proper sterilization.

I will not always load the steam drum with the same quantity of substrate, resulting in varying "warm up" periods. If this wasn't the case I could factor in the warm up period into the countdown timer. I guess by monitoring first sterilization runs at different loadings I can find all the "warm up" periods for corresponding loads and then adjust the Timer accordingly each time I run the system, but figured it would be a more complete solution by having a function of sorts that accounts in way for the "warm up" period programmed into the operation.

 

The above solution you provide will definitely get the job done and I will try it as a starting point this weekend. I did get an error on "run_all_actions" line of the code, Mycodo states that the parameter does not exist? I'll post some screenshot this weekend.

Attached are some pics of my drum and control system - very rudimentary still. I have jacketed the drum since taking the photo and the control system will be housed in a junction box.

 


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 5 years ago
Posts: 0
01/08/2019 8:18 pm  

For stabilizing the temperature sensor Input data, you can create a Math controller (Average (Past, Single Channel)) from the Setup -> Data page that calculates the average of your temperature sensor. You can set the amount of time in the past you want it to calculate the average from (e.g. 5 minutes, 1 hour, 3 hours, etc). This Math controller can then be used in place of the temperature sensor Input. This should smooth out the data significantly.

Note: I would not recommend using the Average Math controller as the input for the PID. Keep the PID using the raw I temperature input, as it needs the most accurate and up-to-date temperature to operate properly, even if it is prone to error. Using the Average Math controller with the PID would make it very difficult to tune, unless you are using a very small period of time to average (e.g. just a few minutes), which in that case may be of benefit. You could create two Average Math controllers, one with a short period that you use with the PID and one with a longer period that you use with the Conditional. 

This post was modified 1 month ago 3 times by Kyle Gabriel

ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 5 years ago
Posts: 0
01/08/2019 8:23 pm  

I haven't experienced the error with the Execute All Actions function as you mention, but if you can explain steps to replicate it (photos help, too), I will try to push a fix for it in the next release.

You're welcome to create a new issue on github with details of the issue, so I can try to replicate it and track the progress fixing it.

https://github.com/kizniche/Mycodo/issues/new

In the meantime, you can mimic the behavior by creating a Trigger Timer (Duration) as you would the Execute All Actions function, with the addition of another Action at the end, a Deactivate Controller Action, that deactivates itself. This ensures it only runs once, like the Execute All Actions function is designed to do. 

This post was modified 1 month ago 2 times by Kyle Gabriel

ReplyQuote