[go: nahoru, domu]

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

hysteresis calculation wrong #49

Open
odenisenko-zz opened this issue Mar 28, 2020 · 1 comment
Open

hysteresis calculation wrong #49

odenisenko-zz opened this issue Mar 28, 2020 · 1 comment

Comments

@odenisenko-zz
Copy link

from recalculateAndTrigger method

function hysteresis(currentTemp, targetValue, thresholdRising, thresholdFalling) {
    var difference = (targetValue - currentTemp);
    var newHeaterStatus = (difference < 0 ? "off" : "on");
    var threshold = (newHeaterStatus === "off" ? thresholdRising : thresholdFalling);
    var changeStatus = (Math.abs(difference) >= threshold);
    if (changeStatus) {
        return newHeaterStatus;
    }
    return null;
}

test-case

var targetValue = 22;
var thresholdRising = 1;
var thresholdFalling = 3;

for (let currentTemp = 19; currentTemp < 25; currentTemp++) {
    console.log(currentTemp, hysteresis(currentTemp, targetValue, thresholdRising, thresholdFalling));
}

result

19 on test.js:17
20 null test.js:17
21 null test.js:17
22 null test.js:17
23 off test.js:17
24 off 
@SergiuToporjinschi
Copy link
Owner

Hi, It's possible, I will take a look. thank you for this scenario.

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