remove most of the defines

This commit is contained in:
2023-08-18 15:34:56 +02:00
parent 4cd2b9368d
commit a82b32087c
21 changed files with 155 additions and 285 deletions
+14 -19
View File
@@ -13,9 +13,9 @@
#include "motorControl.h"
MotorControl::MotorControl() {
this->setMinPwm(PWMMIN);
this->setMaxPwm(PWMMAX);
this->loopDelay = DELAY;
this->setMinPwm(MotorControl::pwmMin);
this->setMaxPwm(MotorControl::pwmMax);
Component::loopDelay = MotorControl::loopDelay;
}
void MotorControl::init(uint8_t pwmPin, uint8_t pwmChannel, uint8_t dir_1, uint8_t dir_2) {
@@ -30,7 +30,7 @@ void MotorControl::init(uint8_t pwmPin, uint8_t pwmChannel, uint8_t dir_1, uint8
digitalWrite(this->dir_1, LOW);
digitalWrite(this->dir_2, LOW);
ledcSetup(this->pwmChannel, PWMFREQ, this->pwmRes);
ledcSetup(this->pwmChannel, MotorControl::pwmFreq, MotorControl::pwmRes);
ledcAttachPin(this->pwmPin, this->pwmChannel);
ledcWrite(this->pwmChannel, 0);
}
@@ -42,14 +42,14 @@ void MotorControl::run() {
// Difference between targetPower and power
int16_t difference = this->targetPower - this->power;
// Check that the target speed is close to 0 and that the abs_difference is lower than powersteps
if (abs(this->targetPower) < powersteps && abs_difference < powersteps) {
// Check that the target speed is close to 0 and that the abs_difference is lower than MotorControl::powerSteps
if (abs(this->targetPower) < MotorControl::powerSteps && abs_difference < MotorControl::powerSteps) {
this->setRealPower(0);
return;
}
// Correct speed
if (abs_difference < powersteps) {
if (abs_difference < MotorControl::powerSteps) {
return;
}
@@ -58,23 +58,23 @@ void MotorControl::run() {
// Positive or negative speed
if (this->power >= 0) {
if (difference > 0) {
this->increasePower(powersteps);
this->increasePower(MotorControl::powerSteps);
} else {
this->increasePower(-powersteps);
this->increasePower(-MotorControl::powerSteps);
}
} else {
this->increasePower(powersteps);
this->increasePower(MotorControl::powerSteps);
}
} else {
// Positive or negative speed
if (this->power >= 0) {
this->increasePower(-powersteps);
this->increasePower(-MotorControl::powerSteps);
} else {
if (difference > 0) {
this->increasePower(powersteps);
this->increasePower(MotorControl::powerSteps);
} else {
this->increasePower(-powersteps);
this->increasePower(-MotorControl::powerSteps);
}
}
}
@@ -94,11 +94,6 @@ void MotorControl::setMaxPwm(uint8_t max) {
this->dutycycleMax = max;
}
uint16_t MotorControl::setPowerSteps(uint8_t increment) {
this->powersteps = increment;
return (uint16_t) (this->loopDelay * ( 100 / powersteps ));
}
void MotorControl::setTargetPower(int8_t power) {
if (power <= 100 && power >= -100)
this->targetPower = power;
@@ -168,7 +163,7 @@ void MotorControl::setRealPower(int8_t power) {
void MotorControl::increasePower(int8_t power) {
//TODO: Exceptionhandling
//TODO: make a stop befor a direction change
if (abs(power) > 2 * powersteps) {
if (abs(power) > 2 * MotorControl::powerSteps) {
Serial.println("Invalid Argument in MotorControl::increasePower");
return;
}