VisClient/org/hfbk/vis/visnode/VisKUKA.java

Go to the documentation of this file.
00001 package org.hfbk.vis.visnode;
00002 
00003 import org.dronus.graph.Node;
00004 import org.hfbk.vis.RS232Listener;
00005 import org.lwjgl.opengl.GL11;
00006 import org.lwjgl.util.vector.Vector3f;
00007 
00008 public class VisKUKA extends VisBalistic implements RS232Listener.Handler{
00009         
00010         
00011         double  axisHeadingOffset=  287894,
00012                         axisHeadingScale=   -(287894-(-177168))/Math.PI,
00013                         
00014                         axisElevationOffset=39196,
00015                         axisElevationScale= -(188435-(-4990)) /(Math.PI/2.5);
00016         
00017         long    axisHeadingMin=128600,
00018                         axisHeadingMax=343844,
00019                         axisElevationMin=-1000,
00020                         axisElevationMax=175000;
00021                         
00022         VisKUKA(Node node, Vector3f pos) {
00023                 super(node, pos);
00024                 RS232Listener.instance.addHandler(this);
00025         }
00026 
00027         @Override
00028         void transform() {
00029                 super.transform();
00030                 GL11.glRotatef(180, 0,1,0);
00031         }
00032         @Override
00033         void renderSelf() {
00034                 super.renderSelf();
00035                 //System.out.println("KUKA: heading:"+heading+" elevation:"+elevation);
00036         }
00037 
00038         public void handleRS232(RS232Listener listener, String msg) {
00039                 //use heading, direction. 
00040                 if (msg.matches("EXT\\?\\: (1|2)\\:.*")){ 
00041                                 
00042                         double axisHeading=  heading  *axisHeadingScale  +axisHeadingOffset;
00043                         double axisElevation=elevation*axisElevationScale+axisElevationOffset;
00044                         
00045                         msg=targetMessage(msg, (long)axisHeading, (long)axisElevation);
00046                         listener.print(msg);            
00047                 }else if (msg.matches("EXT\\?\\: 3\\:.*")){ //wait command
00048                         try {Thread.sleep(5000);} catch (InterruptedException e) {              e.printStackTrace();}
00049                         listener.print("/000"); 
00050                 }else{
00051                         listener.print("/000");
00052                 }
00053         }
00054         
00055         long clamp(long x, long min, long max){
00056                 if (x<min) x=min;
00057                 if (x>max) x=max;
00058                 return x;
00059         }
00060         
00061         String targetMessage(String msg, long axisHeading, long axisElevation){
00062                 String[] params=msg.split(":");
00063                 //TODO korrekter parameterstring
00064                 
00065                 axisHeading=  clamp(axisHeading,   axisHeadingMin,   axisHeadingMax);
00066                 axisElevation=clamp(axisElevation, axisElevationMin, axisElevationMax);
00067                 
00068                 msg=String.format("EXT!:%s:%8d:%s:%8d:%s:%s:%s:%s/",params[1],axisHeading,params[3],axisElevation,params[5],params[6],params[7],params[8]); //usw.
00069                 return msg;
00070         }
00071         
00072         float drawRanges() {
00073                 float rmax=0;
00074                 GL11.glColor4f(1,1,1,.6f);
00075                 
00076                 double end=(axisHeadingMin-axisHeadingOffset)/axisHeadingScale; //2*Math.PI;
00077                 double start=  (axisHeadingMax-axisHeadingOffset)/axisHeadingScale; //2*Math.PI;
00078 
00079                 rmax=(float)wurfweite(bestAngle(y0));  //Reichweite
00080                 
00081                 /*for (float y=-100; y<y0; y+=3){
00082                         rmax=(float)wurfweite(bestAngle(y));  //Reichweite
00083                         if (rmax!=Float.NaN){
00084                                 GL11.glBegin(GL11.GL_LINE_STRIP);
00085                                 for (double i=start; i<end; i+=.01f)
00086                                         GL11.glVertex3f((float)Math.cos(i)*rmax, -y, (float)Math.sin(i)*rmax);          
00087                                 GL11.glEnd();
00088                         }
00089                 }
00090                 */
00091                 for (float r=rmax; r>0; r-=3){
00092                         GL11.glBegin(GL11.GL_LINE_STRIP);
00093                         for (double i=start; i<end; i+=.1f)
00094                                 GL11.glVertex3f((float)Math.cos(i)*r, -y0, (float)Math.sin(i)*r);               
00095                         GL11.glEnd();
00096                 }
00097                 
00098                 GL11.glBegin(GL11.GL_LINES);
00099                 for (double i=start; i<end; i+=.1f){
00100                         GL11.glVertex3f((float)Math.cos(i)*rmax, -y0, (float)Math.sin(i)*rmax);         
00101                         GL11.glVertex3f(0, -y0, 0);
00102                 }
00103                 GL11.glEnd();
00104                 
00105                 return rmax;
00106         }
00107 }

Generated on Tue Apr 7 17:57:21 2009 for visclient by  doxygen 1.5.1