Add power Modeling functions to all components
This commit is contained in:
@@ -56,6 +56,24 @@ class Motor{
|
||||
* @return current speedvalue of the motor
|
||||
*/
|
||||
uint16_t getSpeed(void);
|
||||
|
||||
/**
|
||||
* @brief Get the current consumption of the motor at specified speed
|
||||
*
|
||||
* @param duty the duty cyle that should be considered, can be between 0-8192
|
||||
*
|
||||
* @return current consumption in milliamperes
|
||||
*/
|
||||
float modelCurrentConsumption(uint16_t duty);
|
||||
|
||||
/**
|
||||
* @brief Estimate the energy consumption of the display
|
||||
* @param durationMs time the display will be on
|
||||
* @return consumed energy in coloumbs
|
||||
*/
|
||||
float modelChargeConsumptionOn(uint16_t duty, uint16_t durationMs);
|
||||
|
||||
|
||||
protected:
|
||||
uint8_t pin;
|
||||
ledc_timer_t timer;
|
||||
|
||||
@@ -25,9 +25,7 @@ void Motor::begin(void) {
|
||||
};
|
||||
|
||||
bool 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;
|
||||
const float current = this->modelCurrentConsumption(duty);
|
||||
if (this->pin == MOTOR_LEFT_PIN) {
|
||||
if (!Power::waitForCurrentAllowance(
|
||||
PowerParameters::PowerConsumers::MOTOR_LEFT, current,
|
||||
@@ -69,3 +67,12 @@ bool Motor::setSpeed(uint16_t duty) {
|
||||
};
|
||||
|
||||
uint16_t Motor::getSpeed(void) { return this->duty; };
|
||||
|
||||
float modelCurrentConsumption(uint16_t duty) {
|
||||
const float dutyFactor = duty / static_cast<float>(1 << DUTY_RES);
|
||||
return PowerParameters::CurrentConsumptions::CURRENT_MOTOR_T_ON * dutyFactor;
|
||||
}
|
||||
|
||||
float modelChargeConsumptionOn(uint16_t duty, uint16_t durationMs) {
|
||||
return modelCurrentConsumption(duty) * durationMs * 10e6;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user