Search in sources :

Example 1 with IDeviceConnectionEventListener

use of com.neuronrobotics.sdk.common.IDeviceConnectionEventListener in project bowler-script-kernel by CommonWealthRobotics.

the class FileWatchDeviceWrapper method watch.

public static FileChangeWatcher watch(BowlerAbstractDevice device, File code, IFileChangeListener cadWatcher) {
    try {
        FileChangeWatcher watcher = FileChangeWatcher.watch(code);
        watcher.addIFileChangeListener(cadWatcher);
        device.addConnectionEventListener(new IDeviceConnectionEventListener() {

            @Override
            public void onDisconnect(BowlerAbstractDevice arg0) {
                // TODO Auto-generated method stub
                watcher.removeIFileChangeListener(cadWatcher);
            }

            @Override
            public void onConnect(BowlerAbstractDevice arg0) {
            // TODO Auto-generated method stub
            }
        });
        return watcher;
    } catch (IOException e) {
    // TODO Auto-generated catch block
    // BowlerStudioController.highlightException(code, e);
    }
    return null;
}
Also used : BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) IDeviceConnectionEventListener(com.neuronrobotics.sdk.common.IDeviceConnectionEventListener) IOException(java.io.IOException)

Example 2 with IDeviceConnectionEventListener

use of com.neuronrobotics.sdk.common.IDeviceConnectionEventListener in project bowler-script-kernel by CommonWealthRobotics.

the class MobileBaseCadManager method get.

public static MobileBaseCadManager get(MobileBase device) {
    if (cadmap.get(device) == null) {
        IMobileBaseUIlocal ui2 = new IMobileBaseUIlocal();
        device.addConnectionEventListener(new IDeviceConnectionEventListener() {

            @Override
            public void onDisconnect(BowlerAbstractDevice source) {
                // TODO Auto-generated method stub
                ui2.list.clear();
            }

            @Override
            public void onConnect(BowlerAbstractDevice source) {
            // TODO Auto-generated method stub
            }
        });
        return get(device, ui2);
    }
    return cadmap.get(device);
}
Also used : BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) IDeviceConnectionEventListener(com.neuronrobotics.sdk.common.IDeviceConnectionEventListener)

Example 3 with IDeviceConnectionEventListener

use of com.neuronrobotics.sdk.common.IDeviceConnectionEventListener 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 4 with IDeviceConnectionEventListener

use of com.neuronrobotics.sdk.common.IDeviceConnectionEventListener in project BowlerStudio by CommonWealthRobotics.

the class AbstractBowlerStudioTab method setDevice.

public void setDevice(BowlerAbstractDevice pm) {
    myNames = new ArrayList<>();
    if (getMyNameSpaces().length > 0) {
        for (int i = 0; i < getMyNameSpaces().length; i++) {
            myNames.add(getMyNameSpaces()[i]);
        }
        if (!isMyNamespace(pm.getNamespaces())) {
            throw new RuntimeException("Device and namespaces are incompatible ");
        }
    }
    setOnCloseRequest(this);
    initializeUI(pm);
    pm.addConnectionEventListener(new IDeviceConnectionEventListener() {

        @Override
        public void onDisconnect(BowlerAbstractDevice source) {
            // if the device disconnects, close the tab
            if (source == pm && source != null) {
                requestClose();
                if (MobileBase.class.isInstance(pm)) {
                    MobileBase dev = (MobileBase) pm;
                    try {
                        for (CSG p : MobileBaseCadManager.get(dev).getBasetoCadMap().get(dev)) BowlerStudioController.removeObject(p);
                        for (DHParameterKinematics leg : dev.getAllDHChains()) for (CSG p : MobileBaseCadManager.get(dev).getDHtoCadMap().get(leg)) BowlerStudioController.removeObject(p);
                    } catch (Throwable e) {
                    }
                }
            } else {
            // Not a bug, expected to ensure one device disconnects the rest of the dependent devices
            // System.err.println("Device type was "+source.getClass()+" named "+source.getScriptingName()+" expected "+pm.getClass()+" named "+pm.getScriptingName());
            // new Exception().printStackTrace();
            }
        }

        @Override
        public void onConnect(BowlerAbstractDevice source) {
        // TODO Auto-generated method stub
        }
    });
}
Also used : BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) CSG(eu.mihosoft.vrl.v3d.CSG) IDeviceConnectionEventListener(com.neuronrobotics.sdk.common.IDeviceConnectionEventListener) DHParameterKinematics(com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics) MobileBase(com.neuronrobotics.sdk.addons.kinematics.MobileBase)

Aggregations

BowlerAbstractDevice (com.neuronrobotics.sdk.common.BowlerAbstractDevice)4 IDeviceConnectionEventListener (com.neuronrobotics.sdk.common.IDeviceConnectionEventListener)4 DHLink (com.neuronrobotics.sdk.addons.kinematics.DHLink)1 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)1 MobileBase (com.neuronrobotics.sdk.addons.kinematics.MobileBase)1 DigitalInputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel)1 IDigitalInputListener (com.neuronrobotics.sdk.dyio.peripherals.IDigitalInputListener)1 CSG (eu.mihosoft.vrl.v3d.CSG)1 IOException (java.io.IOException)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