Skip to content

Commit f6c8624

Browse files
committed
Merge pull request #1 from emersion/patch-1
Adds reset() method
2 parents cef08dd + d819ddf commit f6c8624

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,10 @@ Controller.prototype.update = function(current_value) {
2828
return (this.k_p*error) + (this.k_i * this.sumError) + (this.k_d * dError);
2929
};
3030

31-
module.exports = Controller;
31+
Controller.prototype.reset = function() {
32+
this.sumError = 0;
33+
this.lastError = 0;
34+
this.lastTime = 0;
35+
};
36+
37+
module.exports = Controller;

test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,12 @@ describe('pid-controller', function(){
3737
var correction = ctr.update(vt);
3838
correction.should.equal(8);
3939
});
40+
41+
it('should reset the controller', function(){
42+
ctr.reset();
43+
ctr.sumError.should.equal(0);
44+
ctr.lastError.should.equal(0);
45+
ctr.lastTime.should.equal(0);
46+
});
4047

4148
});

0 commit comments

Comments
 (0)