2014年8月7日 星期四

如何將asc檔轉成mesh檔


一、進入MeshLab
File->Import Mesh->找到asc
不要勾選Grid Triangulation->ok



二、轉成ply

File->Expore Mesh As->Files of type ply->save->OK

2014年6月11日 星期三

系統校正及測試

一、測試樣品
     
 利用捲筒衛生紙的內紙筒作一個圓柱體,加一個重物,使得旋轉時不會位移。





二、雷射線、攝影機及轉盤中心呈現一個直角三角型


三、雷射在物品上的線要正,不可斜

四、轉入MeshLab





五、MESH



2014年6月5日 星期四

畢業了

終於結束高工三年生活,也送出所有的備審資料

放煙火慶祝一下









2014年4月20日 星期日

SKY2的影像轉換程式


將影像的最亮點找出來,其他的點均刪除,最後轉為ASC檔,利用MESHLAB為PLY檔



 //objects
 PFont f;

 PrintWriter output;

 //colors
 color black=color(0);
 color white=color(255);

 //variables
 int itr;             //iteration
 float pixBright;
 float maxBright=0;
 int maxBrightPos=0;
 int prevMaxBrightPos;
 int row;
 int col;
 int FileCount=1;
 int brightThHold=250;  //ignore the bright point below brightThHold
 int LaserSum=0;
 int LaserNum=0;

 //scanner parameters
 float NumSteps = 271;  //number of steps per revolution
 float AngleLaserCam = 30*PI/180;  //angle between laser and camera [radian]
 float AngleTwoSteps=2*PI/NumSteps;  //angle between 2 steps [radian]

 //coordinates
 float x, y, z;  //cartesian cords., [milimeter]
 float ro;  //first of polar coordinate, [milimeter]
 float fi; //second of polar coordinate, [radian]
 float distance; //distance between brightest pixel and middle of photo [pixel]
 float PixelHor = 5; //pixels per milimeter horizontally 1px=0.2mm
 float PixelVer = 5; //pixels per milimeter vertically 1px=0.2mm

 //================= CONFIG ===================

 void setup() {
   size(640,480);
   strokeWeight(1);
   smooth();
   background(0);

   //fonts
   f=createFont("Arial",16,true);
   //output file
   output=createWriter("RealImage.asc");

 }

 //============== MAIN PROGRAM =================

 void draw() {
    for (itr=0; itr<NumSteps; itr++){
 
     String RealImageFileName="RealImage-"+nf(itr+1, 3)+".png";
 
     PImage RealImage=loadImage(RealImageFileName);
     String LineImageFileName="LineImage-"+nf(itr+1, 3)+".png";
     PImage LineImage=createImage(RealImage.width, RealImage.height, RGB);
     RealImage.loadPixels();
     LineImage.loadPixels();
     int currentPos;
     fi=itr*AngleTwoSteps;
     println(fi);

     for(row=0; row<RealImage.height; row++){  //starting row analysis
     maxBrightPos=0;
     maxBright=0;

       for(col=0; col<RealImage.width; col++){
         currentPos = row * RealImage.width + col;
         pixBright=brightness(RealImage.pixels[currentPos]);
         if(pixBright>maxBright){
           maxBright=pixBright;
           maxBrightPos=currentPos;
           LaserSum=currentPos;
           LaserNum=1;
         }
         if(pixBright==maxBright){
           LaserSum=LaserSum+currentPos;
           LaserNum=LaserNum+1;
         }
         LineImage.pixels[currentPos]=black; //setting all pixels black
       }  // end od a row analysis

      if (maxBright > brightThHold) {
       maxBrightPos=LaserSum/LaserNum;
       LineImage.pixels[maxBrightPos]=white; //setting brightest pixel white
      }
       distance=((maxBrightPos+1-row*RealImage.width)-RealImage.width/2)/PixelHor;
       ro=distance/sin(AngleLaserCam);
 
   
       x=ro * cos(fi);  //changing polar coords to kartesian
       y=ro * sin(fi);
       z=row/PixelVer;
   
       if( (ro>=-30) && (ro<=60) ){              //printing coordinates
         output.println(x + "," + y + "," + z);
       }
   
     }//end of all  row analysis
 
     LineImage.updatePixels();
     LineImage.save(LineImageFileName);
 
   }
   output.flush();
   output.close();

   println("End processing.........");
     noLoop();
 }









2014年4月6日 星期日

SKY2的影像截取程式

一、SKY1僅需步進馬達驅動程式,其他都由免費軟體程行。SKY2從影像截取、分析到3D坐標轉換都要己來,下面是影像截取程式。

二、開發工具:PROCESSING 2.1
                           下載:https://processing.org/download/
        CAM控制:JMyron 0025
                           下載: http://webcamxtra.sourceforge.net/download.shtml

三、影像截取程式

import JMyron.*;

 //objects
 PFont f;

 JMyron cam;

 PrintWriter output;
 int FileCount=1;

 //colors
 color black=color(0);
 color white=color(255);

 //scanner parameters
 float Steps = 271;  //number steps of motor per revolution
 float AngleLaserCamera = 30*PI/180;  //angle between laser and camera [radian]
 float AngleTwoStep=2*PI/Steps;  //angle between 2 step [radian]


 //================= CONFIG ===================

 void setup() {
   size(640,480);
   strokeWeight(1);
   smooth();
   background(0);
 
   //fonts
  f=createFont("Arial",16,true);
  cam = new JMyron();
  cam.start(width, height);
  cam.findGlobs(0);
   
 }

 //============== MAIN PROGRAM =================

 void draw() {
 
   PImage RealImage=createImage(width,height,RGB);
 
   cam.update();
 
   delay(1000);
     cam.update();
     RealImage.loadPixels();
     int[] currFrame = cam.image();
     loadPixels();
     for (int n=0;n<RealImage.width*RealImage.height;n++){
       RealImage.pixels[n]=currFrame[n];
       pixels[n] = currFrame[n];
     }
     RealImage.updatePixels();
     updatePixels();
     String RealImageFileName="RealImage-"+nf(FileCount, 3)+".png";
     RealImage.save(RealImageFileName);

     println(FileCount);
  if (FileCount == Steps ) {
    println("End getting image......");

    //println("End processing.........");
     noLoop();
    }  else {
    FileCount=FileCount+1;
    }

 }

四、部分結果







(準備統測中,其他部分有空再補)


2014年3月22日 星期六

電路及程式



步進馬達驅動需要較大電流,可用2D掃瞄器的驅動IC及電源,故將UNO的控制信號加在驅動IC的信號輸入端可





UNO程式如下


const int motorPin1 = 11;     
const int motorPin2 = 10;     
const int motorPin3 = 13;     
const int motorPin4 = 12;     
                               
int motorSpeed=1000;            // set stepper speed
float err=0;

void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop(){

 for(int i=0;i<2;i++) cw();

 delay(1000); 
}


//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
void ccw (){
  // 1
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 2
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 3
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 4
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 5
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, LOW);
  delayMicroseconds(motorSpeed);
  // 6
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
  // 7
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
  // 8
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin4, HIGH);
  delayMicroseconds(motorSpeed);
}
//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 4 to 1
void cw(){
  // 1
  digitalWrite(motorPin4, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 2
  digitalWrite(motorPin4, HIGH);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 3
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 4
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, HIGH);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 5
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin1, LOW);
  delayMicroseconds(motorSpeed);
  // 6
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, HIGH);
  digitalWrite(motorPin1, HIGH);
  delayMicroseconds(motorSpeed);
  // 7
  digitalWrite(motorPin4, LOW);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, HIGH);
  delayMicroseconds(motorSpeed);
  // 8
  digitalWrite(motorPin4, HIGH);
  digitalWrite(motorPin3, LOW);
  digitalWrite(motorPin2, LOW);
  digitalWrite(motorPin1, HIGH);
  delayMicroseconds(motorSpeed);

}

2014年3月8日 星期六

安裝測試

安裝測試


一、確認連接埠

控制台->系統->硬體->裝置管理員





二、點選連接埠(COMLPT),記住COM4(每個機器可能不同),這是Arduino的連接埠地址





三、開啓Arduino

四、成功進入arduino


五、設定連接埠

Tools->Serial Port->COM4(要與裝置管理員顯示的一致)




六、設定後會出現打勾



七、打開範例程式—LED

File->Open->c:Program Files\Arduinp\examples\01Basics\Blink\Blink.ino


/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
 */

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;    //LED的長腳接PIN13,短腳接GND

// the setup routine runs once when you press reset:
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);    
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

八、接好硬體

LED的長腳接PIN13,短腳接GND


九、按File->Upload就開始上傳執行碼





十、上傳完,可見LED一閃一閃