Browse Source

send axis position to register

Martin Kunz 3 years ago
parent
commit
f0e0c4404e

+ 3 - 11
src/main/java/at/acdp/urweb/Main.java

@@ -32,20 +32,13 @@ public class Main {
                     .addVariable("target_speed_fraction")
                     .addVariable("speed_scaling");
             r.request(so);
-            var si=new RtdeSetupInputs()
-                    .addVariable("input_int_register_24");
-            r.request(si);
-            System.out.println(si.recipe);
-
             var start=new RtdeControlStart();
             r.request(start);
 
-            var pos=new RtdeInDataPackage(si);
-            pos.put("input_int_register_24","66");
-            r.request(pos);
-
+            PosThread p=new PosThread(r, fhm);
+            p.start();
 
-            FestoXRServer fxrs = new FestoXRServer();
+            FestoXRServer fxrs = new FestoXRServer(r);
             HTTPServerEndpoint xrs = XR.server(fxrs, FestoXRServer.class);
             server.add(xrs);
             server.start();
@@ -59,6 +52,5 @@ public class Main {
             picocli.CommandLine.usage(new Params(), System.out);
             System.exit(1);
         }
-
     }
 }

+ 51 - 0
src/main/java/at/acdp/urweb/PosThread.java

@@ -0,0 +1,51 @@
+package at.acdp.urweb;
+
+import at.acdp.urweb.fhpp.IFHMaster;
+import at.acdp.urweb.fhpp.Status;
+import at.acdp.urweb.rtde.RTDEClient;
+import at.acdp.urweb.rtde.packets.RtdeInDataPackage;
+import at.acdp.urweb.rtde.packets.RtdeSetupInputs;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.concurrent.CompletableFuture;
+
+public class PosThread implements Runnable{
+    private final static org.slf4j.Logger logger = LoggerFactory.getLogger(PosThread.class);
+
+    private final RTDEClient rtde;
+    private final IFHMaster fhm;
+    private Thread thread;
+    private volatile boolean _running=true;
+
+    public PosThread(RTDEClient r, IFHMaster fhm) {
+        this.rtde=r;
+        this.fhm=fhm;
+    }
+
+    public void start() {
+        thread=new Thread(this);
+        thread.start();
+    }
+
+    @Override
+    public void run() {
+        try {
+            var si=new RtdeSetupInputs()
+                    .addVariable("input_int_register_24");
+            rtde.request(si);
+            while(_running) {
+                CompletableFuture<Status> s = fhm.readStatus();
+                Status ss=s.join();
+                var pos=new RtdeInDataPackage(si);
+                pos.put("input_int_register_24", String.valueOf(ss.istPosition));
+                rtde.request(pos);
+                Thread.sleep(100);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 6 - 0
src/main/java/at/acdp/urweb/web/FestoXRServer.java

@@ -1,6 +1,7 @@
 package at.acdp.urweb.web;
 import at.acdp.urweb.Main;
 import at.acdp.urweb.fhpp.Status;
+import at.acdp.urweb.rtde.RTDEClient;
 import com.nmote.xr.XRMethod;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -11,6 +12,11 @@ import java.util.concurrent.ExecutionException;
 
 public class FestoXRServer {
     private final static Logger logger = LoggerFactory.getLogger(FestoXRServer.class);
+    private final RTDEClient rtde;
+
+    public FestoXRServer(RTDEClient r) {
+        this.rtde=r;
+    }
 
     @XRMethod(value = "example.helloWorld", help = "Returns 'Helo ' + argument")
     public static String hello(Object s) {