Browse Source

simulate movement

Martin Kunz 3 years ago
parent
commit
f867a8b101

+ 10 - 9
src/main/java/at/acdp/urweb/fhpp/FHMasterSim.java

@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Timer;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
@@ -26,7 +27,11 @@ public class FHMasterSim implements IFHMaster {
 
     private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
     private volatile boolean started = false;
-    private int curPos=-1;
+    private int targetPos=-1;
+    private float curPos=-1;
+    private float simSpeed=0.1f;
+
+
     public FHMasterSim() {
     }
 
@@ -34,32 +39,28 @@ public class FHMasterSim implements IFHMaster {
     public void start(Params app) throws InterruptedException {
         started = true;
         while(true) {
-            Thread.sleep(1000);
-            readStatus();
+            Thread.sleep(30);
+            curPos = curPos + ((targetPos - curPos) * simSpeed);
         }
     }
 
-
-
     @Override
     public void direktAuftrag(int pos, int speed, int start, boolean relative) {
         logger.info("direktAuftrag {},{},{},{}", pos, speed, start, relative);
-        curPos=pos;
+        targetPos=pos;
     }
 
     @Override
     public CompletableFuture<Status> readStatus() {
         Status s=new Status();
-        s.istPosition = curPos;
+        s.istPosition = (int) curPos;
         s.enabled = true;
         return CompletableFuture.completedFuture(s);
     }
 
-
     @Override
     public void bereitschaft() {
         logger.info("bereitschaft");
-
     }
 
     @Override

+ 4 - 1
src/main/java/at/acdp/urweb/web/FestoXRServer.java

@@ -111,12 +111,15 @@ public class FestoXRServer {
                 Status s= Main.fhm.readStatus().get();
                 int curPos = s.istPosition;
 
-
                 logger.info("curpos {} ({})", curPos, pos);
                 if(curPos==pos) {
                     logger.info("reached {}", pos);
                     return true;
                 }
+                if(s.istMoment==0 && Math.abs(curPos-pos) <5) {
+                    logger.info("reached {} (moment=0)", pos);
+                    return true;
+                }
                 Thread.sleep(500);
             } catch (ExecutionException e) {
                 e.printStackTrace();