Skip to content

Commit

Permalink
refactor to toolehead offset code for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
FarMcKon committed Mar 7, 2012
1 parent 22c39a8 commit 28a1c4e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 65 deletions.
51 changes: 27 additions & 24 deletions src/replicatorg/app/ui/onboard/MachineOnboardParameters.java
Expand Up @@ -81,9 +81,9 @@ public class MachineOnboardParameters extends JPanel {
private JFormattedTextField vref3 = new JFormattedTextField(threePlaces);
private JFormattedTextField vref4 = new JFormattedTextField(threePlaces);

private JFormattedTextField xNozzleOffsetField = new JFormattedTextField(threePlaces);
private JFormattedTextField yNozzleOffsetField = new JFormattedTextField(threePlaces);
private JFormattedTextField zNozzleOffsetField = new JFormattedTextField(threePlaces);
private JFormattedTextField xToolheadOffsetField = new JFormattedTextField(threePlaces);
private JFormattedTextField yToolheadOffsetField = new JFormattedTextField(threePlaces);
private JFormattedTextField zToolheadOffsetField = new JFormattedTextField(threePlaces);


/** Prompts the user to fire a bot reset after the changes have been sent to the board.
Expand Down Expand Up @@ -157,9 +157,9 @@ private void commit() {
target.setStoredStepperVoltage(4, ((Number)vref4.getValue()).intValue());
}

target.eepromStoreToolDelta(0, ((Number)xNozzleOffsetField.getValue()).doubleValue());
target.eepromStoreToolDelta(1, ((Number)yNozzleOffsetField.getValue()).doubleValue());
target.eepromStoreToolDelta(2, ((Number)zNozzleOffsetField.getValue()).doubleValue());
target.eepromStoreToolDelta(0, ((Number)xToolheadOffsetField.getValue()).doubleValue());
target.eepromStoreToolDelta(1, ((Number)yToolheadOffsetField.getValue()).doubleValue());
target.eepromStoreToolDelta(2, ((Number)zToolheadOffsetField.getValue()).doubleValue());

requestResetFromUser();
}
Expand Down Expand Up @@ -234,11 +234,12 @@ private void loadParameters() {
vref3.setValue(this.target.getStoredStepperVoltage(3));
vref4.setValue(this.target.getStoredStepperVoltage(4));
}

xNozzleOffsetField.setValue(this.target.getNozzleOffset(0));
yNozzleOffsetField.setValue(this.target.getNozzleOffset(1));
zNozzleOffsetField.setValue(this.target.getNozzleOffset(2));


if(target.hasToolheadsOffset()) {
xToolheadOffsetField.setValue(this.target.getToolheadsOffset(0));
yToolheadOffsetField.setValue(this.target.getToolheadsOffset(1));
zToolheadOffsetField.setValue(this.target.getToolheadsOffset(2));
}
}

protected void dispose() {
Expand Down Expand Up @@ -340,19 +341,21 @@ public MachineOnboardParameters(OnboardParameters target, Driver driver, JFrame
add(new JLabel("B home offset (mm)"));
add(bAxisHomeOffsetField,"wrap");
}

xNozzleOffsetField.setColumns(10);
yNozzleOffsetField.setColumns(10);
zNozzleOffsetField.setColumns(10);

add(new JLabel("X nozzle offset (mm)"));
add(xNozzleOffsetField, "wrap");

add(new JLabel("Y nozzle offset (mm)"));
add(yNozzleOffsetField, "wrap");

add(new JLabel("Z nozzle offset (mm)"));
add(zNozzleOffsetField, "wrap");

if(target.hasToolheadsOffset()) {
xToolheadOffsetField.setColumns(10);
yToolheadOffsetField.setColumns(10);
zToolheadOffsetField.setColumns(10);

add(new JLabel("X toolhead offset (mm)"));
add(xToolheadOffsetField, "wrap");

add(new JLabel("Y toolhead offset (mm)"));
add(yToolheadOffsetField, "wrap");

add(new JLabel("Z toolhead offset (mm)"));
add(zToolheadOffsetField, "wrap");
}


resetToFactoryButton.addActionListener(new ActionListener() {
Expand Down
8 changes: 7 additions & 1 deletion src/replicatorg/drivers/OnboardParameters.java
Expand Up @@ -42,7 +42,13 @@ public interface OnboardParameters {
double getAxisHomeOffset(int axis);
void setAxisHomeOffset(int axis, double d);

double getNozzleOffset(int axis);

/// returns true if the target machine stores toolhead offsets
boolean hasToolheadsOffset();

/// return the total toolhead offset (tolerance error, plus
/// standard toolhead distance) in mm
double getToolheadsOffset(int axis);

/// set to EEPROM the distance out of tolerance the
/// specified axis is
Expand Down
35 changes: 20 additions & 15 deletions src/replicatorg/drivers/gen3/MightyBoard.java
Expand Up @@ -35,7 +35,7 @@
import replicatorg.drivers.RetryException;
import replicatorg.drivers.Version;
import replicatorg.machine.model.AxisId;
import replicatorg.machine.model.NozzleOffset;
import replicatorg.machine.model.ToolheadsOffset;
import replicatorg.machine.model.ToolModel;
import replicatorg.util.Point5d;

Expand Down Expand Up @@ -260,9 +260,10 @@ public MightyBoard() {

stepperValues= new Hashtable();

// Make sure this accurately reflects what versions this supports
minimumVersion = new Version(5, 3);
preferredVersion = new Version(5, 3);
// Make sure this accurately reflects the minimum prefered
// firmware version we want this driver to support.
minimumVersion = new Version(5,2);
preferredVersion = new Version(5,2);

}

Expand Down Expand Up @@ -769,9 +770,12 @@ public void setAxisHomeOffset(int axis, double offset) {
}

@Override
public double getNozzleOffset(int axis) {
public boolean hasToolheadsOffset() { return true;}

Base.logger.finest("MigtyBoard getNozzleOffset" + axis);
@Override
public double getToolheadsOffset(int axis) {

Base.logger.finest("MigtyBoard getToolheadsOffset" + axis);
if ((axis < 0) || (axis > 2)) {
// TODO: handle this
Base.logger.severe("axis out of range" + axis);
Expand All @@ -782,23 +786,24 @@ public double getNozzleOffset(int axis) {

double val = read32FromEEPROM(MightyBoardEEPROM.TOLERANCE_ERROR_STEPS + axis*4);

NozzleOffset nozzleOffsets = getMachine().getNozzleOffsets();
Point5d stepsPerMM = getMachine().getStepsPerMM();
ToolheadsOffset toolheadsOffset = getMachine().getToolheadsOffsets();
Point5d stepsPerMM = getMachine().getStepsPerMM();
switch(axis) {
case 0:
val = (val)/stepsPerMM.x()/10.0 + nozzleOffsets.x();
val = (val)/stepsPerMM.x()/10.0 + toolheadsOffset.x();
break;
case 1:
val = (val)/stepsPerMM.y()/10.0 + nozzleOffsets.y();
val = (val)/stepsPerMM.y()/10.0 + toolheadsOffset.y();
break;
case 2:
val = (val)/stepsPerMM.z()/10.0 + nozzleOffsets.z();
val = (val)/stepsPerMM.z()/10.0 + toolheadsOffset.z();
break;
}

return val;
}


/**
* Stores to EEPROM in motor steps counts, how far out of
* tolerance the toolhead0 to toolhead1 distance is. XML settings are used
Expand All @@ -816,17 +821,17 @@ public void eepromStoreToolDelta(int axis, double distanceMm) {
int offsetSteps = 0;

Point5d stepsPerMM = getMachine().getStepsPerMM();
NozzleOffset nozzleOffsets = getMachine().getNozzleOffsets();
ToolheadsOffset toolheadsOffset = getMachine().getToolheadsOffsets();

switch(axis) {
case 0:
offsetSteps = (int)((distanceMm-nozzleOffsets.x())*stepsPerMM.x()*10.0);
offsetSteps = (int)((distanceMm-toolheadsOffset.x())*stepsPerMM.x()*10.0);
break;
case 1:
offsetSteps = (int)((distanceMm-nozzleOffsets.y())*stepsPerMM.y()*10.0);
offsetSteps = (int)((distanceMm-toolheadsOffset.y())*stepsPerMM.y()*10.0);
break;
case 2:
offsetSteps = (int)((distanceMm-nozzleOffsets.z())*stepsPerMM.z()*10.0);
offsetSteps = (int)((distanceMm-toolheadsOffset.z())*stepsPerMM.z()*10.0);
break;
}
write32ToEEPROM32(MightyBoardEEPROM.TOLERANCE_ERROR_STEPS + axis*4,offsetSteps);
Expand Down
26 changes: 16 additions & 10 deletions src/replicatorg/drivers/gen3/Sanguino3GDriver.java
Expand Up @@ -285,6 +285,7 @@ protected PacketResponse runQuery(byte[] packet, int retries) {
protected PacketResponse runQuery(byte[] packet) {
return runQuery(packet, 1);
}

//// Get a list of all toolheads we save onboard preferences for
public List<Integer> toolheadsWithStoredData()
{
Expand Down Expand Up @@ -2199,16 +2200,21 @@ public void setAxisHomeOffset(int axis, double offset) {
writeToEEPROM(Sanguino3GEEPRPOM.EEPROM_AXIS_HOME_POSITIONS_OFFSET
+ axis * 4, intToLE(offsetSteps));
}

public double getNozzleOffset(int axis) {
Base.logger.info("Cannot get tolerance error for S3G driver");
return 0.0;
}

public void eepromStoreToolDelta(int axis, double offset){
Base.logger.info("Cannot store tolerance error for S3G driver");
return;
}

@Override
public boolean hasToolheadsOffset() { return false;}

@Override
public double getToolheadsOffset(int axis) {
Base.logger.info("Cannot get tolerance error for S3G driver");
return 0.0;
}

@Override
public void eepromStoreToolDelta(int axis, double offset){
Base.logger.info("Cannot store tolerance error for S3G driver");
return;
}

public void storeHomePositions(EnumSet<AxisId> axes) throws RetryException {
byte b = 0;
Expand Down
15 changes: 8 additions & 7 deletions src/replicatorg/machine/model/MachineModel.java
Expand Up @@ -30,6 +30,7 @@
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.atomic.AtomicReference;
import replicatorg.machine.*;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -89,8 +90,8 @@ public class MachineModel
// our build volume
protected BuildVolume buildVolume;

// nozzle offsets
protected NozzleOffset nozzleOffsets;
// nozzle offsets
protected ToolheadsOffset toolheadsOfffsets;

private MachineType machineType = null;

Expand All @@ -102,7 +103,7 @@ public MachineModel()
clamps = new Vector<ClampModel>();
tools = new Vector<ToolModel>();
buildVolume = new BuildVolume(100,100,100); // preload it with the default values
nozzleOffsets = new NozzleOffset(0.0, 0.0, 0.0);
toolheadsOfffsets = new ToolheadsOffset(0.0, 0.0, 0.0);

//currentPosition = new Point3d();
minimum = new Point5d();
Expand Down Expand Up @@ -221,9 +222,9 @@ private void parseOffsets()
zNozzleOffset = Double.parseDouble(XML.getAttributeValue(offsetNode, "zNozzle"));
} catch (Exception e) {}

nozzleOffsets.setX(xNozzleOffset);
nozzleOffsets.setY(yNozzleOffset);
nozzleOffsets.setZ(zNozzleOffset);
toolheadsOfffsets.setX(xNozzleOffset);
toolheadsOfffsets.setY(yNozzleOffset);
toolheadsOfffsets.setZ(zNozzleOffset);
}
}
}
Expand Down Expand Up @@ -471,7 +472,7 @@ public Point5d stepsToMM(Point5d steps)
/**
* Get steps-mm conversion value
*/
public NozzleOffset getNozzleOffsets() { return nozzleOffsets; }
public ToolheadsOffset getToolheadsOffsets() { return toolheadsOfffsets; }

/*************************************
* Convert millimeters to machine steps
Expand Down
@@ -1,22 +1,22 @@
package replicatorg.machine.model;

/**
*
* Class to contain a machine specific toolheads offset.
*
* NOTE: This breaks our object model a bit (these should be stored per-tool,
* not per-machine) but frankly, we just need to ship this.
* @author alison
*/
public class NozzleOffset {
public class ToolheadsOffset {

private double x;
private double y;
private double z;
/*
* TODO: This, more complex class could implement things like a cut-outs and places to avoid such as tool-changers.
* Perhaps managed whether it's confirmed to be empty or contains objects that we need to travel around?
*/
public NozzleOffset(){

public ToolheadsOffset(){
}

public NozzleOffset(double x, double y, double z){
public ToolheadsOffset(double x, double y, double z){
this.setX(x);
this.setY(y);
this.setZ(z);
Expand Down

0 comments on commit 28a1c4e

Please sign in to comment.