• Please find a attached a port of the Arduino pid library to the Espruino. Function names have been shortened, to make it more suitable for this environment. If there is interest, I'll comment the code and submit it as a module.

    In the short term, this can be saved as a local module for testing.

    var PID = require('pid-controller');
    var model = {};
    model.temp = [0, 0];
    model.setpoint = 66;
    model.duty = 0;
    
    var config = {
    	mash : {
    		"Kc" : 10,
    		"Ti" : 2,
    		"Td" : 2,
    		"setPoint" : model.setpoint,
    		cycleTime : 2000
    	}
    };
    var ctr = new PID(model.temp[0], config.mash.setPoint, config.mash.Kc, config.mash.Ti, config.mash.Td, PID.fwd);
    ctr.mode(PID.auto);
    ctr.setLimits(0, 100);
    setInterval(function () {
    	ctr.compute();
    	model.duty = ctr.getOutput();
    }, 200);
    

    1 Attachment

About

Avatar for Wilberforce @Wilberforce started