Skip to content

Commit

Permalink
Merge pull request #400 from sp-apertus/develop
Browse files Browse the repository at this point in the history
Backlash compensations capabilities added for X/Y Axis
  • Loading branch information
vonnieda committed Jan 3, 2017
2 parents f0f365f + 188df35 commit 3a39bd3
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ private Command() {

@Attribute(required = false)
protected int maxFeedRate = 1000;

@Attribute(required = false)
protected double backlashOffsetX = -1;

@Attribute(required = false)
protected double backlashOffsetY = -1;

@Attribute(required = false)
protected double backlashFeedRateFactor = 0.1;

@Attribute(required = false)
protected int timeoutMilliseconds = 5000;
Expand Down Expand Up @@ -394,8 +403,7 @@ public void moveTo(ReferenceHeadMountable hm, Location location, double speed)
if (xAxis != null || yAxis != null || zAxis != null || rotationAxis != null) {

// For each included axis, if the axis has a transform, transform the target coordinate
// to
// it's raw value.
// to it's raw value.
if (xAxis != null && xAxis.getTransform() != null) {
x = xAxis.getTransform().toRaw(xAxis, hm, x);
}
Expand All @@ -415,12 +423,15 @@ public void moveTo(ReferenceHeadMountable hm, Location location, double speed)
command = substituteVariable(command, "Id", hm.getId());
command = substituteVariable(command, "Name", hm.getName());
command = substituteVariable(command, "FeedRate", maxFeedRate * speed);
command = substituteVariable(command, "BacklashFeedRate", maxFeedRate * speed * backlashFeedRateFactor);

if (xAxis == null || xAxis.getCoordinate() == x) {
command = substituteVariable(command, "X", null);
command = substituteVariable(command, "BacklashOffsetX", null); // Backlash Compensation
}
else {
command = substituteVariable(command, "X", x);
command = substituteVariable(command, "BacklashOffsetX", x + backlashOffsetX); // Backlash Compensation
haveToMove = true;
if (xAxis.getPreMoveCommand() != null) {
sendGcode(xAxis.getPreMoveCommand());
Expand All @@ -430,9 +441,11 @@ public void moveTo(ReferenceHeadMountable hm, Location location, double speed)

if (yAxis == null || yAxis.getCoordinate() == y) {
command = substituteVariable(command, "Y", null);
command = substituteVariable(command, "BacklashOffsetY", null); // Backlash Compensation
}
else {
command = substituteVariable(command, "Y", y);
command = substituteVariable(command, "BacklashOffsetY", y + backlashOffsetY); // Backlash Compensation
haveToMove = true;
if (yAxis.getPreMoveCommand() != null) {
sendGcode(yAxis.getPreMoveCommand());
Expand Down Expand Up @@ -874,6 +887,30 @@ public void setUnits(LengthUnit units) {
this.units = units;
}

public double getBacklashOffsetX() {
return backlashOffsetX;
}

public void setBacklashOffsetX(double BacklashOffsetX) {
this.backlashOffsetX = BacklashOffsetX;
}

public double getBacklashOffsetY() {
return backlashOffsetY;
}

public void setBacklashOffsetY(double BacklashOffsetY) {
this.backlashOffsetY = BacklashOffsetY;
}

public double getBacklashFeedRateFactor() {
return backlashFeedRateFactor;
}

public void setBacklashFeedRateFactor(double BacklashFeedRateFactor) {
this.backlashFeedRateFactor = BacklashFeedRateFactor;
}

public int getMaxFeedRate() {
return maxFeedRate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.openpnp.gui.support.AbstractConfigurationWizard;
import org.openpnp.gui.support.Icons;
import org.openpnp.gui.support.IntegerConverter;
import org.openpnp.gui.support.DoubleConverter;
import org.openpnp.gui.support.MessageBoxes;
import org.openpnp.machine.reference.driver.GcodeDriver;
import org.openpnp.machine.reference.driver.GcodeDriver.Command;
Expand Down Expand Up @@ -65,46 +66,81 @@ public GcodeDriverConfigurationWizard(GcodeDriver driver) {
settingsPanel.setBorder(new TitledBorder(null, "Settings", TitledBorder.LEADING, TitledBorder.TOP, null, null));
contentPanel.add(settingsPanel);
settingsPanel.setLayout(new FormLayout(new ColumnSpec[] {
FormSpecs.RELATED_GAP_COLSPEC, // each line here corresponds to one column in the grid
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,
FormSpecs.RELATED_GAP_COLSPEC,
FormSpecs.DEFAULT_COLSPEC,},
new RowSpec[] {
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC, // each line here corresponds to one row in the grid
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,
FormSpecs.RELATED_GAP_ROWSPEC,
FormSpecs.DEFAULT_ROWSPEC,}));

JLabel lblUnits = new JLabel("Units");
settingsPanel.add(lblUnits, "2, 2, right, default");
settingsPanel.add(lblUnits, "6, 2, right, default");

unitsCb = new JComboBox(LengthUnit.values());
settingsPanel.add(unitsCb, "4, 2, fill, default");
settingsPanel.add(unitsCb, "8, 2, fill, default");

JLabel lblMaxFeedRate = new JLabel("Max Feed Rate");
settingsPanel.add(lblMaxFeedRate, "2, 4, right, default");
JLabel lblMaxFeedRate = new JLabel("Max Feed Rate [Units/Min]");
settingsPanel.add(lblMaxFeedRate, "6, 4, right, default");

maxFeedRateTf = new JTextField();
settingsPanel.add(maxFeedRateTf, "4, 4, fill, default");
maxFeedRateTf.setColumns(10);
settingsPanel.add(maxFeedRateTf, "8, 4, fill, default");
maxFeedRateTf.setColumns(5);

JLabel lblBacklashOffsetX = new JLabel("Backlash Offset X [Units]");
settingsPanel.add(lblBacklashOffsetX, "10, 2, right, default");

backlashOffsetXTf = new JTextField();
settingsPanel.add(backlashOffsetXTf, "12, 2, fill, default");
backlashOffsetXTf.setColumns(5);

JLabel lblBacklashOffsetY = new JLabel("Backlash Offset Y [Units]");
settingsPanel.add(lblBacklashOffsetY, "10, 4, right, default");

backlashOffsetYTf = new JTextField();
settingsPanel.add(backlashOffsetYTf, "12, 4, fill, default");
backlashOffsetYTf.setColumns(5);

JLabel lblBacklashFeedSpeedFactor = new JLabel("Backlash Feed Rate Factor");
settingsPanel.add(lblBacklashFeedSpeedFactor, "14, 2, right, default");

backlashFeedRateFactorTf = new JTextField();
settingsPanel.add(backlashFeedRateFactorTf, "16, 2, fill, default");
backlashFeedRateFactorTf.setColumns(5);

JLabel lblCommandTimeoutms = new JLabel("Command Timeout (ms)");
settingsPanel.add(lblCommandTimeoutms, "2, 6, right, default");
JLabel lblCommandTimeoutms = new JLabel("Command Timeout [ms]");
settingsPanel.add(lblCommandTimeoutms, "2, 2, right, default");

commandTimeoutTf = new JTextField();
settingsPanel.add(commandTimeoutTf, "4, 6, fill, default");
commandTimeoutTf.setColumns(10);
settingsPanel.add(commandTimeoutTf, "4, 2, fill, default");
commandTimeoutTf.setColumns(5);

JLabel lblConnectWaitTime = new JLabel("Connect Wait Time (ms)");
settingsPanel.add(lblConnectWaitTime, "2, 8, right, default");
JLabel lblConnectWaitTime = new JLabel("Connect Wait Time [ms]");
settingsPanel.add(lblConnectWaitTime, "2, 4, right, default");

connectWaitTimeTf = new JTextField();
settingsPanel.add(connectWaitTimeTf, "4, 8, fill, default");
connectWaitTimeTf.setColumns(10);
settingsPanel.add(connectWaitTimeTf, "4, 4, fill, default");
connectWaitTimeTf.setColumns(5);

JPanel gcodePanel = new JPanel();
gcodePanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Gcode", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
Expand Down Expand Up @@ -249,13 +285,21 @@ private void commandTypeChanged() {
@Override
public void createBindings() {
IntegerConverter intConverter = new IntegerConverter();
DoubleConverter doubleConverter =
new DoubleConverter(Configuration.get().getLengthDisplayFormat());

addWrappedBinding(driver, "units", unitsCb, "selectedItem");
addWrappedBinding(driver, "maxFeedRate", maxFeedRateTf, "text", intConverter);
addWrappedBinding(driver, "backlashOffsetX", backlashOffsetXTf, "text", doubleConverter);
addWrappedBinding(driver, "backlashOffsetY", backlashOffsetYTf, "text", doubleConverter);
addWrappedBinding(driver, "backlashFeedRateFactor", backlashFeedRateFactorTf, "text", doubleConverter);
addWrappedBinding(driver, "timeoutMilliseconds", commandTimeoutTf, "text", intConverter);
addWrappedBinding(driver, "connectWaitTimeMilliseconds", connectWaitTimeTf, "text", intConverter);

ComponentDecorators.decorateWithAutoSelect(maxFeedRateTf);
ComponentDecorators.decorateWithAutoSelect(backlashOffsetXTf);
ComponentDecorators.decorateWithAutoSelect(backlashOffsetYTf);
ComponentDecorators.decorateWithAutoSelect(backlashFeedRateFactorTf);
ComponentDecorators.decorateWithAutoSelect(commandTimeoutTf);
ComponentDecorators.decorateWithAutoSelect(connectWaitTimeTf);
}
Expand Down Expand Up @@ -390,6 +434,9 @@ public void actionPerformed(ActionEvent arg0) {
private JComboBox<HeadMountableItem> comboBoxHm;
private JTextArea textAreaCommand;
private JTextField maxFeedRateTf;
private JTextField backlashOffsetXTf;
private JTextField backlashOffsetYTf;
private JTextField backlashFeedRateFactorTf;
private JTextField commandTimeoutTf;
private JTextField connectWaitTimeTf;
private JComboBox unitsCb;
Expand Down

0 comments on commit 3a39bd3

Please sign in to comment.