mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-13 23:06:22 -04:00
fixes a bug in the stepper motor error detection
This commit is contained in:
parent
9b3740643d
commit
baf3f893de
@ -5,10 +5,7 @@
|
||||
*/
|
||||
package de.neemann.digital.core.io;
|
||||
|
||||
import de.neemann.digital.core.Node;
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.ObservableValues;
|
||||
import de.neemann.digital.core.*;
|
||||
import de.neemann.digital.core.element.*;
|
||||
|
||||
import static de.neemann.digital.core.element.PinInfo.input;
|
||||
@ -22,6 +19,12 @@ public class StepperMotorUnipolar extends Node implements Element {
|
||||
*/
|
||||
public static final int STEPS = 72;
|
||||
private static final int SWITCH_SIZE = 2;
|
||||
private static final boolean[] STATE_VALID = new boolean[]{
|
||||
false, true, true, true,
|
||||
true, false, true, false,
|
||||
true, true, false, false,
|
||||
true, false, false, false,
|
||||
};
|
||||
private static final int[][] STEP_TABLE = new int[][]{
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 2, 1, 0, 0, 0, 0, -2, -1, 0, 0, 0, 0, 0, 0},
|
||||
@ -89,14 +92,14 @@ public class StepperMotorUnipolar extends Node implements Element {
|
||||
if (this.pos < 0) this.pos += STEPS;
|
||||
else if (this.pos >= STEPS) this.pos -= STEPS;
|
||||
|
||||
if (step == 0 && lastState != 0) {
|
||||
if (step == 0 && STATE_VALID[lastState] && STATE_VALID[state]) {
|
||||
error += 8;
|
||||
if (error > 8)
|
||||
error = 8;
|
||||
} else if (error > 0)
|
||||
error--;
|
||||
|
||||
if (state != 0)
|
||||
if (STATE_VALID[state])
|
||||
lastState = state;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user