Search in sources :

Example 1 with IDigitalInputListener

use of com.neuronrobotics.sdk.dyio.peripherals.IDigitalInputListener 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)

Aggregations

DHLink (com.neuronrobotics.sdk.addons.kinematics.DHLink)1 BowlerAbstractDevice (com.neuronrobotics.sdk.common.BowlerAbstractDevice)1 IDeviceConnectionEventListener (com.neuronrobotics.sdk.common.IDeviceConnectionEventListener)1 DigitalInputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel)1 IDigitalInputListener (com.neuronrobotics.sdk.dyio.peripherals.IDigitalInputListener)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