From d03de3c50e5946c8c3cf2c3472c8758560786bf0 Mon Sep 17 00:00:00 2001
From: Michael Adams <github@michaeladams.org>
Date: Tue, 22 Nov 2016 20:52:23 +1300
Subject: [PATCH] Grbl: don't send feed rate as part of a G0 rapid, don't send
 spaces (#71)

* Don't send feed rate as part of a G0 rapid for Grbl, and don't send spaces in transmitted gcode
---
 .../drivers/GenericGcodeDriver.java           |  4 +-
 src/com/t_oster/liblasercut/drivers/Grbl.java | 49 +++++++++++++++++++
 2 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java b/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
index aad95e1..bed06a4 100644
--- a/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
+++ b/src/com/t_oster/liblasercut/drivers/GenericGcodeDriver.java
@@ -440,8 +440,8 @@ public class GenericGcodeDriver extends LaserCutter {
       }
     }
   }
-  private double currentPower = -1;
-  private double currentSpeed = -1;
+  protected double currentPower = -1;
+  protected double currentSpeed = -1;
   private double nextPower = -1;
   private double nextSpeed = -1;
   private double currentFocus = 0;
diff --git a/src/com/t_oster/liblasercut/drivers/Grbl.java b/src/com/t_oster/liblasercut/drivers/Grbl.java
index 51d7791..efcb63d 100644
--- a/src/com/t_oster/liblasercut/drivers/Grbl.java
+++ b/src/com/t_oster/liblasercut/drivers/Grbl.java
@@ -160,6 +160,55 @@ public class Grbl extends GenericGcodeDriver
     
     return null;
   }
+  
+  /**
+   * Send a G0 rapid move to Grbl.
+   * Doesn't include travel speed since grbl ignores that anyway.
+   * 
+   * @param out
+   * @param x
+   * @param y
+   * @param resolution
+   * @throws IOException 
+   */
+  @Override
+  protected void move(PrintStream out, double x, double y, double resolution) throws IOException {
+    x = isFlipXaxis() ? getBedWidth() - Util.px2mm(x, resolution) : Util.px2mm(x, resolution);
+    y = isFlipYaxis() ? getBedHeight() - Util.px2mm(y, resolution) : Util.px2mm(y, resolution);
+    currentSpeed = getTravel_speed();
+    if (blankLaserDuringRapids)
+    {
+      currentPower = 0.0;
+      sendLine("G0 X%f Y%f S0", x, y);
+    }
+    else
+    {
+      sendLine("G0 X%f Y%f", x, y);
+    }
+  }
+  
+  /**
+   * Send a line of gcode to the cutter, stripping out any whitespace in the process
+   * @param text
+   * @param parameters
+   * @throws IOException 
+   */
+  @Override
+  protected void sendLine(String text, Object... parameters) throws IOException
+  {
+    out.format(FORMAT_LOCALE, text.replace(" ", "")+LINEEND(), parameters);
+    //TODO: Remove
+    System.out.println(String.format(FORMAT_LOCALE, "> "+text+LINEEND(), parameters));
+    out.flush();
+    if (isWaitForOKafterEachLine())
+    {
+      String line = waitForLine();
+      if (!"ok".equals(line))
+      {
+        throw new IOException("Lasercutter did not respond 'ok', but '"+line+"'instead.");
+      }
+    }
+  }
 
   @Override
   public Grbl clone()
-- 
GitLab