-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
150 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "Controler.h" | ||
|
||
float i_val, lastDifference; | ||
|
||
controler::controler(int p_factor, float d_factor, float i_factor, int max){ | ||
Kp = p_factor; | ||
Kd = d_factor; | ||
Ki = i_factor; | ||
maxOut = max; | ||
} | ||
|
||
float controler::compute(int is, int should){ | ||
float difference = should - is; | ||
|
||
float d_val = difference - lastDifference; | ||
|
||
float result = (difference * Kp) + (d_val * Kd)+(i_val*Ki); | ||
|
||
lastDifference = difference; | ||
i_val += lastDifference; | ||
|
||
if (result > maxOut){ | ||
result = maxOut; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
void controler::setPFactor(int factor){ | ||
Kp = factor; | ||
} | ||
|
||
void controler::setIFactor(int factor){ | ||
Ki = factor; | ||
} | ||
|
||
void controler::setDFactor(int factor){ | ||
Kd = factor; | ||
} | ||
|
||
void controler::setMax(int max){ | ||
maxOut = max; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include <Elegoo.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters