Skip to content

Commit

Permalink
Tested using NullDriver.
Browse files Browse the repository at this point in the history
* Added simulated Homing Error corrected by Visual Homing
* Added simulated non-squareness corrected by Linear Axis Non-Squareness Transformation
* Added simulated vibration to test Camera Settle
* Added simulated camera noise to test Camera Settle
* Added simulated nozzle runout to test Runout Compensation
No Unit yet.
  • Loading branch information
markmaker committed May 12, 2020
1 parent c08725c commit 4b389c7
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 62 deletions.
46 changes: 23 additions & 23 deletions src/main/java/org/openpnp/machine/reference/ReferenceHead.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,30 @@ public void home() throws Exception {
*/
HeadMountable hm = getDefaultCamera();
Part homePart = Configuration.get().getPart("FIDUCIAL-HOME");
if (homePart != null) {
Location homingLocation = Configuration.get().getMachine().getFiducialLocator()
.getHomeFiducialLocation(getHomingFiducialLocation(), homePart);

if (homingLocation == null) {
// Homing failed
throw new Exception("Visual homing failed");
}
if (homePart == null) {
throw new Exception("Visual homing is missing the FIDUCIAL-HOME part. Please create it.");
}
Location homingLocation = Configuration.get().getMachine().getFiducialLocator()
.getHomeFiducialLocation(getHomingFiducialLocation(), homePart);
if (homingLocation == null) {
// Homing failed
throw new Exception("Visual homing failed");
}

ReferenceMachine machine = getMachine();
MappedAxes mappedAxes = hm.getMappedAxes(machine);
AxesLocation axesHomingLocation;
if (getVisualHomingMethod() == VisualHomingMethod.ResetToFiducialLocation) {
// Convert to raw coordinates;
axesHomingLocation = hm.toRaw(hm.toHeadLocation(getHomingFiducialLocation()));
}
else {
axesHomingLocation = mappedAxes.getHomeLocation();
}

// Reset the homing fiducial location as the new current location.
for (Driver driver : mappedAxes.getMappedDrivers(machine)) {
((ReferenceDriver) driver).resetLocation(machine, new MappedAxes(mappedAxes, driver), axesHomingLocation);
}
ReferenceMachine machine = getMachine();
MappedAxes mappedAxes = hm.getMappedAxes(machine);
AxesLocation axesHomingLocation;
if (getVisualHomingMethod() == VisualHomingMethod.ResetToFiducialLocation) {
// Convert to raw coordinates;
axesHomingLocation = hm.toRaw(hm.toHeadLocation(getHomingFiducialLocation()));
}
else {
axesHomingLocation = mappedAxes.getHomeLocation();
}

// Reset the homing fiducial location as the new current location.
for (Driver driver : mappedAxes.getMappedDrivers(machine)) {
((ReferenceDriver) driver).resetLocation(machine, new MappedAxes(mappedAxes, driver), axesHomingLocation);
}
}
// Now that the machine is physically homed, do the logical homing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,24 @@ public double[] getLinearTransform() throws Exception {
}


public static double [] getLinearTransform(ReferenceLinearTransformAxis axis) throws Exception {
private static double [] getLinearTransform(ReferenceLinearTransformAxis axis, double [] unit) throws Exception {
if (axis != null) {
return axis.getLinearTransform();
}
return new double [] { 0, 0, 0, 0, 0 };
return unit;
}

private static double getLinearCoordinate(AxesLocation location,
ReferenceLinearTransformAxis linearAxis, AbstractAxis inputAxis) {
if (linearAxis != null) {
return location.getCoordinate(linearAxis);
}
else {
return location.getCoordinate(inputAxis);
}
}


@Override
public AxesLocation toTransformed(AxesLocation location) {
location = AbstractTransformedAxis.toTransformed(inputAxisX, location);
Expand Down Expand Up @@ -263,21 +274,21 @@ public AxesLocation toRaw(AxesLocation location) throws Exception {
}
// Query each axis for its Affine Transform vector.
double [][] affineTransform = new double [][] {
ReferenceLinearTransformAxis.getLinearTransform(linearAxes[0]),
ReferenceLinearTransformAxis.getLinearTransform(linearAxes[1]),
ReferenceLinearTransformAxis.getLinearTransform(linearAxes[2]),
ReferenceLinearTransformAxis.getLinearTransform(linearAxes[3]),
ReferenceLinearTransformAxis.getLinearTransform(linearAxes[0], new double [] { 1, 0, 0, 0, 0}),
ReferenceLinearTransformAxis.getLinearTransform(linearAxes[1], new double [] { 0, 1, 0, 0, 0}),
ReferenceLinearTransformAxis.getLinearTransform(linearAxes[2], new double [] { 0, 0, 1, 0, 0}),
ReferenceLinearTransformAxis.getLinearTransform(linearAxes[3], new double [] { 0, 0, 0, 1, 0}),
{ 0, 0, 0, 0, 1 }
};

// Compute the inverse.
double [][] invertedAffineTransform = Matrix.inverse(affineTransform);
// Get the transformed vector by querying the linear axes' coordinates.
double [][] transformedVector = new double [][] {
{ location.getCoordinate(linearAxes[0]) },
{ location.getCoordinate(linearAxes[1]) },
{ location.getCoordinate(linearAxes[2]) },
{ location.getCoordinate(linearAxes[3]) },
{ ReferenceLinearTransformAxis.getLinearCoordinate(location, linearAxes[0], inputAxes[0]) },
{ ReferenceLinearTransformAxis.getLinearCoordinate(location, linearAxes[1], inputAxes[1]) },
{ ReferenceLinearTransformAxis.getLinearCoordinate(location, linearAxes[2], inputAxes[2]) },
{ ReferenceLinearTransformAxis.getLinearCoordinate(location, linearAxes[3], inputAxes[3]) },
{ 1 }
};
// Calculate the raw vector by applying the inverdet Affine Transform.
Expand All @@ -289,12 +300,11 @@ public AxesLocation toRaw(AxesLocation location) throws Exception {
location = location.put(new AxesLocation(inputAxes[3], rawVector[3][0]));
// Recurse input axes to raw.
location = AbstractTransformedAxis.toRaw(inputAxes[0], location);
location = AbstractTransformedAxis.toRaw(inputAxes[1], location);
location = AbstractTransformedAxis.toRaw(inputAxes[2], location);
location = AbstractTransformedAxis.toRaw(inputAxes[3], location);
location = AbstractTransformedAxis.toRaw(inputAxes[4], location);
return location;
}

protected void consolidateInputAxes(Axis axis, AbstractAxis inputAxis, Axis.Type inputType,
AbstractAxis[] inputAxes) throws Exception {
int j = inputType.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

package org.openpnp.machine.reference.camera;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeSupport;
import java.net.URL;
Expand Down Expand Up @@ -129,11 +132,10 @@ public synchronized BufferedImage internalCapture() {
*/
BufferedImage frame = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

Graphics gFrame = frame.getGraphics();
Graphics2D gFrame = frame.createGraphics();
gFrame.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

Location location = getLocation()
.convertToUnits(LengthUnit.Millimeters);
location = NullDriver.simulateImperfectLocation(location, getLooking());
Location location = NullDriver.getSimulatedPhysicalLocation(this, getLooking());

double locationX = location.getX();
double locationY = location.getY();
Expand All @@ -146,12 +148,15 @@ public synchronized BufferedImage internalCapture() {

gFrame.drawImage(source, 0, 0, width - 1, height - 1, dx1, dy1, dx1 + width - 1,
dy1 + height - 1, null);

NullDriver.drawSimulatedCameraNoise(gFrame, width, height);

gFrame.dispose();

return frame;
}


private synchronized void initialize() throws Exception {
stop();

Expand All @@ -173,7 +178,7 @@ public void run() {
while (!Thread.interrupted()) {
broadcastCapture(captureForPreview());
try {
Thread.sleep(1000 / fps);
Thread.sleep(100 / fps);
}
catch (InterruptedException e) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
import org.openpnp.CameraListener;
import org.openpnp.gui.support.Wizard;
import org.openpnp.machine.reference.ReferenceCamera;
import org.openpnp.machine.reference.ReferenceHeadMountable;
import org.openpnp.machine.reference.ReferenceMachine;
import org.openpnp.machine.reference.camera.wizards.SimulatedUpCameraConfigurationWizard;
import org.openpnp.machine.reference.driver.NullDriver;
import org.openpnp.model.AxesLocation;
import org.openpnp.model.Configuration;
import org.openpnp.model.Footprint;
import org.openpnp.model.LengthUnit;
import org.openpnp.model.Location;
import org.openpnp.model.MappedAxes;
import org.openpnp.model.Part;
import org.openpnp.spi.Head;
import org.openpnp.spi.Machine;
Expand Down Expand Up @@ -76,17 +79,19 @@ public BufferedImage internalCapture() {
for (Head head : Configuration.get()
.getMachine().getHeads()) {
for (Nozzle nozzle : head.getNozzles()) {
Location l = nozzle.getLocation()
.convertToUnits(LengthUnit.Millimeters);
l = NullDriver.simulateImperfectLocation(l, getLooking());
Location l = NullDriver.getSimulatedPhysicalLocation(nozzle, getLooking());
if (phyBounds.contains(l.getX(), l.getY())) {
drawNozzle(g, nozzle);
}
}
}

g.setTransform(tx);

NullDriver.drawSimulatedCameraNoise(g, width, height);

g.dispose();

return image;
}

Expand All @@ -100,9 +105,7 @@ private void drawNozzle(Graphics2D g, Nozzle nozzle) {

// Draw the nozzle
// Get nozzle offsets from camera
Location l = nozzle.getLocation()
.convertToUnits(LengthUnit.Millimeters);
l = NullDriver.simulateImperfectLocation(l, getLooking());
Location l = NullDriver.getSimulatedPhysicalLocation(nozzle, getLooking());
Location offsets = l.subtractWithRotation(getLocation());

// Create a nozzle shape
Expand Down

0 comments on commit 4b389c7

Please sign in to comment.