File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments