Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2019
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. public class Test {
  2.  
  3.     private static LinkedHashMap<Integer, Integer> time = new LinkedHashMap<>();
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         time.put(0, 0);
  8.         time.put(2, 180);
  9.         time.put(5, 50);
  10.  
  11.         System.out.println("lancement");
  12.         callServoToCalculatedPosition(2500, 2);
  13.  
  14.     }
  15.     public static void callServoToCalculatedPosition(long t, int lastKey) {
  16.         System.out.println(t);
  17.         Map.Entry<Integer, Integer> entry = hasNext(lastKey);
  18.         Integer to = entry.getValue();
  19.         System.out.println("to : "+ to);
  20.         long timeFinish = entry.getKey() * 1000;
  21.         long lastKeyTime = lastKey * 1000;
  22.  
  23.         long espace = timeFinish - t;
  24.         long espacefromLastKey = t - lastKeyTime;
  25.         long totalspace = timeFinish - lastKeyTime;
  26.         System.out.println("espace " + espace);
  27.         System.out.println("espaceFromLastKey " + espacefromLastKey);
  28.         System.out.println("totalspace " + totalspace);
  29.  
  30.         int result = getPourcent(t, lastKeyTime, timeFinish);
  31.         System.out.println("Pourcent" +  result);
  32.  
  33.         long finishPourcent = getPosition(result, time.get(lastKey), to);
  34.         System.out.println("finish position " +  finishPourcent);
  35.     }
  36.  
  37.     public static int getPourcent(long position, long minimum, long maximum) {
  38.         return (int) (((position - minimum) * 100) / (maximum - minimum));
  39.     }
  40.  
  41.     public static int getPosition(int percent, int minimum, int maximum) {
  42.         return ((percent * (maximum - minimum) / 100) + minimum);
  43.     }
  44.  
  45.     public static Map.Entry<Integer, Integer> hasNext(int second){
  46.         boolean next = false;
  47.         for(Map.Entry<Integer, Integer> t : time.entrySet()){
  48.             if(next){
  49.                 return t;
  50.             }
  51.             if(t.getKey() == second){
  52.                 next = true;
  53.             }
  54.         }
  55.         return null;
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement