summaryrefslogtreecommitdiff
path: root/debug/motordriver/PID/PID.ino
diff options
context:
space:
mode:
authorAbel Tim <abel@main.home>2024-07-15 14:53:41 +0200
committerAbel Tim <abel@main.home>2024-07-15 14:53:41 +0200
commit6fcefaf1c7087675d403bc3451ca1997ecaa83d6 (patch)
treee43f6e74fac54aa3c90a514508fe2415430990c3 /debug/motordriver/PID/PID.ino
parent3ce2797f62a124a54644968141feab710b816837 (diff)
downloadrobotica-6fcefaf1c7087675d403bc3451ca1997ecaa83d6.tar.gz
robotica-6fcefaf1c7087675d403bc3451ca1997ecaa83d6.zip
poster
Diffstat (limited to 'debug/motordriver/PID/PID.ino')
-rw-r--r--debug/motordriver/PID/PID.ino36
1 files changed, 16 insertions, 20 deletions
diff --git a/debug/motordriver/PID/PID.ino b/debug/motordriver/PID/PID.ino
index 313b440..c7f351a 100644
--- a/debug/motordriver/PID/PID.ino
+++ b/debug/motordriver/PID/PID.ino
@@ -1,14 +1,15 @@
#include <TimerThree.h>
-#include "ArduPID.h"
+#include <QuickPID.h>
-ArduPID myController;
-double input;
-double output;
-double setpoint = 950; // Desired RPM
-double p = 40; // PID P-term
-double i = 2; // PID I-term
-double d = 0; // PID D-term
+//https://www.pololu.com/product/2997
+//https://www.pololu.com/product/4861
+
+
+float Setpoint, Input, Output;
+float Kp = 2, Ki = 5, Kd = 1;
+QuickPID myPID(&Input, &Output, &Setpoint);
+
int enA = 1; // PWM pin
int enB = 2; // GND
@@ -44,12 +45,10 @@ void setup() {
Serial.begin(9600);
// PID settings
- myController.begin(&input, &output, &setpoint, p, i, d);
- myController.setOutputLimits(0, 1000); // Output limits for PWM control
- myController.setBias(500); // Starting bias for PWM
- myController.setWindUpLimits(-50, 50);
-
- myController.start();
+ Input = rpm;
+ Setpoint = 500;
+ myPID.SetTunings(Kp, Ki, Kd);
+ myPID.SetMode(myPID.Control::automatic);
}
void updatePWM() {
@@ -106,11 +105,8 @@ void move(int sped) {
}
void loop() {
- readenc();
- input = rpm;
- myController.compute();
- myController.debug(&Serial, "myController", PRINT_INPUT);
+ Input = rpm;
+ myPID.Compute();
+ move(Output);
- move(output); // Replace with plant control signal
- delay(100);
}