Search in sources :

Example 1 with MobileBase

use of com.neuronrobotics.sdk.addons.kinematics.MobileBase in project BowlerStudio by CommonWealthRobotics.

the class CreatureLab method initializeUI.

@SuppressWarnings({ "restriction", "restriction" })
@Override
public void initializeUI(BowlerAbstractDevice pm) {
    setGraphic(AssetFactory.loadIcon("CreatureLab-Tab.png"));
    this.pm = pm;
    autoRegen.setSelected(true);
    autoRegen.setOnAction(event -> {
        baseManager.setAutoRegen(autoRegen.isSelected());
        if (autoRegen.isSelected()) {
            generateCad();
        }
    });
    // TODO Auto-generated method stub
    setText(pm.getScriptingName());
    try {
        ScriptingEngine.setAutoupdate(true);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    MobileBase device = (MobileBase) pm;
    // Button save = new Button("Save Configuration");
    FXMLLoader loader;
    try {
        loader = AssetFactory.loadLayout("layout/CreatureLabControlsTab.fxml", true);
        Platform.runLater(() -> {
            loader.setController(tab);
            // This is needed when loading on MAC
            loader.setClassLoader(getClass().getClassLoader());
            try {
                root = loader.load();
                finishLoading(device);
            } catch (Exception e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
            }
        });
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) MobileBase(com.neuronrobotics.sdk.addons.kinematics.MobileBase) FXMLLoader(javafx.fxml.FXMLLoader) 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)

Example 2 with MobileBase

use of com.neuronrobotics.sdk.addons.kinematics.MobileBase in project bowler-script-kernel by CommonWealthRobotics.

the class RobotHelper method inlineScriptRun.

@Override
public Object inlineScriptRun(File code, ArrayList<Object> args) {
    byte[] bytes;
    try {
        bytes = Files.readAllBytes(code.toPath());
        String s = new String(bytes, "UTF-8");
        MobileBase mb;
        try {
            mb = new MobileBase(IOUtils.toInputStream(s, "UTF-8"));
            mb.setGitSelfSource(ScriptingEngine.findGitTagFromFile(code));
            return MobileBaseLoader.get(mb).getBase();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return null;
        }
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // System.out.println("Clojure returned of type="+ret.getClass()+" value="+ret);
    return null;
}
Also used : IOException(java.io.IOException) MobileBase(com.neuronrobotics.sdk.addons.kinematics.MobileBase)

Example 3 with MobileBase

use of com.neuronrobotics.sdk.addons.kinematics.MobileBase in project bowler-script-kernel by CommonWealthRobotics.

the class MobileBaseCadManager method generateBody.

public ArrayList<CSG> generateBody(MobileBase base) {
    getProcesIndictor().set(0);
    setAllCad(new ArrayList<>());
    // DHtoCadMap = new HashMap<>();
    // private HashMap<MobileBase, ArrayList<CSG>> BasetoCadMap = new
    // HashMap<>();
    MobileBase device = base;
    if (getBasetoCadMap().get(device) == null) {
        getBasetoCadMap().put(device, new ArrayList<CSG>());
    }
    if (cadEngine == null) {
        try {
            setDefaultLinkLevelCadEngine();
        } catch (Exception e) {
            getUi().highlightException(null, e);
        }
        if (getCadScript() != null) {
            try {
                cadEngine = ScriptingEngine.inlineFileScriptRun(getCadScript(), null);
            } catch (Exception e) {
                getUi().highlightException(getCadScript(), e);
            }
        }
    }
    getProcesIndictor().set(0.1);
    try {
        getAllCad().clear();
        if (showingStl) {
            // skip the regen
            for (CSG c : getBasetoCadMap().get(device)) {
                getAllCad().add(c);
            }
        } else {
            if (!bail) {
                ArrayList<CSG> newcad = getIgenerateBody().generateBody(device);
                for (CSG c : newcad) {
                    getAllCad().add(c);
                }
                ui.addCSG(newcad, getCadScript());
            } else
                new Exception().printStackTrace();
            ArrayList<CSG> arrayList = getBasetoCadMap().get(device);
            arrayList.clear();
            for (CSG c : getAllCad()) {
                arrayList.add(c);
            }
            new Thread(() -> {
                Thread.currentThread().setUncaughtExceptionHandler(new IssueReportingExceptionHandler());
                // load the cad union in a thread to
                localGetBaseCad(device);
            // make it ready for physics
            }).start();
        }
    } catch (Exception e) {
        getUi().highlightException(getCadScript(), e);
    }
    System.out.println("Displaying Body");
    getProcesIndictor().set(0.35);
    // clears old robot and places base
    getUi().setAllCSG(getBasetoCadMap().get(device), getCadScript());
    System.out.println("Rendering limbs");
    getProcesIndictor().set(0.4);
    ArrayList<DHParameterKinematics> limbs = base.getAllDHChains();
    double numLimbs = limbs.size();
    int i = 0;
    for (DHParameterKinematics l : limbs) {
        if (getDHtoCadMap().get(l) == null) {
            getDHtoCadMap().put(l, new ArrayList<CSG>());
        }
        ArrayList<CSG> arrayList = getDHtoCadMap().get(l);
        int j = 0;
        if (showingStl || !device.isAvailable()) {
            for (CSG csg : arrayList) {
                getAllCad().add(csg);
                getUi().addCsg(csg, getCadScript());
                set(base, (int) i, (int) j);
                j += 1;
            }
        } else {
            arrayList.clear();
            ArrayList<CSG> linksCad = generateCad(l);
            for (CSG csg : linksCad) {
                getAllCad().add(csg);
                arrayList.add(csg);
                getUi().addCsg(csg, getCadScript());
                j += 1;
            }
        }
        i += 1;
    }
    showingStl = false;
    getProcesIndictor().set(1);
    // return PhysicsEngine.getCsgFromEngine();
    return getAllCad();
}
Also used : CSG(eu.mihosoft.vrl.v3d.CSG) DHParameterKinematics(com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics) MobileBase(com.neuronrobotics.sdk.addons.kinematics.MobileBase) IssueReportingExceptionHandler(com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler) 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)

Example 4 with MobileBase

use of com.neuronrobotics.sdk.addons.kinematics.MobileBase in project bowler-script-kernel by CommonWealthRobotics.

the class MobileBaseCadManager method getConfigurationDisplay.

private static ICadGenerator getConfigurationDisplay() {
    if (cadEngineConfiguration == null) {
        try {
            File confFile = ScriptingEngine.fileFromGit("https://github.com/CommonWealthRobotics/DHParametersCadDisplay.git", "dhcad.groovy");
            cadEngineConfiguration = (ICadGenerator) ScriptingEngine.inlineFileScriptRun(confFile, null);
            FileChangeWatcher watcher = FileChangeWatcher.watch(confFile);
            watcher.addIFileChangeListener(new IFileChangeListener() {

                @Override
                public void onFileChange(File fileThatChanged, WatchEvent event) {
                    // TODO Auto-generated method stub
                    try {
                        cadEngineConfiguration = (ICadGenerator) ScriptingEngine.gitScriptRun("https://github.com/CommonWealthRobotics/DHParametersCadDisplay.git", "dhcad.groovy", null);
                        for (MobileBase manager : cadmap.keySet()) {
                            MobileBaseCadManager mobileBaseCadManager = cadmap.get(manager);
                            if (mobileBaseCadManager.autoRegen)
                                if (mobileBaseCadManager.configMode)
                                    mobileBaseCadManager.generateCad();
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            });
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return cadEngineConfiguration;
}
Also used : IFileChangeListener(com.neuronrobotics.sdk.util.IFileChangeListener) FileChangeWatcher(com.neuronrobotics.bowlerstudio.util.FileChangeWatcher) WatchEvent(java.nio.file.WatchEvent) File(java.io.File) MobileBase(com.neuronrobotics.sdk.addons.kinematics.MobileBase) 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)

Example 5 with MobileBase

use of com.neuronrobotics.sdk.addons.kinematics.MobileBase in project bowler-script-kernel by CommonWealthRobotics.

the class MobileBaseLoader method fromGit.

public static MobileBase fromGit(String id, String file) throws Exception {
    String xmlContent = ScriptingEngine.codeFromGit(id, file)[0];
    MobileBase mb = new MobileBase(IOUtils.toInputStream(xmlContent, "UTF-8"));
    mb.setGitSelfSource(new String[] { id, file });
    // ConnectionManager.addConnection(mb, mb.getScriptingName());
    return initializeScripts(mb);
}
Also used : MobileBase(com.neuronrobotics.sdk.addons.kinematics.MobileBase)

Aggregations

MobileBase (com.neuronrobotics.sdk.addons.kinematics.MobileBase)7 IOException (java.io.IOException)4 DHParameterKinematics (com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 InvalidRemoteException (org.eclipse.jgit.api.errors.InvalidRemoteException)3 TransportException (org.eclipse.jgit.api.errors.TransportException)3 CSG (eu.mihosoft.vrl.v3d.CSG)2 IssueReportingExceptionHandler (com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler)1 LinkConfigurationWidget (com.neuronrobotics.bowlerstudio.creature.LinkConfigurationWidget)1 LinkSliderWidget (com.neuronrobotics.bowlerstudio.creature.LinkSliderWidget)1 FileChangeWatcher (com.neuronrobotics.bowlerstudio.util.FileChangeWatcher)1 LinkConfiguration (com.neuronrobotics.sdk.addons.kinematics.LinkConfiguration)1 BowlerAbstractDevice (com.neuronrobotics.sdk.common.BowlerAbstractDevice)1 IDeviceConnectionEventListener (com.neuronrobotics.sdk.common.IDeviceConnectionEventListener)1 IFileChangeListener (com.neuronrobotics.sdk.util.IFileChangeListener)1 File (java.io.File)1 WatchEvent (java.nio.file.WatchEvent)1 FXMLLoader (javafx.fxml.FXMLLoader)1 Group (javafx.scene.Group)1 Scene (javafx.scene.Scene)1