Skip to content
This repository has been archived by the owner on Aug 17, 2021. It is now read-only.

Commit

Permalink
controller: don't switch on PID logic until temperature is x% of targ…
Browse files Browse the repository at this point in the history
…et temperature

prevents PID from skewing over long heating times
  • Loading branch information
andy-haynes committed Jan 19, 2018
1 parent f5afaa4 commit dfd66ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 4 additions & 1 deletion controller/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { w3cwebsocket } from 'websocket';


export default {
PID: {
strikeThreshold: 0.95 // percentage of target temp to reach before switching to PID control
},
thermometer: {
sampleIntervalMS: 750
sampleIntervalMS: 750 // ms between temperature measurements
},
websocket: {
url: 'ws://localhost:8081',
Expand Down
19 changes: 14 additions & 5 deletions controller/controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import BrewUpdate from '../src/models/BrewUpdate';
import config from './config';
import { MockRelay, MockThermometer } from './mocks';
import { PIDController } from './pid';
import ZynetConnection from './connection';
Expand All @@ -9,15 +10,23 @@ const mockRelay = new MockRelay();
const mockThermometer = new MockThermometer(mockRelay);
const mockUpdate = new BrewUpdate(1, 1, 60, 68, 152, false, 0);

const pidController = new PIDController(1.5, 1, 0.5, 3);
pidController.setTargetTemperature(75);

const connection = new ZynetConnection();
connection.connect();

let pidThresholdReached = false;
let targetTemperature = 80;

const pidController = new PIDController(1.5, 1, 0.5, 3);
pidController.setTargetTemperature(targetTemperature);

mockThermometer.sensor$.subscribe((temperature: number) => {
pidController.updateTemperature(temperature);
mockRelay.switch(pidController.state);
if (pidThresholdReached) {
pidController.updateTemperature(temperature);
mockRelay.switch(pidController.state);
} else {
pidThresholdReached = temperature >= (targetTemperature * config.PID.strikeThreshold);
mockRelay.switch(!pidThresholdReached);
}

connection.send(new ZynetMessage(
ZynetMessageType.LogUpdate,
Expand Down

0 comments on commit dfd66ad

Please sign in to comment.