Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix hoting solenoids, and warning when head is left in middle

  • Loading branch information...
commit 3ccaf2f6680f6c1de798e4c1e4d0a8c60411bc03 1 parent 870c9c9
@mcanet authored
View
37 protoAppKnitic_p5/buttons_actions.pde
@@ -25,11 +25,11 @@ void jumpToRow() {
}
}
-void udpLivePatternMode(){
+void udpLivePatternMode() {
}
void changeEditPixels() {
- editPixels =!editPixels;
+ editPixels =! editPixels;
if (editPixels) {
cursor(CROSS);
controlP5.controller("Start edit image").captionLabel().set("Stop edit image");
@@ -39,6 +39,7 @@ void changeEditPixels() {
cursor(ARROW);
}
}
+
void updateEditPixels() {
if (editPixels) {
}
@@ -77,7 +78,6 @@ void fillArrayWithImage(String imgPath) {
lastEndLineStarted = false;
if (cols>0 && rows>0) loadPattern = true;
pixelArray = new int[cols][rows];
- myScrollBar.setupScrollBar();
int restPixels = 200-cols;
leftStick = 100-(restPixels/2);
rightStick = 100-(restPixels/2);
@@ -88,7 +88,6 @@ void fillArrayWithImage(String imgPath) {
if (cols!=200) {
howMuchPatternToLeft("");
}
-
img.loadPixels();
for (int y = 0; y <rows; y++) {
for (int x = 0; x < cols; x++) {
@@ -109,21 +108,27 @@ void fillArrayWithImage(String imgPath) {
}
void howMuchPatternToLeft(String message) {
- String userStartStick="";
- if (message=="") {
- userStartStick = JOptionPane.showInputDialog(frame, "Do you want to start from left " +Integer.toString(leftStick)+"?", Integer.toString(leftStick));
- }
- else {
- userStartStick = JOptionPane.showInputDialog(frame, message, Integer.toString(cols-100));
- }
- if (!userStartStick.equals(Integer.toString(leftStick))) {
- if ((100-Integer.valueOf(userStartStick))+cols>200 ) {
- howMuchPatternToLeft("Is not possible to put that right. The maxium is "+Integer.toString((cols-100)));
+ try {
+ String userStartStick="";
+ if (message=="") {
+ userStartStick = JOptionPane.showInputDialog(frame, "Do you want to start from left " +Integer.toString(leftStick)+"?", Integer.toString(leftStick));
}
else {
- leftStick = Integer.valueOf(userStartStick);
- rightStick = (cols+(100-leftStick))-100;
+ userStartStick = JOptionPane.showInputDialog(frame, message, Integer.toString(cols-100));
}
+ if (!userStartStick.equals(Integer.toString(leftStick))) {
+ if ((100-Integer.valueOf(userStartStick))+cols>200 ) {
+ howMuchPatternToLeft("Is not possible to put that right. The maxium is "+Integer.toString((cols-100)));
+ }
+ else {
+ leftStick = Integer.valueOf(userStartStick);
+ rightStick = (cols+(100-leftStick))-100;
+ }
+ }
+ }
+ catch(Exception e) {
}
}
+
+
View
112 protoAppKnitic_p5/drawElements.pde
@@ -21,7 +21,7 @@ void display() {
rect(15, 340, 190, 35);
rect(15, 390, 190, 35);
rect(15, 440, 190, 35);
-
+
fill(255);
// columne left
if (usbConected) {
@@ -66,7 +66,7 @@ void display() {
else {
text("Right Stick: "+Integer.toString(rightStick), 20, 470);
}
-
+
fill(255);
if (headDirection==0) {
text("Direction: none", 20, 270);
@@ -77,8 +77,6 @@ void display() {
else if (headDirection==-1) {
text("Direction: right", 20, 270);
}
-
-
noStroke();
// scroll bar
fill(16, 62, 104);
@@ -87,12 +85,12 @@ void display() {
// show small lines for rail of visualization knitles
noStroke();
fill(255);
- rect(buttonWithBar-9, 26*3+1,9, 2);
- rect((width-buttonWithBar), 26*3+1,9, 2);
+ rect(buttonWithBar-9, 26*3+1, 9, 2);
+ rect((width-buttonWithBar), 26*3+1, 9, 2);
stroke(255);
}
-void drawDebugVariables(){
+void drawDebugVariables() {
rect(15, 490, 190, 35);
if (endLineStarted) {
text("Started", 20, 520);
@@ -100,27 +98,27 @@ void drawDebugVariables(){
else {
text("Not started", 20, 520);
}
-
+
stroke(255);
noFill();
rect(855, 140, 180, 35);
fill(255);
text("Status: "+status+"/"+statusMachine, 865, 170);
-
+
int n = round(counterMessagesReceive/(millis()*0.001)) ;
text("M per Sec: "+Integer.toString(n), 30, 550);
-
+
text("MouseX:"+Integer.toString(patternMouseX), 855, 510);
text("MouseY:"+Integer.toString(patternMouseY), 855, 550);
text("Available buffer:"+Integer.toString(serialAvailableBuffer), 855, 600);
-
+
if (repedPatternMode) {
text("Repeat: true", 30, 500);
}
else {
text("Repeat: false", 30, 500);
}
- text("Left pixel: "+Integer.toString(((100-leftStick)/8)), 30, 590);
+ text("Left pixel: "+Integer.toString(((100-leftStick)/8)), 30, 590);
text("Right pixel: "+Integer.toString(((100+rightStick)/8)), 30, 630);
text(Integer.toString( -((section-1)*8)+(cols)+(100-rightStick)-16 ), 30, 700);
text("lastChangeHead:"+lastChangeHead, 30, 740);
@@ -135,10 +133,9 @@ void drawDebugVariables(){
void drawPattern() {
pushMatrix();
- translate(buttonWithBar+((100-leftStick)*sizePixel)+(cols*sizePixel),((27-rows)+current_row)*sizePixel);
+ translate(buttonWithBar+((100-leftStick)*sizePixel)+(cols*sizePixel), ((27-rows)+current_row)*sizePixel);
noSmooth();
- scale(-1,1);
-
+ scale(-1, 1);
image(img, 0, 0, img.width*sizePixel, img.height*sizePixel);
smooth();
// draw grid
@@ -222,53 +219,72 @@ void drawAndSetSelectedGrid() {
_16SolenoidsAr[i]="9";
}
// Draw
+
if (totalCub>0) {
pushMatrix();
translate(buttonWithBar+sizePixel*199, 0);
- int y = 26;//(rows-1)-current_row;
+ int y = 26;
// Color direction
int width16Solenoids = sizePixel*totalCub;
int rightStickOffset = 100-rightStick;
- if (headDirection==1) {
- fill(255, 0, 0, 150);
- rect(-((stitchViz-1)*sizePixel)-width16Solenoids, y*sizePixel, width16Solenoids, sizePixel);
- for (int i=(stitchViz-1);i<(stitchViz+totalCub);i++) {
- int solenoidId = ((i)%16);
- int pixelId = getReadPixelsFromPosition(i+rightStickOffset);
- if (pixelId==0 && solenoidId<16 && solenoidId>=0 ) {
- _16SolenoidsAr[solenoidId] = "1";
- }
- else if (pixelId==1 && solenoidId<16 && solenoidId>=0) {
- _16SolenoidsAr[solenoidId] = "0";
- }
- else if (pixelId==9 && solenoidId<16 && solenoidId>=0) {
- _16SolenoidsAr[solenoidId] = "9";
+ try {
+ if (headDirection==1) {
+ fill(255, 0, 0, 150);
+ rect(-((stitchViz-1)*sizePixel)-width16Solenoids, y*sizePixel, width16Solenoids, sizePixel);
+ for (int i=(stitchViz-1);i<(stitchViz+totalCub);i++) {
+ int solenoidId = ((i)%16);
+ int pixelId = getReadPixelsFromPosition(i+rightStickOffset);
+ if (pixelId==0 && solenoidId<16 && solenoidId>=0 ) {
+ _16SolenoidsAr[solenoidId] = "1";
+ }
+ else if (pixelId==1 && solenoidId<16 && solenoidId>=0) {
+ _16SolenoidsAr[solenoidId] = "0";
+ }
+ else if (pixelId==9 && solenoidId<16 && solenoidId>=0 && stitchViz<(201) ) {
+ _16SolenoidsAr[solenoidId] = "9";
+ }
+ else if (stitchViz>=201 ) {
+ _16SolenoidsAr[solenoidId] = "0";
+ }
}
}
- }
- else {
- fill(0, 255, 0, 150);
- rect(-((stitchViz-1)*sizePixel), y*sizePixel, width16Solenoids, sizePixel);
-
- for (int i=(stitchViz-1);i>((stitchViz-1)-totalCub);i--) {
- int solenoidId = ((i)%16);
- int pixelId = getReadPixelsFromPosition(i+rightStickOffset);
- if (pixelId==0 && solenoidId<16 && solenoidId>=0) {
- _16SolenoidsAr[solenoidId] = "1";
- }
- else if (pixelId==1 && solenoidId<16 && solenoidId>=0) {
- _16SolenoidsAr[solenoidId] = "0";
- }
- else if (pixelId==9 && solenoidId<16 && solenoidId>=0) {
- _16SolenoidsAr[solenoidId] = "9";
+ else {
+ fill(0, 255, 0, 150);
+ rect(-((stitchViz-1)*sizePixel), y*sizePixel, width16Solenoids, sizePixel);
+ for (int i=(stitchViz-1);i>((stitchViz-1)-totalCub);i--) {
+ int solenoidId = ((i)%16);
+ int pixelId = getReadPixelsFromPosition(i+rightStickOffset);
+ if (pixelId==0 && solenoidId<16 && solenoidId>=0) {
+ _16SolenoidsAr[solenoidId] = "1";
+ }
+ else if (pixelId==1 && solenoidId<16 && solenoidId>=0) {
+ _16SolenoidsAr[solenoidId] = "0";
+ }
+ else if (pixelId==9 && solenoidId<16 && solenoidId>=0 && stitchViz>-1) {
+ _16SolenoidsAr[solenoidId] = "9";
+ }
+ else if (stitchViz<=-1 ) {
+ _16SolenoidsAr[solenoidId] = "0";
+ }
}
}
}
+ catch(Exception e) {
+ }
popMatrix();
}
// pass from array to string to send to arduino
- for (int i=0;i<16;i++) {
- _16Solenoids +=_16SolenoidsAr[i];
+ try {
+ for (int i=0;i<16;i++) {
+ if (totalCub>0) {
+ _16Solenoids +=_16SolenoidsAr[i];
+ }
+ else {
+ _16Solenoids +="0";
+ }
+ }
+ }
+ catch(Exception e) {
}
}
View
74 protoAppKnitic_p5/protoAppKnitic_p5.pde
@@ -12,7 +12,6 @@ import processing.serial.*;
// Global variables
//------------------------------------------------------------------------------------
ControlP5 controlP5;
-scrollBar myScrollBar;
Serial myPort = null;
PImage kniticLogo;
PImage img;
@@ -26,6 +25,8 @@ String lastSerialData;
String lastChangeHead;
String[] _16SolenoidsAr;
String _16Solenoids = "9999999999999999";
+int lastSolenoidChange;
+boolean headDownSelenoid = false;
float threshold = 127;
int counterMessagesReceive=0;
int sizePixel = 3;
@@ -35,6 +36,7 @@ int[][] pixelArray;
int [] currentPixels;
int current_row = -1;
int stitch = -999;
+int _lastStitch;
int section = -999;
int lastSection = -999;
int leftStick = -1;
@@ -74,16 +76,14 @@ void setup() {
addButtonsInSetup();
kniticLogo = loadImage("logo_knitic.png");
laurentFont = loadFont("Quantico-Regular-20.vlw");
- myScrollBar = new scrollBar();
currentPixels = new int[200];
_16SolenoidsAr = new String[16];
lastMessageReceivedFromSerial = millis();
lastConnection = millis();
-
}
//------------------------------------------------------------------------------------
void draw() {
- frame.setTitle("Knitic pattern manager v.01 F:"+Float.toString(frameRate));
+ frame.setTitle("Knitic pattern manager v.01 F:"+Integer.toString(round(frameRate)));
background(200, 200, 200);
autoConnectAndReceiveSerial();
display();
@@ -92,8 +92,6 @@ void draw() {
drawPattern();
drawAndSetSelectedGrid();
}
- //drawPatternThumbnail();
- myScrollBar.mouseMoveScroll();
brain();
showCursorPosition();
updateEditPixels();
@@ -138,18 +136,18 @@ void keyPressed() {
}
/*
if (key=='1') {
- _16Solenoids = "1100000000000000";
- }
- if (key=='2') {
- _16Solenoids = "1010000100000001";
- }
- if (key=='3') {
- _16Solenoids = "1111111100000000";
- }
- if (key=='4') {
- _16Solenoids = "1111111111111111";
- }
- */
+ _16Solenoids = "1100000000000000";
+ }
+ if (key=='2') {
+ _16Solenoids = "1010000100000001";
+ }
+ if (key=='3') {
+ _16Solenoids = "1111111100000000";
+ }
+ if (key=='4') {
+ _16Solenoids = "1111111111111111";
+ }
+ */
}
//------------------------------------------------------------------------------------
void startRightSide() {
@@ -184,22 +182,37 @@ void brain() {
headDirectionForNewPixels=+1;
current_row += 1;
lastChangeHead = "left";
- if (current_row>=rows && repedPatternMode==true) current_row=0;
+ if (isPatternFinishKnitting() && repedPatternMode==true) {
+ current_row=0;
+ }
+ else {
+ setOFFSolenoids();
+ }
+ //_16SolenoidsNew = "0000000000000000";
println("endLine left");
}
if ( lastChangeHead != "right" && (stitch>=(224) || ((100+leftStick+offsetKeedles)<stitch && lastChangeHead != "right") ) ) {
headDirectionForNewPixels=-1;
current_row += 1;
lastChangeHead = "right";
- if (current_row>=rows && repedPatternMode==true) current_row=0;
+ if (isPatternFinishKnitting() && repedPatternMode==true) {
+ current_row=0;
+ }
+ else {
+ setOFFSolenoids();
+ }
+ //_16SolenoidsNew = "0000000000000000";
println("endLine right");
}
}
lastEndLineStarted = endLineStarted;
lastSection = section;
- sendSerial();
+ checkNotOnSolenoidsForLongTime();
+ sendSerial16();
}
+
+
//------------------------------------------------------------
int getReadPixelsFromPosition(int posXPixel) {
try {
@@ -210,5 +223,24 @@ int getReadPixelsFromPosition(int posXPixel) {
}
return 9;
}
+
+//------------------------------------------------------------
+
+void setOFFSolenoids() {
+ for (int i=0;i<16;i++) {
+ _16SolenoidsAr[i] ="0";
+ }
+}
+
+//------------------------------------------------------------
+
+boolean isPatternFinishKnitting(){
+ return current_row>=rows;
+}
+
+//------------------------------------------------------------
+boolean isPatternOnKnitting(){
+ return current_row>-1 && current_row<rows;
+}
//------------------------------------------------------------
View
79 protoAppKnitic_p5/serial_comunication.pde
@@ -4,7 +4,6 @@ void setupSerialConnection() {
println(Serial.list()[0]);
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[0], 115200);
- //delay(4000);// this is here for fix a mega error
lastConnection = millis();
}
catch(Exception e) {
@@ -35,10 +34,13 @@ void autoConnectAndReceiveSerial() {
}
}
-void sendSerial() {
+void sendSerial16() {
try {
if ( (millis()-lastMessageSendFromSerial)>500 || !last16Solenoids.equals(_16Solenoids) ) {
String _16SolenoidsNew = _16Solenoids.replace('9', '1');
+ if (headDownSelenoid || isPatternFinishKnitting() ) {
+ _16SolenoidsNew ="00000000000000";
+ }
String message = ",s,"+_16SolenoidsNew+","+status+",e,";
println(_16SolenoidsNew);
myPort.write(message);
@@ -47,7 +49,6 @@ void sendSerial() {
filler += "e";
}
myPort.write(filler);
- //println("send serial");
lastMessageSendFromSerial = millis();
}
last16Solenoids = _16Solenoids;
@@ -72,8 +73,6 @@ void receiveSerial() {
break;
}
}
- //findMessage = findOneMessage(all);
- //println(lastSerialData+all);
}
}
catch(Exception e) {
@@ -154,73 +153,3 @@ boolean findOneMessage(String all) {
}
}
-/*
-void receiveSerial() {
- try {
- //println("try to Receive Serial___"+Integer.toString(myPort.available()));
- if (myPort!=null && myPort.available()>0) {
- println("Receive Serial___");
- String all = "";
- while (myPort.available ()>0) {
- all += myPort.readChar();
- }
- myPort.clear();
- //println(lastSerialData+all);
- // get data from serial
- String[] values = split(lastSerialData+all, ',');
-
- int _start =-1;
- int _end =-1;
- // look for start inside string received
- for (int i=0;i<values.length;i++) {
- if (values[i].equals("s")) {
- _start =i;
- break;
- }
- }
- //println("start:"+Integer.toString(_start));
- // look for end inside string received
- if (_start!=-1) {
- for (int i=_start;i<values.length;i++) {
- if (values[i].equals("e")) {
- _end =i;
- break;
- }
- }
- }
- //println("end:"+Integer.toString(_end));
- // when we find start and end then take out variables
- if ( _start!=-1 && _end!=-1 && _end > _start+5 ) {
- println("Receive Serial_WITH ALL MESSAGE");
- lastMessageReceivedFromSerial = millis();
- //section = Integer.valueOf(values[_start+1]);
- //print("section:");
- //println(section);
- stitch = Integer.valueOf(values[_start+2]);
- section = int(stitch/8);
- endLineStarted = !values[_start+3].equals("0");
- headDirection = -Integer.valueOf(values[_start+4]);
- status = values[_start+4];
- if (status=="r" && endLineStarted) {
- status="k";
- if (stitch==0) startRightSide();
- if (stitch==200) startLeftSide();
- }
- // get part message to other
- lastSerialData ="";
- if (_end+1<values.length) {
- for (int i=_end+1;i<values.length;i++) {
- lastSerialData +=","+values[i];
- }
- }
- }
- else {
- lastSerialData +=all;
- }
- }
- }
- catch(Exception e) {
- println("ERROR in receive serial");
- }
- }
- */
View
22 protoAppKnitic_p5/soleanoidsHead.pde
@@ -0,0 +1,22 @@
+void checkNotOnSolenoidsForLongTime() {
+ // Check if the head did move
+ if (stitch !=_lastStitch) {
+ _lastStitch = stitch;
+ lastSolenoidChange = millis();
+ }
+ // Check if the solenoids stay on for more than a minute
+ if (millis()-lastSolenoidChange>60000 && _16Solenoids !="00000000000000" && isPatternOnKnitting() ) {
+ headDownSelenoid = true;
+ sendSerial16();
+ try {
+ JOptionPane.showMessageDialog(frame, "The carriage is left without finish line and can heat up solenoid. Accept and continue knitting.", "Alert from Knitic", 2);
+ lastSolenoidChange = millis();
+ }
+ catch(Exception e) {
+ }
+ }
+ else {
+ headDownSelenoid = false;
+ }
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.