Path finding for CNC, need help please :(
in
Programming Questions
•
1 year ago
Hello,
I am making a Arduino/Processing based CNC. What im trying to create is a line following program in processing. You create a png image on paint or similar program 1000 x 1000 (cutting area of my cnc). You design what you want to be cut/engraved on paint placing black lines (black = cut, white = nocut). You then open this up in processing and it will scan the image until it finds a black line, once its found a black line it will then follow the outline of that black line until it reaches back to the start. Then it carrys on scanning but ignors that part of the line already been cut. When its cutting it outputs the X and Y cord plus Z cord for cut and no cut to the arduino. The idea came from a guy on youtube which his account seems to be inactive so i get no responce from him. So i am trying to recreate it. Here is the video:
http://www.youtube.com/watch?v=qZRcu0J6hCQ&feature=plcp
And here is my code so far:
It kind of works but it gets stuck and im not sure why. Also i have no idea how to do an ignore list to ignore lines it has already done. Any help would be great.
Thanks,
Calum.
I am making a Arduino/Processing based CNC. What im trying to create is a line following program in processing. You create a png image on paint or similar program 1000 x 1000 (cutting area of my cnc). You design what you want to be cut/engraved on paint placing black lines (black = cut, white = nocut). You then open this up in processing and it will scan the image until it finds a black line, once its found a black line it will then follow the outline of that black line until it reaches back to the start. Then it carrys on scanning but ignors that part of the line already been cut. When its cutting it outputs the X and Y cord plus Z cord for cut and no cut to the arduino. The idea came from a guy on youtube which his account seems to be inactive so i get no responce from him. So i am trying to recreate it. Here is the video:
http://www.youtube.com/watch?v=qZRcu0J6hCQ&feature=plcp
And here is my code so far:
- PImage pic;
int xCheck, yCheck, xPlot, yPlot, index, indexPlot, scan, first;
float thresh;
void setup(){
pic = loadImage("image.png");
size(pic.width, pic.height);
image(pic, 0, 0);
scan = 1;
}
void draw(){
noStroke();
if(scan == 1){
first = 0;
for(int i = 0; i < 100; i++){
xCheck++;
if(xCheck > 1000){
yCheck++;
xCheck = 0;
}
if(yCheck > 1000){
xCheck = 0;
yCheck = 0;
}
index = xCheck + yCheck*width;
thresh = brightness(pic.pixels[index]);
if(thresh == 0){
fill(0,255,0);
ellipse(xCheck, yCheck, 1, 1);
scan = 0;
}else{
fill(255,0,0);
ellipse(xCheck, yCheck, 1, 1);
}
}
}else{
if(first == 0){
xPlot = xCheck;
yPlot = yCheck;
first = 1;
}
indexPlot = xPlot + yPlot*width;
fill(150,150,255);
ellipse(xPlot, yPlot, 1, 1);
if(brightness(pic.pixels[indexPlot+1]) == 0){
xPlot++;
}else{
if(brightness(pic.pixels[indexPlot+1000]) == 0){
yPlot++;
}else{
if(brightness(pic.pixels[indexPlot-1]) == 0){
xPlot--;
}else{
if(brightness(pic.pixels[indexPlot+1000]) == 0){
yPlot--;
}
}
}
}
}
}
And heres the image i am testing with:
It kind of works but it gets stuck and im not sure why. Also i have no idea how to do an ignore list to ignore lines it has already done. Any help would be great.
Thanks,
Calum.
1