Reduce step skipping for stepper motor (#559)
* Reduce step skipping for stepper motor * Add stepperParkingExtraSteps
This commit is contained in:
parent
7b3434caca
commit
e0ab7e5671
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue