auto-sync

This commit is contained in:
rusEfi 2015-03-29 18:04:56 -05:00
parent 0c91be95ed
commit eedc5c42ed
4 changed files with 49 additions and 15 deletions

View File

@ -31,6 +31,7 @@
#include "pin_repository.h"
#include "engine_configuration.h"
#include "engine.h"
#include "stepper.h"
#if EFI_IDLE_CONTROL || defined(__DOXYGEN__)
@ -43,6 +44,8 @@ EXTERN_ENGINE
static OutputPin idlePin;
static SimplePwm idleValvePwm;
static StepperMotor iacMotor;
/**
* Idle level calculation algorithm lives in idle_controller.c
*/
@ -64,6 +67,10 @@ static void setIdleControlEnabled(int value) {
showIdleInfo();
}
static void setIdleValvePosition(int position) {
iacMotor.targetPosition = position;
}
static void setIdleValvePwm(percent_t value) {
if (value < 0.01 || value > 99.9)
return;
@ -131,6 +138,11 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) {
void startIdleThread(Logging*sharedLogger, Engine *engine) {
logger = sharedLogger;
if (boardConfiguration->idleStepperDirection != GPIO_UNASSIGNED) {
iacMotor.initialize(boardConfiguration->idleStepperStep, boardConfiguration->idleStepperDirection);
}
/**
* Start PWM for IDLE_VALVE logical / idleValvePin physical
*/
@ -154,6 +166,9 @@ void startIdleThread(Logging*sharedLogger, Engine *engine) {
addConsoleAction("idleinfo", showIdleInfo);
addConsoleActionI("set_idle_rpm", setIdleRpmAction);
addConsoleActionF("set_idle_pwm", setIdleValvePwm);
addConsoleActionI("set_idle_position", setIdleValvePosition);
addConsoleActionI("set_idle_enabled", (VoidInt) setIdleControlEnabled);
}

View File

@ -15,7 +15,6 @@
#include "console_io.h"
#include "adc_inputs.h"
#include "stepper.h"
#include "vehicle_speed.h"
#include "trigger_input.h"
@ -52,8 +51,6 @@ EXTERN_ENGINE
;
extern bool hasFirmwareErrorFlag;
static StepperMotor iacMotor;
static Mutex spiMtx;
int maxNesting = 0;
@ -270,8 +267,6 @@ void initHardware(Logging *l, Engine *engine) {
initMax31855(sharedLogger, getSpiDevice(boardConfiguration->max31855spiDevice), boardConfiguration->max31855_cs);
#endif /* EFI_MAX_31855 */
// iacMotor.initialize(GPIOD_11, GPIOD_10);
#if EFI_CAN_SUPPORT
initCan();
#endif /* EFI_CAN_SUPPORT */
@ -279,7 +274,6 @@ void initHardware(Logging *l, Engine *engine) {
// init_adc_mcp3208(&adcState, &SPID2);
// requestAdcValue(&adcState, 0);
#if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__)
// todo: figure out better startup logic
initTriggerCentral(sharedLogger, engine);

View File

@ -17,23 +17,46 @@
static msg_t stThread(StepperMotor *motor) {
chRegSetThreadName("stepper");
palWritePad(motor->directionPort, motor->directionPin, true);
palWritePad(motor->directionPort, motor->directionPin, false);
// let's part the motor in a known position to begin with
// let's park the motor in a known position to begin with
for (int i = 0; i < ST_COUNT; i++) {
motor->pulse();
}
palWritePad(motor->directionPort, motor->directionPin, false);
while (true) {
int targetPosition = motor->targetPosition;
int currentPosition = motor->currentPosition;
// let's part the motor in a known position to begin with
for (int i = 0; i < ST_COUNT / 2; i++) {
if (targetPosition == currentPosition) {
chThdSleepMilliseconds(ST_DELAY_MS);
continue;
}
bool_t isIncrementing = targetPosition > currentPosition;
palWritePad(motor->directionPort, motor->directionPin, isIncrementing);
if (isIncrementing) {
motor->currentPosition++;
} else {
motor->currentPosition--;
}
motor->pulse();
}
// let's part the motor in a known position to begin with
// for (int i = 0; i < ST_COUNT / 2; i++) {
// motor->pulse();
// }
return 0;
}
StepperMotor::StepperMotor() {
currentPosition = 0;
targetPosition = 0;
directionPort = NULL;
stepPort = NULL;
}
void StepperMotor::pulse() {
palWritePad(stepPort, stepPin, true);
chThdSleepMilliseconds(ST_DELAY_MS);
@ -42,8 +65,6 @@ void StepperMotor::pulse() {
}
void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin) {
position = 0;
stepPort = getHwPort(stepPin);
this->stepPin = getHwPin(stepPin);
@ -55,3 +76,4 @@ void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin) {
chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this);
}

View File

@ -11,17 +11,20 @@
class StepperMotor {
public:
StepperMotor();
void initialize(brain_pin_e stepPin, brain_pin_e directionPin);
void pulse();
GPIO_TypeDef * directionPort;
ioportmask_t directionPin;
int currentPosition;
int targetPosition;
private:
GPIO_TypeDef * stepPort;
ioportmask_t stepPin;
int position;
THD_WORKING_AREA(stThreadStack, UTILITY_THREAD_STACK_SIZE);
};