From df88b636de04d9ecb64e27ce1ec6df7bb19c7931 Mon Sep 17 00:00:00 2001 From: unlockable Date: Fri, 7 Jul 2023 14:27:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=8F=82=E7=BB=93=E6=9D=9F=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Homework/Homework6/Homework6.ino | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Homework/Homework6/Homework6.ino b/Homework/Homework6/Homework6.ino index 29ab0d2..007484e 100644 --- a/Homework/Homework6/Homework6.ino +++ b/Homework/Homework6/Homework6.ino @@ -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(); } \ No newline at end of file