use of com.neuronrobotics.sdk.dyio.peripherals.IDigitalInputListener 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);
}
});
}
Aggregations