Skip to content

Commit

Permalink
* Fixed old, busted max feedrate computation; enabled combination moves
Browse files Browse the repository at this point in the history
* Added prefs checkbox for reenabling old behavior
* (Skipping rewrite of inefficient parser code; this code will get rewritten
  in backend update anyway)
  • Loading branch information
phooky committed Sep 10, 2010
1 parent fbaa70d commit 6e9a505
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 24 deletions.
18 changes: 15 additions & 3 deletions src/replicatorg/app/GCodeParser.java
Expand Up @@ -85,6 +85,9 @@ public class GCodeParser {
boolean absoluteMode = false;

// our feedrate variables.
/**
* Feedrate in mm/minute.
*/
double feedrate = 0.0;

/*
Expand Down Expand Up @@ -132,6 +135,11 @@ public class GCodeParser {
public static final int TB_MESSAGE = 998;
public static final int TB_CLEANUP = 999;

// Replicate old behavior of breaking out Z moves into seperate setTarget
// calls.

private boolean breakoutZMoves = Base.preferences.getBoolean("replicatorg.parser.breakzmoves", false);

/**
* Creates the driver object.
*/
Expand Down Expand Up @@ -177,7 +185,8 @@ protected double getMaxFeedrate() {
public void init(Driver drv) {
// our driver class
driver = drv;

// reload breakout
breakoutZMoves = Base.preferences.getBoolean("replicatorg.parser.breakzmoves", false);
// init our offset variables
currentOffset = driver.getOffset(0);
}
Expand Down Expand Up @@ -681,6 +690,7 @@ private void executeGCodes() throws GCodeException {

// Get feedrate if supplied
if (hasCode("F")) {
// Read feedrate in mm/min.
feedrate = getCodeValue("F");
driver.setFeedrate(feedrate);
}
Expand Down Expand Up @@ -1125,8 +1135,10 @@ private void setTarget(Point3d p) {
// toolpath.
// move z first
Point3d current = driver.getCurrentPosition();
if (p.z != current.z) {
driver.queuePoint(new Point3d(current.x, current.y, p.z));
if (breakoutZMoves) {
if (p.z != current.z) {
driver.queuePoint(new Point3d(current.x, current.y, p.z));
}
}
driver.queuePoint(new Point3d(p));
current = new Point3d(p);
Expand Down
5 changes: 4 additions & 1 deletion src/replicatorg/app/MachineController.java
Expand Up @@ -148,7 +148,10 @@ private boolean buildCodesInternal(GCodeSource source) throws BuildFailureExcept
// Do not continue build if the machine is not building or paused
return false;
}


// Flush any parser cached data
driver.getParser().init(driver);

Iterator<String> i = source.iterator();
while (i.hasNext()) {
String line = i.next();
Expand Down
1 change: 1 addition & 0 deletions src/replicatorg/app/ui/PreferencesWindow.java
Expand Up @@ -117,6 +117,7 @@ public PreferencesWindow() {
addCheckboxForPref(content,"Honor serial port selection in machines.xml","serial.use_machines",true);
addCheckboxForPref(content,"Show experimental machine profiles","machine.showExperimental",false);
addCheckboxForPref(content,"Show simulator during builds","build.showSimulator",false);
addCheckboxForPref(content,"Break Z motion into seperate moves (normally false)","replicatorg.parser.breakzmoves",false);

content.add(new JLabel("Firmware update URL: "),"split");
firmwareUpdateUrlField = new JTextField(34);
Expand Down
4 changes: 4 additions & 0 deletions src/replicatorg/drivers/Driver.java
Expand Up @@ -144,6 +144,10 @@ public interface Driver {
*/
void invalidatePosition();

/**
* Queue the next point to move to.
* @param p The location to move to, in mm.
*/
public void queuePoint(Point3d p);

public Point3d getOffset(int i);
Expand Down
31 changes: 20 additions & 11 deletions src/replicatorg/drivers/DriverBaseImplementation.java
Expand Up @@ -239,16 +239,15 @@ public Point3d getPosition() {
return getCurrentPosition();
}

/**
* Queue the given point.
* @param p The point, in mm.
*/
public void queuePoint(Point3d p) {
Point3d delta = getDelta(p);

// calculate the length of each axis move
double xFactor = Math.pow(delta.x, 2);
double yFactor = Math.pow(delta.y, 2);
double zFactor = Math.pow(delta.z, 2);

// add to the total length
moveLength += Math.sqrt(xFactor + yFactor + zFactor);
moveLength += delta.distance(new Point3d());

// what is our feedrate?
double feedrate = getSafeFeedrate(delta);
Expand Down Expand Up @@ -284,6 +283,11 @@ public double getCurrentFeedrate() {
return currentFeedrate;
}

/**
* Return the maximum safe feedrate, given in mm/min., for the given delta and current feedrate.
* @param delta The delta in mm.
* @return
*/
public double getSafeFeedrate(Point3d delta) {
double feedrate = getCurrentFeedrate();

Expand All @@ -299,13 +303,18 @@ public double getSafeFeedrate(Point3d delta) {
// System.out.println("Zero feedrate!! " + feedrate);
}

// Break down feedrate by axis.
double length = delta.distance(new Point3d(0,0,0));
if (delta.x != 0)
feedrate = Math.min(feedrate, maxFeedrates.x);
if (feedrate*delta.x/length > maxFeedrates.x)
feedrate = maxFeedrates.x * length/delta.x;
if (delta.y != 0)
feedrate = Math.min(feedrate, maxFeedrates.y);
if (delta.z != 0)
feedrate = Math.min(feedrate, maxFeedrates.z);

if (feedrate*delta.y/length > maxFeedrates.y)
feedrate = maxFeedrates.y * length/delta.y;
if (delta.z != 0) {
if (feedrate*delta.z/length > maxFeedrates.z)
feedrate = maxFeedrates.z * length/delta.z;
}
return feedrate;
}

Expand Down
26 changes: 17 additions & 9 deletions src/replicatorg/drivers/gen3/Sanguino3GDriver.java
Expand Up @@ -365,10 +365,13 @@ public void queuePoint(Point3d p) {
if (masterSteps > 0.0) {
// where we going?
Point3d steps = machine.mmToSteps(p);


Point3d delta = getDelta(p);
double feedrate = getSafeFeedrate(delta);

// how fast are we doing it?
long micros = convertFeedrateToMicros(getCurrentPosition(),
p, getSafeFeedrate(deltaSteps));
p, feedrate);

//System.err.println("Steps :"+steps.toString()+" micros "+Long.toString(micros));

Expand Down Expand Up @@ -1011,17 +1014,22 @@ private Point3d getAbsDeltaSteps(Point3d current, Point3d target) {
return machine.mmToSteps(getAbsDeltaDistance(current, target));
}

/**
*
* @param current
* @param target
* @param feedrate Feedrate in mm per minute
* @return
*/
private long convertFeedrateToMicros(Point3d current, Point3d target,
double feedrate) {
Point3d deltaDistance = getAbsDeltaDistance(current, target);
Point3d deltaSteps = getAbsDeltaSteps(current, target);
// how long is our line length?
double distance = Math.sqrt(deltaDistance.x * deltaDistance.x
+ deltaDistance.y * deltaDistance.y + deltaDistance.z
* deltaDistance.z);
Point3d deltaSteps = machine.mmToSteps(deltaDistance);
double masterSteps = getLongestLength(deltaSteps);
// distance is in steps
// feedrate is in steps/
// how long is our line length?
double distance = deltaDistance.distance(new Point3d());
// distance is in mm
// feedrate is in mm/min
// distance / feedrate * 60,000,000 = move duration in microseconds
double micros = distance / feedrate * 60000000.0;
// micros / masterSteps = time between steps for master axis.
Expand Down

0 comments on commit 6e9a505

Please sign in to comment.