diff --git a/CHANGES.md b/CHANGES.md index db7731371a7..ed202449246 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,28 @@ a complete change list, only those that may directly interest or affect users. # 2017-06-28 +* CvPipeline Properties (Breaking Change) + + In an effort to make it easier for developers to integrate custom functionality in CvPipelines, + the pipeline now has a map of properties that can be set be callers. This allows callers of + a pipeline to feed values in for the pipeline to use. This can be things like cameras, feeders, + parts, nozzles, etc. + + This functionality replaces the previously added setFeeder and setNozzle calls. These calls + were too specific to certain pipelines and did not represent a good development direction + for the pipeline as it would eventually become cluttered with variables that did not + make sense for the pipeline as a whole. + + Breaking Change: All existing stages have been migrated to the property system. If you have + custom stages that used getNozzle or getFeeder you will need to make minor updates to switch + these to use properties instead. + + * getNozzle() becomes (Nozzle) getProperty("nozzle") + * getFeeder() becomes (Feeder) getProperty("feeder") + + Finally, this change is the first step into supporting variables in CvPipeline. Eventually + you will be able to reference proeprties and other objects when setting parameters in stages. + * AdvancedLoosePartFeeder ReferenceLoosePartFeeder has received a big upgrade thanks to @dzach. The diff --git a/src/main/java/org/openpnp/machine/reference/feeder/AdvancedLoosePartFeeder.java b/src/main/java/org/openpnp/machine/reference/feeder/AdvancedLoosePartFeeder.java index d532bb2d256..d2b1c4072bc 100644 --- a/src/main/java/org/openpnp/machine/reference/feeder/AdvancedLoosePartFeeder.java +++ b/src/main/java/org/openpnp/machine/reference/feeder/AdvancedLoosePartFeeder.java @@ -71,9 +71,9 @@ public void feed(Nozzle nozzle) throws Exception { private Location getPickLocation(Camera camera, Nozzle nozzle) throws Exception { // Process the pipeline to extract RotatedRect results - pipeline.setCamera(camera); - pipeline.setNozzle(nozzle); - pipeline.setFeeder(this); + pipeline.setProperty("camera", camera); + pipeline.setProperty("nozzle", nozzle); + pipeline.setProperty("feeder", this); pipeline.process(); // Grab the results List results = (List) pipeline.getResult("results").model; diff --git a/src/main/java/org/openpnp/machine/reference/feeder/wizards/AdvancedLoosePartFeederConfigurationWizard.java b/src/main/java/org/openpnp/machine/reference/feeder/wizards/AdvancedLoosePartFeederConfigurationWizard.java index 75a02b731fe..0476f2e3bc2 100644 --- a/src/main/java/org/openpnp/machine/reference/feeder/wizards/AdvancedLoosePartFeederConfigurationWizard.java +++ b/src/main/java/org/openpnp/machine/reference/feeder/wizards/AdvancedLoosePartFeederConfigurationWizard.java @@ -105,8 +105,8 @@ public AdvancedLoosePartFeederConfigurationWizard(AdvancedLoosePartFeeder feeder private void editPipeline() throws Exception { CvPipeline pipeline = feeder.getPipeline(); - pipeline.setCamera(Configuration.get().getMachine().getDefaultHead().getDefaultCamera()); - pipeline.setFeeder(feeder); + pipeline.setProperty("camera", Configuration.get().getMachine().getDefaultHead().getDefaultCamera()); + pipeline.setProperty("feeder", feeder); CvPipelineEditor editor = new CvPipelineEditor(pipeline); JDialog dialog = new JDialog(MainFrame.get(), feeder.getPart().getId() + " Pipeline"); dialog.getContentPane().setLayout(new BorderLayout()); @@ -121,8 +121,8 @@ private void resetPipeline() { private void editTrainingPipeline() throws Exception { CvPipeline pipeline = feeder.getTrainingPipeline(); - pipeline.setCamera(Configuration.get().getMachine().getDefaultHead().getDefaultCamera()); - pipeline.setFeeder(feeder); + pipeline.setProperty("camera", Configuration.get().getMachine().getDefaultHead().getDefaultCamera()); + pipeline.setProperty("feeder", feeder); CvPipelineEditor editor = new CvPipelineEditor(pipeline); JDialog dialog = new JDialog(MainFrame.get(), feeder.getPart().getId() + " Training Pipeline"); dialog.getContentPane().setLayout(new BorderLayout()); diff --git a/src/main/java/org/openpnp/vision/pipeline/stages/ReadPartTemplateImage.java b/src/main/java/org/openpnp/vision/pipeline/stages/ReadPartTemplateImage.java index edf45075be1..94e0a78396b 100644 --- a/src/main/java/org/openpnp/vision/pipeline/stages/ReadPartTemplateImage.java +++ b/src/main/java/org/openpnp/vision/pipeline/stages/ReadPartTemplateImage.java @@ -30,6 +30,7 @@ import org.opencv.highgui.Highgui; import org.openpnp.model.Configuration; import org.openpnp.spi.Camera; +import org.openpnp.spi.Feeder; import org.openpnp.vision.pipeline.CvPipeline; import org.openpnp.vision.pipeline.CvStage; import org.openpnp.vision.pipeline.Property; @@ -119,9 +120,9 @@ public Result process(CvPipeline pipeline) throws Exception { } } else { + Feeder feeder = (Feeder) pipeline.getProperty("feeder"); // path is assumed to be a directory containing template images - if (pipeline.getFeeder() == null || pipeline.getFeeder() - .getPart() == null) { + if (feeder == null || feeder.getPart() == null) { if (log) { Logger.info( "No feeder, part, or useable templateFile found. Cannot figure out part name."); @@ -131,17 +132,15 @@ public Result process(CvPipeline pipeline) throws Exception { if (!filepath.endsWith(File.separator)) { filepath += File.separator; } - filename = filepath + pipeline.getFeeder() - .getPart() - .getId() + filename = filepath + feeder.getPart() + .getId() + extension; file = new File(filename); if (!file.exists()) { // try the package id - filename = filepath + pipeline.getFeeder() - .getPart() - .getPackage() - .getId() + filename = filepath + feeder.getPart() + .getPackage() + .getId() + extension; file = new File(filename); if (!file.exists()) { @@ -150,20 +149,17 @@ public Result process(CvPipeline pipeline) throws Exception { // TODO: it would be best if we could define a package outline, e.g. as a // polygon // and use that to draw the part and match templates - if (pipeline.getFeeder() - .getPart() - .getPackage() - .getFootprint() != null) { - width = pipeline.getFeeder() - .getPart() - .getPackage() - .getFootprint() - .getBodyWidth(); - height = pipeline.getFeeder() - .getPart() - .getPackage() - .getFootprint() - .getBodyHeight(); + if (feeder.getPart() + .getPackage() + .getFootprint() != null) { + width = feeder.getPart() + .getPackage() + .getFootprint() + .getBodyWidth(); + height = feeder.getPart() + .getPackage() + .getFootprint() + .getBodyHeight(); if (width == 0 || height == 0) { if (log) { Logger.info("Package body dimensions are not set."); @@ -178,7 +174,7 @@ public Result process(CvPipeline pipeline) throws Exception { height = tmp; } // get length conversion value from camera - Camera camera = pipeline.getCamera(); + Camera camera = (Camera) pipeline.getProperty("camera"); width /= camera.getUnitsPerPixel() .getX(); height /= camera.getUnitsPerPixel() diff --git a/src/main/java/org/openpnp/vision/pipeline/stages/WritePartTemplateImage.java b/src/main/java/org/openpnp/vision/pipeline/stages/WritePartTemplateImage.java index 19961729f7e..6505b11fe59 100644 --- a/src/main/java/org/openpnp/vision/pipeline/stages/WritePartTemplateImage.java +++ b/src/main/java/org/openpnp/vision/pipeline/stages/WritePartTemplateImage.java @@ -23,6 +23,7 @@ import org.opencv.highgui.Highgui; import org.openpnp.model.Configuration; +import org.openpnp.spi.Feeder; import org.openpnp.vision.pipeline.CvPipeline; import org.openpnp.vision.pipeline.CvStage; import org.openpnp.vision.pipeline.Property; @@ -111,9 +112,8 @@ public Result process(CvPipeline pipeline) throws Exception { // path is assumed to be a directory containing template images // check if a part ID can be found from the feeder this pipeline may belong to - - if (pipeline.getFeeder() == null || pipeline.getFeeder() - .getPart() == null) { + Feeder feeder = (Feeder) pipeline.getProperty("feeder"); + if (feeder == null || feeder.getPart() == null) { throw new Exception( "No part in feeder. Please provide create template image file path."); @@ -126,16 +126,14 @@ public Result process(CvPipeline pipeline) throws Exception { filepath += File.separator; } if (asPackage) { - filepath += pipeline.getFeeder() - .getPart() - .getPackage() - .getId() + filepath += feeder.getPart() + .getPackage() + .getId() + extension; } else { - filepath += pipeline.getFeeder() - .getPart() - .getId() + filepath += feeder.getPart() + .getId() + extension; } file = new File(filepath);