Permalink
Browse files

Lots of changes, mostly to the gcode encoder

  • Loading branch information...
1 parent c42d0cd commit 2a3cb2712f37f532916f1e8433e64c1cd4f29fd3 @johnbentcope committed Jun 12, 2012
Showing with 530 additions and 55 deletions.
  1. +28 −31 Canvas.pde
  2. +62 −0 Encoder.pde
  3. +11 −7 PreviewBox.pde
  4. +2 −1 Robot.pde
  5. +78 −7 Scanner.pde
  6. +34 −4 StateMachine.pde
  7. +41 −5 TagBot.pde
  8. +274 −0 test.gcode
View
@@ -1,61 +1,58 @@
class Canvas {
- // These are in centimeters
+ // These are in inches
// Approximately 2' by 3'
- int wide = 60;
- int high = 90;
+ int shortSide = 24;
+ int longSide = 36;
- int elevation = 30;
+ int wideInches = shortSide;
+ int highInches = longSide;
int spacingX = 4;
int spacingY = 5;
- int marginXmin = 4;
- int marginYmin = 5;
+ int marginXmin = 2;
+ int marginYmin = 3;
- int fieldX = wide-marginXmin*2;
- int fieldY = high-marginYmin*2;
+ int fieldX = wideInches-marginXmin*2;
+ int fieldY = highInches-marginYmin*2;
- int dotsWide = fieldX/spacingX;
- int dotsHigh = fieldY/spacingY;
+ int dotsShort = 20;
+ int dotsLong = 30;
+
+ int dotsWide = dotsShort;
+ int dotsHigh = dotsLong;
String orientation = "portrait";
// Stuff. I don't know. It's declarations.
- Canvas ( int tempwide, int temphigh, int tempelevation ) {
- wide = tempwide;
- high = temphigh;
- elevation = tempelevation; //distance below motor horizonal paper begins
- }
-
- public int getDotsWide() {
- return dotsWide;
- }
-
- public int getDotsHigh() {
- return dotsHigh;
- }
-
- private void stretchCanvas() {
-
+ Canvas () {
}
public String getOrientation() {
-
- return orientation;
+ return "portrait";
+ //return orientation;
}
public boolean setOrientation( String newOrientation) {
- orientation = newOrientation;
+ //orientation = newOrientation;
return true;
}
public boolean flipOrientation() {
- if (orientation == "landscape") {
+ /*if (orientation == "landscape") {
orientation = "portrait";
+ wideInches = shortSide;
+ highInches = longSide;
+ dotsWide = dotsShort;
+ dotsHigh = dotsLong;
} else {
orientation = "landscape";
- }
+ wideInches = longSide;
+ highInches = shortSide;
+ dotsWide = dotsLong;
+ dotsHigh = dotsShort;
+ }*/
return true;
}
View
@@ -0,0 +1,62 @@
+class Encoder {
+
+
+ String derp = "";
+
+ Encoder() {
+ }
+ // 30cm default high
+ // 27cm horizontal inset
+ // 114cm apart
+ // 60cm wide print area
+ // 90cm tall print area
+
+ public void gCodeify(PImage imgTiny){
+ float STEPS = 200;
+ float DIAM = 4; // cm
+ float CIRCUMFERENCE = DIAM * PI;
+ float TPS = CIRCUMFERENCE / STEPS;
+ int elev = 30;
+ int horiOffset = 27;
+ int machineWidth = 114;
+ int printWidth = 60;
+ int printHeight = 90;
+ int horizSpacing = printWidth/imgTiny.width;
+ int vertiSpacing = printHeight/imgTiny.height;
+ String gString = "G20|G92|G90|G21";
+ imgTiny.loadPixels();
+ int arrayLen = imgTiny.pixels.length;
+ //println("BEGIN");
+ for ( int i = 0 ; i < imgTiny.height ; i++) {
+ for ( int j = 0 ; j < imgTiny.width ; j++ ) {
+ if (imgTiny.pixels[i*(imgTiny.width)+j] == color(0) ) {
+ fill(255);
+ ellipse(j*10, i*10,5, 5);
+ float aPos = sqrt(sq(horiOffset+j*horizSpacing)+sq(elev+i*vertiSpacing));
+ float bPos = sqrt(sq(horiOffset+(printWidth-j*horizSpacing))+sq(elev+i*vertiSpacing));
+ gString += "|G1 ";
+ gString += String.format("X%.5g ", aPos);
+ gString += String.format("Y%.5g ", bPos);
+ //gString += "\nM106 \nG4 P300\nM107";
+ //gString += "\nM106 \nM107";
+ //gString += String.format(";i: " + i + " j: " + j);
+ //println( "aPos is " + aPos + " and bPos is " + bPos + " and i:j is " + i + ":"+ j);
+ }
+ }
+ }
+ //gString += "\nM106 \nG4 P300\nM107";
+ String[] gCode = split(gString, '|');
+ println(gString);
+ println("end");
+ /*
+ for ( int i = 0 ; i < gCode.length ; i++ ) {
+ String cmd = gCode[i];
+ int cs = 0;
+ for(i = 0; cmd[i] != '*' && cmd[i] != NULL; i++)
+ cs = cs ^ cmd[i];
+ cs &= 0xff; // Defensive programming...
+ }*/
+ saveStrings("test.gcode", gCode);
+ }
+
+}
View
@@ -54,9 +54,7 @@ class PreviewBox {
rect(0, yMin, xMin, yMax); //left
rect(xMax, yMin, width, yMax); //right
}
- //print(high);
- //println(wide);
-
+ //println(xMax + "ffff" );
}
@@ -65,17 +63,23 @@ class PreviewBox {
}
public int xMax() {
- return xMin;
+ return xMax;
}
public int yMin() {
- return xMin;
+ return yMin;
}
public int yMax() {
- return xMin;
+ return yMax;
}
-
+ public int wide() {
+ return wide;
+ }
+
+ public int high() {
+ return wide;
+ }
}
View
@@ -1,6 +1,7 @@
class Robot {
- int motorSpan = 500; // width between motors in centimeters
+ int elevation = 9;
+ int motorSpan = 45; // width between motors in inches
int numColors = 1;
Robot(int tempMotorSpan, int tempNumColors) {
View
@@ -8,17 +8,81 @@ class Scanner {
private boolean update() {
return true;
}
-
-
- public void render() {
-
- }
-
+
+ public PImage tinyMake( PImage imgScanned , PImage imgTiny , Canvas canvas ) {
+ imgScanned.loadPixels();
+ imgTiny.loadPixels();
+
+ int dotsWide = canvas.dotsWide;
+ int dotsHigh = canvas.dotsHigh;
+ imgTiny.width = dotsWide;
+ imgTiny.height = dotsHigh;
+ int imgWidth = imgScanned.width;
+ int imgHeight = imgScanned.height;
+ int horiSpacing = (imgWidth / dotsWide);
+ int vertSpacing = (imgHeight / dotsHigh);
+ //println("H = " + horiSpacing + " - V = " + vertSpacing);
+ int wideTest= dotsWide-1;
+ int highTest = dotsHigh-1;
+ //println(wideTest + "*" + + imgWidth + "+" + highTest + "*" + vertSpacing);
+
+ int loopWide = dotsWide-1;
+ int loopHigh = dotsHigh-1;
+
+ int tested = (loopHigh*imgWidth)+(loopHigh*horiSpacing)+(loopWide*vertSpacing);
+ //println("TESTED = " + tested);
+ for ( int i = 0 ; i < dotsWide ; i++ ) {
+ for ( int j = 0 ; j < dotsHigh ; j++ ) {
+ imgTiny.pixels[j*dotsWide+i] = imgScanned.pixels[((j+1)*imgWidth*horiSpacing)+((i+1)*vertSpacing)];
+
+ //imgScanned.pixels[((j+1)*imgWidth*horiSpacing)+((i+1)*vertSpacing)] = color(0, 255, 0);
+ }
+ }
+ imgTiny.updatePixels();
+ imgScanned.updatePixels();
+ //println(imgScanned.width + " and " + imgScanned.height);
+ //println(imgScanned.pixels.length);
+
+ //println(imgTiny.width + " and " + imgTiny.height);
+ //println(imgTiny.pixels.length);
+ return imgTiny;
+ }
+
+ public boolean blobMake(PImage imgTiny, PreviewBox previewBox, Canvas canvas) {
+
+ ellipseMode(CORNER);
+ int xMin = previewBox.xMin;
+ int yMin = previewBox.yMin;
+ int xMax = previewBox.xMax;
+ int yMax = previewBox.yMax;
+ int dotsWide = canvas.dotsWide;
+ int dotsHigh = canvas.dotsHigh;
+ int horiSpacing = ((xMax-xMin) / dotsWide);
+ int vertSpacing = ((yMax-yMin) / dotsHigh);
+ //println(imgTiny.height);
+ imgTiny.loadPixels();
+ for ( int i = 0 ; i < imgTiny.height ; i++) {
+ for ( int j = 0 ; j < imgTiny.width ; j++ ) {
+ noStroke();
+ color temp = imgTiny.pixels[i*(imgTiny.width)+j];
+ if ( ((red(temp) + green(temp) + blue(temp))/3) < 250 ) {
+ fill(temp);
+ } else {
+ noFill();
+ }
+ ellipse((j+1)*horiSpacing+xMin, (i+1)*vertSpacing+yMin, 15, 15);
+ }
+ }
+
+
+ return true;
+ }
+
public PImage getWebcam(PImage webcam) {
return webcam;
}
- public PImage crushWebcam(PImage webcam, PreviewBox previewBox) {
+ public PImage crushWebcam(PImage webcam, PreviewBox previewBox, String orientation) {
webcam.loadPixels();
int len = webcam.pixels.length;
int cutoff = floor(mouseY);
@@ -36,8 +100,15 @@ class Scanner {
webcam.pixels[i] = color(#FF0088);
}
}
+
webcam.updatePixels();
+ if (orientation == "portrait") {
+ webcam = webcam.get(previewBox.xMin(), previewBox.yMin(), previewBox.wide, previewBox.high);
+ } else {
+ webcam = webcam.get(previewBox.xMin(), previewBox.yMin(), previewBox.high, previewBox.wide);
+ }
return webcam;
+
}
}
View
@@ -13,7 +13,7 @@ class StateMachine {
}
public boolean aButton() {
- if ( state == 0 ) {
+ if ( state == 0 || state == 2 ) {
state = 1;
return true;
} else {
@@ -22,11 +22,38 @@ class StateMachine {
}
}
+ public boolean sButton(Canvas canvas){
+ canvas.flipOrientation();
+ if (state == 2 ) {
+ state = 1;
+ }
+ return true;
+
+ }
+
public boolean dButton() {
- state = 2;
+ if (state != 0) {
+ state = 2;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public boolean cButton() {
+ state = 3;
return true;
}
+ public boolean gButton() {
+ if (state == 3) {
+ state = 4;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
public boolean makeLogo() {
fill(#FF0088);
textAlign(RIGHT);
@@ -45,10 +72,13 @@ class StateMachine {
stateString = "Strike a pose!";
break;
case 1 :
- stateString = "Preview";
+ stateString = "Super Cool Preview";
break;
case 2:
- stateString = "State 3";
+ stateString = "Frozen";
+ break;
+ case 3:
+ stateString = "Rough Approximation";
break;
}
Oops, something went wrong.

0 comments on commit 2a3cb27

Please sign in to comment.