Send commitlog mailing list submissions to
commitlog@lists.openmoko.org
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.openmoko.org/mailman/listinfo/commitlog
or, via email, send a message with subject or body 'help' to
commitlog-requ...@lists.openmoko.org
You can reach the person managing the list at
commitlog-ow...@lists.openmoko.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of commitlog digest..."
Today's Topics:
1. r5973 - in developers/werner/cncmap: . g2gp
(wer...@docs.openmoko.org)
--- Begin Message ---
Author: werner
Date: 2010-07-29 01:58:08 +0200 (Thu, 29 Jul 2010)
New Revision: 5973
Added:
developers/werner/cncmap/g2gp/
developers/werner/cncmap/g2gp/Makefile
developers/werner/cncmap/g2gp/g2gp.c
Modified:
developers/werner/cncmap/README
Log:
Added G-code to gnuplot converter.
Modified: developers/werner/cncmap/README
===================================================================
--- developers/werner/cncmap/README 2010-07-17 10:34:09 UTC (rev 5972)
+++ developers/werner/cncmap/README 2010-07-28 23:58:08 UTC (rev 5973)
@@ -39,6 +39,9 @@
align: map the model (in gnuplot format) to the workspace coordinates
obtained from "rect". This [...]
+g2gp: convert G-code generated by HeeksCAD to the "gnuplot" format. This
+strips all machine parameters.
+
gp2rml: generate RML commands from a file in "gnuplot" format. Machine
parameters like speed and clearance are passed on the command line.
Added: developers/werner/cncmap/g2gp/Makefile
===================================================================
--- developers/werner/cncmap/g2gp/Makefile (rev 0)
+++ developers/werner/cncmap/g2gp/Makefile 2010-07-28 23:58:08 UTC (rev
5973)
@@ -0,0 +1,25 @@
+#
+# g2gp/Makefile - Build the G-code to gnuplot converter
+#
+# Written 2010 by Werner Almesberger
+# Copyright 2010 Werner Almesberger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+
+
+MAIN=g2gp
+
+OBJS=g2gp.o
+
+CFLAGS = -g -Wall -Wshadow
+LDFLAGS = -lm
+
+$(MAIN): $(OBJS)
+# $(CC) $(LDFLAGS) -o $(MAIN) $(OBJS)
+
+clean:
+ rm -f $(OBJS)
Added: developers/werner/cncmap/g2gp/g2gp.c
===================================================================
--- developers/werner/cncmap/g2gp/g2gp.c (rev 0)
+++ developers/werner/cncmap/g2gp/g2gp.c 2010-07-28 23:58:08 UTC (rev
5973)
@@ -0,0 +1,205 @@
+/*
+ * g2gp.c - Convert from G-code to gnuplot
+ *
+ * Written 2010 by Werner Almesberger
+ * Copyright 2010 Werner Almesberger
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+
+static int up = 1;
+
+
+static void flush_move(double x, double y, double z)
+{
+ if (up)
+ return;
+ printf("%f %f %f\n\n", x, y, z);
+ up = 1;
+}
+
+
+static void do_move(double x, double y, double z)
+{
+ printf("%f %f %f\n", x, y, z);
+ up = 0;
+}
+
+
+static void process_command(char ch, double n)
+{
+ static double x, y, z;
+
+ switch (ch) {
+ case 'F':
+ /* ignore feed rate */
+ break;
+ case 'G':
+ switch ((int) n) {
+ case 0: /* rapid positioning */
+ flush_move(x, y, z);
+ break;
+ case 1: /* linear interpolation */
+ do_move(x, y, z);
+ break;
+ case 10: /* coordinate system origin */
+ break;
+ case 17: /* xy plane */
+ case 21: /* millimeter */
+ break;
+ case 54: /* preset coordinate system 1 */
+ break;
+ case 90: /* absolute */
+ break;
+ default:
+ fprintf(stderr, "igoring G%02d\n", (int) n);
+ break;
+ }
+ break;
+ case 'L':
+ /* loops */
+ break;
+ case 'M':
+ switch ((int) n) {
+ case 2: /* program end */
+ flush_move(x, y, z);
+ break;
+ case 3: /* turn spindle clockwise */
+ break;
+ case 6: /* tool change */
+ break;
+ default:
+ fprintf(stderr, "igoring M%02d\n", (int) n);
+ break;
+ }
+ break;
+ case 'N':
+ /* ignore line numbers */
+ break;
+ case 'O':
+ /* ??? */
+ break;
+ case 'P':
+ /* dwell time */
+ break;
+ case 'R':
+ /* arc radius */
+ break;
+ case 'S':
+ /* spindle speed */
+ break;
+ case 'T':
+ /* tool selection */
+ break;
+ case 'X':
+ x = n;
+ break;
+ case 'Y':
+ y = n;
+ break;
+ case 'Z':
+ z = n;
+ break;
+ default:
+ abort();
+ }
+}
+
+
+static void process_file(FILE *file)
+{
+ char last_ch = 0;
+ double n = 0;
+ double f = 1.0;
+ int text = 0;
+ int minus = 0;
+ char ch;
+
+ while ((ch = fgetc(file)) != EOF) {
+ if (text) {
+ if (ch == ')')
+ text = 0;
+ continue;
+ }
+ if (strchr("FGLMNOPRSTXYZ", toupper(ch))) {
+ if (last_ch)
+ process_command(last_ch, minus ? -n : n);
+ n = 0;
+ f = 1.0;
+ minus = 0;
+ last_ch = ch;
+ continue;
+ }
+ if (strchr("0123456789", ch)) {
+ if (f > 0.5) {
+ n = n*10+(ch-'0');
+ } else {
+ n += f*(ch-'0');
+ f /= 10;
+ }
+ continue;
+ }
+ if (ch == '.') {
+ f = 0.1;
+ continue;
+ }
+ if (ch == '-') {
+ minus = !minus;
+ continue;
+ }
+ if (ch == '(') {
+ text = 1;
+ continue;
+ }
+ if (strchr("\t \r\n", ch))
+ continue;
+ fprintf(stderr, "ignoring \"%c\"\n", ch);
+ }
+}
+
+
+static void usage(const char *name)
+{
+ fprintf(stderr, "usage: %s [file]\n\n", name);
+ exit(1);
+}
+
+
+int main(int argc, const char **argv)
+{
+ FILE *file;
+
+ switch (argc) {
+ case 1:
+ file = stdin;
+ break;
+ case 2:
+ file = fopen(argv[1], "r");
+ if (!file) {
+ perror(argv[1]);
+ return 1;
+ }
+ break;
+ default:
+ usage(*argv);
+ }
+
+ process_file(file);
+
+ if (ferror(stdout))
+ perror("stdout");
+ if (fclose(stdout) == EOF)
+ perror("stdout");
+
+ return 0;
+}
--- End Message ---
_______________________________________________
commitlog mailing list
commitlog@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/commitlog