Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Math calculation order not correct #617

Open
blb4github opened this issue Jan 5, 2025 · 2 comments
Open

Math calculation order not correct #617

blb4github opened this issue Jan 5, 2025 · 2 comments

Comments

@blb4github
Copy link

blb4github commented Jan 5, 2025

Maybe a bit related to issue #557:

Calculation order is not correct. In the below rules set #PIDoutput and #PIDoutput2 should have the same result but they don't. I'm running firmware Alpha-d05c827 on HeishaMon large.

on System#Boot then
	#RoomTempDelta = 2;
	#PIDKp = 3;
	#PIDKi = 0;
	#PIDKd = 0;
	#PIDpreverror = 0;
	#PIDintegral = 0;
	#PIDoutput = 0;

	setTimer(1,10);
end


on test then
	#RoomTempD = #RoomTempDelta * -1;
	#PIDintegral = #PIDintegral + #RoomTempD;
	#PIDoutput = #PIDKp * #RoomTempD + (#PIDKi * #PIDintegral) + (#PIDKd * (#RoomTempD - #PIDpreverror));
	#PIDoutput2 = #PIDKp * #RoomTempD + #PIDKi * #PIDintegral + #PIDKd * (#RoomTempD - #PIDpreverror);
	#PIDpreverror = #RoomTempD;
	#RoomTempControl = round(#PIDoutput);
end

on timer=1 then
	test();
end

the result is:

==== timer=1 ====
rule #3 was executed in 400 microseconds

>>> local variables
 
>>> global variables

 0 #RoomTempDelta = 2
 1 #PIDKp = 3
 2 #PIDKi = 0
 3 #PIDKd = 0
 4 #PIDpreverror = -2
 5 #PIDintegral = -2
 6 #PIDoutput = -6
 7 #RoomTempD = -2
 8 #PIDoutput2 = -12
 9 #RoomTempControl = -6
@Binifada1956
Copy link

You are building a PID controller for OT?! Can you use it to further reduce the hysteresis of the thermostat and bring the controlled variable ?roomTemp as the difference to ?roomTempSet to zero?

Fantastic. I'm really looking forward to your results 👍

@blb4github
Copy link
Author

That's the plan indeed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants