Stepper direct push pull driver (#3751)

* Init DC motor through two brain_pin_e only

* idle: stepper: allow driving stepper through 4 output_pin_e
This commit is contained in:
Andrey G 2022-01-07 19:38:48 +03:00 committed by GitHub
parent 5bc9289d74
commit 77fa9929d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 7 deletions

View File

@ -131,6 +131,23 @@ DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires) {
return &hw.dcMotor;
}
DcMotor* initDcMotor(brain_pin_e coil_p, brain_pin_e coil_m, size_t index) {
auto& hw = dcHardware[index];
hw.start(
true, /* useTwoWires */
GPIO_UNASSIGNED, /* pinEnable */
coil_p,
coil_m,
GPIO_UNASSIGNED, /* pinDisable */
engineConfiguration->stepperDcInvertedPins,
&engine->executor,
engineConfiguration->etbFreq /* same in case of stepper? */
);
return &hw.dcMotor;
}
void setDcMotorFrequency(size_t index, int hz) {
dcHardware[index].setFrequency(hz);
}

View File

@ -12,6 +12,7 @@
class DcMotor;
DcMotor* initDcMotor(const dc_io& io, size_t index, bool useTwoWires);
DcMotor* initDcMotor(brain_pin_e coil_p, brain_pin_e coil_m, size_t index);
// Manual control of motors for use by console commands
void setDcMotorFrequency(size_t index, int hz);

View File

@ -76,7 +76,12 @@ bool isIdleHardwareRestartNeeded() {
isConfigurationChanged(useStepperIdle) ||
isConfigurationChanged(useETBforIdleControl) ||
isConfigurationChanged(idle.solenoidPin) ||
isConfigurationChanged(secondSolenoidPin);
isConfigurationChanged(secondSolenoidPin) ||
isConfigurationChanged(useRawOutputToDriveIdleStepper) ||
isConfigurationChanged(stepper_raw_output[0]) ||
isConfigurationChanged(stepper_raw_output[1]) ||
isConfigurationChanged(stepper_raw_output[2]) ||
isConfigurationChanged(stepper_raw_output[3]);
}
bool isIdleMotorBusy() {
@ -91,9 +96,26 @@ void initIdleHardware() {
if (engineConfiguration->useStepperIdle) {
StepperHw* hw;
if (engineConfiguration->useHbridgesToDriveIdleStepper) {
auto motorA = initDcMotor(engineConfiguration->stepperDcIo[0], 2, /*useTwoWires*/ true);
auto motorB = initDcMotor(engineConfiguration->stepperDcIo[1], 3, /*useTwoWires*/ true);
if (engineConfiguration->useRawOutputToDriveIdleStepper) {
auto motorA = initDcMotor(engineConfiguration->stepper_raw_output[0],
engineConfiguration->stepper_raw_output[1], ETB_COUNT + 0);
auto motorB = initDcMotor(engineConfiguration->stepper_raw_output[2],
engineConfiguration->stepper_raw_output[3], ETB_COUNT + 1);
if (motorA && motorB) {
iacHbridgeHw.initialize(
motorA,
motorB,
engineConfiguration->idleStepperReactionTime
);
}
hw = &iacHbridgeHw;
} else if (engineConfiguration->useHbridgesToDriveIdleStepper) {
auto motorA = initDcMotor(engineConfiguration->stepperDcIo[0],
ETB_COUNT + 0, /*useTwoWires*/ true);
auto motorB = initDcMotor(engineConfiguration->stepperDcIo[1],
ETB_COUNT + 1, /*useTwoWires*/ true);
if (motorA && motorB) {
iacHbridgeHw.initialize(

View File

@ -66,13 +66,20 @@ void idleDebug(const char *msg, percent_t value) {
static void showIdleInfo() {
const char * idleModeStr = getIdle_mode_e(engineConfiguration->idleMode);
efiPrintf("useStepperIdle=%s useHbridges=%s",
boolToString(engineConfiguration->useStepperIdle), boolToString(engineConfiguration->useHbridgesToDriveIdleStepper));
efiPrintf("useStepperIdle=%s useHbridges=%s useRawOutput=%s",
boolToString(engineConfiguration->useStepperIdle),
boolToString(engineConfiguration->useHbridgesToDriveIdleStepper),
boolToString(engineConfiguration->useRawOutputToDriveIdleStepper));
efiPrintf("idleMode=%s position=%.2f",
idleModeStr, getIdlePosition());
if (engineConfiguration->useStepperIdle) {
if (engineConfiguration->useHbridgesToDriveIdleStepper) {
if (engineConfiguration->useRawOutputToDriveIdleStepper) {
efiPrintf(" A+=%s", hwPortname(engineConfiguration->stepper_raw_output[0]));
efiPrintf(" A-=%s", hwPortname(engineConfiguration->stepper_raw_output[1]));
efiPrintf(" B+=%s", hwPortname(engineConfiguration->stepper_raw_output[2]));
efiPrintf(" B-=%s", hwPortname(engineConfiguration->stepper_raw_output[3]));
} else if (engineConfiguration->useHbridgesToDriveIdleStepper) {
efiPrintf("Coil A:");
efiPrintf(" pin1=%s", hwPortname(engineConfiguration->stepperDcIo[0].directionPin1));
efiPrintf(" pin2=%s", hwPortname(engineConfiguration->stepperDcIo[0].directionPin2));