Skip to content

Commit

Permalink
Reworked Drivers to flat list.
Browse files Browse the repository at this point in the history
  • Loading branch information
markmaker committed May 2, 2020
1 parent 51ea613 commit e61af78
Show file tree
Hide file tree
Showing 21 changed files with 524 additions and 219 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/openpnp/gui/support/Icons.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public class Icons {
public static Icon processActivity1Icon = getIcon("/icons/process-activity-1.svg");
public static Icon processActivity2Icon = getIcon("/icons/process-activity-2.svg");

public static Icon axisAll = getIcon("/icons/axis-all.svg");
public static Icon driver = getIcon("/icons/driver.svg");

public static Icon getIcon(String resourceName, int width, int height) {
if (resourceName.endsWith(".svg")) {
return new SvgIcon(Icons.class.getResource(resourceName), width, height);
Expand Down
14 changes: 1 addition & 13 deletions src/main/java/org/openpnp/machine/neoden4/NeoDen4Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ public class NeoDen4Driver extends AbstractReferenceDriver implements Named {

@Attribute(required = false)
protected int connectWaitTimeMilliseconds = 3000;

@Attribute(required = false)
protected String name = "NeoDen4Driver";


@Attribute(required = false)
protected double homeCoordinateX = -437.;

Expand Down Expand Up @@ -866,16 +863,7 @@ public PropertySheet[] getPropertySheets() {
new PropertySheetWizardAdapter(new Neoden4DriverConfigurationWizard(this), "Machine")
};
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
firePropertyChange("name", null, getName());
}

public LengthUnit getUnits() {
return units;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.Closeable;

import org.openpnp.model.Location;
import org.openpnp.spi.Driver;
import org.openpnp.spi.PropertySheetHolder;
import org.openpnp.spi.WizardConfigurable;

Expand All @@ -37,7 +38,7 @@
* movements by one of these objects. This allows the driver to make decisions as to what axes
* should be moved to accomplish a specific task.
*/
public interface ReferenceDriver extends WizardConfigurable, PropertySheetHolder, Closeable {
public interface ReferenceDriver extends Driver, WizardConfigurable, PropertySheetHolder, Closeable {
/**
* Performing the hardware homing operation for the given Head. When this call completes the
* Head should be at it's 0,0,0,0 position.
Expand Down
68 changes: 49 additions & 19 deletions src/main/java/org/openpnp/machine/reference/ReferenceMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.openpnp.gui.support.PropertySheetWizardAdapter;
import org.openpnp.gui.support.Wizard;
import org.openpnp.machine.marek.MarekNozzle;
import org.openpnp.machine.neoden4.NeoDen4Driver;
import org.openpnp.machine.neoden4.Neoden4Camera;
import org.openpnp.machine.reference.camera.ImageCamera;
import org.openpnp.machine.reference.camera.OnvifIPCamera;
Expand All @@ -39,6 +40,7 @@
import org.openpnp.machine.reference.camera.SimulatedUpCamera;
import org.openpnp.machine.reference.camera.SwitcherCamera;
import org.openpnp.machine.reference.camera.Webcams;
import org.openpnp.machine.reference.driver.GcodeDriver;
import org.openpnp.machine.reference.driver.NullDriver;
import org.openpnp.machine.reference.feeder.AdvancedLoosePartFeeder;
import org.openpnp.machine.reference.feeder.BlindsFeeder;
Expand All @@ -57,6 +59,7 @@
import org.openpnp.machine.reference.psh.ActuatorsPropertySheetHolder;
import org.openpnp.machine.reference.psh.AxesPropertySheetHolder;
import org.openpnp.machine.reference.psh.CamerasPropertySheetHolder;
import org.openpnp.machine.reference.psh.DriversPropertySheetHolder;
import org.openpnp.machine.reference.psh.NozzleTipsPropertySheetHolder;
import org.openpnp.machine.reference.psh.SignalersPropertySheetHolder;
import org.openpnp.machine.reference.signaler.ActuatorSignaler;
Expand All @@ -68,6 +71,7 @@
import org.openpnp.spi.Actuator;
import org.openpnp.spi.Axis;
import org.openpnp.spi.Camera;
import org.openpnp.spi.Driver;
import org.openpnp.spi.Feeder;
import org.openpnp.spi.FiducialLocator;
import org.openpnp.spi.Head;
Expand All @@ -83,8 +87,9 @@
import org.simpleframework.xml.core.Commit;

public class ReferenceMachine extends AbstractMachine {
@Deprecated
@Element(required = false)
private ReferenceDriver driver = new NullDriver();
private ReferenceDriver driver = null;

@Element(required = false)
protected PnpJobProcessor pnpJobProcessor = new ReferencePnpJobProcessor();
Expand All @@ -103,21 +108,18 @@ public class ReferenceMachine extends AbstractMachine {

private List<Class<? extends Feeder>> registeredFeederClasses = new ArrayList<>();

private List<Class<? extends Driver>> registeredDriverClasses = new ArrayList<>();

@Commit
protected void commit() {
super.commit();
}

@Deprecated
public ReferenceDriver getDriver() {
return driver;
}

public void setDriver(ReferenceDriver driver) throws Exception {
if (driver != this.driver) {
setEnabled(false);
close();
}
this.driver = driver;
// TODO: all callers must do axis mapping.
// For now, just return the first Driver
return (ReferenceDriver) drivers.get(0);
}

public ReferenceMachine() {
Expand All @@ -130,6 +132,20 @@ public void configurationLoaded(Configuration configuration)
if (partAlignments.isEmpty()) {
partAlignments.add(new ReferenceBottomVision());
}
// Migrate the one-driver property to the list of drivers.
// Also migrate the GcodeDriver specific sub-drivers.
if (driver != null) {
addDriver(driver);
if (driver instanceof GcodeDriver) {
GcodeDriver gcodeDriver= (GcodeDriver)driver;
drivers.addAll(gcodeDriver.getSubDrivers());
}
driver = null;
}
// But if this is a brand new Machine, create a NullDriver.
if (drivers.isEmpty()) {
drivers.add(new NullDriver());
}
}
});
}
Expand All @@ -144,7 +160,9 @@ public void setEnabled(boolean enabled) throws Exception {
Logger.debug("setEnabled({})", enabled);
if (enabled) {
try {
driver.setEnabled(true);
for (Driver driver : getDrivers()) {
((ReferenceDriver)driver).setEnabled(true);
}
this.enabled = true;
}
catch (Exception e) {
Expand All @@ -155,7 +173,9 @@ public void setEnabled(boolean enabled) throws Exception {
}
else {
try {
driver.setEnabled(false);
for (Driver driver : getDrivers()) {
((ReferenceDriver)driver).setEnabled(false);
}
this.enabled = false;
}
catch (Exception e) {
Expand Down Expand Up @@ -189,8 +209,7 @@ public PropertySheetHolder[] getChildPropertySheetHolders() {
children.add(new NozzleTipsPropertySheetHolder("Nozzle Tips", getNozzleTips(), null));
children.add(new CamerasPropertySheetHolder(null, "Cameras", getCameras(), null));
children.add(new ActuatorsPropertySheetHolder(null, "Actuators", getActuators(), null));
children.add(
new SimplePropertySheetHolder("Driver", Collections.singletonList(getDriver())));
children.add(new DriversPropertySheetHolder(this, "Drivers", getDrivers(), null));
children.add(new SimplePropertySheetHolder("Job Processors",
Arrays.asList(getPnpJobProcessor())));

Expand Down Expand Up @@ -286,6 +305,15 @@ public List<Class<? extends Signaler>> getCompatibleSignalerClasses() {
return l;
}

@Override
public List<Class<? extends Driver>> getCompatibleDriverClasses() {
List<Class<? extends Driver>> l = new ArrayList<>();
l.add(NullDriver.class);
l.add(GcodeDriver.class);
l.add(NeoDen4Driver.class);
return l;
}

private List<Class<? extends PartAlignment>> registeredAlignmentClasses = new ArrayList<>();

@Override
Expand All @@ -310,11 +338,13 @@ public void home() throws Exception {

@Override
public void close() throws IOException {
try {
driver.close();
}
catch (Exception e) {
e.printStackTrace();
for (Driver driver : getDrivers()) {
try {
driver.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
for (Camera camera : getCameras()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ public Wizard getConfigurationWizard() {

@Override
public Location transformToRaw(Location location) {
return null;
switch(type) {
case X:
return location.derive(-location.getX(), null, null, null);
case Y:
return location.derive(null, -location.getY(), null, null);
case Z:
return location.derive(null, null, -location.getZ(), null);
case Rotation:
return location.derive(null, null, null, -location.getRotation());
default:
return location;
}
}

@Override
public Location transformFromRaw(Location location) {
return null;
// it's reversible
return transformToRaw(location);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import org.openpnp.machine.reference.driver.wizards.AbstractReferenceDriverConfigurationWizard;
import org.openpnp.model.AbstractModelObject;
import org.openpnp.spi.PropertySheetHolder;
import org.openpnp.spi.base.AbstractDriver;
import org.pmw.tinylog.Logger;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.core.Commit;

public abstract class AbstractReferenceDriver extends AbstractModelObject implements ReferenceDriver, Closeable {
public abstract class AbstractReferenceDriver extends AbstractDriver implements ReferenceDriver {
@Element(required = false)
protected SerialPortCommunications serial = new SerialPortCommunications();

Expand Down Expand Up @@ -221,27 +222,6 @@ public void setPort(int port) {
tcp.setPort(port);
}


@Override
public Icon getPropertySheetHolderIcon() {
return null;
}

@Override
public String getPropertySheetHolderTitle() {
return getClass().getSimpleName();
}

@Override
public PropertySheetHolder[] getChildPropertySheetHolders() {
return null;
}

@Override
public Action[] getPropertySheetHolderActions() {
return null;
}

@Override
public PropertySheet[] getPropertySheets() {
return new PropertySheet[]{new PropertySheetWizardAdapter(getConfigurationWizard())};
Expand Down
44 changes: 21 additions & 23 deletions src/main/java/org/openpnp/machine/reference/driver/GcodeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,13 @@ private Command() {
@ElementList(required = false, inline = true)
public ArrayList<Command> commands = new ArrayList<>();

@Deprecated
@ElementList(required = false)
protected List<GcodeDriver> subDrivers = new ArrayList<>();

@ElementList(required = false)
protected List<Axis> axes = new ArrayList<>();

@Attribute(required = false)
protected String name = "GcodeDriver";

private Thread readerThread;
private boolean disconnectRequested;
private boolean connected;
Expand Down Expand Up @@ -1120,6 +1118,20 @@ static protected boolean hasVariable(String command, String name) {
}



@Override
public PropertySheet[] getPropertySheets() {
return new PropertySheet[] {
new PropertySheetWizardAdapter(new GcodeDriverSettings(this), "Driver Settings"),
new PropertySheetWizardAdapter(new GcodeDriverGcodes(this), "Gcode"),
new PropertySheetWizardAdapter(new GcodeDriverConsole(this), "Console"),
new PropertySheetWizardAdapter(super.getConfigurationWizard(), "Communications")
};
}

/*
*
*
@Override
public String getPropertySheetHolderTitle() {
return getName() == null ? "GcodeDriver" : getName();
Expand All @@ -1133,16 +1145,6 @@ public PropertySheetHolder[] getChildPropertySheetHolders() {
}
return children.toArray(new PropertySheetHolder[] {});
}

@Override
public PropertySheet[] getPropertySheets() {
return new PropertySheet[] {
new PropertySheetWizardAdapter(new GcodeDriverGcodes(this), "Gcode"),
new PropertySheetWizardAdapter(new GcodeDriverSettings(this), "General Settings"),
new PropertySheetWizardAdapter(new GcodeDriverConsole(this), "Console"),
new PropertySheetWizardAdapter(super.getConfigurationWizard(), "Communications")
};
}
@Override
public Action[] getPropertySheetHolderActions() {
Expand Down Expand Up @@ -1189,7 +1191,7 @@ public void actionPerformed(ActionEvent arg0) {
}
}
};

*/
public LengthUnit getUnits() {
return units;
}
Expand Down Expand Up @@ -1270,15 +1272,6 @@ public void setConnectWaitTimeMilliseconds(int connectWaitTimeMilliseconds) {
this.connectWaitTimeMilliseconds = connectWaitTimeMilliseconds;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
firePropertyChange("name", null, getName());
}

public boolean isVisualHomingEnabled() {
return visualHomingEnabled;
}
Expand All @@ -1295,6 +1288,11 @@ public void setBackslashEscapedCharactersEnabled(boolean backslashEscapedCharact
this.backslashEscapedCharactersEnabled = backslashEscapedCharactersEnabled;
}

@Deprecated
public List<GcodeDriver> getSubDrivers() {
return subDrivers;
}

public static class Axis {
public enum Type {
X,
Expand Down

0 comments on commit e61af78

Please sign in to comment.