Search in sources :

Example 1 with BowlerJInputDevice

use of com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice in project BowlerStudio by CommonWealthRobotics.

the class JogWidget method RemoveGameController.

private BowlerJInputDevice RemoveGameController() {
    BowlerJInputDevice stale = getGameController();
    getGameController().removeListeners(this);
    game.setText("Add Game Controller");
    setGameController(null);
    return stale;
}
Also used : BowlerJInputDevice(com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice)

Example 2 with BowlerJInputDevice

use of com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice in project BowlerStudio by CommonWealthRobotics.

the class MobleBaseMenueFactory method loadSingleLimb.

@SuppressWarnings("unchecked")
private static void loadSingleLimb(MobileBase base, TreeView<String> view, DHParameterKinematics dh, TreeItem<String> rootItem, HashMap<TreeItem<String>, Runnable> callbackMapForTreeitems, HashMap<TreeItem<String>, Group> widgetMapForTreeitems, CreatureLab creatureLab, boolean creatureIsOwnedByUser) throws Exception {
    TreeItem<String> dhItem = new TreeItem<>(dh.getScriptingName(), AssetFactory.loadIcon("Move-Limb.png"));
    JogWidget widget = new JogWidget(dh, base);
    callbackMapForTreeitems.put(dhItem, () -> {
        if (widgetMapForTreeitems.get(dhItem) == null) {
            // create the widget for the leg when looking at it for the
            // first time
            VBox jog = new VBox(10);
            jog.getChildren().add(new Label("Jog Limb"));
            jog.getChildren().add(widget);
            widgetMapForTreeitems.put(dhItem, new Group(jog));
        }
        BowlerJInputDevice controller = creatureLab.getController();
        if (controller != null) {
            widget.setGameController(controller);
        }
        widget.setCurrent(dh.getCurrentPoseTarget());
        BowlerStudio.select(base, dh);
    });
    TreeItem<String> remove = new TreeItem<>("Remove " + dh.getScriptingName(), AssetFactory.loadIcon("Remove-Limb.png"));
    callbackMapForTreeitems.put(remove, () -> {
        Platform.runLater(() -> {
            Alert alert = new Alert(AlertType.CONFIRMATION);
            alert.setTitle("Confirm removing limb");
            alert.setHeaderText("This will remove " + dh.getScriptingName());
            alert.setContentText("Are sure you wish to remove this limb?");
            Optional<ButtonType> result = alert.showAndWait();
            view.getSelectionModel().select(rootItem);
            if (result.get() == ButtonType.OK) {
                rootItem.getChildren().remove(dhItem);
                if (base.getLegs().contains(dh)) {
                    base.getLegs().remove(dh);
                }
                if (base.getAppendages().contains(dh)) {
                    base.getAppendages().remove(dh);
                }
                if (base.getSteerable().contains(dh)) {
                    base.getSteerable().remove(dh);
                }
                if (base.getDrivable().contains(dh)) {
                    base.getDrivable().remove(dh);
                }
                if (base.getParallelGroup(dh) != null)
                    base.getParallelGroup(dh).removeLimb(dh);
                creatureLab.generateCad();
            }
        });
    });
    int j = 0;
    try {
        for (LinkConfiguration conf : dh.getFactory().getLinkConfigurations()) {
            loadSingleLink(j++, base, view, conf, dh, dhItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUser);
        }
        TreeItem<String> addLink = new TreeItem<>("Add Link", AssetFactory.loadIcon("Add-Link.png"));
        callbackMapForTreeitems.put(addLink, () -> {
            // if(widgetMapForTreeitems.get(advanced)==null){
            // //create the widget for the leg when looking at it for the first
            // time
            // widgetMapForTreeitems.put(advanced, new DhChainWidget(dh,
            // creatureLab));
            // }
            Platform.runLater(() -> {
                TextInputDialog dialog = new TextInputDialog("Link_" + dh.getLinkConfigurations().size());
                dialog.setTitle("Add a new link of");
                dialog.setHeaderText("Set the scripting name for this link");
                dialog.setContentText("Please the name of the new link:");
                // Traditional way to get the response value.
                Optional<String> result = dialog.showAndWait();
                if (result.isPresent()) {
                    view.getSelectionModel().select(rootItem);
                    new Thread() {

                        public void run() {
                            System.out.println("Your new link: " + result.get());
                            LinkConfiguration newLink = new LinkConfiguration();
                            ArrayList<LinkConfiguration> linkConfigurations = dh.getFactory().getLinkConfigurations();
                            int numOfLinks = linkConfigurations.size();
                            String typeOfLink;
                            try {
                                typeOfLink = linkConfigurations.get(numOfLinks - 1).getTypeString();
                            } catch (Exception ex) {
                                typeOfLink = LinkType.VIRTUAL.getName();
                            }
                            if (typeOfLink == null)
                                typeOfLink = LinkType.VIRTUAL.getName();
                            // newLink.setType(typeOfLink);
                            newLink.setTypeString(typeOfLink.toString());
                            getNextChannel(base, newLink);
                            newLink.setName(result.get());
                            if (dh != null)
                                dh.addNewLink(newLink, new DHLink(0, 0, 100, 0));
                            try {
                                loadSingleLink(dh.getLinkConfigurations().size() - 1, base, view, newLink, dh, dhItem, callbackMapForTreeitems, widgetMapForTreeitems, creatureLab, creatureIsOwnedByUser);
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            creatureLab.generateCad();
                        }
                    }.start();
                }
            });
        });
        dhItem.getChildren().addAll(addLink, remove);
    } catch (Throwable T) {
        T.printStackTrace();
    }
    TreeItem<String> parallel = new TreeItem<>("Parallel Settings", AssetFactory.loadIcon("Design-Parameter-Adjustment.png"));
    callbackMapForTreeitems.put(parallel, () -> {
        if (widgetMapForTreeitems.get(parallel) == null) {
            // first time
            try {
                widgetMapForTreeitems.put(parallel, new ParallelWidget(base, dh, creatureLab));
            } catch (Exception ex) {
                BowlerStudio.printStackTrace(ex);
            }
        }
        ((ParallelWidget) widgetMapForTreeitems.get(parallel)).configure(base, dh, creatureLab);
    });
    dhItem.getChildren().addAll(parallel);
    TreeItem<String> PlaceLimb = new TreeItem<>("Move Root Of Limb", AssetFactory.loadIcon("Design-Parameter-Adjustment.png"));
    callbackMapForTreeitems.put(PlaceLimb, () -> {
        if (widgetMapForTreeitems.get(PlaceLimb) == null) {
            // first time
            try {
                widgetMapForTreeitems.put(PlaceLimb, new Group(new TransformWidget("Move place where limb is attached to body", dh.getRobotToFiducialTransform(), new IOnTransformChange() {

                    @Override
                    public void onTransformFinished(TransformNR newTrans) {
                        // Force a cad regeneration
                        creatureLab.onSliderDoneMoving(null, 0);
                    }

                    @Override
                    public void onTransformChaging(TransformNR newTrans) {
                        Log.debug("Limb to base" + newTrans.toString());
                        dh.setRobotToFiducialTransform(newTrans);
                        dh.refreshPose();
                    }
                })));
            } catch (Exception ex) {
                BowlerStudio.printStackTrace(ex);
            }
        }
    });
    dhItem.getChildren().addAll(PlaceLimb);
    // });
    if (creatureIsOwnedByUser) {
        // TreeItem<String> owner = new
        // TreeItem<>("Scripts",AssetFactory.loadIcon("Owner.png"));
        TreeItem<String> setCAD = new TreeItem<>("Set CAD Engine...", AssetFactory.loadIcon("Set-CAD-Engine.png"));
        callbackMapForTreeitems.put(setCAD, () -> {
            PromptForGit.prompt("Select a CAD Engine From Git", dh.getGitCadEngine()[0], (gitsId, file) -> {
                Log.warn("Loading cad engine");
                try {
                    creatureLab.setGitCadEngine(gitsId, file, dh);
                    openCadTab(creatureLab, gitsId, file);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            });
        });
        TreeItem<String> editCAD = new TreeItem<>("Edit CAD Engine...", AssetFactory.loadIcon("Edit-CAD-Engine.png"));
        callbackMapForTreeitems.put(editCAD, () -> {
            try {
                openCadTab(creatureLab, dh.getGitCadEngine()[0], dh.getGitCadEngine()[1]);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
        TreeItem<String> resetWalking = new TreeItem<>("Set Dh Kinematics Engine...", AssetFactory.loadIcon("Set-DH-Kinematics.png"));
        callbackMapForTreeitems.put(resetWalking, () -> {
            PromptForGit.prompt("Select a DH Solver Engine From Git", dh.getGitDhEngine()[0], (gitsId, file) -> {
                Log.warn("Loading walking engine");
                try {
                    creatureLab.setGitDhEngine(gitsId, file, dh);
                    File code = ScriptingEngine.fileFromGit(gitsId, file);
                    BowlerStudio.createFileTab(code);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            });
        });
        TreeItem<String> editWalking = new TreeItem<>("Edit Kinematics Engine...", AssetFactory.loadIcon("Edit-Kinematics-Engine.png"));
        callbackMapForTreeitems.put(editWalking, () -> {
            try {
                File code = ScriptingEngine.fileFromGit(dh.getGitDhEngine()[0], dh.getGitDhEngine()[1]);
                BowlerStudio.createFileTab(code);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
        dhItem.getChildren().addAll(editWalking, editCAD, resetWalking, setCAD);
    }
    rootItem.getChildren().add(dhItem);
    double[] vect = dh.getCurrentJointSpaceVector();
    for (int i = 0; i < vect.length; i++) {
        vect[i] = 0;
    }
    try {
        dh.setDesiredJointSpaceVector(vect, 1);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    dh.updateCadLocations();
}
Also used : Group(javafx.scene.Group) ParallelGroup(com.neuronrobotics.sdk.addons.kinematics.parallel.ParallelGroup) ArrayList(java.util.ArrayList) BowlerJInputDevice(com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice) TransformNR(com.neuronrobotics.sdk.addons.kinematics.math.TransformNR) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException) VBox(javafx.scene.layout.VBox) File(java.io.File)

Example 3 with BowlerJInputDevice

use of com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice in project BowlerStudio by CommonWealthRobotics.

the class MobleBaseMenueFactory method loadSingleLink.

@SuppressWarnings("restriction")
private static void loadSingleLink(int linkIndex, MobileBase base, TreeView<String> view, LinkConfiguration conf, DHParameterKinematics dh, TreeItem<String> rootItem, HashMap<TreeItem<String>, Runnable> callbackMapForTreeitems, HashMap<TreeItem<String>, Group> widgetMapForTreeitems, CreatureLab creatureLab, boolean isOwner) throws Exception {
    TreeItem<String> link = new TreeItem<>(conf.getName(), AssetFactory.loadIcon("Move-Single-Motor.png"));
    DHLink dhLink;
    try {
        dhLink = dh.getChain().getLinks().get(linkIndex);
    } catch (java.lang.IndexOutOfBoundsException ex) {
        return;
    }
    // LinkConfigurationWidget confWidget =setHardwareConfig(base, conf,
    // dh.getFactory(), link, callbackMapForTreeitems, widgetMapForTreeitems);
    // lsw.setTrimController(confWidget);
    LinkConfigurationWidget confWidget = new LinkConfigurationWidget(conf, dh.getFactory(), MobileBaseCadManager.get(base));
    LinkSliderWidget lsw = new LinkSliderWidget(linkIndex, dh, confWidget);
    TreeItem<String> hwConf = new TreeItem<>("Hardware Config " + conf.getName(), AssetFactory.loadIcon("Hardware-Config.png"));
    callbackMapForTreeitems.put(hwConf, () -> {
        if (widgetMapForTreeitems.get(hwConf) == null) {
            // create the widget for the leg when looking at it for the
            // first time
            Platform.runLater(() -> widgetMapForTreeitems.put(hwConf, lsw));
            lsw.enable();
        }
        if (linkIndex == 0)
            BowlerStudio.select(base, dh);
        else
            BowlerStudio.select((javafx.scene.transform.Affine) dh.getAbstractLink(linkIndex - 1).getGlobalPositionListener());
    });
    link.getChildren().add(hwConf);
    callbackMapForTreeitems.put(link, () -> {
        if (widgetMapForTreeitems.get(link) == null) {
            // create the widget for the leg when looking at it for the
            // first time
            widgetMapForTreeitems.put(link, lsw);
        }
        BowlerJInputDevice controller = creatureLab.getController();
        if (controller != null) {
            lsw.setGameController(controller);
        }
        try {
            if (linkIndex == 0)
                BowlerStudio.select(base, dh);
            else
                BowlerStudio.select((javafx.scene.transform.Affine) dh.getAbstractLink(linkIndex - 1).getGlobalPositionListener());
        } catch (Exception ex) {
            System.err.println("Limb not loaded yet");
        }
        lsw.enable();
    // select( base, dh);
    // activate controller
    });
    TreeItem<String> slaves = new TreeItem<>("Slaves to " + conf.getName(), AssetFactory.loadIcon("Slave-Links.png"));
    LinkFactory slaveFactory = dh.getFactory().getLink(conf).getSlaveFactory();
    for (LinkConfiguration co : conf.getSlaveLinks()) {
        setHardwareConfig(base, co, slaveFactory, slaves, callbackMapForTreeitems, widgetMapForTreeitems);
    }
    TreeItem<String> addSlaves = new TreeItem<>("Add Slave to " + conf.getName(), AssetFactory.loadIcon("Add-Slave-Links.png"));
    callbackMapForTreeitems.put(addSlaves, () -> {
        // if(widgetMapForTreeitems.get(advanced)==null){
        // //create the widget for the leg when looking at it for the first
        // time
        // widgetMapForTreeitems.put(advanced, new DhChainWidget(dh,
        // creatureLab));
        // }
        Platform.runLater(() -> {
            TextInputDialog dialog = new TextInputDialog(conf.getName() + "_SLAVE_" + conf.getSlaveLinks().size());
            dialog.setTitle("Add a new Slave link of");
            dialog.setHeaderText("Set the scripting name for this Slave link");
            dialog.setContentText("Please the name of the new Slave link:");
            // Traditional way to get the response value.
            Optional<String> result = dialog.showAndWait();
            if (result.isPresent()) {
                view.getSelectionModel().select(rootItem);
                new Thread() {

                    public void run() {
                        System.out.println("Your new link: " + result.get());
                        LinkConfiguration newLink = new LinkConfiguration();
                        // newLink.setType(conf.getTypeEnum());
                        newLink.setTypeString(conf.getTypeString());
                        getNextChannel(base, newLink);
                        newLink.setName(result.get());
                        conf.getSlaveLinks().add(newLink);
                        slaveFactory.getLink(newLink);
                        try {
                            setHardwareConfig(base, newLink, slaveFactory, slaves, callbackMapForTreeitems, widgetMapForTreeitems);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                }.start();
            }
        });
    });
    slaves.getChildren().add(0, addSlaves);
    TreeItem<String> remove = new TreeItem<>("Remove " + conf.getName(), AssetFactory.loadIcon("Remove-Link.png"));
    callbackMapForTreeitems.put(remove, () -> {
        Platform.runLater(() -> {
            Alert alert = new Alert(AlertType.CONFIRMATION);
            alert.setTitle("Confirm removing link");
            alert.setHeaderText("This will remove " + conf.getName());
            alert.setContentText("Are sure you wish to remove this link?");
            Optional<ButtonType> result = alert.showAndWait();
            view.getSelectionModel().select(rootItem);
            if (result.get() == ButtonType.OK) {
                rootItem.getChildren().remove(link);
                LinkFactory factory = dh.getFactory();
                // remove the link listener while the number of links could
                // chnage
                factory.removeLinkListener(dh);
                DHChain chain = dh.getDhChain();
                chain.getLinks().remove(linkIndex);
                factory.deleteLink(linkIndex);
                // set the modified kinematics chain
                dh.setChain(chain);
                // once the new link configuration is set up, re add the
                // listener
                factory.addLinkListener(dh);
                creatureLab.generateCad();
            }
        });
    });
    TreeItem<String> design = new TreeItem<>("Design Parameters " + conf.getName(), AssetFactory.loadIcon("Design-Parameter-Adjustment.png"));
    callbackMapForTreeitems.put(design, () -> {
        if (widgetMapForTreeitems.get(design) == null) {
            // create the widget for the leg when looking at it for the
            // first time
            widgetMapForTreeitems.put(design, new DhSettingsWidget(dhLink, dh, new IOnEngineeringUnitsChange() {

                @Override
                public void onSliderMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
                // TODO Auto-generated method stub
                }

                @Override
                public void onSliderDoneMoving(EngineeringUnitsSliderWidget source, double newAngleDegrees) {
                    creatureLab.onSliderDoneMoving(source, newAngleDegrees);
                }
            }));
        }
        if (linkIndex == 0)
            BowlerStudio.select(base, dh);
        else
            BowlerStudio.select((javafx.scene.transform.Affine) dh.getAbstractLink(linkIndex - 1).getGlobalPositionListener());
    });
    link.getChildren().addAll(design);
    link.getChildren().addAll(slaves, remove);
    rootItem.getChildren().add(0, link);
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) TransportException(org.eclipse.jgit.api.errors.TransportException) InvalidRemoteException(org.eclipse.jgit.api.errors.InvalidRemoteException) BowlerJInputDevice(com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice)

Example 4 with BowlerJInputDevice

use of com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice in project BowlerStudio by CommonWealthRobotics.

the class ConnectionManager method onConnectGamePad.

public static void onConnectGamePad() {
    ArrayList<String> ca = BowlerJInputDevice.getControllers();
    List<String> choices = new ArrayList<>();
    if (ca.size() == 0)
        return;
    for (String s : ca) {
        choices.add(s);
    }
    ChoiceDialog<String> dialog = new ChoiceDialog<>(choices.get(0), choices);
    dialog.setTitle("JInput Game Controller Select");
    dialog.setHeaderText("Connect a game controller");
    dialog.setContentText("Controller:");
    // Traditional way to get the response value.
    Optional<String> result = dialog.showAndWait();
    // The Java 8 way to get the response value (with lambda expression).
    result.ifPresent(letter -> {
        for (String s : BowlerJInputDevice.getControllers()) {
            if (letter.contains(s)) {
                BowlerJInputDevice p = new BowlerJInputDevice(s);
                p.connect();
                addConnection(p, p.getName());
                return;
            }
        }
    });
}
Also used : ArrayList(java.util.ArrayList) BowlerJInputDevice(com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice)

Example 5 with BowlerJInputDevice

use of com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice in project BowlerStudio by CommonWealthRobotics.

the class CalibrateGameControl method initializeUI.

@Override
public void initializeUI(BowlerAbstractDevice pm) {
    BowlerJInputDevice dev = (BowlerJInputDevice) pm;
    File fxmlFIle;
    try {
        fxmlFIle = AssetFactory.loadFile("layout/jogTrainerWidget.fxml");
        URL fileURL = fxmlFIle.toURI().toURL();
        FXMLLoader loader = new FXMLLoader(fileURL);
        loader.setLocation(fileURL);
        Parent root;
        w = new JogTrainerWidget(dev);
        loader.setController(w);
        // This is needed when loading on MAC
        loader.setClassLoader(JogTrainerWidget.class.getClassLoader());
        root = loader.load();
        setContent(root);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    setText("Calibrate Game Control");
    onTabReOpening();
}
Also used : Parent(javafx.scene.Parent) JogTrainerWidget(com.neuronrobotics.sdk.addons.gamepad.JogTrainerWidget) BowlerJInputDevice(com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice) File(java.io.File) FXMLLoader(javafx.fxml.FXMLLoader) URL(java.net.URL)

Aggregations

BowlerJInputDevice (com.neuronrobotics.sdk.addons.gamepad.BowlerJInputDevice)5 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 InvalidRemoteException (org.eclipse.jgit.api.errors.InvalidRemoteException)2 TransportException (org.eclipse.jgit.api.errors.TransportException)2 JogTrainerWidget (com.neuronrobotics.sdk.addons.gamepad.JogTrainerWidget)1 TransformNR (com.neuronrobotics.sdk.addons.kinematics.math.TransformNR)1 ParallelGroup (com.neuronrobotics.sdk.addons.kinematics.parallel.ParallelGroup)1 URL (java.net.URL)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Group (javafx.scene.Group)1 Parent (javafx.scene.Parent)1 VBox (javafx.scene.layout.VBox)1