refactore motorControl

This commit is contained in:
2023-08-13 13:42:22 +02:00
parent 1e15cf5d5d
commit cd319f43e4
2 changed files with 48 additions and 48 deletions
+17 -17
View File
@@ -35,17 +35,17 @@ class MotorControl {
/**
* @brief Initialize the motorController
*
* @param pwm_pin The output pin for the signal on the esp.
* @param pwm_channel One of the pwm channels from the esp.
* @param pwmPin The output pin for the signal on the esp.
* @param pwmChannel One of the pwm channels from the esp.
* @param dir_1 First direction pin for the H-Bridge.
* @param dir_2 Second direction pin for the H-Bridge.
*/
void init(uint8_t pwm_pin, uint8_t pwm_channel, uint8_t dir_1, uint8_t dir_2);
void init(uint8_t pwmPin, uint8_t pwmChannel, uint8_t dir_1, uint8_t dir_2);
/**
* @brief Calls runMotorControl() to update the pwm signal
*
* This function should be called every mainloop. If the delay is not reached, than the
* This function should be called every mainloop. If the delayLoop is not reached, than the
* functions returns immediately.
* @see runMotorControl()
* @see DELAY
@@ -81,10 +81,10 @@ class MotorControl {
*
* Set the increment of the steps with which the dutycycle is
* increased or decreased. Note the dependency between the increment
* and delay().
* and delayLoop().
*
* The formula for the time between 0% and 100% power is:
* time[ms] = delay * ( 100 / increment )
* time[ms] = delayLoop * ( 100 / increment )
* 500 ms are recommended
*
* @see setDelay()
@@ -105,17 +105,17 @@ class MotorControl {
void setTargetPower(int8_t power);
/**
* @brief Set the min delay between each loop
* @brief Set the min delayLoop between each loop
*
* Note the dependency between delay and
* Note the dependency between delayLoop and
* setPowerSteps().
*
* @see setPowerSteps()
*
* @param delay time in Milliseconds
* @param delayLoop time in Milliseconds
* @return time from 0% power to 100% power in Milliseconds
*/
uint16_t setDelay(uint8_t delay);
uint16_t setDelay(uint8_t delayLoop);
/**
* @brief Stops the motor like setTargetPower() to 0
@@ -152,19 +152,19 @@ class MotorControl {
void setRealPower(int8_t power);
void increasePower(int8_t power);
int8_t target_power = 0;
int8_t targetPower = 0;
int8_t power = 0;
uint8_t direction = 0; // 0 = stop, 1 = forward, 2 = backward
uint8_t pwm_pin;
uint8_t pwm_channel;
uint8_t pwm_res = PWMRES;
uint8_t pwmPin;
uint8_t pwmChannel;
uint8_t pwmRes = PWMRES;
uint16_t dutycycle = 0;
uint8_t dutycycle_min;
uint8_t dutycycle_max;
uint8_t dutycycleMin;
uint8_t dutycycleMax;
uint8_t dir_1;
uint8_t dir_2;
uint8_t delay = DELAY;
uint8_t delayLoop = DELAY;
uint8_t powersteps = POWERSTEPS;
uint32_t lastMillis = 0;