Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Lots of changes, mostly to the gcode encoder

commit 2a3cb2712f37f532916f1e8433e64c1cd4f29fd3 1 parent c42d0cd
John Cope authored
59 Canvas.pde
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;
}
62 Encoder.pde
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);
+ }
+
+}
18 PreviewBox.pde
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;
+ }
}
3  Robot.pde
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) {
85 Scanner.pde
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;
+
}
}
38 StateMachine.pde
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;
}
46 TagBot.pde
View
@@ -4,18 +4,19 @@ import processing.video.*;
/*** INSTANTIALIZINATE SOME OBJECTS ***/
PImage imgBase;
PImage imgScanned;
+PImage imgTiny;
PFont creepster;
PFont dillenia;
Capture webcam;
PreviewBox previewBox;
Canvas canvas;
+Encoder encoder;
Robot robot;
Scanner scanner;
StateMachine stateMachine;
-int prevMargin = 50; //makes setting margins simpler
-
+int prevMargin = 10; //makes setting margins simpler
/*** Global vars... Probably too many of these
@@ -41,20 +42,30 @@ void setup() {
}
imgBase = new PImage(width, height);
+ imgScanned = new PImage(width, height);
+
// PreviewBox ( int xMin, int yMin, int xMax, int yMax )
previewBox = new PreviewBox(prevMargin, prevMargin,
width-prevMargin, height-prevMargin);
+
// Canvas ( int tempwide, int temphigh, int tempelevation )
- canvas = new Canvas(60, 90, 30);
+ canvas = new Canvas();
+
+
+ imgTiny = new PImage(canvas.dotsWide, canvas.dotsHigh);
// Robot ( int motorSpan, in numColors )
robot = new Robot(500, 1);
scanner = new Scanner();
+ encoder = new Encoder();
+
stateMachine = new StateMachine();
+
+
dillenia = loadFont("DilleniaUPCBold-27.vlw");
creepster = loadFont("Creepster-Regular-48.vlw");
@@ -77,23 +88,42 @@ void draw() {
case 0:
image(imgBase, 0, 0);
previewBox.makeIt(canvas.getOrientation());
+ //previewBox.makeIt("portrait");
break;
case 1:
- image(scanner.crushWebcam(imgBase, previewBox),0 ,0 );
+ imgScanned = scanner.crushWebcam(imgBase, previewBox, canvas.getOrientation());
+ image( imgScanned, previewBox.xMin() , previewBox.yMin() );
+ //image(scanner.crushWebcam(imgBase, previewBox), 173, 20);
previewBox.makeIt(canvas.getOrientation());
+ //previewBox.makeIt("portrait");
break;
case 2:
+ background(255);
+ image( imgScanned, previewBox.xMin() , previewBox.yMin() );
+ imgTiny = scanner.tinyMake( imgScanned , imgTiny, canvas );
+ //scanner.blobShow(scanner.crushWebcam(imgBase, previewBox));
+ break;
+ case 3:
+ background(255);
+ image(imgTiny, 150, 200);
+ scanner.blobMake(imgTiny, previewBox, canvas);
+ break;
+ case 4:
+ encoder.gCodeify(imgTiny);
+ //exit;
break;
}
+
stateMachine.makeLogo();
stateMachine.displayState();
stateMachine.helpText();
+
}
void keyPressed() {
switch (key) {
case 's' :
- canvas.flipOrientation();
+ stateMachine.sButton(canvas);
break;
case 'a' :
stateMachine.aButton();
@@ -101,6 +131,12 @@ void keyPressed() {
case 'd' :
stateMachine.dButton();
break;
+ case 'c' :
+ stateMachine.cButton();
+ break;
+ case 'g' :
+ stateMachine.gButton();
+ break;
}
274 test.gcode
View
@@ -0,0 +1,274 @@
+G20
+G92
+G90
+G21
+G1 X40.361 Y92.027
+G1 X42.426 Y89.196
+G1 X44.598 Y86.377
+G1 X46.861 Y83.570
+G1 X54.083 Y75.240
+G1 X59.169 Y69.778
+G1 X61.774 Y67.082
+G1 X64.413 Y64.413
+G1 X67.082 Y61.774
+G1 X69.778 Y59.169
+G1 X72.498 Y56.604
+G1 X75.240 Y54.083
+G1 X78.000 Y51.614
+G1 X80.777 Y49.204
+G1 X83.570 Y46.861
+G1 X89.196 Y42.426
+G1 X42.638 Y93.048
+G1 X44.598 Y90.250
+G1 X46.669 Y87.464
+G1 X48.836 Y84.694
+G1 X51.088 Y81.939
+G1 X53.413 Y79.202
+G1 X60.745 Y71.120
+G1 X63.285 Y68.476
+G1 X68.476 Y63.285
+G1 X71.120 Y60.745
+G1 X73.790 Y58.249
+G1 X76.485 Y55.803
+G1 X79.202 Y53.413
+G1 X81.939 Y51.088
+G1 X84.694 Y48.836
+G1 X87.464 Y46.669
+G1 X90.250 Y44.598
+G1 X45.000 Y94.154
+G1 X46.861 Y91.389
+G1 X48.836 Y88.640
+G1 X50.912 Y85.907
+G1 X60.000 Y75.180
+G1 X64.900 Y69.971
+G1 X80.498 Y55.317
+G1 X83.193 Y53.075
+G1 X85.907 Y50.912
+G1 X88.640 Y48.836
+G1 X91.389 Y46.861
+G1 X47.434 Y95.341
+G1 X49.204 Y92.612
+G1 X51.088 Y89.900
+G1 X55.154 Y84.534
+G1 X57.315 Y81.884
+G1 X59.548 Y79.259
+G1 X84.534 Y55.154
+G1 X87.207 Y53.075
+G1 X89.900 Y51.088
+G1 X92.612 Y49.204
+G1 X49.930 Y96.607
+G1 X51.614 Y93.915
+G1 X53.413 Y91.241
+G1 X55.317 Y88.589
+G1 X57.315 Y85.959
+G1 X85.959 Y57.315
+G1 X88.589 Y55.317
+G1 X91.241 Y53.413
+G1 X93.915 Y51.614
+G1 X52.479 Y97.949
+G1 X54.083 Y95.294
+G1 X55.803 Y92.661
+G1 X57.628 Y90.050
+G1 X59.548 Y87.464
+G1 X61.555 Y84.906
+G1 X63.640 Y82.377
+G1 X87.464 Y59.548
+G1 X90.050 Y57.628
+G1 X92.661 Y55.803
+G1 X95.294 Y54.083
+G1 X55.073 Y99.363
+G1 X56.604 Y96.747
+G1 X58.249 Y94.154
+G1 X60.000 Y91.586
+G1 X61.847 Y89.045
+G1 X63.781 Y86.533
+G1 X89.045 Y61.847
+G1 X91.586 Y60.000
+G1 X94.154 Y58.249
+G1 X96.747 Y56.604
+G1 X59.169 Y98.270
+G1 X60.745 Y95.718
+G1 X62.426 Y93.193
+G1 X64.203 Y90.697
+G1 X66.068 Y88.233
+G1 X90.697 Y64.203
+G1 X93.193 Y62.426
+G1 X95.718 Y60.745
+G1 X98.270 Y59.169
+G1 X60.374 Y102.40
+G1 X61.774 Y99.860
+G1 X63.285 Y97.350
+G1 X64.900 Y94.868
+G1 X66.611 Y92.418
+G1 X68.411 Y90.000
+G1 X70.292 Y87.618
+G1 X87.618 Y70.292
+G1 X90.000 Y68.411
+G1 X92.418 Y66.611
+G1 X94.868 Y64.900
+G1 X97.350 Y63.285
+G1 X99.860 Y61.774
+G1 X64.413 Y101.51
+G1 X65.863 Y99.045
+G1 X67.417 Y96.607
+G1 X69.065 Y94.202
+G1 X70.803 Y91.831
+G1 X72.622 Y89.499
+G1 X74.518 Y87.207
+G1 X82.759 Y78.518
+G1 X84.959 Y76.485
+G1 X87.207 Y74.518
+G1 X89.499 Y72.622
+G1 X91.831 Y70.803
+G1 X94.202 Y69.065
+G1 X96.607 Y67.417
+G1 X99.045 Y65.863
+G1 X101.51 Y64.413
+G1 X67.082 Y103.23
+G1 X68.476 Y100.80
+G1 X69.971 Y98.407
+G1 X73.239 Y93.723
+G1 X75.000 Y91.439
+G1 X76.837 Y89.196
+G1 X78.746 Y87.000
+G1 X82.759 Y82.759
+G1 X87.000 Y78.746
+G1 X93.723 Y73.239
+G1 X96.047 Y71.561
+G1 X100.80 Y68.476
+G1 X103.23 Y67.082
+G1 X69.778 Y105.00
+G1 X71.120 Y102.62
+G1 X72.560 Y100.26
+G1 X77.421 Y93.434
+G1 X79.202 Y91.241
+G1 X81.056 Y89.095
+G1 X82.976 Y87.000
+G1 X84.959 Y84.959
+G1 X87.000 Y82.976
+G1 X102.62 Y71.120
+G1 X105.00 Y69.778
+G1 X72.498 Y106.83
+G1 X73.790 Y104.48
+G1 X75.180 Y102.18
+G1 X78.230 Y97.673
+G1 X79.881 Y95.483
+G1 X81.609 Y93.338
+G1 X83.409 Y91.241
+G1 X89.196 Y85.276
+G1 X91.241 Y83.409
+G1 X106.83 Y72.498
+G1 X77.827 Y104.14
+G1 X91.439 Y87.618
+G1 X106.40 Y76.485
+G1 X108.71 Y75.240
+G1 X84.906 Y99.725
+G1 X93.723 Y90.000
+G1 X95.671 Y88.233
+G1 X97.673 Y86.533
+G1 X106.15 Y80.498
+G1 X108.37 Y79.202
+G1 X110.63 Y78.000
+G1 X96.047 Y92.418
+G1 X97.949 Y90.697
+G1 X99.905 Y89.045
+G1 X110.39 Y81.939
+G1 X98.407 Y94.868
+G1 X100.26 Y93.193
+G1 X102.18 Y91.586
+G1 X104.14 Y90.050
+G1 X110.31 Y85.907
+G1 X112.45 Y84.694
+G1 X97.350 Y100.80
+G1 X99.045 Y99.045
+G1 X100.80 Y97.350
+G1 X102.62 Y95.718
+G1 X104.48 Y94.154
+G1 X106.40 Y92.661
+G1 X108.37 Y91.241
+G1 X110.39 Y89.900
+G1 X112.45 Y88.640
+G1 X114.55 Y87.464
+G1 X101.51 Y101.51
+G1 X105.00 Y98.270
+G1 X106.83 Y96.747
+G1 X108.71 Y95.294
+G1 X110.63 Y93.915
+G1 X112.61 Y92.612
+G1 X114.63 Y91.389
+G1 X116.69 Y90.250
+G1 X95.341 Y114.87
+G1 X107.42 Y100.85
+G1 X109.20 Y99.363
+G1 X111.04 Y97.949
+G1 X112.93 Y96.607
+G1 X114.87 Y95.341
+G1 X116.85 Y94.154
+G1 X118.87 Y93.048
+G1 X98.087 Y117.15
+G1 X106.53 Y106.53
+G1 X108.17 Y104.96
+G1 X109.86 Y103.45
+G1 X111.61 Y102.00
+G1 X113.41 Y100.62
+G1 X115.26 Y99.318
+G1 X117.15 Y98.087
+G1 X119.10 Y96.933
+G1 X121.08 Y95.859
+G1 X110.68 Y107.54
+G1 X112.33 Y106.07
+G1 X114.04 Y104.66
+G1 X115.80 Y103.32
+G1 X117.61 Y102.04
+G1 X119.47 Y100.85
+G1 X121.38 Y99.725
+G1 X123.33 Y98.681
+G1 X125.32 Y97.719
+G1 X113.21 Y110.15
+G1 X114.83 Y108.71
+G1 X116.50 Y107.33
+G1 X118.22 Y106.02
+G1 X120.00 Y104.79
+G1 X121.82 Y103.62
+G1 X123.69 Y102.53
+G1 X125.61 Y101.51
+G1 X127.56 Y100.58
+G1 X118.98 Y110.02
+G1 X120.67 Y108.75
+G1 X122.41 Y107.54
+G1 X124.20 Y106.40
+G1 X126.04 Y105.34
+G1 X127.91 Y104.36
+G1 X129.83 Y103.45
+G1 X107.21 Y130.25
+G1 X121.49 Y112.73
+G1 X123.15 Y111.49
+G1 X124.85 Y110.31
+G1 X126.61 Y109.20
+G1 X128.41 Y108.17
+G1 X130.25 Y107.21
+G1 X132.14 Y106.32
+G1 X124.02 Y115.45
+G1 X125.64 Y114.24
+G1 X127.31 Y113.09
+G1 X129.03 Y112.01
+G1 X130.80 Y111.00
+G1 X132.61 Y110.06
+G1 X134.47 Y109.20
+G1 X111.32 Y138.68
+G1 X114.83 Y131.49
+G1 X128.16 Y117.00
+G1 X129.80 Y115.88
+G1 X131.49 Y114.83
+G1 X133.22 Y113.84
+G1 X135.00 Y112.93
+G1 X136.82 Y112.09
+G1 X114.24 Y141.03
+G1 X133.96 Y117.65
+G1 X135.67 Y116.69
+G1 X137.41 Y115.80
+G1 X139.20 Y114.98
+G1 X117.15 Y143.41
+G1 X139.85 Y118.68
+G1 X141.61 Y117.88
+G1 X120.78 Y144.03
Please sign in to comment.
Something went wrong with that request. Please try again.