pid: recalibrate with ziegler-nichols2 and matlab simulation

main
EmaMaker 2024-01-05 12:55:24 +01:00
parent 75c2c969fe
commit f2e85c4629
4 changed files with 18 additions and 18 deletions

View File

@ -9,14 +9,18 @@ constexpr float MOT_DX_MULT = 1.0;
ArduPID myController; ArduPID myController;
// Calculated with matlab, then adjusted by hand // Calculated with matlab, then adjusted by hand
// Decent values?
/*constexpr double KP = 2.5;
constexpr double KI = 0.04;
constexpr double KD = 0.03;*/
// Event better /* With KP = 10, about 12 periods of oscillation in 1sec
constexpr double KP = 4; Pc = 0.083
constexpr double KI = 5;
PID Kp = 0.6Kc, Ti = 0.5Pc Td = 0.125Pc
Ki = KpTc/ti
Kd = KpTd/Tc
*/
constexpr double KP = 6;
constexpr double KI = 0.2;
constexpr double KD = 0.1; constexpr double KD = 0.1;
//double setpoint = -0.015; //double setpoint = -0.015;
@ -36,22 +40,18 @@ void setup(void) {
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); digitalWrite(LED_BUILTIN, HIGH);
myController.begin(&input, &output, &setpoint, KP, KI, KD, P_ON_E, FORWARD);
myController.setOutputLimits(-0.72, 0.72); // double of max torque motors can exhert
myController.setWindUpLimits(-0.2, 0.02);
myController.setSampleTime(1);
myController.start();
// Let the initial error from madgwick filter discharge without affecting the integral term of the PID // Let the initial error from madgwick filter discharge without affecting the integral term of the PID
unsigned long t = millis(); unsigned long t = millis();
while (millis() - t < 3000) { while (millis() - t < 3000) {
compute(); update_imu();
} }
move_pwm(MOT_SX, 0); myController.begin(&input, &output, &setpoint, KP, KI, KD, P_ON_E, FORWARD);
move_pwm(MOT_DX, 0); myController.setOutputLimits(-0.72, 0.72); // double of max torque motors can exhert
myController.reset(); // myController.setWindUpLimits(-0.2 , 0.02);
delay(1000); myController.setSampleTime(1);
myController.start();
digitalWrite(LED_BUILTIN, LOW); digitalWrite(LED_BUILTIN, LOW);
} }

Binary file not shown.