// slightly cleaned up from harvey moon's drawing machine // // gridding off space available in the image plane // repeatibility // accuracy // precision // // rtwomey@u.washington.edu // // Key 1 = 0,0 // Key 2 = width,0 // Key 3 = width,height // Key 4 = 0,height // Keys 5-8, corners of svg image // Key 0 = Home // Key H = home device // Key h = set origin and init coords. // Key S = stop // Key G = go Bot machine; import processing.serial.*; // serial communication import java.io.*; //Java // configuration boolean serialOn = false; boolean writeToFile = true; boolean printToConsole = true; PrintWriter writer; //--------------------------------------------------- // physical setup float MOTORSEP = 96.0;//72.0; // how far apart are the two steppers // offsets // line A, at limit switch, is 2.0 inches out. // line B, at limit switch, is 1.25 inches out. // paper size float PAGEW = 84.0;//36.0;//17.0;//22.0;//44.0; // width float PAGEH = 60.0;//14.0;//30;//30.0; // height float MARGIN = 2.0; // page location relative to motors float PAGE0X = (MOTORSEP-PAGEW)/2.0; // upper left float PAGE0Y = 6.0;//6.0-PAGEH; // top of paper //12.0;//40.0; // home position of pen. where it is when the program starts float HOMEA = 81.0;//82.0;// 58.5225650924496; // 108 float HOMEB = 81.0;//82.0;//56.02580320709378; // 108 // scale image to screen for display int windowH = 900; float onScreenScale=windowH/PAGEH; int windowW = int(PAGEW*onScreenScale); // feed rates float FASTFEED = 200.0;//200.0; float SLOWFEED = 100.0;//15.0; static int PEN_UP = 0; static int PEN_DOWN = 1; // limit of the process int MAXDEPTH=4; int PATTERN_A = 1; int PATTERN_B= 2; int PATTERN_C = 3; //----------------------------------- // state variables boolean On = false;// USED SO THAT THE KEY 'S' AND 'G' START AND STOP THE DRAWING SEQUENCE, starts off to calibrate boolean done = false; boolean jumping = true; boolean atPoint = true; // if the arduino returns that it is at the point, turn true. boolean atHome=true; int scale=0; int x=0; int y=0; int state=PATTERN_A; PVector Last, Current; //------------------------------------ // main program void setup() { // graphics size(windowW, windowH); // load a font for text display PFont font; font = loadFont("Serif-24.vlw"); textFont(font, 12); // // store progress images // Photo = new OutputImage(); // arduino g-code interface machine = new Bot(this); machine.waitForStart(); writer = createWriter("test.txt"); machine.setupWriting(writer); background(255); // calc home values for X and Y (upper left corner of page) //HOMEA = sqrt(pow(PAGE0X, 2)+pow(PAGE0Y, 2)); //HOMEB = sqrt(pow(MOTORSEP-(PAGE0X), 2)+pow(PAGE0Y, 2)); if (printToConsole) println("(HOME: "+HOMEA + " " +HOMEB+")"); machine.storeHome(); machine.penUp(); Current = new PVector(MOTORSEP/2, sqrt(81*81-(MOTORSEP/2*MOTORSEP/2)), 0); println("(at "+Current.x+","+Current.y+" relative to PAGE(0,0))"); noCursor(); } void draw() { stroke(120); strokeWeight(2); fill(220); if (On && !done) { drawGridAtScale(MARGIN, MARGIN, PAGEW-MARGIN, PAGEH-MARGIN, int(pow(2, scale))); if (incrementPosition(int(pow(2, scale)))) { scale++; if(printToConsole) println("(grid "+scale+":"+MAXDEPTH+")"); if (scale>MAXDEPTH) { drawBox(MARGIN, MARGIN, PAGEW-MARGIN, PAGEH-MARGIN); done=true; } } } } boolean incrementPosition(int scale) { x++; if (x>=scale) { x=0; y++; if(printToConsole) println("(line "+y+":"+scale+")"); if (y>=scale) { y=0; return true; } } else { if(state==PATTERN_B) { state=PATTERN_C; } else { state=PATTERN_B; } } return false; } void drawGridAtScale(float left, float top, float right, float bot, int scale) { float ux=(right-left)/(float)scale; float uy=(bot-top)/(float)scale; // print(ux); // print(" "); // println(uy); // for(int x=0;x