Fix stepper motor (#541)
This commit is contained in:
parent
4765c0a861
commit
ac43689791
|
@ -30,8 +30,6 @@ static int loadStepperPos() {
|
||||||
static msg_t stThread(StepperMotor *motor) {
|
static msg_t stThread(StepperMotor *motor) {
|
||||||
chRegSetThreadName("stepper");
|
chRegSetThreadName("stepper");
|
||||||
|
|
||||||
motor->directionPin.setValue(false);
|
|
||||||
|
|
||||||
// try to get saved stepper position (-1 for no data)
|
// try to get saved stepper position (-1 for no data)
|
||||||
motor->currentPosition = loadStepperPos();
|
motor->currentPosition = loadStepperPos();
|
||||||
|
|
||||||
|
@ -60,6 +58,10 @@ static msg_t stThread(StepperMotor *motor) {
|
||||||
saveStepperPos(motor->currentPosition);
|
saveStepperPos(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) {
|
while (true) {
|
||||||
int targetPosition = motor->getTargetPosition();
|
int targetPosition = motor->getTargetPosition();
|
||||||
int currentPosition = motor->currentPosition;
|
int currentPosition = motor->currentPosition;
|
||||||
|
@ -142,6 +144,10 @@ void StepperMotor::initialize(brain_pin_e stepPin, brain_pin_e directionPin, pin
|
||||||
efiSetPadMode("stepper enable", enablePin, PAL_MODE_OUTPUT_PUSHPULL);
|
efiSetPadMode("stepper enable", enablePin, PAL_MODE_OUTPUT_PUSHPULL);
|
||||||
palWritePad(this->enablePort, enablePin, true); // disable stepper
|
palWritePad(this->enablePort, enablePin, true); // disable stepper
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this);
|
chThdCreateStatic(stThreadStack, sizeof(stThreadStack), NORMALPRIO, (tfunc_t) stThread, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue