Advertisement
sirinehamza

Gcode to cartesian

Apr 23rd, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package fromgcodetocartesian;
  7.  
  8. import static com.sun.xml.internal.bind.v2.schemagen.Util.equal;
  9. import java.io.BufferedReader;
  10. import java.io.FileReader;
  11. import java.io.IOException;
  12.  
  13. /**
  14.  *
  15.  * @author sirine
  16.  */
  17. public class FromGcodeToCartesian {
  18.  
  19.     /**
  20.     * @param args the command line arguments
  21.     */    
  22.     static void getCartesian(String expression_Initiale){
  23.         if(equal(expression_Initiale.substring(0,3),"G01")
  24.                 ||equal(expression_Initiale.substring(0,3),"G02")
  25.                 ||equal(expression_Initiale.substring(0,3),"G03")
  26.                 ||equal(expression_Initiale.substring(0,3),"G04")){
  27.             if(expression_Initiale.charAt(4)=='X'||expression_Initiale.charAt(4)=='Y'){
  28.                 String X = expression_Initiale.substring(5,10);
  29.                 Double XPrime = Double.parseDouble(X);
  30.                 String Y = expression_Initiale.substring(12,17);
  31.                 Double YPrime = Double.parseDouble(Y);  
  32.                 System.out.println("(X="+XPrime+",Y="+YPrime+")");  
  33.                 //Create the point and add it to the object                
  34.     }}
  35. }
  36.     public static void main(String[] args) {
  37.         // TODO code application logic here
  38.         BufferedReader reader;
  39.         try{
  40.             reader=new BufferedReader(new FileReader("/Users/apple/Desktop/IP.txt"));
  41.             String line = reader.readLine();
  42.             while(line!=null){
  43.                 getCartesian(line);
  44.                 //read the next line
  45.                 line = reader.readLine();
  46.             }
  47.             reader.close();
  48.         }catch(IOException e){
  49.             e.printStackTrace();
  50.         }  
  51.     }    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement