Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LSM9DS1 RangeFinder FastPWM
Dependents: PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board ... more
Diff: SpeedController.cpp
- Revision:
- 5:6cd242a61e4c
- Parent:
- 4:9c003c402033
- Child:
- 6:41dd03654c44
--- a/SpeedController.cpp Tue Apr 06 11:21:54 2021 +0000
+++ b/SpeedController.cpp Tue Apr 06 12:19:29 2021 +0000
@@ -11,7 +11,7 @@
const float SpeedController::MIN_DUTY_CYCLE = 0.02f; // minimum duty-cycle
const float SpeedController::MAX_DUTY_CYCLE = 0.98f; // maximum duty-cycle
-SpeedController::SpeedController(float COUNTS_PER_TURN, float KN, float KP, float MAX_VOLTAGE, PwmOut& pwm, EncoderCounter& encoderCounter) : pwm(pwm), encoderCounter(encoderCounter), thread(osPriorityHigh, 4096)
+SpeedController::SpeedController(float COUNTS_PER_TURN, float KN, float KP, float MAX_VOLTAGE, FastPWM& pwm, EncoderCounter& encoderCounter) : pwm(pwm), encoderCounter(encoderCounter), thread(osPriorityHigh, 4096)
{
this->COUNTS_PER_TURN = COUNTS_PER_TURN;
this->KN = KN;
@@ -19,8 +19,8 @@
this->MAX_VOLTAGE = MAX_VOLTAGE;
// Initialisieren der PWM Ausgaenge
- pwm.period(0.00005f); // PWM Periode von 50 us
- pwm = 0.5f; // Duty-Cycle von 50%
+ pwm.period(0.00005); // PWM Periode von 50 us
+ pwm.write(0.5); // Duty-Cycle von 50%
// Initialisieren von lokalen Variabeln
previousValueCounter = encoderCounter.read();
@@ -81,7 +81,7 @@
float dutyCycle = 0.5f + 0.5f*voltage/MAX_VOLTAGE;
if (dutyCycle < MIN_DUTY_CYCLE) dutyCycle = MIN_DUTY_CYCLE;
else if (dutyCycle > MAX_DUTY_CYCLE) dutyCycle = MAX_DUTY_CYCLE;
- pwm.write(dutyCycle);
+ pwm.write(static_cast<double>(dutyCycle));
}
}
