DC motor improvements (#1025)
* extract interface, comments, conform names * fwd declare
This commit is contained in:
parent
19ebea8b95
commit
bb22296f61
|
@ -136,7 +136,7 @@ public:
|
|||
pin_output_mode_e *pinEnableMode,
|
||||
brain_pin_e pinDir1,
|
||||
brain_pin_e pinDir2) {
|
||||
dcMotor.SetType(useTwoWires ? TwoPinDcMotor::ControlType::PwmDirectionPins : TwoPinDcMotor::ControlType::PwmEnablePin);
|
||||
dcMotor.setType(useTwoWires ? TwoPinDcMotor::ControlType::PwmDirectionPins : TwoPinDcMotor::ControlType::PwmEnablePin);
|
||||
|
||||
m_pinEnable.initPin("ETB Enable", pinEnable, pinEnableMode);
|
||||
m_pinDir1.initPin("ETB Dir 1", pinDir1);
|
||||
|
@ -211,7 +211,7 @@ static percent_t currentEtbDuty;
|
|||
}
|
||||
|
||||
if (startupPositionError) {
|
||||
etb->dcMotor.Set(0);
|
||||
etb->dcMotor.set(0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -221,12 +221,12 @@ static percent_t currentEtbDuty;
|
|||
}
|
||||
|
||||
if (!cisnan(directPwmValue)) {
|
||||
etb->dcMotor.Set(directPwmValue);
|
||||
etb->dcMotor.set(directPwmValue);
|
||||
return;
|
||||
}
|
||||
|
||||
if (boardConfiguration->pauseEtbControl) {
|
||||
etb->dcMotor.Set(0);
|
||||
etb->dcMotor.set(0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ static percent_t currentEtbDuty;
|
|||
autoTune.output,
|
||||
value);
|
||||
scheduleMsg(&logger, "AT PID=%f", value);
|
||||
etb->dcMotor.Set(ETB_PERCENT_TO_DUTY(value));
|
||||
etb->dcMotor.set(ETB_PERCENT_TO_DUTY(value));
|
||||
|
||||
if (result) {
|
||||
scheduleMsg(&logger, "GREAT NEWS! %f/%f/%f", autoTune.GetKp(), autoTune.GetKi(), autoTune.GetKd());
|
||||
|
@ -275,7 +275,7 @@ static percent_t currentEtbDuty;
|
|||
currentEtbDuty = engine->engineState.etbFeedForward +
|
||||
etbPid.getOutput(targetPosition, actualThrottlePosition);
|
||||
|
||||
etb->dcMotor.Set(ETB_PERCENT_TO_DUTY(currentEtbDuty));
|
||||
etb->dcMotor.set(ETB_PERCENT_TO_DUTY(currentEtbDuty));
|
||||
|
||||
if (engineConfiguration->isVerboseETB) {
|
||||
etbPid.showPidStatus(&logger, "ETB");
|
||||
|
@ -348,7 +348,7 @@ void setThrottleDutyCycle(percent_t level) {
|
|||
float dc = ETB_PERCENT_TO_DUTY(level);
|
||||
directPwmValue = dc;
|
||||
for (int i = 0 ; i < ETB_COUNT; i++) {
|
||||
etbControls[i].dcMotor.Set(dc);
|
||||
etbControls[i].dcMotor.set(dc);
|
||||
}
|
||||
scheduleMsg(&logger, "duty ETB duty=%f", dc);
|
||||
}
|
||||
|
@ -379,7 +379,7 @@ static void showEthInfo(void) {
|
|||
for (int i = 0 ; i < ETB_COUNT; i++) {
|
||||
EtbControl *etb = &etbControls[i];
|
||||
|
||||
scheduleMsg(&logger, "%d: dir=%d DC=%f", i, etb->dcMotor.isOpenDirection(), etb->dcMotor.Get());
|
||||
scheduleMsg(&logger, "%d: dir=%d DC=%f", i, etb->dcMotor.isOpenDirection(), etb->dcMotor.get());
|
||||
}
|
||||
|
||||
etbPid.showPidStatus(&logger, "ETB");
|
||||
|
@ -400,7 +400,7 @@ static void etbReset() {
|
|||
scheduleMsg(&logger, "etbReset");
|
||||
|
||||
for (int i = 0 ; i < ETB_COUNT; i++) {
|
||||
etbControls[i].dcMotor.Set(0);
|
||||
etbControls[i].dcMotor.set(0);
|
||||
}
|
||||
etbPid.reset();
|
||||
|
||||
|
@ -648,11 +648,11 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|||
for (int i = 0 ; i < ETB_COUNT; i++) {
|
||||
EtbControl *etb = &etbControls[i];
|
||||
|
||||
etb->dcMotor.Set(70);
|
||||
etb->dcMotor.set(70);
|
||||
chThdSleep(600);
|
||||
// todo: grab with proper index
|
||||
grabTPSIsWideOpen();
|
||||
etb->dcMotor.Set(-70);
|
||||
etb->dcMotor.set(-70);
|
||||
chThdSleep(600);
|
||||
// todo: grab with proper index
|
||||
grabTPSIsClosed();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
#include "dc_motor.h"
|
||||
#include "pwm_generator_logic.h"
|
||||
|
||||
TwoPinDcMotor::TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2)
|
||||
: m_enable(enable)
|
||||
|
@ -19,14 +20,14 @@ bool TwoPinDcMotor::isOpenDirection() const {
|
|||
return m_value >= 0;
|
||||
}
|
||||
|
||||
float TwoPinDcMotor::Get() const {
|
||||
float TwoPinDcMotor::get() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param duty value between -1.0 and 1.0
|
||||
*/
|
||||
bool TwoPinDcMotor::Set(float duty)
|
||||
bool TwoPinDcMotor::set(float duty)
|
||||
{
|
||||
m_value = duty;
|
||||
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "pwm_generator_logic.h"
|
||||
|
||||
/**
|
||||
* @brief Brushed or brushless DC motor interface
|
||||
*
|
||||
|
@ -23,9 +21,19 @@ public:
|
|||
* @param duty +1.0f represents full power forward, and -1.0f represents full power backward.
|
||||
* @return True if any fault was detected driving the motor, and false if successful.
|
||||
*/
|
||||
virtual bool Set(float duty) = 0;
|
||||
virtual bool set(float duty) = 0;
|
||||
|
||||
/**
|
||||
* @brief Get the current motor duty cycle.
|
||||
* @return The current duty cycle setting. +1.0f represents full power forward, and -1.0f represents full power backward.
|
||||
*/
|
||||
virtual float get() const = 0;
|
||||
|
||||
virtual bool isOpenDirection() const = 0;
|
||||
};
|
||||
|
||||
class SimplePwm;
|
||||
|
||||
/**
|
||||
* @brief Represents a DC motor controller (H bridge) with one pin for enable (PWM),
|
||||
* and two pins for direction control.
|
||||
|
@ -70,9 +78,9 @@ public:
|
|||
*/
|
||||
TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2);
|
||||
|
||||
virtual bool Set(float duty) override;
|
||||
float Get() const;
|
||||
bool isOpenDirection() const;
|
||||
virtual bool set(float duty) override;
|
||||
float get() const override;
|
||||
bool isOpenDirection() const override;
|
||||
|
||||
void SetType(ControlType type) { m_type = type; }
|
||||
void setType(ControlType type) { m_type = type; }
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue