added constant term
This commit is contained in:
parent
3f2727464b
commit
043bb622fb
1 changed files with 15 additions and 3 deletions
|
@ -24,11 +24,11 @@ protected:
|
|||
enum CTRL_MODE : uint8_t {CTRL_DIRECT, CTRL_SPEED};
|
||||
volatile CTRL_MODE ctrlMode = CTRL_DIRECT;
|
||||
|
||||
// TODO: After you tune your motors, set the gains here.
|
||||
float Kp = 2.50;
|
||||
float Kp = 2.50; // proportional to error
|
||||
float Ki = 0.03;
|
||||
float Kd = 0;
|
||||
float Kf = 3.00;
|
||||
float Kf = 3.00; // proportional to setpoint
|
||||
int16_t C = 22; // constant added to effort
|
||||
|
||||
// Used to keep track of the target speed, in counts / interval.
|
||||
float targetSpeed = 0;
|
||||
|
@ -140,6 +140,18 @@ protected:
|
|||
// Calculate the effort from the PID gains
|
||||
int16_t effort = Kp * error + Ki * sumError + Kd * errorDiff + Kf * targetSpeed;
|
||||
|
||||
// increase effort to match static friction
|
||||
if (effort > 0) {
|
||||
effort += C;
|
||||
} else if (effort < 0) {
|
||||
effort -= C;
|
||||
}
|
||||
|
||||
// stop motor if halted and stopped
|
||||
if (abs(error) < 3. && targetSpeed == 0) {
|
||||
effort = 0;
|
||||
}
|
||||
|
||||
// Set the effort for the motor
|
||||
SetEffort(effort);
|
||||
|
||||
|
|
Loading…
Reference in a new issue