/* GCode Generator For Robotic Microscope (C) 2012 Jason Hunt - nulluser@gmail.com */ #include int main(int argc, char *argv[]) { FILE *f = fopen("path.nc", "wt"); double x_span = 0.07; double y_span = 0.07; double x_advance = 0.005; double y_advance = 0.005; double base_feed = 20; double image_feed = 10; double image_delay = 30; // Calcs int x_steps = x_span / x_advance + 1; int y_steps = y_span / y_advance + 1; // Home and make sure shutter is off fprintf(f, "G00 X0.0 Y0.1 Z-0.001 \n"); fprintf(f, "G00 Z0.0\n"); fprintf(f, "G00 Y0\n"); double y_pos = 0; // Y Movement for (int y = 0; y < y_steps; y++) { double x_pos = 0; // Rapid locate to start of row fprintf(f, "F%7.3f\n", base_feed); fprintf(f, "G00 X%7.3f Y%7.3f\n", x_pos, y_pos); // X Movement for (int x = 0; x < x_steps; x++) { fprintf(f, "F%7.3f\n", base_feed); fprintf(f, "G01 X%7.3f Y%7.3f\n", x_pos, y_pos); fprintf(f, "F%7.3f\n", image_feed); fprintf(f, "G01 Z%7.3f\n", image_delay/1000.0); // Delay to stabalize fprintf(f, "G01 Z-0.010\n"); // take image fprintf(f, "G00 Z0.0 \n"); // return x_pos += x_advance; } y_pos -= y_advance; } // Home fprintf(f,"G01 X0.0 Y0.0\n"); fclose(f); printf("X Steps: %d Y Steps: %d Total: %d\n", x_steps, y_steps, x_steps * y_steps); getchar(); return 0; }