diff --git a/JCSG b/JCSG index f6d3ef64..ab0a9453 160000 --- a/JCSG +++ b/JCSG @@ -1 +1 @@ -Subproject commit f6d3ef6486a6f3826547773c73967a7056e38068 +Subproject commit ab0a9453e8086780072c81551b4834756046038c diff --git a/src/main/java/com/neuronrobotics/bowlerkernel/Bezier3d/BezierEditor.java b/src/main/java/com/neuronrobotics/bowlerkernel/Bezier3d/BezierEditor.java index 60c53ce8..0a9f5a13 100644 --- a/src/main/java/com/neuronrobotics/bowlerkernel/Bezier3d/BezierEditor.java +++ b/src/main/java/com/neuronrobotics/bowlerkernel/Bezier3d/BezierEditor.java @@ -192,10 +192,17 @@ public void update() { ArrayList transforms = transforms(); for (int i = 0; i < getNumParts(); i++) { TransformNR nr = TransformFactory.csgToNR(transforms.get(i)); - Affine partsGetGetManipulator = getPartsInternal().get(i).getManipulator(); - BowlerKernel.runLater(() -> { - TransformFactory.nrToAffine(nr, partsGetGetManipulator); - }); + Affine partsGetGetManipulator; + try { + partsGetGetManipulator = getPartsInternal().get(i).getManipulator(); + BowlerKernel.runLater(() -> { + TransformFactory.nrToAffine(nr, partsGetGetManipulator); + }); + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } updateLines(start, cp1Manip, cp1Line, cp1LinePose); diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/creature/LimbOption.java b/src/main/java/com/neuronrobotics/bowlerstudio/creature/LimbOption.java index ca0b58d9..43eed73d 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/creature/LimbOption.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/creature/LimbOption.java @@ -38,6 +38,7 @@ import eu.mihosoft.vrl.v3d.CSG; import eu.mihosoft.vrl.v3d.FileUtil; +import eu.mihosoft.vrl.v3d.MissingManipulatorException; import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance; import javafx.embed.swing.SwingFXUtils; @@ -65,13 +66,14 @@ public class LimbOption { private Image image; public DHParameterKinematics getLimb(CSGDatabaseInstance db,String uniqueName) throws Exception { - String xmlContent = ScriptingEngine.codeFromGit(url, file)[0]; + String xmlContent = ScriptingEngine.codeFromGit(getUrl(), getSourceFile())[0]; if (!composite) { DHParameterKinematics newLimb = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8")); newLimb.setScriptingName(uniqueName); + MobileBaseLoader.setDefaultDhParameterKinematics(db, newLimb); return newLimb; } else { - MobileBase base = RobotHelper.fileToRobot(db,url, file); + MobileBase base = RobotHelper.fileToRobot(db,getUrl(), getSourceFile()); DHParameterKinematics newLimb = base.getAllDHChains().get(0); newLimb.setScriptingName(uniqueName); return newLimb; @@ -96,7 +98,7 @@ public static ArrayList getOptions() @Override public String toString() { - return getType() + " " + getName() + " " + url + "/" + file + "\n\tConsumes:" + getConsumes() + "\n\tProvides:" + getProvides(); + return getType() + " " + getName() + " " + getUrl() + "/" + getSourceFile() + "\n\tConsumes:" + getConsumes() + "\n\tProvides:" + getProvides(); } public ControllerFeatures getConsumes() { @@ -145,26 +147,30 @@ public void build(CaDoodleFile f) throws IOException { f.getCsgDBinstance().delete(s); } } - BowlerKernel.runLater(() -> { - image = ThumbnailImage.get(f.getCsgDBinstance(),so); - }); - while(image==null) { + if(f.getImageEngine()!=null) { + BowlerKernel.runLater(() -> { + image = f.getImageEngine().get(f.getCsgDBinstance(),so); + }); + long start =System.currentTimeMillis(); + + while(image==null && (System.currentTimeMillis()-start<250)) { + try { + Thread.sleep(20); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + com.neuronrobotics.sdk.common.Log.error(e); + } + } try { - Thread.sleep(20); - } catch (InterruptedException e) { - // TODO Auto-generated catch block + BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null); + ImageIO.write(bufferedImage, "png", imageFile); + System.err.println("Thumbnail saved successfully to " + imageFile.getAbsolutePath()); + } catch (Exception e) { + // com.neuronrobotics.sdk.common.Log.error("Error saving image: " + + // e.getMessage()); com.neuronrobotics.sdk.common.Log.error(e); } } - try { - BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null); - ImageIO.write(bufferedImage, "png", imageFile); - System.err.println("Thumbnail saved successfully to " + imageFile.getAbsolutePath()); - } catch (Exception e) { - // com.neuronrobotics.sdk.common.Log.error("Error saving image: " + - // e.getMessage()); - com.neuronrobotics.sdk.common.Log.error(e); - } indicator = get(so.get(0)); if (so.size() > 1) { for(int i=1;i controllers = new ArrayList(); - ArrayList limbs = new ArrayList(); - ArrayList mods = new ArrayList(); +// ArrayList controllers = new ArrayList(); +// ArrayList limbs = new ArrayList(); +// ArrayList mods = new ArrayList(); + ArrayList operations = new ArrayList(); private MobileBase mobileBase; private String gitURL; private String xmlName = null; @@ -43,18 +36,18 @@ public class MobileBaseBuilder { // Channel management private Map> deviceChannelMap = new HashMap<>(); private CSGDatabaseInstance db; + private String name; // Constructor for creating a new MobileBase - public MobileBaseBuilder(CSGDatabaseInstance db,String gitURL, String name) { - this.db=db; + public MobileBaseBuilder(CSGDatabaseInstance db, String gitURL, String name) { + this.db = db; this.gitURL = gitURL; - this.mobileBase = new MobileBase(); - this.mobileBase.setScriptingName(name); - initializeChannelMap(); + this.name = name; + clear(null); } // Constructor for extending an existing MobileBase - public MobileBaseBuilder(CSGDatabaseInstance db,MobileBase existingBase) { + public MobileBaseBuilder(CSGDatabaseInstance db, MobileBase existingBase) { this.db = db; this.gitURL = existingBase.getGitSelfSource()[0]; this.mobileBase = existingBase; @@ -233,6 +226,8 @@ public MobileBaseBuilder addDefaultLeg(String legName) { "https://github.com/CommonWealthRobotics/BowlerStudioExampleRobots.git", "defaultleg.xml")[0]; DHParameterKinematics newLeg = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8")); newLeg.setScriptingName(legName); + MobileBaseLoader.setDefaultDhParameterKinematics(db, newLeg); + return addLeg(newLeg); } catch (Exception e) { Log.error("Failed to add default leg: " + e.getMessage()); @@ -255,6 +250,8 @@ public MobileBaseBuilder addDefaultArm(String armName) { "https://github.com/CommonWealthRobotics/BowlerStudioExampleRobots.git", "defaultarm.xml")[0]; DHParameterKinematics newArm = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8")); newArm.setScriptingName(armName); + MobileBaseLoader.setDefaultDhParameterKinematics(db, newArm); + return addArm(newArm); } catch (Exception e) { Log.error("Failed to add default arm: " + e.getMessage()); @@ -278,6 +275,8 @@ public MobileBaseBuilder addDefaultSteerableWheel(String wheelName) { DHParameterKinematics newWheel = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8")); newWheel.setScriptingName(wheelName); + MobileBaseLoader.setDefaultDhParameterKinematics(db, newWheel); + return addSteerableWheel(newWheel); } catch (Exception e) { Log.error("Failed to add default steerable wheel: " + e.getMessage()); @@ -293,11 +292,12 @@ public MobileBaseBuilder addFixedWheel(DHParameterKinematics wheel) { return this; } - public MobileBaseBuilder addFixedWheelFromOptions(CSGDatabaseInstance db,String wheelType) { + public MobileBaseBuilder addFixedWheelFromOptions(CSGDatabaseInstance db, String wheelType) { try { @SuppressWarnings("unchecked") HashMap> options = (HashMap>) ScriptingEngine - .gitScriptRun(CSGDatabase.getInstance(),"https://github.com/CommonWealthRobotics/BowlerStudioExampleRobots.git", + .gitScriptRun(CSGDatabase.getInstance(), + "https://github.com/CommonWealthRobotics/BowlerStudioExampleRobots.git", "wheelOptions.json"); if (options.containsKey(wheelType)) { @@ -308,9 +308,11 @@ public MobileBaseBuilder addFixedWheelFromOptions(CSGDatabaseInstance db,String values.get("scriptFile").toString())[0]; DHParameterKinematics newWheel = new DHParameterKinematics(null, IOUtils.toInputStream(xmlContent, "UTF-8")); + MobileBaseLoader.setDefaultDhParameterKinematics(db, newWheel); + return addFixedWheel(newWheel); } else { - MobileBase base = RobotHelper.fileToRobot(db,values.get("scriptGit").toString(), + MobileBase base = RobotHelper.fileToRobot(db, values.get("scriptGit").toString(), values.get("scriptFile").toString()); DHParameterKinematics newWheel = base.getDrivable().get(0); return addFixedWheel(newWheel); @@ -385,6 +387,7 @@ private DHParameterKinematics copyDHParameterKinematics(DHParameterKinematics so if (source.getGitDhEngine() != null) { copy.setGitDhEngine(copyGitFile(source.getGitDhEngine(), gitURL)); } + MobileBaseLoader.setDefaultDhParameterKinematics(db, copy); return copy; } @@ -400,111 +403,139 @@ public File getFile() throws Exception { public MobileBase build(CSGDatabaseInstance db) throws Exception { if (!mobileBase.isAvailable()) mobileBase.connect(); - this.db=db; + this.db = db; String filename = (xmlName != null) ? xmlName : mobileBase.getScriptingName(); mobileBase.setGitSelfSource(new String[] { gitURL, filename }); - for (int i = 0; i < controllers.size(); i++) { - AddRobotController con = controllers.get(i); - for (VitaminLocation l : con.getVitamins(con.getName() + "_" + i)) { - try { - if (!mobileBase.hasVitamin(l)) - mobileBase.addVitamin(l); - } catch (Exception ex) { - com.neuronrobotics.sdk.common.Log.error(ex);; + ArrayList toRemove = new ArrayList(); + for (int i = 0; i < operations.size(); i++) { + CaDoodleOperation op = operations.get(i); + if (AddRobotController.class.isInstance(op)) { + AddRobotController con = (AddRobotController) op; + for (VitaminLocation l : con.getVitamins(con.getName() + "_" + i)) { + try { + if (!mobileBase.hasVitamin(l)) + mobileBase.addVitamin(l); + } catch (Exception ex) { + com.neuronrobotics.sdk.common.Log.error(ex); + + } } } - } - for (int i = 0; i < limbs.size(); i++) { - AddRobotLimb limb = limbs.get(i); - if (mobileBase.getLimbByName(limb.getName()) == null) { - TransformNR location = limb.getLocation(); - DHParameterKinematics kin = limb.getLimb().getLimb(db,limb.getName()); - kin.setRobotToFiducialTransform(location.copy()); - // TODO add the channel mapping here - kin.connect(); - kin.zero(); - switch (limb.getLimb().getType()) { - case arm: - case flap: - case hand: - case head: - mobileBase.getAppendages().add(kin); - break; - case leg: - mobileBase.getLegs().add(kin); - break; - case steerable: - mobileBase.getSteerable().add(kin); - break; - case wheel: - mobileBase.getFixed().add(kin); - break; - default: - throw new RuntimeException("Unknown limb type in builder! " + limb.getLimb().getType()); + if (AddRobotLimb.class.isInstance(op)) { + AddRobotLimb limb = (AddRobotLimb) op; + if (mobileBase.getLimbByName(limb.getName()) == null) { + TransformNR location = limb.getLocation(); + DHParameterKinematics kin = limb.getLimb().getLimb(db, limb.getName()); + TransformNR existing = kin.getRobotToFiducialTransform(); + kin.setRobotToFiducialTransform(location.copy().times(existing)); + // TODO add the channel mapping here + kin.connect(); + kin.zero(); + limb.setKinematics(kin); + switch (limb.getLimb().getType()) { + case arm: + case flap: + case hand: + case head: + mobileBase.getAppendages().add(kin); + break; + case leg: + mobileBase.getLegs().add(kin); + break; + case steerable: + mobileBase.getSteerable().add(kin); + break; + case wheel: + mobileBase.getFixed().add(kin); + break; + default: + throw new RuntimeException("Unknown limb type in builder! " + limb.getLimb().getType()); + } } } - } - ArrayList toRemove = new ArrayList(); - for (int i = 0; i < mods.size(); i++) { - ModifyLimb mod = mods.get(i); - DHParameterKinematics kin = mod.getLimb(); - if (kin == null) - continue; - - TransformNR base = mod.getBase(); - if (base != null) { - //com.neuronrobotics.sdk.common.Log.debug("Base set to " + base); - kin.setRobotToFiducialTransform(base); - } - if (mod.getTip() != null) { - try { - kin.setDesiredTaskSpaceTransform(mod.getTip(), 0); - }catch(Exception ex) { - com.neuronrobotics.sdk.common.Log.error(ex);; - toRemove.add(mod); + if (ModifyLimb.class.isInstance(op)) { + ModifyLimb mod = (ModifyLimb) op; + DHParameterKinematics kin = mod.getLimb(); + if (kin == null) + continue; + + TransformNR base = mod.getBase(); + if (base != null) { + // com.neuronrobotics.sdk.common.Log.debug("Base set to " + base); + kin.setRobotToFiducialTransform(base); + } + if (mod.getTip() != null) { + try { + kin.setDesiredTaskSpaceTransform(mod.getTip(), 0); + } catch (Exception ex) { + // com.neuronrobotics.sdk.common.Log.error(ex); + ; + // toRemove.add(mod); + } } } } - mods.removeAll(toRemove); + operations.removeAll(toRemove); getCadManager().render(); + // Push to git - //ScriptingEngine.pushCodeToGit(gitURL, null, filename, mobileBase.getXml(), "Builder Write XML", true); + ScriptingEngine.pushCodeToGit(gitURL, null, filename, mobileBase.getXml(), "Builder Write XML", true); return mobileBase; } public void addController(AddRobotController controller) { - if (!controllers.contains(controller)) - getControllers().add(controller); + if (!operations.contains(controller)) + operations.add(controller); } public void removeController(AddRobotController controller) { - if (controllers.contains(controller)) - getControllers().remove(controller); - for (int i = 0; i < controllers.size(); i++) { - AddRobotController con = controllers.get(i); - for (VitaminLocation l : con.getVitamins(con.getName() + "_" + i)) { - try { - mobileBase.removeVitamin(l); - } catch (Exception ex) { - com.neuronrobotics.sdk.common.Log.error(ex);; + if (operations.contains(controller)) { + for (int i = 0; i < operations.size(); i++) { + CaDoodleOperation op = operations.get(i); + if (AddRobotController.class.isInstance(op)) { + AddRobotController con = (AddRobotController) op; + for (VitaminLocation l : con.getVitamins(con.getName() + "_" + i)) { + try { + mobileBase.removeVitamin(l); + } catch (Exception ex) { + com.neuronrobotics.sdk.common.Log.error(ex); + ; + } + } } } + operations.remove(controller); } } public ArrayList getControllers() { + ArrayList controllers = new ArrayList(); + for (int i = 0; i < operations.size(); i++) { + CaDoodleOperation op = operations.get(i); + if (AddRobotController.class.isInstance(op)) { + AddRobotController c = (AddRobotController) op; + controllers.add(c); + } + } return controllers; } public ControllerFeatures getCapibilities() { ControllerFeatures test = new ControllerFeatures(); - for (AddRobotController c : controllers) { - test.add(c.getController().getProvides()); - test.subtract(c.getController().getConsumes()); - } - for (AddRobotLimb c : limbs) { - test.add(c.getLimb().getProvides()); - test.subtract(c.getLimb().getConsumes()); + for (int i = 0; i < operations.size(); i++) { + CaDoodleOperation op = operations.get(i); + if (AddRobotController.class.isInstance(op)) { + AddRobotController c = (AddRobotController) op; + + test.add(c.getController().getProvides()); + test.subtract(c.getController().getConsumes()); + } + if (AddRobotLimb.class.isInstance(op)) { + AddRobotLimb c = (AddRobotLimb) op; + + test.add(c.getLimb().getProvides()); + test.subtract(c.getLimb().getConsumes()); + } } return test; } @@ -518,8 +549,8 @@ public void addLimb(AddRobotLimb controller, boolean forceLoad) { if (!checkOptionSupported(consumes) && !forceLoad) { throw new RuntimeException("Robot doesnt have enough resources to support " + controller.getLimb()); } - if (!getLimmbs().contains(controller)) - getLimmbs().add(controller); + if (!operations.contains(controller)) + operations.add(controller); } public boolean checkOptionSupported(LimbOption consumes) { @@ -527,30 +558,91 @@ public boolean checkOptionSupported(LimbOption consumes) { } public void addModification(ModifyLimb modifyLimb) { - if (!mods.contains(modifyLimb)) - mods.add(modifyLimb); + if (!operations.contains(modifyLimb)) + operations.add(modifyLimb); } public void removeModification(ModifyLimb modifyLimb) { - if (mods.contains(modifyLimb)) - mods.remove(modifyLimb); + if (operations.contains(modifyLimb)) + operations.remove(modifyLimb); } public void removeLimb(AddRobotLimb controller) { - if (getLimmbs().contains(controller)) - getLimmbs().remove(controller); + if (operations.contains(controller)) + operations.remove(controller); mobileBase.deleteLimbByName(controller.getName()); } - public ArrayList getLimmbs() { + public ArrayList getLimbs() { + ArrayList limbs = new ArrayList(); + for (int i = 0; i < operations.size(); i++) { + CaDoodleOperation op = operations.get(i); + if (AddRobotLimb.class.isInstance(op)) { + AddRobotLimb c = (AddRobotLimb) op; + limbs.add(c); + } + } return limbs; + } public MobileBaseCadManager getCadManager() { - MobileBaseCadManager mobileBaseCadManager = MobileBaseCadManager.get(db,mobileBase); + MobileBaseCadManager mobileBaseCadManager = MobileBaseCadManager.get(db, mobileBase); mobileBaseCadManager.setAutoRegen(false); mobileBaseCadManager.setConfigurationViewerMode(false); return mobileBaseCadManager; } + public void clear(CaDoodleOperation from) { + if (from == null) { + if (mobileBase != null) { + mobileBase.disconnect(); + try { + MobileBaseCadManager cm = MobileBaseCadManager.get(db, mobileBase); + cm.clear(); + } catch (Exception ex) { + Log.error(ex); + } + } + this.mobileBase = new MobileBase(); + operations.clear(); + } else { + while (operations.size() > 0) { + + CaDoodleOperation op =operations.remove(operations.size() - 1); + if (AddRobotLimb.class.isInstance(op)) { + AddRobotLimb c = (AddRobotLimb) op; + DHParameterKinematics kin = c.getKinematics(); + switch (c.getLimb().getType()) { + case arm: + case flap: + case hand: + case head: + mobileBase.getAppendages().remove(kin); + break; + case leg: + mobileBase.getLegs().remove(kin); + break; + case steerable: + mobileBase.getSteerable().remove(kin); + break; + case wheel: + mobileBase.getFixed().remove(kin); + break; + default: + throw new RuntimeException("Unknown limb type in builder! " + c.getLimb().getType()); + } + } + if (from == op) { + break; + } + } + } + this.mobileBase.setScriptingName(name); + initializeChannelMap(); + if(MobileBaseCadManager.exists(mobileBase)) { + MobileBaseCadManager.get(db, mobileBase).clear(); + } + } + } \ No newline at end of file diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseCadManager.java b/src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseCadManager.java index 90d72fcc..de600969 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseCadManager.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseCadManager.java @@ -438,7 +438,7 @@ public Vector3d computeLowestPoint() { return lowest; } - protected void clear() { + public void clear() { // Cad generator cadScriptCache.clear(); // clear the csgs from the list @@ -1570,9 +1570,11 @@ public void setAllCad(ArrayList allCad) { this.allCad.clear(); this.allCad = allCad; } - + public static boolean exists(MobileBase device) { + return cadmap.get(device) != null; + } public static MobileBaseCadManager get(CSGDatabaseInstance csgDatabaseInstance,MobileBase device, IMobileBaseUI ui) { - if (cadmap.get(device) == null) { + if (!exists(device)) { // new RuntimeException("No Mobile Base Cad Manager UI // specified").printStackTrace(); MobileBaseCadManager mbcm = new MobileBaseCadManager(csgDatabaseInstance,device, ui); diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseLoader.java b/src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseLoader.java index 3f2119dc..823b6140 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseLoader.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/creature/MobileBaseLoader.java @@ -49,17 +49,17 @@ private MobileBaseLoader(CSGDatabaseInstance dbIn,MobileBase base) { public void setGitDhEngine(String gitsId, String file, DHParameterKinematics dh) { dh.setGitDhEngine(new String[] { gitsId, file }); - setDefaultDhParameterKinematics(dh); + setDefaultDhParameterKinematics(db,dh); } - public File setDefaultDhParameterKinematics(DHParameterKinematics device) { + public static File setDefaultDhParameterKinematics(CSGDatabaseInstance db,DHParameterKinematics device) { File code = null; try { String remoteURI = device.getGitDhEngine()[0]; String fileInRepo = device.getGitDhEngine()[1]; code = ScriptingEngine.fileFromGit(remoteURI, fileInRepo); - DhInverseSolver defaultDHSolver = (DhInverseSolver) ScriptingEngine.inlineFileScriptRun(getDb(),code, null); + DhInverseSolver defaultDHSolver = (DhInverseSolver) ScriptingEngine.inlineFileScriptRun(db,code, null); File c = code; FileWatchDeviceWrapper.watch(device, code,new IFileChangeListener() { @@ -75,10 +75,10 @@ public void onFileChange(File fileThatChanged, WatchEvent event) { try { com.neuronrobotics.sdk.common.Log.error("D-H Solver changed, updating " + device.getScriptingName()); - DhInverseSolver d = (DhInverseSolver) ScriptingEngine.inlineFileScriptRun(getDb(),c, null); + DhInverseSolver d = (DhInverseSolver) ScriptingEngine.inlineFileScriptRun(db,c, null); device.setInverseSolver(d); } catch (Exception ex) { - MobileBaseCadManager.get(db,base).getUi().highlightException(c, ex); + Log.error(ex); } } }); @@ -86,7 +86,7 @@ public void onFileChange(File fileThatChanged, WatchEvent event) { device.setInverseSolver(defaultDHSolver); return code; } catch (Exception e1) { - MobileBaseCadManager.get(db,base).getUi().highlightException(code, e1); + Log.error(e1); } return null; @@ -97,7 +97,7 @@ public void setDefaultWalkingEngine(MobileBase device) { setGitWalkingEngine(device.getGitWalkingEngine()[0], device.getGitWalkingEngine()[1], device); } for (DHParameterKinematics dh : device.getAllDHChains()) { - setDefaultDhParameterKinematics(dh); + setDefaultDhParameterKinematics(db,dh); } } diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/creature/ThumbnailImage.java b/src/main/java/com/neuronrobotics/bowlerstudio/creature/ThumbnailImage.java index 37aa0d42..1f51bccc 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/creature/ThumbnailImage.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/creature/ThumbnailImage.java @@ -9,6 +9,7 @@ import eu.mihosoft.vrl.v3d.Bounds; import eu.mihosoft.vrl.v3d.CSG; +import eu.mihosoft.vrl.v3d.MissingManipulatorException; import eu.mihosoft.vrl.v3d.Vector3d; import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance; @@ -63,12 +64,18 @@ public static Bounds getSellectedBounds(List incoming) { return new Bounds(min, max); } - public static WritableImage get(CSGDatabaseInstance instance,List c) { + public WritableImage get(CSGDatabaseInstance instance,List c) { ArrayList csgList=new ArrayList() ; for(CSG cs:c) { - if(cs.getManipulator()!=null) { - TransformNR nr = TransformFactory.affineToNr(cs.getManipulator()); - csgList.add(cs.transformed(TransformFactory.nrToCSG(nr)).syncProperties(instance,cs)); + if(cs.hasManipulator()) { + TransformNR nr; + try { + nr = TransformFactory.affineToNr(cs.getManipulator()); + csgList.add(cs.transformed(TransformFactory.nrToCSG(nr)).syncProperties(instance,cs)); + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } }else csgList.add(cs); } diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/physics/CSGPhysicsManager.java b/src/main/java/com/neuronrobotics/bowlerstudio/physics/CSGPhysicsManager.java index ec3de2d0..c5360421 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/physics/CSGPhysicsManager.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/physics/CSGPhysicsManager.java @@ -20,6 +20,7 @@ import eu.mihosoft.vrl.v3d.CSG; import eu.mihosoft.vrl.v3d.Cube; +import eu.mihosoft.vrl.v3d.MissingManipulatorException; import eu.mihosoft.vrl.v3d.Polygon; import eu.mihosoft.vrl.v3d.Sphere; import eu.mihosoft.vrl.v3d.Vertex; @@ -43,8 +44,15 @@ public CSGPhysicsManager(List baseCSG, Transform pose, double mass, boolean ObjectArrayList arg0 = new ObjectArrayList<>(); for (int i = 0; i < baseCSG.size(); i++) { - CSG back = loadCSGToPoints(baseCSG.get(i), adjustCenter, pose, arg0); - back.setManipulator(baseCSG.get(i).getManipulator()); + CSG csg = baseCSG.get(i); + CSG back = loadCSGToPoints(csg, adjustCenter, pose, arg0); + try { + if(csg.hasManipulator()) + back.setManipulator(csg.getManipulator()); + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } baseCSG.set(i, back); } CollisionShape fallShape = new com.bulletphysics.collision.shapes.ConvexHullShape(arg0); diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/physics/MobileBasePhysicsManager.java b/src/main/java/com/neuronrobotics/bowlerstudio/physics/MobileBasePhysicsManager.java index b79934ab..a8ec06dd 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/physics/MobileBasePhysicsManager.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/physics/MobileBasePhysicsManager.java @@ -31,6 +31,7 @@ import Jama.Matrix; import eu.mihosoft.vrl.v3d.CSG; +import eu.mihosoft.vrl.v3d.MissingManipulatorException; import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance; //import eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil; //import eu.mihosoft.vvecmath.Vector3d; @@ -127,7 +128,14 @@ public MobileBasePhysicsManager(CSGDatabaseInstance db,MobileBase base, ArrayLis BowlerKernel.runLater(new Runnable() { @Override public void run() { - TransformFactory.bulletToAffine(baseCad.get(0).getManipulator(), start); + try { + CSG csg = baseCad.get(0); + if(csg.hasManipulator()) + TransformFactory.bulletToAffine(csg.getManipulator(), start); + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } }); CSG collisionBod; diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/physics/MuJoCoPhysicsManager.java b/src/main/java/com/neuronrobotics/bowlerstudio/physics/MuJoCoPhysicsManager.java index 4fe0611f..a3e1bf65 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/physics/MuJoCoPhysicsManager.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/physics/MuJoCoPhysicsManager.java @@ -46,6 +46,7 @@ import eu.mihosoft.vrl.v3d.CSG; import eu.mihosoft.vrl.v3d.Cube; +import eu.mihosoft.vrl.v3d.MissingManipulatorException; import eu.mihosoft.vrl.v3d.Parabola; import eu.mihosoft.vrl.v3d.Polygon; import eu.mihosoft.vrl.v3d.RoundedCylinder; @@ -115,8 +116,8 @@ public void sleep(long ms, int ns) throws InterruptedException { } } - public MuJoCoPhysicsManager(CSGDatabaseInstance db,String name, List bases, List freeObjects, List fixedObjects, - File workingDir) throws IOException, JAXBException { + public MuJoCoPhysicsManager(CSGDatabaseInstance db, String name, List bases, List freeObjects, + List fixedObjects, File workingDir) throws IOException, JAXBException { this.db = db; this.name = name.trim(); if (!(name.length() > 0)) @@ -150,7 +151,8 @@ public void controlStep(MuJoCoModelManager manager) { double target = Math.toRadians(link.getCurrentEngineeringUnits()) * gearRatios.get(link); // double error = target-positions.get(s); // double effort = error * kp; - // com.neuronrobotics.sdk.common.Log.error("Actuator "+s+" position "+positions.get(s)+" effort + // com.neuronrobotics.sdk.common.Log.error("Actuator "+s+" position + // "+positions.get(s)+" effort // "+effort); setEfforts.put(s, target); } @@ -242,7 +244,7 @@ public void generateNewModel(CSGDatabaseInstance db) throws IOException, JAXBExc if (bases.size() > 0) { actuators = builder.addActuator(); for (MobileBase cat : bases) { - loadBase(db,cat); + loadBase(db, cat); } } if (freeObjects != null) { @@ -344,7 +346,13 @@ private void step() { ArrayList mapNameToCSGParts = getMapNameToCSGParts(name); for (int i = 0; i < mapNameToCSGParts.size(); i++) { CSG bodyBall = mapNameToCSGParts.get(i); - TransformFactory.nrToAffine(local, bodyBall.getManipulator()); + if (bodyBall.hasManipulator()) + try { + TransformFactory.nrToAffine(local, bodyBall.getManipulator()); + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } poss.clear(); @@ -391,16 +399,15 @@ public void initializeModel(String name) { if (fixedObjects == null) { fixedObjects = new ArrayList<>(); } - boolean hasFloor=false; - for(CSG item:fixedObjects) { - if(item.getMaxZ()>0) + boolean hasFloor = false; + for (CSG item : fixedObjects) { + if (item.getMaxZ() > 0) continue; - hasFloor=true; + hasFloor = true; } - if(!hasFloor) + if (!hasFloor) fixedObjects.add(floor); - } public int getIterations() { @@ -422,17 +429,17 @@ public boolean checkLinkPhysics(MobileBaseCadManager cadMan, LinkConfiguration c } public double computeLowestPoint(MobileBase cat) { - MobileBaseCadManager cadMan = MobileBaseCadManager.get(db,cat); + MobileBaseCadManager cadMan = MobileBaseCadManager.get(db, cat); return cadMan.computeLowestPoint().z; } - public void loadBase(CSGDatabaseInstance db,MobileBase cat) throws IOException { - loadBase(db,cat, null, new TransformNR()); + public void loadBase(CSGDatabaseInstance db, MobileBase cat) throws IOException { + loadBase(db, cat, null, new TransformNR()); } - public void loadBase(CSGDatabaseInstance db,MobileBase cat, org.mujoco.xml.BodyarchType.Builder linkBody2, TransformNR offsetGlobal) - throws IOException { + public void loadBase(CSGDatabaseInstance db, MobileBase cat, org.mujoco.xml.BodyarchType.Builder linkBody2, + TransformNR offsetGlobal) throws IOException { if (contacts == null) contacts = builder.addContact(); boolean freeBase = cat.getSteerable().size() > 0 || cat.getDrivable().size() > 0 || cat.getLegs().size() > 0; @@ -440,8 +447,8 @@ public void loadBase(CSGDatabaseInstance db,MobileBase cat, org.mujoco.xml.Bodya // println "\n\nLowest point "+lowestPoint+" \n\n"; String bodyName = getMujocoName(cat); - MobileBaseCadManager cadMan = MobileBaseCadManager.get(db,cat); - loadCadForMobileBase(db,cadMan); + MobileBaseCadManager cadMan = MobileBaseCadManager.get(db, cat); + loadCadForMobileBase(db, cadMan); double lowestPoint = (-computeLowestPoint(cat)) / 1000.0; int bodyParts = 0; @@ -483,20 +490,30 @@ public void loadBase(CSGDatabaseInstance db,MobileBase cat, org.mujoco.xml.Bodya TransformNR center = cat.getCenterOfMassFromCentroid(); boolean foundPart = false; for (DHParameterKinematics k : cat.getAllDHChains()) { - if (k.getRootListener() == part.getManipulator()) { - TransformNR fiducial = k.getRobotToFiducialTransform(); - TransformNR kfed = fiducial; - // center=kfed.times(center); - // center=kfed.times(center.inverse()); - center = new TransformNR(); - limbBase.put(part, kfed); - foundPart = true; - break; + try { + if (k.getRootListener() == part.getManipulator()) { + TransformNR fiducial = k.getRobotToFiducialTransform(); + TransformNR kfed = fiducial; + // center=kfed.times(center); + // center=kfed.times(center.inverse()); + center = new TransformNR(); + limbBase.put(part, kfed); + foundPart = true; + break; + } + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } } if (!foundPart) { - if (part.getManipulator() != cat.getRootListener()) - continue; + try { + if (part.getManipulator() != cat.getRootListener()) + continue; + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } limbBase.put(part, new TransformNR()); } baseParts.put(part, center.copy()); @@ -520,7 +537,7 @@ public void loadBase(CSGDatabaseInstance db,MobileBase cat, org.mujoco.xml.Bodya TransformNR offset = limbBase.get(part); double mass = cat.getMassKg() / numPartsWithoutMass; bodyParts++; - String nameOfCSG = bodyName + "_CSG_" + bodyParts+"_"+part.getName(); + String nameOfCSG = bodyName + "_CSG_" + bodyParts + "_" + part.getName(); CSG transformed = part.transformed(TransformFactory.nrToCSG(center.inverse().times(offset))); CSG hull; @@ -543,13 +560,12 @@ public void loadBase(CSGDatabaseInstance db,MobileBase cat, org.mujoco.xml.Bodya + center.getRotation().getRotationMatrix2QuaturnionY() + " " + center.getRotation().getRotationMatrix2QuaturnionZ(); geomToSourceCSG.put(geom, part); - geom.withPos(centerString) - .withQuat(quat); - if(part.hasMassSet()) { + geom.withPos(centerString).withQuat(quat); + if (part.hasMassSet()) { double val = part.getMassKG(mass) * KgtoMujocoMass; geom.withMass(BigDecimal.valueOf(val)); } else { - com.neuronrobotics.sdk.common.Log.error("\nUsing density for "+part.getName()); + com.neuronrobotics.sdk.common.Log.error("\nUsing density for " + part.getName()); } } @@ -592,7 +608,7 @@ public void loadBase(CSGDatabaseInstance db,MobileBase cat, org.mujoco.xml.Bodya linkBody = loadLink(cat, k, i, parts, linkBody, linkToBulder); MobileBase follower = k.getFollowerMobileBase(link); if (follower != null) { - loadBase(db,follower, linkBody, k.getDHStep(i)); + loadBase(db, follower, linkBody, k.getDHStep(i)); } } for (String affineNameMapGet : geomToCSGMap.keySet()) { @@ -604,20 +620,20 @@ public void loadBase(CSGDatabaseInstance db,MobileBase cat, org.mujoco.xml.Bodya for (org.mujoco.xml.body.GeomType.Builder geom : geoms) { // println "Mass of "+affineNameMapGet+" is "+mass CSG csg = geomToSourceCSG.get(geom); - if(!csg.getStorage().getValue("massKg").isPresent()) { + if (!csg.getStorage().getValue("massKg").isPresent()) { numPartsWithoutMassLink++; } } - if(numPartsWithoutMassLink==0) - numPartsWithoutMassLink=1; + if (numPartsWithoutMassLink == 0) + numPartsWithoutMassLink = 1; for (org.mujoco.xml.body.GeomType.Builder geom : geoms) { // println "Mass of "+affineNameMapGet+" is "+mass CSG csg = geomToSourceCSG.get(geom); - if(csg.hasMassSet()) { - double val = csg.getMassKG(linkMass/numPartsWithoutMassLink) * KgtoMujocoMass; + if (csg.hasMassSet()) { + double val = csg.getMassKG(linkMass / numPartsWithoutMassLink) * KgtoMujocoMass; geom.withMass(BigDecimal.valueOf(val)); } else { - com.neuronrobotics.sdk.common.Log.error("\nUsing density for "+csg.getName()); + com.neuronrobotics.sdk.common.Log.error("\nUsing density for " + csg.getName()); } } } @@ -680,10 +696,10 @@ public org.mujoco.xml.BodyarchType.Builder loadLink(MobileBase cat, DHParamet .withRange(ctrlRange) // engineering units range .withRef(BigDecimal.valueOf(0)) // set the reference position on loading as the links 0 degrees value .withType(JointtypeType.HINGE) // hinge type - .withLimited(true) - .withFrictionloss(BigDecimal.valueOf(conf.isPassive()?0.0001:0.01))// experementally determined + .withLimited(true).withFrictionloss(BigDecimal.valueOf(conf.isPassive() ? 0.0001 : 0.01))// experementally + // determined - //.withDamping(BigDecimal.valueOf(0.000001)) + // .withDamping(BigDecimal.valueOf(0.000001)) // .withStiffness(BigDecimal.valueOf(1)) .withSolreflimit("4e-3 1").withSolimplimit(".95 .99 1e-3").withName(name); double forceKgCm = 3.5;// mg92b default @@ -717,18 +733,21 @@ public org.mujoco.xml.BodyarchType.Builder loadLink(MobileBase cat, DHParamet CSG part = cad.get(i); if (!checkForPhysics(part)) continue; - Affine cGetManipulator = part.getManipulator(); - if (cGetManipulator != null) { - String affineNameMapGet = affineNameMap.get(cGetManipulator); - if (affineNameMapGet != null) { - DHParameterKinematics k = l; - - AbstractLink myLink = mapNameToLink.get(affineNameMapGet); - - double myposition = link.getCurrentEngineeringUnits(); - TransformNR myStep = new TransformNR(k.getDhLink(myLink).DhStep(0)); - CSG transformed = part.transformed(TransformFactory.nrToCSG(myStep)); - CSG hull; + Affine cGetManipulator; + if (part.hasManipulator()) + try { + cGetManipulator = part.getManipulator(); + if (cGetManipulator != null) { + String affineNameMapGet = affineNameMap.get(cGetManipulator); + if (affineNameMapGet != null) { + DHParameterKinematics k = l; + + AbstractLink myLink = mapNameToLink.get(affineNameMapGet); + + double myposition = link.getCurrentEngineeringUnits(); + TransformNR myStep = new TransformNR(k.getDhLink(myLink).DhStep(0)); + CSG transformed = part.transformed(TransformFactory.nrToCSG(myStep)); + CSG hull; // if(cat.isWheel(myLink)) { // double height = part.getTotalZ(); // double radius =( part.getTotalY()+part.getTotalX())/4.0; @@ -742,53 +761,57 @@ public org.mujoco.xml.BodyarchType.Builder loadLink(MobileBase cat, DHParamet // .movez(transformed.getMinZ()) // ; // }else - try { - hull = transformed.hull(); - } catch (Exception ex) { - hull = transformed; - } - // if(myLink!=link) - // hull = part.hull(); - transformed.setManipulator(new Affine()); - String geomname = name + "_" + i+"_"+part.getName(); - - try { - putCSGInAssets(geomname, hull, true); - org.mujoco.xml.body.GeomType.Builder geom = linkToBulderMap.get(myLink).addGeom(); - geomToSourceCSG.put(geom, part); - - ArrayList parts = getMapNameToCSGParts(affineNameMapGet); - if (geomToCSGMap.get(affineNameMapGet) == null) { - geomToCSGMap.put(affineNameMapGet, - new ArrayList>()); - } - geomToCSGMap.get(affineNameMapGet).add(geom); - parts.add(transformed); - if (cat.isWheel(myLink)) { - setWheelMeshToGeom(geomname, geom, part); - // default is 1 0.005 0.0001 - // println "Setting Wheel Friction for "+part.getName() - - geom.withFriction("2 0.001 0.00005"); - - } else { - setCSGMeshToGeom(geomname, geom); - - if (cat.isFoot(myLink)) { - // default is 1 0.005 0.0001 - // println "Setting Foot Friction for "+part.getName() - geom.withFriction("1.2 0.001 0.00005"); + try { + hull = transformed.hull(); + } catch (Exception ex) { + hull = transformed; + } + // if(myLink!=link) + // hull = part.hull(); + transformed.setManipulator(new Affine()); + String geomname = name + "_" + i + "_" + part.getName(); + + try { + putCSGInAssets(geomname, hull, true); + org.mujoco.xml.body.GeomType.Builder geom = linkToBulderMap.get(myLink).addGeom(); + geomToSourceCSG.put(geom, part); + + ArrayList parts = getMapNameToCSGParts(affineNameMapGet); + if (geomToCSGMap.get(affineNameMapGet) == null) { + geomToCSGMap.put(affineNameMapGet, + new ArrayList>()); + } + geomToCSGMap.get(affineNameMapGet).add(geom); + parts.add(transformed); + if (cat.isWheel(myLink)) { + setWheelMeshToGeom(geomname, geom, part); + // default is 1 0.005 0.0001 + // println "Setting Wheel Friction for "+part.getName() + + geom.withFriction("2 0.001 0.00005"); + + } else { + setCSGMeshToGeom(geomname, geom); + + if (cat.isFoot(myLink)) { + // default is 1 0.005 0.0001 + // println "Setting Foot Friction for "+part.getName() + geom.withFriction("1.2 0.001 0.00005"); + } + } + } catch (IOException e) { + // Auto-generated catch block + e.printStackTrace(); } + } else { + // println "ERROR! "+name+" for part "+part.getName()+" produced no matching + // affine" } - } catch (IOException e) { - // Auto-generated catch block - e.printStackTrace(); } - } else { - // println "ERROR! "+name+" for part "+part.getName()+" produced no matching - // affine" + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - } } return linkBody; } @@ -814,32 +837,32 @@ public void addFreePart(List partsIn) throws IOException { continue; ; // try { - CSG hull = part.moveToCenter(); - - Vector3d center = part.getCenter(); - - nameOfCSG = part.getName(); - if (nameOfCSG.length() == 0) { - nameOfCSG = "Part-" + (count); - } - nameOfCSG += "-" + count + "-" + "free"; - - if (nameOfBODY == null) { - nameOfBODY = nameOfCSG; - addBody.addFreejoint(); - setStartLocation(center, addBody); - centerGroup = center; - addBody.withName(nameOfBODY); - } - - hull = hull.move(center.minus(centerGroup)); - hull.setManipulator(new Affine()); - ArrayList parts = getMapNameToCSGParts(nameOfBODY); - putCSGInAssets(nameOfCSG, hull, true); - org.mujoco.xml.body.GeomType.Builder geom; - geom = addBody.addGeom().withMass(BigDecimal.valueOf(part.getMassKG(0.001))); - parts.add(hull); - setCSGMeshToGeom(nameOfCSG, geom); + CSG hull = part.moveToCenter(); + + Vector3d center = part.getCenter(); + + nameOfCSG = part.getName(); + if (nameOfCSG.length() == 0) { + nameOfCSG = "Part-" + (count); + } + nameOfCSG += "-" + count + "-" + "free"; + + if (nameOfBODY == null) { + nameOfBODY = nameOfCSG; + addBody.addFreejoint(); + setStartLocation(center, addBody); + centerGroup = center; + addBody.withName(nameOfBODY); + } + + hull = hull.move(center.minus(centerGroup)); + hull.setManipulator(new Affine()); + ArrayList parts = getMapNameToCSGParts(nameOfBODY); + putCSGInAssets(nameOfCSG, hull, true); + org.mujoco.xml.body.GeomType.Builder geom; + geom = addBody.addGeom().withMass(BigDecimal.valueOf(part.getMassKG(0.001))); + parts.add(hull); + setCSGMeshToGeom(nameOfCSG, geom); // }catch(Throwable t) { // t.printStackTrace(System.out); // } @@ -882,29 +905,21 @@ public ArrayList getMapNameToCSGParts(String nameOfCSG) { } public void setCSGMeshToGeom(String nameOfCSG, org.mujoco.xml.body.GeomType.Builder geom) { - geom - .withName(nameOfCSG) - .withType(GeomtypeType.MESH).withMesh(nameOfCSG) - .withCondim(getCondim()) - .withDensity(BigDecimal.valueOf(Density_OF_PLA / 2.0)) - .withMaterial(nameOfCSG) - ; + geom.withName(nameOfCSG).withType(GeomtypeType.MESH).withMesh(nameOfCSG).withCondim(getCondim()) + .withDensity(BigDecimal.valueOf(Density_OF_PLA / 2.0)).withMaterial(nameOfCSG); } public void setWheelMeshToGeom(String nameOfCSG, org.mujoco.xml.body.GeomType.Builder geom, CSG part) { String fromto = "0 0 " + part.getMinZ() / 1000.0 + " 0 0 " + part.getMaxZ() / 1000.0; - geom.withName(nameOfCSG) - .withType(GeomtypeType.MESH).withMesh(nameOfCSG) - .withCondim(getCondim()) - .withDensity(BigDecimal.valueOf(Density_OF_PLA / 2.0)) - .withMaterial(nameOfCSG) + geom.withName(nameOfCSG).withType(GeomtypeType.MESH).withMesh(nameOfCSG).withCondim(getCondim()) + .withDensity(BigDecimal.valueOf(Density_OF_PLA / 2.0)).withMaterial(nameOfCSG) // .withType(GeomtypeType.CYLINDER).withSize("" + part.getTotalX() / 2000.0) // .withFromto(fromto) // .withCondim(getCondim()) // .withDensity(BigDecimal.valueOf(Density_OF_PLA/2.0)) // .withMaterial(nameOfCSG) - - ; + + ; } public void setStartLocation(Vector3d center, org.mujoco.xml.BodyarchType.Builder addBody) { @@ -953,9 +968,9 @@ public void putCSGInAssets(String nameOfCSG, CSG hull, boolean isFree) throws IO // InputStream in=new ByteArrayInputStream(obj.getBytes(StandardCharsets.UTF_8)); // // ObjImporter importer = new ObjImporter(in); - + Files.write(Paths.get(tempFile.getAbsolutePath()), obj.getBytes()); - System.out.print(" " + (System.currentTimeMillis() - start+"\n")); + System.out.print(" " + (System.currentTimeMillis() - start + "\n")); } else { com.neuronrobotics.sdk.common.Log.error("Loading cache " + tempFile.getName()); } @@ -980,7 +995,7 @@ public String getMujocoName(MobileBase cat) { return cat.getScriptingName().trim() + "_base"; } - public void loadCadForMobileBase(CSGDatabaseInstance db,MobileBaseCadManager cadMan) { + public void loadCadForMobileBase(CSGDatabaseInstance db, MobileBaseCadManager cadMan) { cadMan.run(); if (!cadMan.isCADstarted() && cadMan.getProcesIndictor().get() < 0.1) { cadMan.generateCad(db); diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Align.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Align.java index 47a14e45..de707572 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Align.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Align.java @@ -12,27 +12,28 @@ import eu.mihosoft.vrl.v3d.Bounds; import eu.mihosoft.vrl.v3d.CSG; +import eu.mihosoft.vrl.v3d.MissingManipulatorException; import eu.mihosoft.vrl.v3d.Transform; import eu.mihosoft.vrl.v3d.Vector3d; import javafx.scene.transform.Affine; -public class Align extends CaDoodleOperation{ - @Expose (serialize = true, deserialize = true) +public class Align extends CaDoodleOperation { + @Expose(serialize = true, deserialize = true) private List names = new ArrayList(); - @Expose (serialize = true, deserialize = true) - public Alignment z=null; - @Expose (serialize = true, deserialize = true) - public Alignment y=null; - @Expose (serialize = true, deserialize = true) - public Alignment x=null; - @Expose (serialize = true, deserialize = true) - private TransformNR workplane=null; + @Expose(serialize = true, deserialize = true) + public Alignment z = null; + @Expose(serialize = true, deserialize = true) + public Alignment y = null; + @Expose(serialize = true, deserialize = true) + public Alignment x = null; + @Expose(serialize = true, deserialize = true) + private TransformNR workplane = null; @Deprecated - @Expose (serialize = true, deserialize = true) - public StoragbeBounds bounds=null; - @Expose (serialize = true, deserialize = true) + @Expose(serialize = true, deserialize = true) + public StoragbeBounds bounds = null; + @Expose(serialize = true, deserialize = true) private List boundNames = null; - + @Expose(serialize = true, deserialize = true) protected String name = null; @@ -46,16 +47,17 @@ public String getName() { public void setName(String name) { this.name = name; } + @Override public String getType() { return "Align"; } - + @Override - public String toString(){ - String string = getType()+" "+x+" "+y+" "+z; - for(String n:getNamesAddedInThisOperation()) { - string+=" "+n; + public String toString() { + String string = getType() + " " + x + " " + y + " " + z; + for (String n : getNamesAddedInThisOperation()) { + string += " " + n; } return string; } @@ -65,35 +67,35 @@ public List process(List incoming) { ArrayList back = new ArrayList(); back.addAll(incoming); - Bounds bounds2 =getBounds(incoming);// - - HashMap moves= new HashMap<>(); - HashMap objects = new HashMap(); - for(String name :names) { - for(CSG tmp:back) { - if(!tmp.getName().contentEquals(name)) + Bounds bounds2 = getBounds(incoming);// + + HashMap moves = new HashMap<>(); + HashMap objects = new HashMap(); + for (String name : names) { + for (CSG tmp : back) { + if (!tmp.getName().contentEquals(name)) continue; objects.put(name, tmp); CSG c = tmp.transformed(TransformFactory.nrToCSG(getWorkplane(tmp)).inverse()); TransformNR tf = performTransform(bounds2, c); - moves.put(c.getName(),tf); + moves.put(c.getName(), tf); } } - for(String name:moves.keySet()) { + for (String name : moves.keySet()) { TransformNR nr = moves.get(name); TransformNR wp = getWorkplane(objects.get(name)); TransformNR wpinv = wp.inverse(); - + TransformNR times = wp.times(nr.times(wpinv)); - Transform tf = TransformFactory.nrToCSG(times); - CaDoodleFile.applyToAllConstituantElements(false, name, back, (incoming1, depth) ->{ + Transform tf = TransformFactory.nrToCSG(times); + CaDoodleFile.applyToAllConstituantElements(false, name, back, (incoming1, depth) -> { ArrayList b = new ArrayList<>(); - CSG c=incoming1.transformed(tf); - sync(incoming1,c); - MoveCenter.set(getName() , c, times); + CSG c = incoming1.transformed(tf); + sync(incoming1, c); + MoveCenter.set(getName(), c, times); b.add(c); return b; - }, 1,new HashSet()); + }, 1, new HashSet()); } return back; } @@ -110,63 +112,61 @@ public List process(List incoming) { // } private TransformNR performTransform(Bounds reference, CSG incoming) { - //CSG c = incoming; - double tx=0,ty=0,tz=0; - if(z!=null) { - switch(z) { + // CSG c = incoming; + double tx = 0, ty = 0, tz = 0; + if (z != null) { + switch (z) { case negative: - tz=-incoming.getMinZ()+reference.getMinZ(); + tz = -incoming.getMinZ() + reference.getMinZ(); break; case middle: - tz=-incoming.getCenterZ()+reference.getCenterZ(); + tz = -incoming.getCenterZ() + reference.getCenterZ(); break; case positive: - tz=-incoming.getMaxZ()+reference.getMaxZ(); + tz = -incoming.getMaxZ() + reference.getMaxZ(); break; default: break; } } - if(x!=null) { - switch(x) { + if (x != null) { + switch (x) { case negative: - tx=-incoming.getMinX()+reference.getMinX(); + tx = -incoming.getMinX() + reference.getMinX(); break; case middle: - tx=-incoming.getCenterX()+reference.getCenterX(); + tx = -incoming.getCenterX() + reference.getCenterX(); break; case positive: - tx=-incoming.getMaxX()+reference.getMaxX(); + tx = -incoming.getMaxX() + reference.getMaxX(); break; default: break; - + } } - if(y!=null) { - switch(y) { + if (y != null) { + switch (y) { case negative: - ty=-incoming.getMinY()+reference.getMinY(); + ty = -incoming.getMinY() + reference.getMinY(); break; case middle: - ty=-incoming.getCenterY()+reference.getCenterY(); + ty = -incoming.getCenterY() + reference.getCenterY(); break; case positive: - ty=-incoming.getMaxY()+reference.getMaxY(); + ty = -incoming.getMaxY() + reference.getMaxY(); break; default: break; - + } } - return new TransformNR(tx,ty,tz); + return new TransformNR(tx, ty, tz); } private CSG sync(CSG incoming, CSG c) { - return c.syncProperties(getCaDoodleFile().getCsgDBinstance(),incoming) - .setName(incoming.getName()) - .setColor(incoming.getColor()) - .setID(incoming); + return c.syncProperties(getCaDoodleFile().getCsgDBinstance(), incoming).setName(incoming.getName()) + .setColor(incoming.getColor()).setID(incoming); } public List getNamesAddedInThisOperation() { @@ -177,18 +177,31 @@ public Align setNames(List names) { this.names = names; return this; } - public Align setAlignParams(Alignment X, Alignment Y,Alignment Z) { - x=X; - y=Y; - z=Z; + + public Align setAlignParams(Alignment X, Alignment Y, Alignment Z) { + x = X; + y = Y; + z = Z; return this; } public TransformNR getWorkplane(CSG c) { - if(workplane==null) - workplane= new TransformNR(); - Affine af = c.getManipulator(); - TransformNR afNR = TransformFactory.affineToNr(af).inverse(); + if (workplane == null) + workplane = new TransformNR(); + Affine af; + TransformNR afNR = null; + if (c.hasManipulator()) + try { + af = c.getManipulator(); + afNR = TransformFactory.affineToNr(af).inverse(); + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + else { + afNR = new TransformNR(); + } + return afNR.times(workplane); } @@ -198,40 +211,44 @@ public Align setWorkplane(TransformNR workplane) { } public Bounds getBounds(List incoming) { - if(bounds!=null) { + if (bounds != null) { Log.error("Depricated Bounds in the align step!"); return bounds.getBounds(); - }if(boundNames!=null) { - List selectedCSG = getSelectedCSG(boundNames,incoming); - return Align.getBounds(selectedCSG, workplane, new HashMap()); } - else { + if (boundNames != null) { + List selectedCSG = getSelectedCSG(boundNames, incoming); + return Align.getBounds(selectedCSG, workplane, new HashMap()); + } else { throw new RuntimeException("Align can not be initialized without bounds!"); } - + } - public List getSelectedCSG(Iterable sele,List incoming) { + + public List getSelectedCSG(Iterable sele, List incoming) { ArrayList back = new ArrayList(); for (String sel : sele) { - CSG t = getSelectedCSG(sel,incoming); + CSG t = getSelectedCSG(sel, incoming); if (t != null) { back.add(t); } } return back; } - private CSG getSelectedCSG(String string,List incoming) { - for (CSG c :incoming) { + + private CSG getSelectedCSG(String string, List incoming) { + for (CSG c : incoming) { if (c.getName().contentEquals(string)) return c; } return null; } + public Align setBounds(List boundNames) { - this.boundNames=boundNames; - bounds=null; + this.boundNames = boundNames; + bounds = null; return this; } + public static Bounds getBounds(List incoming, TransformNR frame, HashMap cache) { if (cache == null) cache = new HashMap<>(); @@ -242,10 +259,17 @@ public static Bounds getBounds(List incoming, TransformNR frame, HashMap incoming, TransformNR frame, HashMap currentState) { - if (currentState == null) + if (currentState == null || imageEngine==null) throw new RuntimeException("Can not be null"); ArrayList holder = new ArrayList(); try { BowlerKernel.runLater(() -> { try { - holder.add(ThumbnailImage.get(getCsgDBinstance(), currentState)); + holder.add(imageEngine.get(getCsgDBinstance(), currentState)); }catch(Exception ex) { holder.add(new WritableImage(1000, 1000)); } @@ -1209,7 +1210,7 @@ private javafx.scene.image.WritableImage loadingImageFromUIThread(List curr com.neuronrobotics.sdk.common.Log.error(e); break; } - if (System.currentTimeMillis() - start > 25000 && holder.size() == 0) { + if (System.currentTimeMillis() - start > 250 && holder.size() == 0) { throw new RuntimeException("Failed to create image"); } } @@ -1485,4 +1486,12 @@ public void clearIgnore() { e.printStackTrace(); } } + + public ThumbnailImage getImageEngine() { + return imageEngine; + } + + public void setImageEngine(ThumbnailImage imageEngine) { + this.imageEngine = imageEngine; + } } diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleOperation.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleOperation.java index 29411766..b66bad02 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleOperation.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/CaDoodleOperation.java @@ -46,6 +46,8 @@ public String getBuilder(List selected, List state) { MobileBaseBuilder b = getRobots().get(mobileBaseName.get()); if(b!=null) { return mobileBaseName.get(); + }else { + throw new RuntimeException("MobilBase name set but builder missing"); } } } diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Group.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Group.java index 7cd5bf41..dbb2e1fc 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Group.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Group.java @@ -11,6 +11,7 @@ import com.neuronrobotics.bowlerstudio.physics.TransformFactory; import eu.mihosoft.vrl.v3d.CSG; +import eu.mihosoft.vrl.v3d.MissingManipulatorException; import eu.mihosoft.vrl.v3d.parametrics.IParametric; import javafx.scene.paint.Color; import javafx.scene.transform.Affine; @@ -60,7 +61,12 @@ public List process(List incoming) { } } if(csg.hasManipulator()) - manip=csg.getManipulator(); + try { + manip=csg.getManipulator(); + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } replace.add(csg); CSG clone = csg.clone(); diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Mirror.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Mirror.java index 3f78cfd4..f66c86a4 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Mirror.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/Mirror.java @@ -10,6 +10,7 @@ import com.neuronrobotics.sdk.addons.kinematics.math.TransformNR; import eu.mihosoft.vrl.v3d.CSG; +import eu.mihosoft.vrl.v3d.MissingManipulatorException; import eu.mihosoft.vrl.v3d.Transform; import javafx.scene.transform.Affine; @@ -23,6 +24,7 @@ public class Mirror extends CaDoodleOperation { @Expose(serialize = true, deserialize = true) protected String name = null; private int index; + public String getName() { if (name == null) { setName(RandomStringFactory.generateRandomString()); @@ -33,17 +35,16 @@ public String getName() { public void setName(String name) { this.name = name; } + @Override public String getType() { return "Move Center"; } private CSG sync(CSG incoming, CSG c) { - return c.syncProperties(getCaDoodleFile().getCsgDBinstance(),incoming) - .setName(incoming.getName()) - .setColor(incoming.getColor()) - .setID(incoming); - } + return c.syncProperties(getCaDoodleFile().getCsgDBinstance(), incoming).setName(incoming.getName()) + .setColor(incoming.getColor()).setID(incoming); + } @Override public List process(List incoming) { @@ -52,7 +53,7 @@ public List process(List incoming) { index = 0; for (String name : names) { for (CSG csg : incoming) { - if(!csg.getName().contentEquals(name)) + if (!csg.getName().contentEquals(name)) continue; // if(csg.isNoScale()) // continue; @@ -61,16 +62,16 @@ public List process(List incoming) { .movez(base.getCenterZ()); Transform sc = new Transform(); if (location == MirrorOrentation.x) { - sc=new Transform().scaleX(-1); + sc = new Transform().scaleX(-1); } if (location == MirrorOrentation.y) { - sc=new Transform().scaleY(-1); + sc = new Transform().scaleY(-1); } if (location == MirrorOrentation.z) { - sc=new Transform().scaleZ(-1); + sc = new Transform().scaleZ(-1); } - Transform scale=sc; - + Transform scale = sc; + CaDoodleFile.applyToAllConstituantElements(false, name, back, (incoming1, depth) -> { ArrayList b = new ArrayList<>(); Transform inverse = TransformFactory.nrToCSG(getWorkplane(incoming1)).inverse(); @@ -79,18 +80,17 @@ public List process(List incoming) { centered = centered.transformed(scale); centered = centered.transformed(mirroringCenter); Transform wp = TransformFactory.nrToCSG(getWorkplane(incoming1)); - centered = centered.transformed(wp); - CSG tf = centered.setName(name).syncProperties(getCaDoodleFile().getCsgDBinstance(),incoming1); + centered = centered.transformed(wp); + CSG tf = centered.setName(name).syncProperties(getCaDoodleFile().getCsgDBinstance(), incoming1); sync(incoming1, tf); - MoveCenter.set(getName()+(index++) , tf, inverse); - MoveCenter.set(getName()+(index++) , tf, mirroringCenter.inverse()); - MoveCenter.set(getName()+(index++) , tf, scale); - MoveCenter.set(getName()+(index++) , tf, mirroringCenter); - MoveCenter.set(getName()+(index++) , tf, wp); + MoveCenter.set(getName() + (index++), tf, inverse); + MoveCenter.set(getName() + (index++), tf, mirroringCenter.inverse()); + MoveCenter.set(getName() + (index++), tf, scale); + MoveCenter.set(getName() + (index++), tf, mirroringCenter); + MoveCenter.set(getName() + (index++), tf, wp); b.add(tf); return b; - }, 1,new HashSet() -); + }, 1, new HashSet()); } } return back; @@ -128,7 +128,7 @@ private CSG mirror(CSG csg, String name) { } centered = centered.transformed(mirroringCenter); centered = centered.transformed(TransformFactory.nrToCSG(getWorkplane(csg))); - return centered.setName(name).syncProperties(getCaDoodleFile().getCsgDBinstance(),csg); + return centered.setName(name).syncProperties(getCaDoodleFile().getCsgDBinstance(), csg); } public MirrorOrentation getLocation() { @@ -152,8 +152,20 @@ public Mirror setNames(List names) { public TransformNR getWorkplane(CSG c) { if (workplane == null) workplane = new TransformNR(); - Affine af = c.getManipulator(); - TransformNR afNR = TransformFactory.affineToNr(af).inverse(); + Affine af; + TransformNR afNR = null; + if (c.hasManipulator()) + try { + af = c.getManipulator(); + afNR = TransformFactory.affineToNr(af).inverse(); + + } catch (MissingManipulatorException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + else { + afNR = new TransformNR(); + } return afNR.times(workplane); } diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/robot/AddRobotLimb.java b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/robot/AddRobotLimb.java index ba509f7c..10b3c24f 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/robot/AddRobotLimb.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/scripting/cadoodle/robot/AddRobotLimb.java @@ -28,6 +28,7 @@ public class AddRobotLimb extends AbstractAddFrom{ @Expose(serialize = true, deserialize = true) private List names; public boolean forceLoad = false; + private DHParameterKinematics kin; @Override public void pruneCleanup() { if (getBuilderName() != null) { @@ -104,4 +105,14 @@ public String getBuilderName() { public void setBuilderName(String builderName) { this.builderName = builderName; } + + public MobileBaseBuilder getMobilBaseBuilder() { + return getRobots().get(getBuilderName()); + } + public void setKinematics(DHParameterKinematics kin) { + this.kin = kin; + } + public DHParameterKinematics getKinematics() { + return kin; + } } diff --git a/src/main/java/com/neuronrobotics/bowlerstudio/util/FileChangeWatcher.java b/src/main/java/com/neuronrobotics/bowlerstudio/util/FileChangeWatcher.java index 9c8a8d5b..dab94436 100644 --- a/src/main/java/com/neuronrobotics/bowlerstudio/util/FileChangeWatcher.java +++ b/src/main/java/com/neuronrobotics/bowlerstudio/util/FileChangeWatcher.java @@ -40,6 +40,7 @@ import java.util.*; import com.neuronrobotics.bowlerstudio.IssueReportingExceptionHandler; +import com.neuronrobotics.sdk.common.Log; // Auto-generated Javadoc /** @@ -292,16 +293,15 @@ public void watch() { } // print out event // System.out.format("%s: %s\n", event.kind().name(), child); - com.neuronrobotics.sdk.common.Log.error("File Changed: " + getFileToWatch().getAbsolutePath()); for (int i = 0; i < listeners.size(); i++) { + com.neuronrobotics.sdk.common.Log.debug((i+1)+" of "+listeners.size()+" kind:"+kind+" event type "+listeners.get(i).getClass()+" File Changed: " + getFileToWatch().getAbsolutePath()); listeners.get(i).onFileChange(child.toFile(), event); - Thread.sleep(50);// pad out the events to avoid file box + Thread.sleep(16);// pad out the events to avoid file box // overwrites } } catch (Exception e) { - // Auto-generated catch block - e.printStackTrace(); + Log.error(e); } } @@ -363,4 +363,8 @@ public void close() { activeListener.remove(fileToWatch.getAbsolutePath()); } + public void removeIFileChangeListeners() { + listeners.clear(); + } + } diff --git a/test/java/src/junit/bowler/ArduinoLoaderTest.java b/test/java/src/junit/bowler/ArduinoLoaderTest.java index 69b932dd..4f27ea76 100644 --- a/test/java/src/junit/bowler/ArduinoLoaderTest.java +++ b/test/java/src/junit/bowler/ArduinoLoaderTest.java @@ -10,6 +10,7 @@ import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.TransportException; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import com.neuronrobotics.bowlerstudio.BowlerKernel; @@ -23,11 +24,9 @@ public class ArduinoLoaderTest { private static final String portname = "/dev/ttyACM0"; private boolean hasPort; - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test + @Ignore public void test() throws Exception { hasPort = false; for (String s : NRSerialPort.getAvailableSerialPorts()) { diff --git a/test/java/src/junit/bowler/BlenderLoadingTest.java b/test/java/src/junit/bowler/BlenderLoadingTest.java index 18c14f3b..52659095 100644 --- a/test/java/src/junit/bowler/BlenderLoadingTest.java +++ b/test/java/src/junit/bowler/BlenderLoadingTest.java @@ -19,10 +19,7 @@ import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; public class BlenderLoadingTest { - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test public void test() throws Exception { CSG loaded =(CSG)ScriptingEngine.gitScriptRun(CSGDatabase.getInstance(), diff --git a/test/java/src/junit/bowler/Build123dTest.java b/test/java/src/junit/bowler/Build123dTest.java index d19f0e65..6099df4c 100644 --- a/test/java/src/junit/bowler/Build123dTest.java +++ b/test/java/src/junit/bowler/Build123dTest.java @@ -9,6 +9,7 @@ import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.TransportException; +import org.junit.Ignore; import org.junit.Test; import com.neuronrobotics.bowlerstudio.scripting.Build123dLoader; @@ -18,18 +19,19 @@ public class Build123dTest { @Test + @Ignore public void test() throws InvalidRemoteException, TransportException, GitAPIException, IOException, InterruptedException { -// Build123dLoader loader = new Build123dLoader(); -// Log.enableDebugPrint(); -// // create test file -// File testblend = new File("build123dTest.py"); -// if(!testblend.exists()) -// loader.getDefaultContents(testblend); -// HashMap params = new HashMap(); -// Build123dLoader.toSTLFile(testblend, new File("build123dTest.py.stl"),params); -// -// File gears = ScriptingEngine.fileFromGit("https://github.com/GarryBGoode/gggears.git", "examples/examples.py"); -// Build123dLoader.toSTLFile(gears, new File("gears.stl"),params); + Build123dLoader loader = new Build123dLoader(); + Log.enableDebugPrint(); + // create test file + File testblend = new File("build123dTest.py"); + if(!testblend.exists()) + loader.getDefaultContents(testblend); + HashMap params = new HashMap(); + Build123dLoader.toSTLFile(testblend, new File("build123dTest.py.stl"),params); + + File gears = ScriptingEngine.fileFromGit("https://github.com/GarryBGoode/gggears.git", "examples/examples.py"); + Build123dLoader.toSTLFile(gears, new File("gears.stl"),params); } diff --git a/test/java/src/junit/bowler/CaDoodleWorkflowTest.java b/test/java/src/junit/bowler/CaDoodleWorkflowTest.java index 10f93009..6c6d128c 100644 --- a/test/java/src/junit/bowler/CaDoodleWorkflowTest.java +++ b/test/java/src/junit/bowler/CaDoodleWorkflowTest.java @@ -247,8 +247,10 @@ public void test() throws Exception { loaded.setSelf(self2); com.neuronrobotics.sdk.common.Log.error(after); - while(loaded.isForwardAvailible()) + while(loaded.isForwardAvailible()) { + System.out.println("Moving forward the Doodle"); loaded.forward(); + } selectAll = new ArrayList(); for(CSG c:loaded.getCurrentState()) { selectAll.add(c.getName()); @@ -261,11 +263,12 @@ public void test() throws Exception { ScriptingEngine.pull(ControllerOption.URL_OF_OPTIONS); ArrayList controllers = ControllerOption.getOptions(); for(ControllerOption o:controllers) { - System.out.println(o); + System.out.println("Adding a Controller: "+o); AddRobotController con = new AddRobotController() .setNames(selectAll) .setController(o); loaded.addOpperation(con).join(); + System.out.println("Added!"); } loaded.save(); ScriptingEngine.pull("https://github.com/madhephaestus/carl-the-hexapod.git"); diff --git a/test/java/src/junit/bowler/GitHub.java b/test/java/src/junit/bowler/GitHub.java index 5b17c12b..d0ea3004 100644 --- a/test/java/src/junit/bowler/GitHub.java +++ b/test/java/src/junit/bowler/GitHub.java @@ -32,10 +32,6 @@ public class GitHub { private static boolean shutdownInProgress; - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } static { Runtime.getRuntime().addShutdownHook(new Thread(() -> { if (shutdownInProgress) return; @@ -172,17 +168,6 @@ public void test() throws Exception { com.neuronrobotics.sdk.common.Log.error("Current Branch # " + ScriptingEngine.getFullBranch(asstsRepo)); */ } - @AfterClass - public static void tearDownJavaFX() throws InterruptedException { - CountDownLatch latch = new CountDownLatch(1); - Platform.runLater(() -> { - Platform.exit(); - latch.countDown(); - }); - latch.await(5, TimeUnit.SECONDS); - - // Give time for cleanup - Thread.sleep(1000); - } + } diff --git a/test/java/src/junit/bowler/IssueReportingTest.java b/test/java/src/junit/bowler/IssueReportingTest.java index 7c886d93..fbf8d192 100644 --- a/test/java/src/junit/bowler/IssueReportingTest.java +++ b/test/java/src/junit/bowler/IssueReportingTest.java @@ -15,10 +15,7 @@ import com.neuronrobotics.bowlerstudio.scripting.PasswordManager; public class IssueReportingTest { - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test public void test() throws Exception { // PasswordManager.login(); diff --git a/test/java/src/junit/bowler/KotlinHelperTest.java b/test/java/src/junit/bowler/KotlinHelperTest.java deleted file mode 100644 index a56d72fe..00000000 --- a/test/java/src/junit/bowler/KotlinHelperTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package junit.bowler; - -//import com.neuronrobotics.bowlerstudio.scripting.KotlinHelper; -// -//import static org.junit.Assert.assertEquals; -// -//import org.junit.Test; -// -//import java.util.ArrayList; -//import java.util.Collections; -// -//public class KotlinHelperTest { -// -// private KotlinHelper helper = new KotlinHelper(); -// -// @Test -// public void testReturningNonClassValue() throws Exception { -// assertEquals(42, helper.inlineScriptRun("42", null)); -// } -// -// @Test -// public void testReturningClassValue() throws Exception { -// assertEquals("Foo", helper.inlineScriptRun("class Foo\nFoo::class.java", null).getClass() -// .getSimpleName()); -// } -// -// @Test -// public void testReturningKotlinScriptSkeletonInstance() throws Exception { -// assertEquals(42, helper.inlineScriptRun( -// "import com.neuronrobotics.bowlerstudio.scripting.KotlinScriptSkeleton\n" -// + "class Foo : KotlinScriptSkeleton {\n" -// + "override fun runScript(args: List?): Any? = 42\n" + "}\n" -// + "Foo::class.java", null)); -// } -// -// @Test -// public void testReturningKotlinScriptSkeletonInstanceWithArguments() throws Exception { -// ArrayList args = new ArrayList<>(Collections.singletonList(42)); -// assertEquals(args, helper.inlineScriptRun( -// "import com.neuronrobotics.bowlerstudio.scripting.KotlinScriptSkeleton\n" -// + "class Foo : KotlinScriptSkeleton {\n" -// + "override fun runScript(args: List?): Any? = args\n" + "}\n" -// + "Foo::class.java", args)); -// } -//} diff --git a/test/java/src/junit/bowler/MobileBaseBuilderTest.java b/test/java/src/junit/bowler/MobileBaseBuilderTest.java index 906e1b67..7a41879a 100644 --- a/test/java/src/junit/bowler/MobileBaseBuilderTest.java +++ b/test/java/src/junit/bowler/MobileBaseBuilderTest.java @@ -8,6 +8,7 @@ import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.TransportException; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import com.neuronrobotics.bowlerstudio.BowlerKernel; @@ -21,11 +22,9 @@ import eu.mihosoft.vrl.v3d.parametrics.CSGDatabaseInstance; public class MobileBaseBuilderTest { - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test + @Ignore public void test() throws Exception { JavaFXInitializer.go(); MobileBaseBuilder builder = new MobileBaseBuilder(CSGDatabase.getInstance(), diff --git a/test/java/src/junit/bowler/MobileBaseLoading.java b/test/java/src/junit/bowler/MobileBaseLoading.java index dc01dd7b..aaa499b4 100644 --- a/test/java/src/junit/bowler/MobileBaseLoading.java +++ b/test/java/src/junit/bowler/MobileBaseLoading.java @@ -10,6 +10,7 @@ import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.TransportException; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import com.neuronrobotics.bowlerstudio.BowlerKernel; @@ -24,11 +25,9 @@ public class MobileBaseLoading { int numCSG =0; - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test + @Ignore public void test() throws Exception { /* ScriptingEngine.setupAnyonmous(); diff --git a/test/java/src/junit/bowler/MuJoCoTest.java b/test/java/src/junit/bowler/MuJoCoTest.java index d32a625c..65dc00c6 100644 --- a/test/java/src/junit/bowler/MuJoCoTest.java +++ b/test/java/src/junit/bowler/MuJoCoTest.java @@ -17,6 +17,7 @@ public class MuJoCoTest { @Test + @Ignore public void test() { com.neuronrobotics.sdk.common.Log.error("mujocoJNILoadTest"); System.setProperty("org.bytedeco.javacpp.logger.debug", "true"); diff --git a/test/java/src/junit/bowler/SSHGitTest.java b/test/java/src/junit/bowler/SSHGitTest.java index 98b16952..31f7015b 100644 --- a/test/java/src/junit/bowler/SSHGitTest.java +++ b/test/java/src/junit/bowler/SSHGitTest.java @@ -15,10 +15,7 @@ import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine; public class SSHGitTest { - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test public void test() throws InvalidRemoteException, TransportException, GitAPIException, IOException { /* diff --git a/test/java/src/junit/bowler/SVGLoadTest.java b/test/java/src/junit/bowler/SVGLoadTest.java index 0d247cae..1fdb3289 100644 --- a/test/java/src/junit/bowler/SVGLoadTest.java +++ b/test/java/src/junit/bowler/SVGLoadTest.java @@ -12,6 +12,7 @@ import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.TransportException; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import com.neuronrobotics.bowlerstudio.BowlerKernel; @@ -21,11 +22,9 @@ import eu.mihosoft.vrl.v3d.svg.SVGLoad; public class SVGLoadTest { - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test + @Ignore public void test() throws IOException { File svg = new File("Test.SVG"); if(!svg.exists()) diff --git a/test/java/src/junit/bowler/SequenceTest.java b/test/java/src/junit/bowler/SequenceTest.java index 978a5d24..f290b193 100644 --- a/test/java/src/junit/bowler/SequenceTest.java +++ b/test/java/src/junit/bowler/SequenceTest.java @@ -18,10 +18,7 @@ import eu.mihosoft.vrl.v3d.parametrics.CSGDatabase; public class SequenceTest { - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test public void test() throws Exception { // try { diff --git a/test/java/src/junit/bowler/TestCheckout.java b/test/java/src/junit/bowler/TestCheckout.java index ee677173..55d30bf3 100644 --- a/test/java/src/junit/bowler/TestCheckout.java +++ b/test/java/src/junit/bowler/TestCheckout.java @@ -41,7 +41,7 @@ public void test() throws IOException, GitAPIException, InterruptedException { } catch (Exception e) { Log.error(e); - Thread.sleep(1000); + Thread.sleep(10); fail(); } } diff --git a/test/java/src/junit/bowler/VoiceTest.java b/test/java/src/junit/bowler/VoiceTest.java index ceabf5a2..68b0c5fd 100644 --- a/test/java/src/junit/bowler/VoiceTest.java +++ b/test/java/src/junit/bowler/VoiceTest.java @@ -14,10 +14,7 @@ import com.neuronrobotics.bowlerstudio.BowlerKernel; public class VoiceTest { - @Before - public void setup() throws InvalidRemoteException, TransportException, IOException, GitAPIException, Exception { - BowlerKernel.startupProcedures(); - } + @Test @Ignore public void test() {