Skip to content

Commit 2ee1cd4

Browse files
committed
bugfix in moveTimed for the case of multiple steps per command
1 parent 52bf6ab commit 2ee1cd4

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

examples/MoveTimed/MoveTimed.ino

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct control_s controlY = {
3131

3232
// This means, the circle is executed in 360*4ms = 1440ms
3333
#ifndef TIMESTEP_TICKS
34-
#define TIMESTEP_TICKS (TICKS_PER_S/4000)
34+
#define TIMESTEP_TICKS (TICKS_PER_S/250)
3535
#endif
3636

3737
// Table generated by python:
@@ -40,6 +40,8 @@ int16_t steps[91] = { 0, 27, 55, 83, 111, 139, 167, 194, 222, 250, 277, 305, 332
4040
};
4141

4242
void setup() {
43+
Serial.begin(115200);
44+
Serial.println("Init");
4345
engine.init();
4446
stepperX = engine.stepperConnectToPin(stepPinStepperX);
4547
stepperY = engine.stepperConnectToPin(stepPinStepperY);
@@ -49,9 +51,9 @@ void setup() {
4951
}
5052
}
5153
stepperX->setDirectionPin(dirPinStepperX);
52-
stepperX->setEnablePin(enablePinStepperY);
54+
stepperX->setEnablePin(enablePinStepperX);
5355
stepperX->setAutoEnable(false);
54-
stepperY->setDirectionPin(dirPinStepperX);
56+
stepperY->setDirectionPin(dirPinStepperY);
5557
stepperY->setEnablePin(enablePinStepperY);
5658
stepperY->setAutoEnable(false);
5759

@@ -105,22 +107,44 @@ void moveStepper(FastAccelStepper *stepper, struct control_s *control) {
105107
rc = stepper->moveTimed(steps,duration,&actual,true);
106108
switch(rc) {
107109
case MOVE_TIMED_EMPTY:
108-
Serial.println("Empty");
110+
Serial.print("Empty:");
111+
Serial.println(stepper->getStepPin() == dirPinStepperX ? 'X':'Y');
109112
/* fallthrough */
110113
case MOVE_TIMED_OK:
111114
control->drift = duration-actual;
112115
control->time += actual;
113116
control->phi += 1;
114117
break;
115118
case MOVE_TIMED_BUSY:
119+
//Serial.println("Busy");
116120
break;
117121
case MOVE_TIMED_TOO_LARGE_ERROR:
118122
Serial.println("Too large");
119123
break;
124+
case AQE_ERROR_TICKS_TOO_LOW:
125+
Serial.print("Ticks too low:");
126+
Serial.print(duration/steps);
127+
Serial.print(" steps:");
128+
Serial.println(steps);
129+
default:
130+
Serial.println(rc);
120131
}
121132
}
122133

134+
uint32_t last_millis = 0;
135+
123136
void loop() {
137+
if (last_millis != millis()) {
138+
Serial.print(uint32_t(controlX.time));
139+
Serial.print(' ');
140+
Serial.print(uint32_t(controlY.time));
141+
Serial.print(' ');
142+
Serial.print(stepperX->getPositionAfterCommandsCompleted());
143+
Serial.print(' ');
144+
Serial.println(millis());
145+
last_millis = millis();
146+
}
147+
124148
if (controlX.time < controlY.time) {
125149
moveStepper(stepperX, &controlX);
126150
}

src/FastAccelStepper.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,9 @@ int8_t FastAccelStepper::moveTimed(int16_t steps, uint32_t duration,
10531053
uint32_t cmd_duration = cmd.ticks;
10541054
cmd_duration *= cmd.steps;
10551055
if (actual_duration) {
1056-
*actual_duration += cmd.ticks;
1056+
uint32_t d = cmd.ticks;
1057+
d *= steps;
1058+
*actual_duration += d;
10571059
}
10581060
steps -= cmd.steps;
10591061
}

0 commit comments

Comments
 (0)