use of com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics in project bowler-script-kernel by CommonWealthRobotics.
the class MobileBaseCadManager method _generateStls.
private ArrayList<File> _generateStls(MobileBase base, File baseDirForFiles, boolean kinematic) throws IOException {
ArrayList<File> allCadStl = new ArrayList<>();
ArrayList<DHParameterKinematics> limbs = base.getAllDHChains();
double numLimbs = limbs.size();
int i;
// Start by generating the legs using the DH link based generator
ArrayList<CSG> totalAssembly = new ArrayList<>();
double offset = 0;
for (i = 0; i < limbs.size(); i += 1) {
double progress = (1.0 - ((numLimbs - i) / numLimbs)) / 2;
getProcesIndictor().set(progress);
DHParameterKinematics l = limbs.get(i);
ArrayList<CSG> parts = getDHtoCadMap().get(l);
for (int j = 0; j < parts.size(); j++) {
CSG csg = parts.get(j);
String name = csg.getName();
try {
CSG tmp;
if (!kinematic)
csg = csg.prepForManufacturing();
if (csg != null) {
if (!kinematic) {
tmp = csg.toXMax().toYMax();
} else {
tmp = csg;
}
if (totalAssembly.size() > 0 && !kinematic)
totalAssembly.add(tmp.movey(.5 + totalAssembly.get(totalAssembly.size() - 1).getMaxY() + Math.abs(csg.getMinY())));
else
totalAssembly.add(tmp);
LinkConfiguration conf = getLinkConfiguration(parts.get(j));
String linkNum = conf.getLinkIndex() + "_Link_";
File dir = new File(baseDirForFiles.getAbsolutePath() + "/" + base.getScriptingName() + "/" + l.getScriptingName());
if (!dir.exists())
dir.mkdirs();
System.out.println("Making STL for " + name);
File stl = new File(dir.getAbsolutePath() + "/" + linkNum + name + "_limb_" + i + "_Part_" + j + ".stl");
FileUtil.write(Paths.get(stl.getAbsolutePath()), tmp.toStlString());
allCadStl.add(stl);
// totalAssembly.add(tmp);
getUi().setAllCSG(totalAssembly, getCadScript());
set(base, i, j);
}
} catch (Exception ex) {
getUi().highlightException(getCadScript(), ex);
}
// legAssembly.setManufactuing(new PrepForManufacturing() {
// public CSG prep(CSG arg0) {
// return null;
// }
// });
}
// offset =
// -2-((legAssembly.get(legAssembly.size()-1).getMaxX()+legAssembly.get(legAssembly.size()-1).getMinX())*i);
// legAssembly=legAssembly.movex(offset);
}
int link = 0;
// now we genrate the base pieces
for (CSG csg : getBasetoCadMap().get(base)) {
String name = csg.getName();
try {
if (!kinematic)
csg = csg.prepForManufacturing();
if (csg != null) {
if (!kinematic) {
csg = csg.toYMin().movex(-2 - csg.getMaxX() + offset);
}
File dir = new File(baseDirForFiles.getAbsolutePath() + "/" + base.getScriptingName() + "/");
if (!dir.exists())
dir.mkdirs();
File stl = new File(dir.getAbsolutePath() + "/" + name + "_Body_part_" + link + ".stl");
FileUtil.write(Paths.get(stl.getAbsolutePath()), csg.toStlString());
allCadStl.add(stl);
totalAssembly.add(csg);
getUi().setAllCSG(totalAssembly, getCadScript());
link++;
}
} catch (Exception ex) {
getUi().highlightException(getCadScript(), ex);
}
}
// ui.setCsg(BasetoCadMap.get(base),getCadScript());
// for(CSG c: DHtoCadMap.get(base.getAllDHChains().get(0))){
// ui.addCsg(c,getCadScript());
// }
showingStl = true;
getProcesIndictor().set(1);
return allCadStl;
}
use of com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics 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();
}
use of com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics in project bowler-script-kernel by CommonWealthRobotics.
the class MobileBaseCadManager method generateCad.
/**
* This function iterates through the links generating them
*
* @param dh
* @return
*/
public ArrayList<CSG> generateCad(DHParameterKinematics dh) {
ArrayList<CSG> dhLinks = new ArrayList<>();
if (cadEngine == null) {
try {
setDefaultLinkLevelCadEngine();
} catch (Exception e) {
getUi().highlightException(getCadScript(), e);
}
}
try {
IgenerateCad generatorToUse = getIgenerateCad();
if (dhCadGen.get(dh) != null) {
Object object = dhCadGen.get(dh);
if (IgenerateCad.class.isInstance(object))
generatorToUse = (IgenerateCad) object;
}
int j = 0;
for (DHParameterKinematics dhtest : getMobileBase().getAllDHChains()) {
if (dhtest == dh)
break;
j++;
}
for (int i = 0; i < dh.getNumberOfLinks(); i++) {
set(base, (int) j, (int) i);
if (!bail) {
ArrayList<CSG> tmp = generatorToUse.generateCad(dh, i);
getUi().addCSG(tmp, getCadScript());
LinkConfiguration configuration = dh.getLinkConfiguration(i);
if (getLinktoCadMap().get(configuration) == null) {
getLinktoCadMap().put(configuration, new ArrayList<>());
} else
getLinktoCadMap().get(configuration).clear();
for (CSG c : tmp) {
dhLinks.add(c);
// add to
getLinktoCadMap().get(configuration).add(c);
// the
// regestration
// storage
}
AbstractLink link = dh.getFactory().getLink(configuration);
link.addLinkListener(new ILinkListener() {
@Override
public void onLinkPositionUpdate(AbstractLink arg0, double arg1) {
// TODO Auto-generated method stub
}
@Override
public void onLinkLimit(AbstractLink arg0, PIDLimitEvent arg1) {
if (getAutoRegen())
selectCsgByLink(base, configuration);
}
});
}
}
return dhLinks;
} catch (Exception e) {
getUi().highlightException(getCadScript(), e);
}
return null;
}
use of com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics in project bowler-script-kernel by CommonWealthRobotics.
the class MobileBaseCadManager method setDefaultLinkLevelCadEngine.
private void setDefaultLinkLevelCadEngine() throws Exception {
String[] cad;
cad = base.getGitCadEngine();
if (cadEngine == null) {
setGitCadEngine(cad[0], cad[1], base);
}
for (DHParameterKinematics kin : base.getAllDHChains()) {
String[] kinEng = kin.getGitCadEngine();
if (!cad[0].contentEquals(kinEng[0]) || !cad[1].contentEquals(kinEng[1])) {
setGitCadEngine(kinEng[0], kinEng[1], kin);
}
}
}
use of com.neuronrobotics.sdk.addons.kinematics.DHParameterKinematics in project BowlerStudio by CommonWealthRobotics.
the class AppTestLinkWidgets method start.
@Override
public void start(Stage stage) throws Exception {
ScriptingEngine.gitScriptRun("https://github.com/CommonWealthRobotics/DeviceProviders.git", "loadAll.groovy", null);
MobileBase base = MobileBaseLoader.fromGit("https://github.com/Hephaestus-Arm/HephaestusArm2.git", "hephaestus.xml");
DHParameterKinematics limb = base.getAllDHChains().get(0);
int index = 2;
LinkConfiguration conf = limb.getLinkConfiguration(index);
LinkConfigurationWidget theWidget = new LinkConfigurationWidget(conf, limb.getFactory(), MobileBaseCadManager.get(base));
LinkSliderWidget lsw = new LinkSliderWidget(index, limb, theWidget);
VBox box = new VBox();
box.getChildren().addAll(lsw);
Group root = new Group(box);
Scene scene = new Scene(root, 800, 900);
stage.setTitle("My JavaFX Application");
stage.setScene(scene);
stage.show();
}
Aggregations