diff --git a/PercTeacher/Sources/Action.java b/PercTeacher/Sources/Action.java new file mode 100644 index 0000000..b7b3455 --- /dev/null +++ b/PercTeacher/Sources/Action.java @@ -0,0 +1,88 @@ + + +public class Action { + public static final long DELAI_DEFAULT = 1000; + + private boolean endAction = true; + + private long deltaL = 0; + private long deltaR = 0; + + private long delaiL = DELAI_DEFAULT; // in us + private long delaiR = DELAI_DEFAULT; // in us + + public Action() {} + public Action(long deltaL, long deltaR) { + this.deltaL = deltaL; + this.deltaR = deltaR; + this.endAction = false; + } + public Action(long deltaL, long deltaR, long delaiL, long delaiR) { + this.deltaL = deltaL; + this.deltaR = deltaR; + this.delaiL = delaiL; + this.delaiR = delaiR; + this.endAction = false; + } + + public void addDeltaL(long amount){this.deltaL += amount; endAction = false;} + public void addDeltaR(long amount){this.deltaR += amount; endAction = false;} + public void setDeltaL(long amount){this.deltaL = amount; endAction = false;} + public void setDeltaR(long amount){this.deltaR = amount; endAction = false;} + public long getDeltaL(){return this.deltaL;} + public long getDeltaR(){return this.deltaR;} + + public void setDelaiL(long delai){this.delaiL = delai; endAction = false;} + public void setDelaiR(long delai){this.delaiR = delai; endAction = false;} + public long getDelaiL(){return this.delaiL;} + public long getDelaiR(){return this.delaiR;} + + public boolean isEmpty() {return endAction;} + + public void calculateDelais(long microseconds) { + // left + double ticksL = (double) microseconds / (double) deltaL; + delaiL = (long) (ticksL / 2d); // 1 step = 1 "on state" + 1 "off state" + + // right + double ticksR = (double) microseconds / (double) deltaR; + delaiR = (long) (ticksR / 2d); + + // tests + if(delaiL < 50 || delaiR < 50) + System.out.println("Warning : delais are very small ! (< 50 us)"); + } + + @Override + public String toString() { + if(endAction) + return "End sequence"; + if(deltaL == 0 && deltaR == 0) + return "Pause for " + String.valueOf((double) delaiL / 1000d) + " miliseconds"; + if(deltaL == 0) { + if(deltaR > 0) + return "Turning right forward for " + String.valueOf(deltaR) + " steps during " + String.valueOf((double) (deltaR * delaiR) / 1000d) + " miliseconds"; + else + return "Turning right backward for " + String.valueOf(-deltaR) + " steps during " + String.valueOf((double) (-deltaR * delaiR) / 1000d) + " miliseconds"; + } if(deltaR == 0) { + if(deltaL > 0) + return "Turning left forward for " + String.valueOf(deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; + else + return "Turning left backward for " + String.valueOf(-deltaL) + " steps during " + String.valueOf((double) (-deltaL * delaiL) / 1000d) + " miliseconds"; + } if(deltaR == deltaL) { + if(deltaL > 0) + return "Going forward for " + String.valueOf(deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; + else + return "Going backward for " + String.valueOf(-deltaL) + " steps during " + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; + } if(deltaR == -deltaL) { + if(deltaL > 0) + return "Turning on the spot clockwise for " + String.valueOf(deltaL) + " steps during " + + String.valueOf((double) (deltaL * delaiL) / 1000d) + " miliseconds"; + else + return "Turning on the spot anti-clockwise for " + String.valueOf(deltaR) + " steps during " + + String.valueOf((double) (deltaR * delaiR) / 1000d) + " miliseconds"; + } + return "Custom curve dL:" + String.valueOf(deltaL) + "steps tL:" + String.valueOf((double) (deltaL * delaiL) / 1000d) + "ms | dR" + + String.valueOf(deltaR) + "steps tR:" + String.valueOf((double) (deltaR * delaiR) / 1000d) + "ms"; + } +} diff --git a/PercTeacher/Sources/ActionList.java b/PercTeacher/Sources/ActionList.java new file mode 100644 index 0000000..de7b6fb --- /dev/null +++ b/PercTeacher/Sources/ActionList.java @@ -0,0 +1,128 @@ +import java.util.ArrayList; + +public class ActionList { + private ArrayList actions; + + public ActionList() { + actions = new ArrayList<>(); + actions.add(new Action()); + } + public ActionList(long[] leftDeltaArray, long[] rightDeltaArray, long[] leftDelaiArray, long[] rightDelaiArray) { + if(leftDelaiArray.length != rightDelaiArray.length + || leftDelaiArray.length != leftDelaiArray.length + || leftDelaiArray.length != rightDelaiArray.length) + throw new InvalidActionListArrays(); + actions = new ArrayList<>(); + for(int i=0; i