use of com.neuronrobotics.sdk.common.BowlerAbstractDevice in project java-bowler by NeuronRobotics.
the class Jfx3dManager method attachArm.
public void attachArm(final DHParameterKinematics model) {
master = model.getFactory().getDyio();
if (master != null)
new DigitalInputChannel(master, 23).addDigitalInputListener(new IDigitalInputListener() {
@Override
public void onDigitalValueChange(DigitalInputChannel source, final boolean isHigh) {
// System.err.println("Button pressed");
Platform.runLater(new Runnable() {
@Override
public void run() {
if (!isHigh) {
ObservableList<Node> cadBits = lookGroup.getChildren();
for (Node n : cadBits) {
double x = n.getTranslateX();
double y = n.getTranslateY();
double z = n.getTranslateZ();
// if (threedBoundCheck(x, y, z,/selsectedAffine, 10)) {
if (MeshView.class.isInstance(n)) {
System.out.println("Selecting Object");
selectedObject = (MeshView) n;
} else {
System.out.println("Not Touching " + n.getClass());
}
// }
}
if (selectedObject != null) {
System.out.println("Grabbing Object ");
selectedObject.getTransforms().clear();
selectedObject.getTransforms().addAll(robotBase, selsectedAffine);
}
} else {
// button released, look for devices
if (selectedObject != null) {
// freeze it in place
selectedObject.getTransforms().clear();
selectedObject.getTransforms().addAll(robotBase, selsectedAffine.clone());
selectedObject = null;
}
}
}
});
}
});
Platform.runLater(new Runnable() {
@Override
public void run() {
ArrayList<DHLink> links = model.getDhChain().getLinks();
for (DHLink dh : links) {
final Axis a = new Axis(15);
a.getChildren().add(new Sphere(5));
a.getTransforms().add(dh.getListener());
manipulator.getChildren().add(a);
if (master != null)
master.addConnectionEventListener(new IDeviceConnectionEventListener() {
@Override
public void onDisconnect(BowlerAbstractDevice source) {
// TODO Auto-generated method stub
manipulator.getChildren().remove(a);
a.getTransforms().clear();
}
@Override
public void onConnect(BowlerAbstractDevice source) {
// TODO Auto-generated method stub
}
});
}
// get the affine of the tip of the chain
selsectedAffine = links.get(links.size() - 1).getListener();
robotBase.setTx(100);
robotBase.setTy(100);
robotBase.setTz(-5);
manipulator.getTransforms().add(robotBase);
world.getChildren().addAll(manipulator);
}
});
}
use of com.neuronrobotics.sdk.common.BowlerAbstractDevice in project BowlerStudio by CommonWealthRobotics.
the class BowlerStudioController method addObject.
public static void addObject(Object o, File source) {
if (List.class.isInstance(o)) {
List<Object> c = (List<Object>) o;
for (int i = 0; i < c.size(); i++) {
// Log.warning("Loading array Lists with removals " + c.get(i));
addObject(c.get(i), source);
}
return;
}
if (CSG.class.isInstance(o)) {
CSG csg = (CSG) o;
Platform.runLater(() -> {
// new RuntimeException().printStackTrace();
CreatureLab3dController.getEngine().addObject(csg, source);
});
return;
} else if (Tab.class.isInstance(o)) {
getBowlerStudio().addTab((Tab) o, true);
return;
} else if (Node.class.isInstance(o)) {
getBowlerStudio().addNode((Node) o);
return;
} else if (Polygon.class.isInstance(o)) {
Polygon p = (Polygon) o;
List<Vertex> vertices = p.vertices;
javafx.scene.paint.Color color = new javafx.scene.paint.Color(Math.random() * 0.5 + 0.5, Math.random() * 0.5 + 0.5, Math.random() * 0.5 + 0.5, 1);
// double stroke = 0.5;
// for (int i = 1; i < vertices.size(); i++) {
// Line3D line = new Line3D(vertices.get(i - 1), vertices.get(i));
// line.setStrokeWidth(stroke);
// line.setStroke(color);
// getBowlerStudio().addNode(line);
// }
// // Connecting line
// Line3D line = new Line3D(vertices.get(0), vertices.get(vertices.size() - 1));
// line.setStrokeWidth(stroke);
// line.setStroke(color);
MeshContainer mesh = CSGtoJavafx.meshFromPolygon(p);
javafx.scene.shape.MeshView current = mesh.getAsMeshViews().get(0);
current.setMaterial(new PhongMaterial(color));
current.setCullFace(CullFace.NONE);
getBowlerStudio().addNode(current);
return;
} else if (BowlerAbstractDevice.class.isInstance(o)) {
BowlerAbstractDevice bad = (BowlerAbstractDevice) o;
ConnectionManager.addConnection((BowlerAbstractDevice) o, bad.getScriptingName());
return;
} else if (DMDevice.wrappable(o)) {
BowlerAbstractDevice bad;
try {
bad = new DMDevice(o);
ConnectionManager.addConnection(bad, bad.getScriptingName());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of com.neuronrobotics.sdk.common.BowlerAbstractDevice in project BowlerStudio by CommonWealthRobotics.
the class AbstractBowlerStudioTab method setDevice.
public void setDevice(BowlerAbstractDevice pm) {
myNames = new ArrayList<>();
if (getMyNameSpaces().length > 0) {
for (int i = 0; i < getMyNameSpaces().length; i++) {
myNames.add(getMyNameSpaces()[i]);
}
if (!isMyNamespace(pm.getNamespaces())) {
throw new RuntimeException("Device and namespaces are incompatible ");
}
}
setOnCloseRequest(this);
initializeUI(pm);
pm.addConnectionEventListener(new IDeviceConnectionEventListener() {
@Override
public void onDisconnect(BowlerAbstractDevice source) {
// if the device disconnects, close the tab
if (source == pm && source != null) {
requestClose();
if (MobileBase.class.isInstance(pm)) {
MobileBase dev = (MobileBase) pm;
try {
for (CSG p : MobileBaseCadManager.get(dev).getBasetoCadMap().get(dev)) BowlerStudioController.removeObject(p);
for (DHParameterKinematics leg : dev.getAllDHChains()) for (CSG p : MobileBaseCadManager.get(dev).getDHtoCadMap().get(leg)) BowlerStudioController.removeObject(p);
} catch (Throwable e) {
}
}
} else {
// Not a bug, expected to ensure one device disconnects the rest of the dependent devices
// System.err.println("Device type was "+source.getClass()+" named "+source.getScriptingName()+" expected "+pm.getClass()+" named "+pm.getScriptingName());
// new Exception().printStackTrace();
}
}
@Override
public void onConnect(BowlerAbstractDevice source) {
// TODO Auto-generated method stub
}
});
}
Aggregations