Clean & pid tuning
This commit is contained in:
parent
f3021c1f58
commit
b86484d59d
@ -20,25 +20,29 @@ void ControlledMotor::SetTargetSpeed(float speed) {
|
||||
}
|
||||
|
||||
void ControlledMotor::Update(float currentTimeMs) {
|
||||
actualSpeed = encoder->GetRevolutionsPerSecond(currentTimeMs);
|
||||
this->actualSpeed = encoder->GetRevolutionsPerSecond(currentTimeMs);
|
||||
if (this->currentTargetSpeed < 0)
|
||||
actualSpeed = -actualSpeed;
|
||||
this->actualSpeed = -this->actualSpeed;
|
||||
|
||||
float deltaTime = currentTimeMs - this->lastUpdateTime;
|
||||
|
||||
float error = currentTargetSpeed - actualSpeed;
|
||||
float error = this->currentTargetSpeed - this->actualSpeed;
|
||||
float errorChange = (error - lastError) * deltaTime;
|
||||
|
||||
float delta = error * pidP + errorChange * pidD;
|
||||
|
||||
// Serial.print(" actualSpeed ");
|
||||
// Serial.print(actualSpeed);
|
||||
// Serial.print(" motor target speed ");
|
||||
// Serial.print(motor->currentTargetSpeed);
|
||||
// Serial.print(" + ");
|
||||
// Serial.print(error * pidP);
|
||||
// Serial.print(" + ");
|
||||
// Serial.println(errorChange * pidD);
|
||||
Serial.print(" actual Speed ");
|
||||
Serial.print(actualSpeed);
|
||||
Serial.print(" target Speed ");
|
||||
Serial.print(this->currentTargetSpeed);
|
||||
Serial.print(" motor target speed ");
|
||||
Serial.print(motor->currentTargetSpeed);
|
||||
Serial.print(" + ");
|
||||
Serial.print(error * pidP);
|
||||
Serial.print(" + ");
|
||||
Serial.print(errorChange * pidD);
|
||||
Serial.print(" = ");
|
||||
Serial.println(motor->currentTargetSpeed + delta);
|
||||
|
||||
motor->SetTargetSpeed(motor->currentTargetSpeed +
|
||||
delta); // or something like that
|
||||
|
@ -19,9 +19,9 @@ public:
|
||||
}
|
||||
float velocity;
|
||||
|
||||
float pidP = 0.02F;
|
||||
float pidD = 0.001F;
|
||||
float pidI = 0;
|
||||
float pidP = 0.1F;
|
||||
float pidD = 0.0F;
|
||||
float pidI = 0.0F;
|
||||
|
||||
void Update(float currentTimeMs) override;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user