Assistance with tun...
 
Notifications
Clear all

[Solved] Assistance with tuning PID - Conditional Controller or PID Controller


wilden
(@wilden)
New Member
Joined: 4 months ago
Posts: 3
Topic starter  

Hello!

I've been working on trying to tune in my environment, but having a bit of trouble. I currently have a 5x5x8 room I framed in my basement to grow some plants. I'm using a 440 CFM exhaust fan, 3 disc ultrasonic fogger in a 17 gallon tote for a humidifier, and a 16" oscillating fan for circulation. I have all 3 hooked up to a 4 channel relay from your hydrponics build. My basement is unfinished and my room sits about 30 ft away from my furnace, so keeping things dialed in have been a bit challenging for me :D

I found a post in the forum where you provided a python script to control 3 inputs (heater, humidifier and fan: https://kylegabriel.com/forum/general-discussion/pid-controller-conflict/#post-383) and have been using a modified version of that, but still having a few issues.

1.) First issue, is the logs. I've been seeing a lot of repeated errors stating "ERROR - mycodo.outputs.on_off_gpio_be2ee682 - Cannot manipulate Output be2ee682-7b6c-4ca4-8385-6ff579e3fc4e: output channel doesn't exist: None" and "ERROR - mycodo.outputs.on_off_gpio_be2ee682 - Status check error: None"

Here is an excerpt from the logs:

2021-02-07 11:17:02,589 - DEBUG - mycodo.controllers.controller_conditional_494527f6 - Last measurements: temperature: 73.57771, humidity: 48.43976501106279
2021-02-07 11:17:02,589 - DEBUG - mycodo.controllers.controller_conditional_494527f6 - PID: Input: 73.57771, Output: P: -52.577709999999996, I: -10.0, D: 0.0, Out: -62.577709999999996
2021-02-07 11:17:02,590 - DEBUG - mycodo.controllers.controller_conditional_494527f6 - PID: Input: 48.43976501106279, Output: P: 1.5602349889372107, I: 10.0, D: 0.004928664072632927, Out: 11.565163653009844
2021-02-07 11:17:02,590 - DEBUG - mycodo.controllers.controller_conditional_494527f6 - Control variables: PID_Temp: -62.577709999999996, PID_Hum: 11.565163653009844
2021-02-07 11:17:02,590 - DEBUG - mycodo.controllers.controller_conditional_494527f6 - Temperature: Raise: False, Lower: True; Humidity: Raise: True, Lower: False
2021-02-07 11:17:02,590 - DEBUG - mycodo.controllers.controller_conditional_494527f6 - Lower temperature
2021-02-07 11:17:02,597 - DEBUG - mycodo.controllers.controller_output - output_on_off(be2ee682-7b6c-4ca4-8385-6ff579e3fc4e, on, None, None, 62.577709999999996, 0.0, True)
2021-02-07 11:17:02,597 - DEBUG - mycodo.outputs.on_off_gpio_be2ee682 - output_on_off(on, None, None, 62.577709999999996, 0.0, True)
2021-02-07 11:17:02,597 - ERROR - mycodo.outputs.on_off_gpio_be2ee682 - Status check error: None
2021-02-07 11:17:02,598 - ERROR - mycodo.outputs.on_off_gpio_be2ee682 - Cannot manipulate Output be2ee682-7b6c-4ca4-8385-6ff579e3fc4e: output channel doesn't exist: None
2021-02-07 11:17:02,599 - DEBUG - mycodo.controllers.controller_conditional_494527f6 - Raise humidity
2021-02-07 11:17:02,606 - DEBUG - mycodo.controllers.controller_output - output_on_off(be2ee682-7b6c-4ca4-8385-6ff579e3fc4e, on, None, None, 11.565163653009844, 0.0, True)
2021-02-07 11:17:02,606 - DEBUG - mycodo.outputs.on_off_gpio_be2ee682 - output_on_off(on, None, None, 11.565163653009844, 0.0, True)
2021-02-07 11:17:02,606 - ERROR - mycodo.outputs.on_off_gpio_be2ee682 - Status check error: None
2021-02-07 11:17:02,607 - ERROR - mycodo.outputs.on_off_gpio_be2ee682 - Cannot manipulate Output be2ee682-7b6c-4ca4-8385-6ff579e3fc4e: output channel doesn't exist: None

The errors above also displayed for my exhaust fan (which has an output id of 3bb8e39f-0769-4fc5-bcbc-e34904e45546) but it's no longer displaying. Are these real errors that I'm seeing in the logs? Or can I ignore them?

2.) The script you provided that I've been using has been working better than my attempts at configuring a PID previously, but I do miss being able to see the duration of my outputs (exhaust and fogger) with the rest of the data on the graph. Is there a way to display the duration of my outputs on a graph with the rest of my data while using the conditional controller? Based on the above errors, I'm having a hard time determining how long each is actually running.

Here is the script I copied and modified to suit my environment: 

 

import time
from mycodo.utils.pid_controller_default import PIDControl

output_id_humidifier = "be2ee682-7b6c-4ca4-8385-6ff579e3fc4e"
output_id_exhaust = "3bb8e39f-0769-4fc5-bcbc-e34904e45546"

period = 30

pid_1_setpoint = 26
pid_1_kp = 1.0
pid_1_ki = 0.1
pid_1_kd = 0.01
pid_1_integrator_min = -100
pid_1_integrator_max = 100
pid_1_direction = "both"
pid_1_band = 0

pid_2_setpoint = 60
pid_2_kp = 1.0
pid_2_ki = 0.1
pid_2_kd = 0.01
pid_2_integrator_min = -100
pid_2_integrator_max = 100
pid_2_direction = "both"
pid_2_band = 0

# Initialize
if 'timer' not in self.variables:
self.variables['timer'] = time.time()

if 'PID_Temperature' not in self.variables:
self.variables['PID_Temperature'] = PIDControl(
self.logger, pid_1_setpoint, pid_1_kp, pid_1_ki, pid_1_kd, pid_1_direction,
pid_1_band, pid_1_integrator_min, pid_1_integrator_max)
self.logger.debug("PID 1 initialized")

if 'PID_Humidity' not in self.variables:
self.variables['PID_Humidity'] = PIDControl(
self.logger, pid_2_setpoint, pid_2_kp, pid_2_ki, pid_2_kd, pid_2_direction,
pid_2_band, pid_2_integrator_min, pid_2_integrator_max)
self.logger.debug("PID 2 initialized")

# Start loop
while self.running:
if time.time() > self.variables['timer']:
while time.time() > self.variables['timer']:
self.variables['timer'] = self.variables['timer'] + period
# Get latest measurements
measurement_temperature = self.condition("{3589f235}")
measurement_humidity = self.condition("{75a0d764}")
self.logger.debug("Last measurements: temperature: {temp}, humidity: {hum}".format(
temp=measurement_temperature, hum=measurement_humidity))

# Update control variables (CV)
self.variables['PID_Temperature'].update_pid_output(measurement_temperature)
self.variables['PID_Humidity'].update_pid_output(measurement_humidity)
self.logger.debug("Control variables: PID_Temp: {cvt}, PID_Hum: {cvh}".format(
cvt=self.variables['PID_Temperature'].control_variable,
cvh=self.variables['PID_Humidity'].control_variable))

# Determine if temperature and humidity need to raise or lower
if self.variables['PID_Temperature'].control_variable > 0:
# CV positive: Temperature is too low and needs to be raised
raise_temperature = True
lower_temperature = False
else:
# CV negative: Temperature is too high and needs to be lowered
raise_temperature = False
lower_temperature = True

if self.variables['PID_Humidity'].control_variable > 0:
# CV positive: Humidity is too low and needs to be raised
raise_humidity = True
lower_humidity = False
else:
# CV negative: Humidity is too high and needs to be lowered
raise_humidity = False
lower_humidity = True

self.logger.debug(
"Temperature: Raise: {tr}, Lower: {tl}; "
"Humidity: Raise: {hr}, Lower: {hl}".format(
tr=raise_temperature, tl=lower_temperature,
hr=raise_humidity, hl=lower_humidity))

# Manipulate outputs based on need to raise or lower temperature and humidity
if lower_humidity and lower_temperature:
# Here is a conflict where the humidifier should stay off to lower humidity
# but should also turn on to lower temperature.
# What to do? Average absolute values of control variables (they're negative),
# and run exhaust for that duration.
average_control_variables = (
abs(self.variables['PID_Temperature'].control_variable) +
abs(self.variables['PID_Humidity'].control_variable)) / 2
self.logger.debug("Both Hum and Temp lower. CV average is {}".format(
average_control_variables))
control.output_on(
output_id_exhaust, amount=average_control_variables)
else:
self.logger.debug("Lower temperature")
control.output_on(
output_id_humidifier,
amount=abs(self.variables['PID_Temperature'].control_variable))

# Run humidifier to raise humidity, exhaust to lower humidity
if raise_humidity:
self.logger.debug("Raise humidity")
control.output_on(
output_id_humidifier,
amount=self.variables['PID_Humidity'].control_variable)
else:
self.logger.debug("Lower humidity")
control.output_on(
output_id_exhaust,
amount=abs(self.variables['PID_Humidity'].control_variable))

I just ripped out the portions that pertained to the heater.

 

Also, I'm trying to add pictures of my current graph and controller setup, but having a hard time finding the spot to add images lol so I will add images as soon as I figure that out


Quote
Topic Tags
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

This code is old and incompatible with the latest version of Mycodo. The output_on() function now requires the output_channel argument.

Mycodo Developer


wilden liked
ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 
Posted by: @wilden

Based on the above errors, I'm having a hard time determining how long each is actually running

The above errors mean the outputs were not running, hence why their duration wasn't being saved to the measurement database.

Mycodo Developer


wilden liked
ReplyQuote
wilden
(@wilden)
New Member
Joined: 4 months ago
Posts: 3
Topic starter  

@kylegabriel much appreciated good sir! I'll tinker around with that script using the output_channel argument 👍 hahah and that would also make sense why the errors were appearing lol

 

For debugging mycodo in general, what IDE do you find easiest? I have VS Code and was looking at the repo, but my Python chops aren't the greatest haha (C# and Swift is what I use at work)

 

Also, dumb question, but how do I attach images on here? I was going to post the specs of my current PID controller to see if you might be able to lend some wisdom on further fine tune it. I've been reading up more on PID controllers and am trying to dial in a PID using the VPD after reading this page over PID Controllers: https://kizniche.github.io/Mycodo/Functions/

 

I feel like I'm starting to grasp everything, which is nice :D but getting it fine tuned is an arduous process hahah

 

While poking around in Mycodo, I also noticed you have a section to control a sunrise/sunset, which is really cool! I put together an LED light and soldered a dimmer switch to it, but have you messed around with, or know of a way to control the dimming of an LED light with Mycodo? Is that currently possible? 

 

I've been really nerding over what you've put together since I first saw your hydroponics video on youtube, and am so glad I finally was able to get all working and going. I will for sure be throwing some cash your way on Patreon for what you've accomplished 👍 I'm all about open source, knowledge and giving the power back to the people, so anyway I can help make this even better, I'm down! For the Patreon, if I make incremental donations, can I still unlock the Guardian level? I'd like to contribute to the project and be able to chat with other folks that have been down this rabbit hole and discuss issues/resolutions/ideas, but can't throw down 100 bones all at once :/ be cool if I could break it up into smaller installments >_<

 

Anyway, thanks again for taking the time to reply and I look forward to sharing what I've created using Mycodo!! Keep up the awesome work!


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 
Posted by: @wilden

what IDE do you find easiest?

I use PyCharm Pro, but there's a free community edition.

Posted by: @wilden

how do I attach images on here?

There should be an attach image button next to the send button.

Posted by: @wilden

I've been really nerding over what you've put together

😁

Mycodo Developer


ReplyQuote
mondgans
(@mondgans)
New Member
Joined: 3 weeks ago
Posts: 2
 

@kylegabriel I am getting the same error when unsing the 'output' option with the camera to activate a foto light for timelapse images. Is this a dependency in camera module?

2021-02-13 21:15:59,753 - ERROR - mycodo.outputs.on_off_gpio_baa29cf4 - Status check error: 'b447bc19-f034-438a-9b32-7a482a9b2e5a'
2021-02-13 21:15:59,757 - ERROR - mycodo.outputs.on_off_gpio_baa29cf4 - Status check error: 'b447bc19-f034-438a-9b32-7a482a9b2e5a'
2021-02-13 21:15:59,757 - ERROR - mycodo.outputs.on_off_gpio_baa29cf4 - Cannot manipulate Output baa29cf4-958e-4220-bb4f-b5ca33fa743a: output channel doesn't exist: b447bc19-f034-438a-9b32-7a482a9b2e5a
2021-02-13 21:16:05,760 - ERROR - mycodo.outputs.on_off_gpio_baa29cf4 - Status check error: 'b447bc19-f034-438a-9b32-7a482a9b2e5a'
2021-02-13 21:16:05,760 - ERROR - mycodo.outputs.on_off_gpio_baa29cf4 - Cannot manipulate Output baa29cf4-958e-4220-bb4f-b5ca33fa743a: output channel doesn't exist: b447bc19-f034-438a-9b32-7a482a9b2e5a


ReplyQuote
Kyle Gabriel
(@kylegabriel)
Member Admin
Joined: 6 years ago
Posts: 570
 

This was fixed in 793f4a1 and will be released with v8.9.0.

Mycodo Developer


ReplyQuote
mondgans
(@mondgans)
New Member
Joined: 3 weeks ago
Posts: 2
 

Hey Kyle,

this was a fast replay. It works!!

Thank you


ReplyQuote