Drehmoment wird nun normal gemittelt, output Variable ist jetzt global, PID Parameter aktualisiert, der Spannungsausgang bleibt erhalten - auch wenn die Regelung pausiert wurde.

This commit is contained in:
2024-07-25 16:28:38 +02:00
parent a49ca289e1
commit 34218c251f
5 changed files with 443 additions and 180 deletions

View File

@@ -17,7 +17,8 @@
#define BLOCK_DETECTION_VALUE setpoint
#define ROTATION_DETECTION_VALUE 100
#define _getTorque abs(prg.getTorque(false, ALPHA))
//#define _getTorque abs(prg.getTorque(false, ALPHA))
#define _getTorque abs(prg.getTorque(false))
#define _getAngle prg.getAngle()
struct Timer {
@@ -65,6 +66,7 @@ float filteredTorque = 0; // gefilterter Wert
float filteredSetpoint = 0;
float setpoint;
int oldSetpoint;
unsigned int output;
static int lastOutput;
float manVolt;
unsigned char CW;
@@ -75,8 +77,8 @@ unsigned char BLOCK_SOLVED;
bool In_Src_Sw = false;
float Kp = 0.0;
float Ki = 0.1;
float Kp = 0.11;
float Ki = 0.9;
float Kd = 0.0;
/*float Kp = 1.0;
@@ -172,12 +174,6 @@ void loop() {
waitStart(speedcheck_timer, SPEEDCHECK_TIME);
}
if (Richtungswechsel) {
myPID.reset();
Richtungswechsel = 0;
}
if (!BLOCK) {
// Aktualisieren des Setpoints basierend auf dem Winkel
int index = (float)angle * 0.002; // 0.5 Grad pro Index
@@ -196,13 +192,20 @@ void loop() {
}*/
myPID.setTunings(Kp, Ki, Kd);
if (lastAnglePID != angle && Pon && !manOut && !checkLimits(setpoint, abs(actTorque), upperLimit, lowerLimit) &&((abs(actTorque) >= 1000 || abs(RotSpeed) >= 400) || abs(actTorque) > setpoint)) {
unsigned int output = myPID.compute(setpoint, actTorque);
prg.setOutput(output);
prg.ActOut = output;
} else if (abs(actTorque) < 1000) {
myPID.reset();
if (Richtungswechsel) {
//myPID.reset();
Richtungswechsel = 0;
}
if (lastAnglePID != angle && Pon && !manOut && !checkLimits(setpoint, abs(actTorque), upperLimit, lowerLimit) &&((abs(actTorque) >= 1000 || abs(RotSpeed) >= 400) || abs(actTorque) > setpoint)) {
output = myPID.compute(setpoint, abs(actTorque));
prg.setOutput(output);
//prg.ActOut = output;
} else if (abs(actTorque) < 1000) {
//myPID.reset();
}
prg.ActOut = output;
lastAnglePID = angle;
if (LOGGING) {
@@ -285,6 +288,7 @@ void setAnalogResolution(unsigned char res) {
void UPDATE_VALUES() {
angle = _getAngle;
actTorque = _getTorque;
prg.updateActOut(actTorque);
@@ -322,7 +326,7 @@ void DEBUG_PRINTER() {
Serial.print("Winkel: ");
Serial.println((float)angle / 1000, 3);
Serial.print("Drehmoment: ");
Serial.println((float)actTorque / 1000, 3);
Serial.println(abs(actTorque) / 1000, 2);
Serial.print("Geschwindigkeit: ");
Serial.println(RotSpeed);
Serial.print("Drehrichtung: ");
@@ -386,7 +390,7 @@ void parseCommand(const String &command) {
} else if (command[0] == 'a') {
Serial.print(angle);
Serial.print(";");
Serial.print(actTorque);
Serial.print(abs(actTorque));
Serial.print(";");
Serial.print(prg.getSetPoint(1));
Serial.print(";");