Skip to content

Instantly share code, notes, and snippets.

@roboter
Created October 4, 2020 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roboter/dd6c80a60cbdd93eb584c35bba259eaf to your computer and use it in GitHub Desktop.
Save roboter/dd6c80a60cbdd93eb584c35bba259eaf to your computer and use it in GitHub Desktop.
using System.Globalization;
using System.IO;
using System.Text;
namespace DrillBoardGcode
{
class Program
{
static double DRILLDEPTH = -4;
static double DRILLFEED = 5 * 60;
static double MOVEFEED = 20 * 60;
static double MAGIC = 2.54;
static void Main()
{
var builder = new StringBuilder();
builder.AppendLine("M3 S1000"); // Spindle ON
builder.AppendLine("G90");
for (double i = 0; i < 85.5; i += MAGIC)
{
for (double j = 0; j < 54; j += MAGIC)
{
builder.AppendLine(MoveTo(i, j));
builder.AppendLine(DrillInto());
builder.AppendLine(DrillOut());
}
}
builder.AppendLine(MoveTo(0, 0));
builder.AppendLine("M5"); // Spindle OFF
using var w = new StreamWriter("output_2_54.gcode");
w.Write(builder);
}
static string MoveTo(double X, double Y) => $"G01 X{Format(X)} Y{Format(Y)} F{MOVEFEED}";
private static string Format(double value) => value.ToString("0.00", CultureInfo.InvariantCulture.NumberFormat);
static string DrillInto() => $"G01 Z{DRILLDEPTH} F{DRILLFEED}";
static string DrillOut() => $"G01 Z0 F{MOVEFEED}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment