Skip to content

Commit

Permalink
Resolved openpnp#998 merging issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
markmaker committed May 10, 2020
1 parent 0139331 commit b36f6e9
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public boolean isInsideSoftLimits(HeadMountable hm, Location location) throws E
*/
if (hm instanceof ReferenceHeadMountable) {
Location cameraLocation = ((AbstractHeadMountable) hm).toHeadLocation(location);
cameraLocation = ((ReferenceCamera) getDefaultCamera()).fromHeadLocation(cameraLocation);
cameraLocation = ((ReferenceCamera) getDefaultCamera()).toHeadMountableLocation(cameraLocation);
Location minLocation = this.minLocation.convertToUnits(cameraLocation.getUnits());
Location maxLocation = this.maxLocation.convertToUnits(cameraLocation.getUnits());
if (cameraLocation.getX() < minLocation.getX() || cameraLocation.getX() > maxLocation.getX() ||
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/org/openpnp/machine/reference/ReferenceNozzle.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.openpnp.spi.Nozzle;
import org.openpnp.spi.NozzleTip;
import org.openpnp.spi.PropertySheetHolder;
import org.openpnp.spi.Movable.MoveToOption;
import org.openpnp.spi.base.AbstractNozzle;
import org.openpnp.util.MovableUtils;
import org.openpnp.util.SimpleGraph;
Expand Down Expand Up @@ -334,7 +335,7 @@ public boolean isCalibrated() {
}

@Override
public Location toHeadLocation(Location location, Location currentLocation) {
public Location toHeadLocation(Location location, Location currentLocation, LocationOption... options) {
location = super.toHeadLocation(location, currentLocation);
// Nozzle rotation handling
if (limitRotation) {
Expand All @@ -348,6 +349,12 @@ public Location toHeadLocation(Location location, Location currentLocation) {
}
// Apply runout compensation.
ReferenceNozzleTip calibrationNozzleTip = getCalibrationNozzleTip();
// check if totally raw move, in that case disable nozzle calibration
for (LocationOption option: options) {
if (option == LocationOption.SuppressCompensation) {
calibrationNozzleTip = null;
}
}
if (calibrationNozzleTip != null && calibrationNozzleTip.getCalibration().isCalibrated(this)) {
Location correctionOffset = calibrationNozzleTip.getCalibration().getCalibratedOffset(this, location.getRotation());
location = location.subtract(correctionOffset);
Expand All @@ -359,10 +366,16 @@ public Location toHeadLocation(Location location, Location currentLocation) {
}

@Override
public Location fromHeadLocation(Location location, Location currentLocation) {
location = super.fromHeadLocation(location, currentLocation);
public Location toHeadMountableLocation(Location location, Location currentLocation, LocationOption... options) {
location = super.toHeadMountableLocation(location, currentLocation);
// Unapply runout compensation.
ReferenceNozzleTip calibrationNozzleTip = getCalibrationNozzleTip();
// Check SuppressCompensation, in that case disable nozzle calibration.
for (LocationOption option: options) {
if (option == LocationOption.SuppressCompensation) {
calibrationNozzleTip = null;
}
}
if (calibrationNozzleTip != null && calibrationNozzleTip.getCalibration().isCalibrated(this)) {
Location offset =
calibrationNozzleTip.getCalibration().getCalibratedOffset(this, location.getRotation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ public void moveTo(ReferenceHeadMountable hm, MappedAxes mappedAxes, Location lo
for (MoveToOption currentOption: options) {
switch (currentOption) {
case SpeedOverPrecision: // for this move backslash is zero
case RawMove: // for this move all corrections are zero
enableBacklash = false;
break;
}
Expand Down
21 changes: 18 additions & 3 deletions src/main/java/org/openpnp/spi/Movable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,27 @@
public interface Movable extends Locatable {
/**
* Contains all possible options for the moveTo command.
* RawMove: disable all internal corrections, just tell the driver to move to that position
* SpeedOverPrecision: disable backslash compensation or anything else, that causes additional moves
*/
public enum MoveToOption { RawMove, SpeedOverPrecision }
public enum MoveToOption { SpeedOverPrecision }

/**
* Contains all possible options for getting approximative locations.
* KeepX, KeepY, KeepZ, KeepRotation: keep these raw coordinates the same.
* SuppressCompensation: calculate a location that will result in no extra moves for compensation.
*/
public enum LocationOption { KeepX, KeepY, KeepZ, KeepRotation, SuppressCompensation }

/**
* Get an approximative Location in order to avoid extra compensation moves.
*
* @param currentLocation The current location, usually obtained using Headmountable.getLocation()
* @param desiredLocation The desired location to approximate.
* @param options Options for the approximation.
* @return
*/
Location getApproximativeLocation(Location currentLocation, Location desiredLocation, LocationOption... options);


/**
* Move the object to the Location at the feedRate.
*
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/openpnp/spi/MovableMountable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.openpnp.model.Location;
import org.openpnp.model.MappedAxes;
import org.openpnp.spi.Movable.LocationOption;

/**
* Anything that can be mounted to the machine and is Movable has an association
Expand All @@ -21,7 +22,7 @@ public interface MovableMountable extends Movable {

MappedAxes getMappedAxes();

Location toTransformed(Location location);
Location toTransformed(Location location, LocationOption... options);

Location toRaw(Location location);
Location toRaw(Location location, LocationOption... options);
}
57 changes: 47 additions & 10 deletions src/main/java/org/openpnp/spi/base/AbstractHeadMountable.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.openpnp.model.Location;
import org.openpnp.model.MappedAxes;
import org.openpnp.spi.Axis;
import org.openpnp.spi.Movable.LocationOption;
import org.openpnp.spi.Movable.MoveToOption;
import org.openpnp.util.Matrix;
import org.pmw.tinylog.Logger;
Expand Down Expand Up @@ -151,7 +152,7 @@ public MappedAxes getMappedAxes() {
AbstractAxis.getControllerAxis(axisRotation));
}

public Location toHeadLocation(Location location, Location currentLocation) {
public Location toHeadLocation(Location location, Location currentLocation, LocationOption... options) {
// Shortcut Double.NaN. Sending Double.NaN in a Location is an old API that should no
// longer be used. It will be removed eventually:
// https://github.com/openpnp/openpnp/issues/255
Expand All @@ -166,11 +167,11 @@ public Location toHeadLocation(Location location, Location currentLocation) {
location = location.subtract(getHeadOffsets());
return location;
}
final public Location toHeadLocation(Location location) {
return toHeadLocation(location, getLocation());
final public Location toHeadLocation(Location location, LocationOption... options) {
return toHeadLocation(location, getLocation(), options);
}

public Location fromHeadLocation(Location location, Location currentLocation) {
public Location toHeadMountableLocation(Location location, Location currentLocation, LocationOption... options) {
if (currentLocation != null) {
// Shortcut Double.NaN. Sending Double.NaN in a Location is an old API that should no
// longer be used. It will be removed eventually:
Expand All @@ -187,22 +188,22 @@ public Location fromHeadLocation(Location location, Location currentLocation) {
location = location.add(getHeadOffsets());
return location;
}
final public Location fromHeadLocation(Location location) {
return fromHeadLocation(location, null);
final public Location toHeadMountableLocation(Location location, LocationOption... options) {
return toHeadMountableLocation(location, null, options);
}

@Override
public Location toTransformed(Location location) {
public Location toTransformed(Location location, LocationOption... options) {
// The forward transformation is easy, as it can be done axis by axis.
double x = AbstractTransformedAxis.toTransformed(axisX, location);
double y = AbstractTransformedAxis.toTransformed(axisY, location);
double z = AbstractTransformedAxis.toTransformed(axisZ, location);
double rotation = AbstractTransformedAxis.toTransformed(axisRotation, location);
return new Location (location.getUnits(), x, y, z, rotation);
return new Location(location.getUnits(), x, y, z, rotation);
}

@Override
public Location toRaw(Location location) {
public Location toRaw(Location location, LocationOption... options) {
// The backward transformation is a bit more complicated, as it may have transformations
// based on multiple input axis. Currently we only allow linear transformations and only
// at the last stage. Given this simplification we can solve the inverse by inverting the
Expand Down Expand Up @@ -234,7 +235,43 @@ public Location getLocation() {
MappedAxes mappedAxes = getMappedAxes();
Location location = toTransformed(mappedAxes.getLocation(null));
// From head to HeadMountable.
location = fromHeadLocation(location);
location = toHeadMountableLocation(location);
return location;
}

@Override
public Location getApproximativeLocation(Location currentLocation, Location desiredLocation, LocationOption... options) {
// Convert the desired location to a raw location, applying the approximation options,
// which means some extra motion for compensation effects is suppressed.
Location desiredHeadLocation = toHeadLocation(desiredLocation, options);
Location currentHeadLocation = toHeadLocation(currentLocation);
Location desiredRawLocation = toRaw(desiredHeadLocation, options);
Location currentRawLocation = toRaw(currentHeadLocation);
Location aproximativeRawLocation = desiredRawLocation;
// Evaluate the Keep options.
for (LocationOption option: options) {
switch (option) {
case KeepX:
desiredRawLocation = desiredRawLocation.derive(currentRawLocation, true, false, false, false);
break;
case KeepY:
desiredRawLocation = desiredRawLocation.derive(currentRawLocation, false, true, false, false);
break;
case KeepZ:
desiredRawLocation = desiredRawLocation.derive(currentRawLocation, false, false, true, false);
break;
case KeepRotation:
desiredRawLocation = desiredRawLocation.derive(currentRawLocation, false, false, false, true);
break;
default:
break;
}
}
// Now convert it back NOT applying any options, i.e. when a moveTo() is later made,
// effectively reversing the option-less transformation, the result will be the same.
// The approximation will in effect be applied.
Location headApproximativeLocation = toTransformed(desiredRawLocation);
Location approximativeLocation = toHeadMountableLocation(headApproximativeLocation);
return approximativeLocation;
}
}

0 comments on commit b36f6e9

Please sign in to comment.