Example #1
0
			every(100, function() {

				if(flag)
				{
					my.esc.angle(65);
				//my.servo.angle(160);
				my.lidar.distance(function(err, data) {
					dis=parseInt(data);
				});
				if(Math.abs(dis-ctr.getInput())<200)
				// if(dis>200)
				// 	ctr.setPoint(dis);
				// if(dis<150)
				// 	ctr.setPoint(30);
				//if(1)
				{
					ctr.setInput(dis);
				ctr.compute();
				my.servo.angle(110+Math.round(ctr.getOutput()));

				}
				else
					{my.servo.angle(110);
					console.log("print no in!");
				}
				console.log("set"+ctr.getSetPoint()+"distance: " + dis+",output:"+Math.round(ctr.getOutput()));
				}
				if(!flag)
				{

				my.servo.angle(45);



				turning=0;
				}
	})}}).start();
Example #2
0
function faketemp() {
	//temp=Math.round((temp+.1));
	if ( temp < 69 ) temp=(temp+.1);
	console.log(temp);
	ctr.setInput(temp); 
}
Example #3
0
var PID = require('pid-controller');

var temp=50;
var ctr = new PID(50, 66, 10,2,1, PID.DIRECT )
ctr.setMode(ctr.AUTOMATIC);
ctr.setTunings(10,2,1);
ctr.setOutputLimits(0,100);
ctr.setInput(temp); 

// 
function checktemp() {
	ctr.compute();
	console.log(ctr);
}

function faketemp() {
	//temp=Math.round((temp+.1));
	if ( temp < 69 ) temp=(temp+.1);
	console.log(temp);
	ctr.setInput(temp); 
}

ctr.compute(); 

setInterval(checktemp, 1000 );
setInterval(faketemp, 700 );