Week16 : Machine Design

Group Work

Group assignmet is here

Problem from last week

Continuing from last week, we are making a circuit making machine using conductive ink. We had the mirrored image problem last week as written in the group page .
This week we started off by fixing that problem. We tested all pattern of connection and we checked motor direction program. Jun played a central role in solving this problem.

My Contribution

Pen Slider

We had a problem that the penslider was unstable as follows.

My role was fixing this problem. I thought that there were two solution, one was changing the structure, another was improving the accuracy without changing the structure. I chose the latter way.
The cause of that problem was too much margin and the length of the pen holder that I designed.

I repeatedly adjusted.


Eventually became the leftmost one.
The penslider was improved as following movie.

Gcode generator

Next, I tried to make G-code generator with Processing. Following program is very limited use because of it is available only for svg polygon. But making GCode generator made me to understand G-Code a little.
ArrayList<Polygon> mypg;

//Serial myPort;
PrintWriter output;

public void setup() {
  size(300,300);

  output = createWriter("g.ngc");
  //--------------------------------------------------------------------------------------------------
}

void draw() {
  gcode();
  exit();
}

class Polygon{
  public ArrayList<PVector> mypoint;
  PVector ppp;
  public String myname;
  Polygon(String x){
    //println(x);
     mypoint=new ArrayList();
     String[] p = splitTokens(x,":");
     for (int i = 0; i < p.length; i++) { 
         String[] pp=splitTokens(p[i],",");
         //println(pp[0] +":" +pp[1]);
         ppp=new  PVector(float(pp[0]),float(pp[1]));
         mypoint.add(ppp);
     }
  }
}


void gcode(){
  String lines[];
  boolean pflag=false;
  String sd;
  Polygon myp;
 

  mypg=new ArrayList();
  //--------------------------
  
  lines = loadStrings("a.svg");
  sd="";
  for (int i = 0; i < lines.length; i++) { 
      try{
          String[] m1 = match(lines[i], "polygon");
          String[] m2 = match(lines[i], "</g>");
          if(m1!= null && pflag==false) {
            pflag=true;
          }
          if(m2!= null && pflag) {
            pflag=false;
          }
          if(pflag){
              //polygonデータを分割する
              String[] s = splitTokens(lines[i]);
              for(int j=0; j<s.length; j++){

                 s[j]=s[j].replaceAll("points=\"","");
                 String[] m3 = match(s[j], "polygon");
                 String[] m4 = match(s[j], "/>");
                 String[] m5 = match(s[j], "\"");
                 if(m4!=null){
                   myp=new Polygon(sd);
                   mypg.add(myp);
                   sd="";
                 }
                 
                 if(m3== null && m4== null && m5== null) {
                   sd=sd+":" +s[j];
                 }
              } 
          }
      }catch(StringIndexOutOfBoundsException e){
      }catch(NullPointerException e){
      }
  }
  //最大値----------------------------------------------------------------------------------------------
  float maxv=0;
  for (int i = 0; i < mypg.size(); i++) { 
      Polygon op=mypg.get(i);
        for (int j = 1; j < op.mypoint.size(); j++) { 
          if (maxv<op.mypoint.get(j).x){
            maxv=op.mypoint.get(j-1).x;
          }
          if (maxv<op.mypoint.get(j).y){
            maxv=op.mypoint.get(j-1).y;
          }
        }
  }
//--------------------------------------------------------------------------------------------------  
  output.print("T2 S1\n");
  output.flush();
   for (int i = 0; i < mypg.size(); i++) { 
      Polygon op=mypg.get(i);
        for (int j = 0; j < op.mypoint.size(); j++) { 
          int cvx=round(op.mypoint.get(j).x * 20/maxv);
          int cvy=round(op.mypoint.get(j).y * 20/maxv+10);
          
          if (j==0){
             output.print("G00 X"+cvx+" Y"+cvy+"\n");
             output.flush();
          }        
          output.print("G01 X"+cvx+" Y"+cvy+"\n");
          output.flush();       
          if (j==op.mypoint.size()-1){
            output.print("G00 X"+cvx+" Y"+cvy+"\n");
            output.flush();
          }
          //delay(500);
        }  
  }
  output.print("G00 X0 Y0 \n");
  output.flush();
  output.print("T2 S1\n");
  output.flush();
}

Above svg data is trasrated to G-Code as follows.
T2 S1
G00 X9 Y21
G01 X9 Y21
G01 X9 Y15
G01 X19 Y15
G01 X19 Y21
G00 X19 Y21
G00 X9 Y24
G01 X9 Y24
G01 X9 Y30
G01 X19 Y30
G01 X19 Y24
G00 X19 Y24
G00 X0 Y0 
T2 S1
I used this G-code with our machin !(It is part of the circuit)

Files

Files can be downloaded from here.