mirror of
https://gitlab.dit.htwk-leipzig.de/phillip.kuehne/dezibot.git
synced 2025-07-05 10:04:31 +02:00
Integrate Motors into Power Management
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
#include "Motion.h"
|
||||
#include "power/Power.h"
|
||||
|
||||
#define MOTOR_LEFT_PIN 12
|
||||
#define MOTOR_RIGHT_PIN 11
|
||||
|
||||
Motor::Motor(uint8_t pin, ledc_timer_t timer, ledc_channel_t channel){
|
||||
this->pin = pin;
|
||||
this->channel = channel;
|
||||
@ -24,6 +27,13 @@ void Motor::begin(void){
|
||||
};
|
||||
|
||||
void Motor::setSpeed(uint16_t duty){
|
||||
const float dutyFactor = duty / static_cast<float>(1 << DUTY_RES);
|
||||
const float current = PowerParameters::CurrentConsumptions::CURRENT_MOTOR_T_ON * dutyFactor;
|
||||
if (this->pin == MOTOR_LEFT_PIN){
|
||||
Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::MOTOR_LEFT, current, MOTOR_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
} else {
|
||||
Power::waitForCurrentAllowance(PowerParameters::PowerConsumers::MOTOR_RIGHT, current, MOTOR_MAX_EXECUTION_DELAY_MS, NULL);
|
||||
}
|
||||
int difference = duty-this->getSpeed();
|
||||
if (difference > 0){
|
||||
for(int i = 0;i<difference;i+=difference/20){
|
||||
|
Reference in New Issue
Block a user