some progress
This commit is contained in:
parent
c62427a3a1
commit
a339ceb163
@ -24,11 +24,7 @@ void MotorController::loadDefaults()
|
||||
|
||||
void MotorController::setTargetSpeed(int targetSpeedPercent)
|
||||
{
|
||||
if (targetSpeed != targetSpeedPercent)
|
||||
{
|
||||
Serial.print("MC: set targetSpeed to: ");
|
||||
Serial.println(targetSpeed);
|
||||
}
|
||||
|
||||
targetSpeed = constrain(targetSpeedPercent, 0, 100);
|
||||
}
|
||||
|
||||
@ -109,14 +105,6 @@ int MotorController::applyDynamicResponse(int targetPercent)
|
||||
smoothedPromille += delta;
|
||||
lastUpdateTime = currentTime;
|
||||
|
||||
// Debug-Ausgabe
|
||||
Serial.print("TargetPromille: ");
|
||||
Serial.print(targetPromille);
|
||||
Serial.print(", Delta: ");
|
||||
Serial.print(delta);
|
||||
Serial.print(", SmoothedPromille: ");
|
||||
Serial.println(smoothedPromille);
|
||||
|
||||
// Rückgabe in Prozent (gerundet)
|
||||
return (smoothedPromille + 5) / 10; // Rundung durch Addition von 5 vor Division
|
||||
}
|
||||
|
24
src/main.cpp
24
src/main.cpp
@ -111,7 +111,21 @@ void loop()
|
||||
}
|
||||
else if (serialControlEnabled)
|
||||
{
|
||||
// Serial control active, do nothing here; speed controlled via serial commands
|
||||
static int lastSpeed = 0;
|
||||
int currSpeed = motor.getSpeed();
|
||||
|
||||
if (lastSpeed > currSpeed)
|
||||
{
|
||||
Serial.print("Decreased Speed to: ");
|
||||
Serial.println(currSpeed);
|
||||
lastSpeed = currSpeed;
|
||||
}
|
||||
else if (lastSpeed < currSpeed)
|
||||
{
|
||||
Serial.print("Increased Speed to: ");
|
||||
Serial.println(currSpeed);
|
||||
lastSpeed = currSpeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -254,14 +268,10 @@ void handleSerialInput()
|
||||
case '+':
|
||||
serialControlEnabled = true;
|
||||
motor.setTargetSpeed(motor.getSpeed() + 1);
|
||||
Serial.print("Increased Speed to: ");
|
||||
Serial.println(motor.getSpeed());
|
||||
break;
|
||||
case '-':
|
||||
serialControlEnabled = true;
|
||||
motor.setTargetSpeed(motor.getSpeed() - 1);
|
||||
Serial.print("Decreased Speed to: ");
|
||||
Serial.println(motor.getSpeed());
|
||||
break;
|
||||
case '0':
|
||||
case '1':
|
||||
@ -300,6 +310,6 @@ void printHelp()
|
||||
|
||||
void configurePWMFrequency()
|
||||
{
|
||||
// Configure Timer1 for higher PWM frequency (e.g., ~8 kHz)
|
||||
TCCR1B = (TCCR1B & 0b11111000) | 0x01; // Set prescaler to 1
|
||||
// Configure Timer1 for higher PWM frequency (~4 kHz)
|
||||
TCCR1B = (1<<CS11); // Set prescaler to 8
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user