Search in sources :

Example 6 with BowlerAbstractDevice

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

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

the class BowlerStudioController method addObject.

public static void addObject(Object o, File source) {
    if (List.class.isInstance(o)) {
        List<Object> c = (List<Object>) o;
        for (int i = 0; i < c.size(); i++) {
            // Log.warning("Loading array Lists with removals " + c.get(i));
            addObject(c.get(i), source);
        }
        return;
    }
    if (CSG.class.isInstance(o)) {
        CSG csg = (CSG) o;
        Platform.runLater(() -> {
            // new RuntimeException().printStackTrace();
            CreatureLab3dController.getEngine().addObject(csg, source);
        });
        return;
    } else if (Tab.class.isInstance(o)) {
        getBowlerStudio().addTab((Tab) o, true);
        return;
    } else if (Node.class.isInstance(o)) {
        getBowlerStudio().addNode((Node) o);
        return;
    } else if (Polygon.class.isInstance(o)) {
        Polygon p = (Polygon) o;
        List<Vertex> vertices = p.vertices;
        javafx.scene.paint.Color color = new javafx.scene.paint.Color(Math.random() * 0.5 + 0.5, Math.random() * 0.5 + 0.5, Math.random() * 0.5 + 0.5, 1);
        // double stroke = 0.5;
        // for (int i = 1; i < vertices.size(); i++) {
        // Line3D line = new Line3D(vertices.get(i - 1), vertices.get(i));
        // line.setStrokeWidth(stroke);
        // line.setStroke(color);
        // getBowlerStudio().addNode(line);
        // }
        // // Connecting line
        // Line3D line = new Line3D(vertices.get(0), vertices.get(vertices.size() - 1));
        // line.setStrokeWidth(stroke);
        // line.setStroke(color);
        MeshContainer mesh = CSGtoJavafx.meshFromPolygon(p);
        javafx.scene.shape.MeshView current = mesh.getAsMeshViews().get(0);
        current.setMaterial(new PhongMaterial(color));
        current.setCullFace(CullFace.NONE);
        getBowlerStudio().addNode(current);
        return;
    } else if (BowlerAbstractDevice.class.isInstance(o)) {
        BowlerAbstractDevice bad = (BowlerAbstractDevice) o;
        ConnectionManager.addConnection((BowlerAbstractDevice) o, bad.getScriptingName());
        return;
    } else if (DMDevice.wrappable(o)) {
        BowlerAbstractDevice bad;
        try {
            bad = new DMDevice(o);
            ConnectionManager.addConnection(bad, bad.getScriptingName());
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : DMDevice(com.neuronrobotics.sdk.common.DMDevice) Color(java.awt.Color) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException) MeshContainer(eu.mihosoft.vrl.v3d.MeshContainer) BowlerAbstractDevice(com.neuronrobotics.sdk.common.BowlerAbstractDevice) LocalFileScriptTab(com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab) Tab(javafx.scene.control.Tab) CSG(eu.mihosoft.vrl.v3d.CSG) ArrayList(java.util.ArrayList) List(java.util.List) Polygon(eu.mihosoft.vrl.v3d.Polygon) PhongMaterial(javafx.scene.paint.PhongMaterial)

Example 8 with BowlerAbstractDevice

use of com.neuronrobotics.sdk.common.BowlerAbstractDevice 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)8 IDeviceConnectionEventListener (com.neuronrobotics.sdk.common.IDeviceConnectionEventListener)4 IOException (java.io.IOException)4 CSG (eu.mihosoft.vrl.v3d.CSG)3 ArrayList (java.util.ArrayList)3 Tab (javafx.scene.control.Tab)2 LocalFileScriptTab (com.neuronrobotics.bowlerstudio.tabs.LocalFileScriptTab)1 DHLink (com.neuronrobotics.sdk.addons.kinematics.DHLink)1 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)1 MobileBase (com.neuronrobotics.sdk.addons.kinematics.MobileBase)1 BowlerDataType (com.neuronrobotics.sdk.common.BowlerDataType)1 BowlerDatagram (com.neuronrobotics.sdk.common.BowlerDatagram)1 DMDevice (com.neuronrobotics.sdk.common.DMDevice)1 MACAddress (com.neuronrobotics.sdk.common.MACAddress)1 RpcEncapsulation (com.neuronrobotics.sdk.common.RpcEncapsulation)1 BowlerAbstractDeviceServerNamespace (com.neuronrobotics.sdk.common.device.server.BowlerAbstractDeviceServerNamespace)1 BowlerAbstractServer (com.neuronrobotics.sdk.common.device.server.BowlerAbstractServer)1 IBowlerCommandProcessor (com.neuronrobotics.sdk.common.device.server.IBowlerCommandProcessor)1 DigitalInputChannel (com.neuronrobotics.sdk.dyio.peripherals.DigitalInputChannel)1 IDigitalInputListener (com.neuronrobotics.sdk.dyio.peripherals.IDigitalInputListener)1