Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- private static LinkedHashMap<Integer, Integer> time = new LinkedHashMap<>();
- public static void main(String[] args) {
- time.put(0, 0);
- time.put(2, 180);
- time.put(5, 50);
- System.out.println("lancement");
- callServoToCalculatedPosition(2500, 2);
- }
- public static void callServoToCalculatedPosition(long t, int lastKey) {
- System.out.println(t);
- Map.Entry<Integer, Integer> entry = hasNext(lastKey);
- Integer to = entry.getValue();
- System.out.println("to : "+ to);
- long timeFinish = entry.getKey() * 1000;
- long lastKeyTime = lastKey * 1000;
- long espace = timeFinish - t;
- long espacefromLastKey = t - lastKeyTime;
- long totalspace = timeFinish - lastKeyTime;
- System.out.println("espace " + espace);
- System.out.println("espaceFromLastKey " + espacefromLastKey);
- System.out.println("totalspace " + totalspace);
- int result = getPourcent(t, lastKeyTime, timeFinish);
- System.out.println("Pourcent" + result);
- long finishPourcent = getPosition(result, time.get(lastKey), to);
- System.out.println("finish position " + finishPourcent);
- }
- public static int getPourcent(long position, long minimum, long maximum) {
- return (int) (((position - minimum) * 100) / (maximum - minimum));
- }
- public static int getPosition(int percent, int minimum, int maximum) {
- return ((percent * (maximum - minimum) / 100) + minimum);
- }
- public static Map.Entry<Integer, Integer> hasNext(int second){
- boolean next = false;
- for(Map.Entry<Integer, Integer> t : time.entrySet()){
- if(next){
- return t;
- }
- if(t.getKey() == second){
- next = true;
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement