Search in sources :

Example 1 with DigitalInputChannel

use of com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel in project java-bowler by NeuronRobotics.

the class DigitalInputTestSync method main.

/**
 * @param args
 * @throws InterruptedException
 */
public static void main(String[] args) throws InterruptedException {
    DyIO dyio = new DyIO();
    if (!ConnectionDialog.getBowlerDevice(dyio)) {
        System.exit(1);
    }
    Log.enableDebugPrint();
    DigitalInputChannel dig = new DigitalInputChannel(dyio.getChannel(0));
    // Loop forever printing out the state of the button
    while (true) {
        System.out.println(dig.isHigh());
        Thread.sleep(100);
    }
}
Also used : DigitalInputChannel(com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel) DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Example 2 with DigitalInputChannel

use of com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel in project java-bowler by NeuronRobotics.

the class Jfx3dManager method attachArm.

public void attachArm(final DHParameterKinematics model) {
    master = model.getFactory().getDyio();
    if (master != null)
        new DigitalInputChannel(master, 23).addDigitalInputListener(new IDigitalInputListener() {

            @Override
            public void onDigitalValueChange(DigitalInputChannel source, final boolean isHigh) {
                // System.err.println("Button pressed");
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        if (!isHigh) {
                            ObservableList<Node> cadBits = lookGroup.getChildren();
                            for (Node n : cadBits) {
                                double x = n.getTranslateX();
                                double y = n.getTranslateY();
                                double z = n.getTranslateZ();
                                // if (threedBoundCheck(x, y, z,/selsectedAffine, 10)) {
                                if (MeshView.class.isInstance(n)) {
                                    System.out.println("Selecting Object");
                                    selectedObject = (MeshView) n;
                                } else {
                                    System.out.println("Not Touching " + n.getClass());
                                }
                            // }
                            }
                            if (selectedObject != null) {
                                System.out.println("Grabbing Object ");
                                selectedObject.getTransforms().clear();
                                selectedObject.getTransforms().addAll(robotBase, selsectedAffine);
                            }
                        } else {
                            // button released, look for devices
                            if (selectedObject != null) {
                                // freeze it in place
                                selectedObject.getTransforms().clear();
                                selectedObject.getTransforms().addAll(robotBase, selsectedAffine.clone());
                                selectedObject = null;
                            }
                        }
                    }
                });
            }
        });
    Platform.runLater(new Runnable() {

        @Override
        public void run() {
            ArrayList<DHLink> links = model.getDhChain().getLinks();
            for (DHLink dh : links) {
                final Axis a = new Axis(15);
                a.getChildren().add(new Sphere(5));
                a.getTransforms().add(dh.getListener());
                manipulator.getChildren().add(a);
                if (master != null)
                    master.addConnectionEventListener(new IDeviceConnectionEventListener() {

                        @Override
                        public void onDisconnect(BowlerAbstractDevice source) {
                            // TODO Auto-generated method stub
                            manipulator.getChildren().remove(a);
                            a.getTransforms().clear();
                        }

                        @Override
                        public void onConnect(BowlerAbstractDevice source) {
                        // TODO Auto-generated method stub
                        }
                    });
            }
            // get the affine of the tip of the chain
            selsectedAffine = links.get(links.size() - 1).getListener();
            robotBase.setTx(100);
            robotBase.setTy(100);
            robotBase.setTz(-5);
            manipulator.getTransforms().add(robotBase);
            world.getChildren().addAll(manipulator);
        }
    });
}
Also used : Node(javafx.scene.Node) ArrayList(java.util.ArrayList) DigitalInputChannel(com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel) Sphere(javafx.scene.shape.Sphere) BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) ObservableList(javafx.collections.ObservableList) IDeviceConnectionEventListener(com.neuronrobotics.sdk.common.IDeviceConnectionEventListener) DHLink(com.neuronrobotics.sdk.addons.kinematics.DHLink) IDigitalInputListener(com.neuronrobotics.sdk.dyio.peripherals.IDigitalInputListener) MeshView(javafx.scene.shape.MeshView)

Example 3 with DigitalInputChannel

use of com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel in project java-bowler by NeuronRobotics.

the class SpeedTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    DyIO.disableFWCheck();
    ByteList.setUseStaticBuffer(true);
    // BowlerAbstractConnection c =  new SerialConnection("/dev/DyIO0")
    // BowlerAbstractConnection c =  new SerialConnection("COM65")
    BowlerAbstractConnection c = ConnectionDialog.promptConnection();
    c.setThreadedUpstreamPackets(false);
    if (c == null)
        System.exit(1);
    System.out.println("Starting test");
    DyIO dyio = new DyIO(c);
    // dyio.setThreadedUpstreamPackets(false);
    long start = System.currentTimeMillis();
    dyio.connect();
    dyio.setServoPowerSafeMode(false);
    System.out.println("Startup time: " + (System.currentTimeMillis() - start) + " ms");
    // dyio.enableDebug();
    dyio.setServoPowerSafeMode(false);
    for (int i = 0; i < 24; i++) {
        dyio.getChannel(i).setAsync(false);
    }
    DigitalInputChannel dip = new DigitalInputChannel(dyio.getChannel(0));
    ServoChannel dop = new ServoChannel(dyio.getChannel(1));
    // new PPMReaderChannel(dyio.getChannel(23));
    // new ServoChannel(dyio.getChannel(11));
    double avg = 0;
    int i;
    avg = 0;
    start = System.currentTimeMillis();
    double best = 1000;
    double worst = 0;
    for (i = 0; i < 500; i++) {
        dyio.ping();
        double ms = System.currentTimeMillis() - start;
        avg += ms;
        start = System.currentTimeMillis();
        if (ms < best)
            best = ms;
        if (ms > worst)
            worst = ms;
    }
    System.out.println("Average cycle time for ping: " + (avg / i) + " ms" + " best=" + best / 2 + "ms worst=" + worst / 2);
    boolean high = false;
    // dyio.setCachedMode(true);
    avg = 0;
    best = 1000;
    worst = 0;
    double numLoops = 500.0;
    for (i = 0; i < numLoops; i++) {
        start = System.currentTimeMillis();
        try {
            dip.getValue();
            dop.SetPosition((int) ((((double) i) / numLoops) * 255.0));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        double ms = System.currentTimeMillis() - start;
        if (ms < best)
            best = ms;
        if (ms > worst)
            worst = ms;
        avg += ms;
        start = System.currentTimeMillis();
    // System.out.println("Average cycle time: "+(int)(avg/i)/2+"ms\t\t\t this loop was: "+ms/2+"\t\tindex="+i);
    }
    dop.SetPosition(128);
    System.out.println("Average cycle time for IO : " + (avg / (i + 1)) / 2 + " ms best=" + best / 2 + "ms worst=" + worst / 2);
    avg = 0;
    best = 1000;
    worst = 0;
    dyio.setCachedMode(true);
    // Log.enableDebugPrint(true);
    for (i = 0; i < 500; i++) {
        start = System.currentTimeMillis();
        dyio.flushCache(0);
        double ms = System.currentTimeMillis() - start;
        if (ms < best)
            best = ms;
        if (ms > worst)
            worst = ms;
        avg += ms;
        start = System.currentTimeMillis();
    // System.out.println("Average cycle time: "+(int)(avg/i)+"ms\t\t\t this loop was: "+ms);
    }
    System.out.println("Average cycle time for cache flush: " + (avg / (i + 1)) + " ms best=" + best + "ms worst=" + worst);
    avg = 0;
    best = 1000;
    worst = 0;
    dyio.setCachedMode(true);
    // Log.enableDebugPrint(true);
    for (i = 0; i < 500; i++) {
        start = System.currentTimeMillis();
        dyio.getAllChannelValues();
        double ms = System.currentTimeMillis() - start;
        if (ms < best)
            best = ms;
        if (ms > worst)
            worst = ms;
        avg += ms;
        start = System.currentTimeMillis();
    // System.out.println("Average cycle time: "+(int)(avg/i)+"ms\t\t\t this loop was: "+ms);
    }
    System.out.println("Average cycle time for values get: " + (avg / (i + 1)) + " ms best=" + best + "ms worst=" + worst);
    dyio.setServoPowerSafeMode(true);
    System.exit(0);
}
Also used : DigitalInputChannel(com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel) ServoChannel(com.neuronrobotics.sdk.dyio.peripherals.ServoChannel) BowlerAbstractConnection(com.neuronrobotics.sdk.common.BowlerAbstractConnection) DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Example 4 with DigitalInputChannel

use of com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel in project java-bowler by NeuronRobotics.

the class DIgitalOutputTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    Log.enableInfoPrint();
    DyIO.disableFWCheck();
    DyIO dyio = new DyIO();
    if (!ConnectionDialog.getBowlerDevice(dyio)) {
        System.exit(1);
    }
    DigitalInputChannel dic = new DigitalInputChannel(dyio.getChannel(1));
    DigitalOutputChannel doc = new DigitalOutputChannel(dyio.getChannel(1));
    // Blink the LED 5 times
    for (int i = 0; i < 10; i++) {
        System.out.println("Blinking.");
        // Set the value high every other time, exit if unsuccessful
        if (!doc.setHigh(i % 2 == 1)) {
            System.err.println("Could not connect to the device.");
            System.exit(0);
        }
        // pause between cycles so that the changes are visible
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    System.exit(0);
}
Also used : DigitalInputChannel(com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel) DigitalOutputChannel(com.neuronrobotics.sdk.dyio.peripherals.DigitalOutputChannel) DyIO(com.neuronrobotics.sdk.dyio.DyIO)

Aggregations

DigitalInputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel)4 DyIO (com.neuronrobotics.sdk.dyio.DyIO)3 DHLink (com.neuronrobotics.sdk.addons.kinematics.DHLink)1 BowlerAbstractConnection (com.neuronrobotics.sdk.common.BowlerAbstractConnection)1 BowlerAbstractDevice (com.neuronrobotics.sdk.common.BowlerAbstractDevice)1 IDeviceConnectionEventListener (com.neuronrobotics.sdk.common.IDeviceConnectionEventListener)1 DigitalOutputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalOutputChannel)1 IDigitalInputListener (com.neuronrobotics.sdk.dyio.peripherals.IDigitalInputListener)1 ServoChannel (com.neuronrobotics.sdk.dyio.peripherals.ServoChannel)1 ArrayList (java.util.ArrayList)1 ObservableList (javafx.collections.ObservableList)1 Node (javafx.scene.Node)1 MeshView (javafx.scene.shape.MeshView)1 Sphere (javafx.scene.shape.Sphere)1