调参结束!

This commit is contained in:
unlockable
2023-07-07 14:27:41 +08:00
parent 0ac253b356
commit df88b636de

View File

@@ -12,14 +12,14 @@ double output_level = 0;
// PID
double err = 0, diff_err = 0, accumulate_err = 0;
const double Kp = 1, Ki = 0, Kd = 2.5;
const unsigned long DO_PID_CONTROL_IN_US = 50000;
const double Kp = 2, Ki = 0, Kd = 6;
const unsigned long DO_PID_CONTROL_IN_US = 1000;
// Settings for the level
long goal_step = 0;
long current_step = 0;
const int DISTANCE_BETWEEN_LEVELS = 300;
const int DISTANCE_BETWEEN_LEVELS = 50;
const int NUMBER_OF_LEVELS = 5;
const long MAX_GOAL_STEP = DISTANCE_BETWEEN_LEVELS * NUMBER_OF_LEVELS;
@@ -41,11 +41,13 @@ void onEncoAChange() {
DISTANCE_BETWEEN_LEVELS / 2 &&
goal_step < MAX_GOAL_STEP) {
goal_step += DISTANCE_BETWEEN_LEVELS;
accumulate_err = 0;
}
if ((goal_step - current_step) % DISTANCE_BETWEEN_LEVELS >
DISTANCE_BETWEEN_LEVELS / 2 &&
goal_step > 0) {
goal_step -= DISTANCE_BETWEEN_LEVELS;
accumulate_err = 0;
}
}
@@ -100,9 +102,12 @@ void setup() {
}
void loop() {
Serial.print("Goal: ");
// Serial.print("Goal: ");
Serial.print('$');
Serial.print(goal_step);
Serial.print(" Current: ");
Serial.println(current_step);
// Serial.print(" Current: ");
Serial.print(", ");
Serial.print(current_step);
Serial.print(";");
drawOLED();
}