This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Outside compensation curve
#7
(04.12.2018, 13:45)merel Wrote: Hello.

You can try this:

Code:
function linear_by_table(input,curve,offset) local FDY = offset or 0     fk1= (curve["y"][1] - curve["y"][2]) / (curve["x"][1] - curve["x"][2])     fk2= (curve["y"][2] - curve["y"][3]) / (curve["x"][2] - curve["x"][3])     fk3= (curve["y"][3] - curve["y"][4]) / (curve["x"][3] - curve["x"][4])     if input < curve["x"][1] then         out = curve["y"][1] + FDY;     elseif input >= curve["x"][1] and input < curve["x"][2] then             out = fk1 * (input - curve["x"][1]) + curve["y"][1] + FDY     elseif input >= curve["x"][2] and input < curve["x"][3] then         out = fk2 * (input - curve["x"][2]) + curve["y"][2] + FDY     elseif input >= curve["x"][3] and input < curve["x"][4] then             out = fk3 * (input - curve["x"][3]) + curve["y"][3] + FDY     else         out = curve["y"][4] + FDY     end  return out end curve = {} curve["x"] = {-20,-10,0,20} curve["y"] = {80,70,65,18} --offset=2 --log(linear_by_table(20,curve,offset)) log(linear_by_table(-15,curve))
Wow. Thanks! Used this today and made some small changes.

My code looks like this and runs nicely.
 

Code:
function linear_by_table(input, curve, offset)     local FDY = offset or 0     local n = #curve["x"] -- Number of points     if n ~= #curve["y"] then         error("x and y lists must have the same number of values")     end     local out     if input < curve["x"][1] then         out = curve["y"][1] + FDY     elseif input >= curve["x"][n] then         out = curve["y"][n] + FDY     else         for i = 1, n - 1 do             if input >= curve["x"][i] and input < curve["x"][i + 1] then                 local fk = (curve["y"][i + 1] - curve["y"][i]) / (curve["x"][i + 1] - curve["x"][i])                 out = fk * (input - curve["x"][i]) + curve["y"][i] + FDY                 break             end         end     end     return out end -- Define the curve for interpolation local curve = {x = {-20, -10, 0, 10, 20}, y = {42, 34, 32, 25, 15}} -- Adjust offset to shift the entire curve local offset = 0 -- Get outdoor temperature from KNX address 0/3/0 local outdoor_temp = grp.getvalue('0/3/0') -- Calculate the flow setpoint based on the outdoor temperature local flow_setpoint = linear_by_table(outdoor_temp, curve, offset) -- Write the calculated value to KNX address 5/5/0 grp.write('5/5/0', flow_setpoint) -- Log the results log('Outdoor temperature: ' .. outdoor_temp .. ', Flow setpoint: ' .. flow_setpoint)
Reply


Messages In This Thread
Outside compensation curve - by oyvindnordbo - 04.12.2018, 07:13
RE: Outside compensation curve - by admin - 04.12.2018, 07:29
RE: Outside compensation curve - by admin - 04.12.2018, 09:20
RE: Outside compensation curve - by Daniel - 04.12.2018, 09:22
RE: Outside compensation curve - by merel - 04.12.2018, 13:45
RE: Outside compensation curve - by jerryhenke - 16.01.2025, 11:42
RE: Outside compensation curve - by admin - 17.01.2025, 08:18

Forum Jump: