2dof / esp_control

Standard PID control library for esp32 Micropython platform
MIT License
15 stars 4 forks source link

PID Setpoint Tracking #2

Closed isabido closed 4 months ago

isabido commented 8 months ago

HI 2dof!

I am designing a system at home where I need all photovoltaic production to be used to heat water.

What I need is, if the solar panels are generating 1kw (this measurement is extracted by mqtt from the inverter and it would be the setpoint remote) I need to divert all that power to a resistor controlled by a dimmer with a 0-3.3v signal input.

Regulator 25A https://es.aliexpress.com/item/20000003997748.html?spm=a2g0o.cart.0.0.eec37a9dSt4vWf&mp=1&gatewayAdapt=glo2esp

0-3.3v to 4-20mA converter https://es.aliexpress.com/item/1005002960048002.html?spm=a2g0o.cart.0.0.eec37a9dSt4vWf&mp=1&gatewayAdapt=glo2esp

The PV value would be obtained from a clamp meter with this simple circuit connected to an input of the ESP32 image

In this case the set point is variable depending on the energy produced by the solar panels.

I think this is called PID Setpoint Tracking where the value SP=PV.

Thanks for sharing your project!

2dof commented 8 months ago

Hi @isabido, You wrote:

"In this case the set point is variable depending on the energy produced by the solar panels. I think this is called PID Setpoint Tracking where the value SP=PV."

So Yes, I agree with Your statement. In Your case, You track how much power You Have, how much You use in home appliance then how much you can divert.

Power_procced_by_solar (Ps) = power_for_household_appliances(Pa)+power_for_heater(Ph)
Power for heater (Ph) is always surplus, so You need to calculate actual (Ps , Pa then surplus power = Ps - Pa

Then Set point SP = Ps - Pa -Power_margin(Pm). Power margin (Pm) is for safety (we do not put all surplus power for heating). Here we're tracking actual power available. Since all diverted power will be used by heater so PV is actual heater power consumption, since Ph=I^2 * R, then You need to measure current in heating element (R-heater resistance is known). (Note that the ADC of the ESP32 has nonlinear conversion, if you plan to use Wi_FI or BT is better use external ADC (for example ADS1115) then You can avoid a lot of problems)

Some My comments, but first I start from "the end" (not necessary, direct with Your topic):

  1. Type of control: for home water boiler heating it is no need to use PID (in home application almost newer used), better use on-off controller (relay control), You can find info in internet or just some examples in my git ( probably you read it)
    • On-off controller
    • example as "set point tracking" - this example refers to thermal control of ceramic kiln heating type plant (to show that on-off controller is able to SP tracking (with some errors). Even this solution for boiler water heating is too much. Why? because in standard home application you just set some constant temperature in your boiler (for example 70 [°C]) and when:
    • water will cool down in boiler (geyser) heat loss and during circulation (if circulation pump is used) ,
    • or when you will use hot water and cold water will be added (and mixed) in boiler from cold water system. Here, You use taps (hot /cold) to set (by touch) preferred temp of water, boiler(geyser) will turn on heating.

Now some comments about using pv-cell to heat (typical simplest) applications :

  1. a.) Using diverter: [pv panels]->[main control unit: inverter or/with solar diverter]->[household appliances]+(when surplus)->[boiler(geyser) control heating system]
    solar diverter - device through which any solar power not being used is diverted to an electrical appliance (heater) - it is just DC-AC (120 or 220 AC) inverter will all safety implementation and here You use standard boiler temp control.

    -> Yo Want that solution

    b.) Using direct DC from pv panel: [pv_panels]-[control unit (DC-DC)] - [ Your Water temp Control unit] control unit (DC-DC) - it can be optional, but main task of unit is to protect pv-cell (current protection). [Water temp Control unit] - Your heater controller.

MAIN RECOMMENDATION: A. do not build your own Diverter (if you are not experiences) - use commercial solution . You will be sure that PV-cell with inverter will be protected by safety solution, then You can (split) your power control project to Power source (pv-cell + commercial inverter/ diverter) and rest application (water temperature control and monitoring via mqtt/Bt etc).

It is better (safer) to learn a PID (or on-off) control strategy on some simple process (temperature water control) than directly on power unit (inverter and home build diverter -in that way better damage esp32 than inverter, ad You will still have the opportunity divert power from heating control (but not from inverter) - as result You will get want You want first: hot water from pv-cells (savings on bills) , You will be able to test/play wit mqtt (measuring power consumption, temperature, logging data and secure transmission)

B. If You want build diverter use confirmed solutions (electric/electronic circuit if if available) -> Always Safety first.

isabido commented 8 months ago

Hi @2dof

First of all... thank you very much for taking all this time to respond to me. Now comes the difficult part for me to make myself understood, since my English is very bad.

Because I don't think I did it correctly.

First of all, I don't want to use surplus to heat the water, I want to use all the solar production to heat the water, until it reaches 70º. For me the priority is to heat the water, and when finished use the energy generated for the rest of the consumers in the house.

I don't really want to do a PID by temperature. The boiler's own thermostat will cut off when it reaches the temperature. In this sense there is no need to worry, it is a safe operation.

What I want to do is...

I read the producer value for the panels (via mqtt).

Let's imagine that there is 1Kw, now I need to send a proportional signal 0-3.3v to the dimmer through the ESP32 output until I obtain a reading of 1kw on the current clamp installed on the thermos resistance.

The SP is dynamic and is the MQTT value collected from the generation of the panels, and the PV is the clamp located on the resistor.

Thanks again for your time!

isabido commented 8 months ago

image

2dof commented 8 months ago

So i did not clearly understood your first descctiption. Also your second schematic is little messy so lets clear (confirm or correct me):

If yes, then it is typical solution like in solar diverter but here heater has priority in this case.

Then process control you described ( correct me if wrong) :

isabido commented 8 months ago

I finally understand! You have interpreted it perfectly.

Excuse me my bad English, I make you a summary taking your words.

Read actual power available via mqtt from inverter (SP value) range 0-2kW

OUT (OUT ESP32 0-3.3V >> 4-20mA then with that signal control PWM SSR ( your Regulator 25A) and read current ( PV) to calcate power of heater. (in ADC 0-3.3v clamp meter)

Just as you have explained, thanks for taking your time to understand it!

2dof commented 8 months ago

@isabido,

I still recommend You: consider commercial diverter, compare costs with mk2pvrouter project (maybe mk2pvroute will be cheaper, but at least you got complete project ( good start to adapt for Your requirement).

based on description of Your Regulator 25 A: It is widely used in lighting equipment,temperature control equipment,Ac motor soft start, ac train wave speed control and other power automatic adjustment occasions ) it is good choice for switching element, but You cant just simple "connect" signals" - there should be some controller from management power transfer, tracking, safety and switching power (like diverter) to home grid when heater is off.

isabido commented 8 months ago

Thanks for the recommendation, but I would like to continue working on my idea!! I'm trying to use NODERED with a PID node, but I would really like to do it on an ESP32.

2dof commented 8 months ago

"but I would like to continue working on my idea!! I'm trying to use NODERED with a PID node, but I would really like to do it on an ESP32." from My experience:

  1. control algorithm implement "locally" -> do it on esp32, if You want use code from my repo: use only pure PID algorithm (cut-off all selectors (P, PI, PD ( see figure 2.2 PID with anti-windup, no advances SP and PV (and MV) processing part is needed, or just implement PID algorithm on Your own. ( control plant will be "fixed" - once you Tune -it will stay)

-> But I think You could use even simple compensator algorithm ( lead-lag based solution).

  1. On MQTT/NodeRed implement visualisation/data acquisition and management (sending commands to main (esp32) controller. (other solution to run all ( controller and MQTT/node red) on Raspberry Pi as server based solution).

  2. If You want run control algorithm on node-red (and send command to esp32) - then be sure:

    • communication speed is sufficient for "plant" dynamics ( power fluctuations)
    • Implement safety in case of lost of communication

If you have any questions in future - ask :).

isabido commented 8 months ago

Massive thank you! for all your time and recommendations @2dof, but with your excellent work I am not able to implement it on an ESP32.

A practical example would really be interesting with a 0-3.3v analog input for PV, an 0-3.3v analog OUT output and a remote SP in a signal collected by MQTT.

I know that the nodered option is not optimal even to implement in an industrial process, although I am running everything on raspberry. It's much simpler for me.

Really, thank you very much for your support.

2dof commented 8 months ago

"A practical example would really be interesting with a 0-3.3v analog input for PV, an 0-3.3v ...." -> it is just scaling/normalization signal, since You got power from 0kW (night) to max 1kW (designed) so it is scaling in range 0- 3.3V ( or just like I prefer: 0 - 100% control range)

My code is to complicated/overshoot for Your needs (expect libs for signal processing), code is more base for hardware realization like Farnell omron and others (but with simens step 7 libs functionality also for server implementation) - Your solution is more like a Driver type controller - only tracking and main task is to design proper communication and safety.

About node-red in industrial automation - it is used with success in Visualisation ( all control run in OPC server then typical operator Dashboards in dedicated soft, and for clients/users: visualisation via mqtt in web browser)

Run all in RPI is good idea (all in one/compact), if it is Your first project like that, then try both solution ( good for learning):

  1. Your solution: controller on node-red (node-red-contrib-pid or node-red-contrib-easy-pid-controller ), but note thant "node red is great for prototypes and proof of concept projects" but not recommended for "industrial" solution - but for You maybe will fit.
  2. All control/regulation implement ass application/process in RPI (some simple server like solution ) and then connect via mosquitto mqtt and node-red to visualisation/dashboard): You get more flexibility in control sampling time (application) and for Node-red not deed fast flow refreshing (since it is just "operator" side management).

Thermal process like home water heating is slow (sampling rate could be even couple of seconds (depends form size of boiler), the fastest part will be power fluctuation delivered by inverter (solar panels) , so You need ensure that "tracking" reaction will be a little faster. first build simple model power fluctuation (see some profiles] and tracking (simple simulator) as base for design/testing mqtt/node-red and after that connect to hardware.

isabido commented 8 months ago

Thanks again for such an extensive response! A big greeting!