diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index 5ca3040d7a..09f9f8f127 100644 --- a/firmware/controllers/algo/engine_configuration_generated_structures.h +++ b/firmware/controllers/algo/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Fri Jan 26 22:46:29 EST 2018 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 28 21:16:58 EET 2018 // begin #ifndef ENGINE_CONFIGURATION_GENERATED_H_ #define ENGINE_CONFIGURATION_GENERATED_H_ @@ -722,7 +722,7 @@ typedef struct { /** * offset 582 */ - int16_t unusedPD; + int16_t stepperParkingExtraSteps; /** * offset 584 */ @@ -2330,4 +2330,4 @@ typedef struct { #endif // end -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Fri Jan 26 22:46:29 EST 2018 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 28 21:16:58 EET 2018 diff --git a/firmware/controllers/algo/rusefi_generated.h b/firmware/controllers/algo/rusefi_generated.h index 077e754990..561c092eed 100644 --- a/firmware/controllers/algo/rusefi_generated.h +++ b/firmware/controllers/algo/rusefi_generated.h @@ -54,7 +54,7 @@ #define MAP_ACCEL_TAPER 8 #define BARO_CORR_SIZE 4 #define MAF_DECODING_COUNT 256 -#define debug_mode_e_enum "Alternator_PID", "TPS accel enrich", "Warmup PID", "IDLE", "EL accl enrich", "Trigger Counters", "FSIO_ADC", "AUX_PID_1", "VVT PID", "Cranking", "Timing", "Closed-loop fuel corr PID", "VSS", "SD card", "sr5", "Knock", "Trigger Sync", "Electronic Throttle", "Executor", "Bench Test", "Aux Valves", "ADC", "INSTANT_RPM", "FSIO_EXPRESSION", "Status", "mode25", "mode26", "mode27", "mode28", "mode29" +#define debug_mode_e_enum "Alternator_PID", "TPS accel enrich", "Warmup PID", "IDLE", "EL accl enrich", "Trigger Counters", "FSIO_ADC", "AUX_PID_1", "VVT PID", "Cranking", "Timing", "Closed-loop fuel corr PID", "VSS", "SD card", "sr5", "Knock", "Trigger Sync", "Electronic Throttle", "Executor", "Bench Test", "Aux Valves", "ADC", "INSTANT_RPM", "FSIO_EXPRESSION", "Status", "CJ125", "mode26", "mode27", "mode28", "mode29" #define vvt_mode_e_enum "First half", "Second half", "2GZ", "Miata NB2", "mode4", "mode5", "mode6", "mode7" #define mass_storage_e_enum "Auto", "Always", "Never" #define brain_input_pin_e_enum "INVALID", "PA1", "PA2", "PA3", "INVALID", "PA5", "PA6", "PA7", "PA8", "PA9", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PA15", "INVALID", "INVALID", "INVALID", "PB3", "PB4", "PB5", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PC6", "PC7", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PE5", "PE6", "INVALID", "INVALID", "PE9", "INVALID", "PE11", "INVALID", "INVALID", "INVALID", "INVALID", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" @@ -706,8 +706,8 @@ #define mapMinBufferLength_offset_hex 4a0 #define idlePidDeactivationTpsThreshold_offset 1188 #define idlePidDeactivationTpsThreshold_offset_hex 4a4 -#define unusedPD_offset 1190 -#define unusedPD_offset_hex 4a6 +#define stepperParkingExtraSteps_offset 1190 +#define stepperParkingExtraSteps_offset_hex 4a6 #define nb2ratioFrom_offset 1192 #define nb2ratioFrom_offset_hex 4a8 #define nb2ratioTo_offset 1196 diff --git a/firmware/hw_layer/stepper.cpp b/firmware/hw_layer/stepper.cpp index 2c9a264fac..8213136c58 100644 --- a/firmware/hw_layer/stepper.cpp +++ b/firmware/hw_layer/stepper.cpp @@ -48,20 +48,23 @@ static msg_t stThread(StepperMotor *motor) { * * I believe it's safer to retract the valve for parking - at least on a bench I've seen valves * disassembling themselves while pushing too far out. + * + * Add extra steps to compensate step skipping by some old motors. */ - for (int i = 0; i < motor->totalSteps; i++) { + int numParkingSteps = (int)efiRound((1.0f + (float)boardConfiguration->stepperParkingExtraSteps / PERCENT_MULT) * motor->totalSteps, 1.0f); + for (int i = 0; i < numParkingSteps; i++) { motor->pulse(); } // set & save zero stepper position after the parking completion motor->currentPosition = 0; saveStepperPos(motor->currentPosition); + } else { + // The initial target position should correspond to the saved stepper position. + // Idle thread starts later and sets a new target position. + motor->setTargetPosition(motor->currentPosition); } - // The initial target position should correspond to the saved stepper position. - // Idle thread starts later and sets a new target position. - motor->setTargetPosition(motor->currentPosition); - while (true) { int targetPosition = motor->getTargetPosition(); int currentPosition = motor->currentPosition; @@ -71,7 +74,7 @@ static msg_t stThread(StepperMotor *motor) { continue; } bool isIncrementing = targetPosition > currentPosition; - motor->directionPin.setValue(isIncrementing); + motor->setDirection(isIncrementing); if (isIncrementing) { motor->currentPosition++; } else { @@ -109,6 +112,16 @@ void StepperMotor::setTargetPosition(int targetPosition) { this->targetPosition = targetPosition; } +void StepperMotor::setDirection(bool isIncrementing) { + if (isIncrementing != this->currentDirection) { + // compensate stepper motor inertia + chThdSleepMilliseconds(reactionTime); + this->currentDirection = isIncrementing; + } + + directionPin.setValue(isIncrementing); +} + void StepperMotor::pulse() { palWritePad(enablePort, enablePin, false); // ebable stepper @@ -147,6 +160,7 @@ void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin, pin // All pins must be 0 for correct hardware startup (e.g. stepper auto-disabling circuit etc.). palWritePad(this->stepPort, this->stepPin, false); this->directionPin.setValue(false); + this->currentDirection = false; chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this); } diff --git a/firmware/hw_layer/stepper.h b/firmware/hw_layer/stepper.h index 28357c23a4..23c1435934 100644 --- a/firmware/hw_layer/stepper.h +++ b/firmware/hw_layer/stepper.h @@ -19,9 +19,11 @@ public: void pulse(); void setTargetPosition(int targetPosition); int getTargetPosition(); + void setDirection(bool isIncrementing); OutputPin directionPin; int currentPosition; + bool currentDirection; float reactionTime; int totalSteps; private: diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index af8b2f4e75..52715ae9fc 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -574,7 +574,7 @@ custom uart_device_e 4 bits,U32, @OFFSET@, [0:1], "Off", "UART1", "UART2", "UA uart_device_e consoleUartDevice; int mapMinBufferLength;;"count", 1, 0, 0, 24, 0 int16_t idlePidDeactivationTpsThreshold;;"%", 1, 0, 0, 100.0, 0 - int16_t unusedPD;;"ms", 1, 0, 0, 1000.0, 0 + int16_t stepperParkingExtraSteps;;"%", 1, 0, 0, 3000.0, 0 float nb2ratioFrom;;"value", 1, 0, 0, 1000, 5 float nb2ratioTo;;"value", 1, 0, 0, 1000, 5 diff --git a/firmware/tunerstudio/rusefi.ini b/firmware/tunerstudio/rusefi.ini index d05fa48599..1d0d0e66d9 100644 --- a/firmware/tunerstudio/rusefi.ini +++ b/firmware/tunerstudio/rusefi.ini @@ -63,7 +63,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Fri Jan 26 22:46:29 EST 2018 +; this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 28 21:16:58 EET 2018 pageSize = 20000 page = 1 @@ -372,7 +372,7 @@ page = 1 consoleUartDevice = bits,U32, 1180, [0:1], "Off", "UART1", "UART2", "UART3" mapMinBufferLength = scalar, S32, 1184, "count", 1, 0, 0, 24, 0 idlePidDeactivationTpsThreshold = scalar, S16, 1188, "%", 1, 0, 0, 100.0, 0 - unusedPD = scalar, S16, 1190, "ms", 1, 0, 0, 1000.0, 0 + stepperParkingExtraSteps = scalar, S16, 1190, "%", 1, 0, 0, 3000.0, 0 nb2ratioFrom = scalar, F32, 1192, "value", 1, 0, 0, 1000, 5 nb2ratioTo = scalar, F32, 1196, "value", 1, 0, 0, 1000, 5 triggerErrorPin = bits, U32, 1200, [0:6], "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PA8", "PA9", "PA10", "PA11", "PA12", "PA13", "PA14", "PA15", "PB0", "PB1", "PB2", "PB3", "PB4", "PB5", "PB6", "PB7", "PB8", "PB9", "PB10", "PB11", "PB12", "PB13", "PB14", "PB15", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5", "PC6", "PC7", "PC8", "PC9", "PC10", "PC11", "PC12", "PC13", "PC14", "PC15", "PD0", "PD1", "PD2", "PD3", "PD4", "PD5", "PD6", "PD7", "PD8", "PD9", "PD10", "PD11", "PD12", "PD13", "PD14", "PD15", "PE0", "PE1", "PE2", "PE3", "PE4", "PE5", "PE6", "PE7", "PE8", "PE9", "PE10", "PE11", "PE12", "PE13", "PE14", "PE15", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID" @@ -2330,6 +2330,7 @@ cmd_stop_engine = "w\x00\x99\x00\x00" field = "Idle Stepper Enable mode", stepperEnablePinMode, useStepperIdle field = "Stepper reaction time", idleStepperReactionTime, useStepperIdle field = "Stepper total steps", idleStepperTotalSteps, useStepperIdle + field = "Stepper parking extra steps, %", stepperParkingExtraSteps, useStepperIdle dialog = idleHwType, "Idle Valve Hardware", border field = "use stepper", useStepperIdle diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 6b07bf6968..94843d1083 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1511,6 +1511,7 @@ cmd_stop_engine = "w\x00\x99\x00\x00" field = "Idle Stepper Enable mode", stepperEnablePinMode, useStepperIdle field = "Stepper reaction time", idleStepperReactionTime, useStepperIdle field = "Stepper total steps", idleStepperTotalSteps, useStepperIdle + field = "Stepper parking extra steps, %", stepperParkingExtraSteps, useStepperIdle dialog = idleHwType, "Idle Valve Hardware", border field = "use stepper", useStepperIdle diff --git a/java_console/models/src/com/rusefi/config/Fields.java b/java_console/models/src/com/rusefi/config/Fields.java index c002efd98a..899af024c6 100644 --- a/java_console/models/src/com/rusefi/config/Fields.java +++ b/java_console/models/src/com/rusefi/config/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config; -// this file was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Fri Jan 26 22:46:29 EST 2018 +// this file was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jan 28 21:16:58 EET 2018 public class Fields { public static final int LE_COMMAND_LENGTH = 200; public static final int BLOCKING_FACTOR = 400; @@ -492,7 +492,7 @@ public class Fields { public static final int consoleUartDevice_offset = 1180; public static final int mapMinBufferLength_offset = 1184; public static final int idlePidDeactivationTpsThreshold_offset = 1188; - public static final int unusedPD_offset = 1190; + public static final int stepperParkingExtraSteps_offset = 1190; public static final int nb2ratioFrom_offset = 1192; public static final int nb2ratioTo_offset = 1196; public static final int triggerErrorPin_offset = 1200; @@ -1455,7 +1455,7 @@ public class Fields { public static final Field CONSOLEUARTDEVICE = Field.create("CONSOLEUARTDEVICE", 1180, FieldType.INT); public static final Field MAPMINBUFFERLENGTH = Field.create("MAPMINBUFFERLENGTH", 1184, FieldType.INT); public static final Field IDLEPIDDEACTIVATIONTPSTHRESHOLD = Field.create("IDLEPIDDEACTIVATIONTPSTHRESHOLD", 1188, FieldType.INT); - public static final Field UNUSEDPD = Field.create("UNUSEDPD", 1190, FieldType.INT); + public static final Field STEPPERPARKINGEXTRASTEPS = Field.create("STEPPERPARKINGEXTRASTEPS", 1190, FieldType.INT); public static final Field NB2RATIOFROM = Field.create("NB2RATIOFROM", 1192, FieldType.FLOAT); public static final Field NB2RATIOTO = Field.create("NB2RATIOTO", 1196, FieldType.FLOAT); public static final Field TRIGGERERRORPIN = Field.create("TRIGGERERRORPIN", 1200, FieldType.INT, brain_pin_e); @@ -1694,7 +1694,7 @@ public class Fields { public static final Field TPSDECELENLEANMENTTHRESHOLD = Field.create("TPSDECELENLEANMENTTHRESHOLD", 2208, FieldType.FLOAT); public static final Field TPSDECELENLEANMENTMULTIPLIER = Field.create("TPSDECELENLEANMENTMULTIPLIER", 2212, FieldType.FLOAT); public static final Field SLOWADCALPHA = Field.create("SLOWADCALPHA", 2216, FieldType.FLOAT); - public static final String[] debug_mode_e = {"Alternator_PID", "TPS accel enrich", "Warmup PID", "IDLE", "EL accl enrich", "Trigger Counters", "FSIO_ADC", "AUX_PID_1", "VVT PID", "Cranking", "Timing", "Closed-loop fuel corr PID", "VSS", "SD card", "sr5", "Knock", "Trigger Sync", "Electronic Throttle", "Executor", "Bench Test", "Aux Valves", "ADC", "INSTANT_RPM", "FSIO_EXPRESSION", "Status", "mode25", "mode26", "mode27", "mode28", "mode29"}; + public static final String[] debug_mode_e = {"Alternator_PID", "TPS accel enrich", "Warmup PID", "IDLE", "EL accl enrich", "Trigger Counters", "FSIO_ADC", "AUX_PID_1", "VVT PID", "Cranking", "Timing", "Closed-loop fuel corr PID", "VSS", "SD card", "sr5", "Knock", "Trigger Sync", "Electronic Throttle", "Executor", "Bench Test", "Aux Valves", "ADC", "INSTANT_RPM", "FSIO_EXPRESSION", "Status", "CJ125", "mode26", "mode27", "mode28", "mode29"}; public static final Field DEBUGMODE = Field.create("DEBUGMODE", 2220, FieldType.INT, debug_mode_e); public static final Field AUXVALVES1 = Field.create("AUXVALVES1", 2224, FieldType.INT, brain_pin_e); public static final Field AUXVALVES2 = Field.create("AUXVALVES2", 2228, FieldType.INT, brain_pin_e); diff --git a/java_console/rusefi.xml b/java_console/rusefi.xml index 6461645bb6..ba1ac8204e 100644 --- a/java_console/rusefi.xml +++ b/java_console/rusefi.xml @@ -1,6 +1,6 @@ - +