Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: Java  |  size: 1.68 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.io.BufferedReader;
  2. import java.io.DataInputStream;
  3. import java.io.FileInputStream;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6.  
  7. import javaclient3.PlayerClient;
  8. import javaclient3.Position2DInterface;
  9. import javaclient3.SonarInterface;
  10. import javaclient3.structures.PlayerConstants;
  11.  
  12.  
  13. public class Localizer {
  14.         public static void main(String[] args) {
  15.             ArrayList<ArrayList<Double>> points =new ArrayList<ArrayList<Double>>();
  16.                 PlayerClient pc;
  17.                 if (args.length == 0){
  18.                        
  19.                     pc = new PlayerClient("localhost",6665);
  20.  
  21.                 }else{
  22.                     pc = new PlayerClient(args[0],Integer.valueOf(args[1]));
  23.                 }
  24.                 Position2DInterface pos = pc.requestInterfacePosition2D(0,PlayerConstants.PLAYER_OPEN_MODE);
  25.                 double ninty=90 * Math.PI/180;
  26.                 double turn=0.0;
  27.                 double fwd=0.0;
  28.                 boolean done=false;
  29.                 pc.readAll();
  30.                 double startang=pos.getYaw();
  31.                 //System.out.println("three sixtay " + three_sixty );
  32.                 SonarInterface ranger =pc.requestInterfaceSonar(0,PlayerConstants.PLAYER_OPEN_MODE);
  33.                 while(pc.requestInterfaceSonar(0,PlayerConstants.PLAYER_OPEN_MODE)==null){
  34.                 ranger = pc.requestInterfaceSonar(0,PlayerConstants.PLAYER_OPEN_MODE);
  35.                 }
  36.                 double old_ang=pos.getYaw();
  37.                 double start_ang=pos.getYaw();
  38.                 double ammount_turned=0.0;
  39.                 System.out.println("I started at " + start_ang *180/Math.PI);
  40.                 //System.out.println("start+360 "+ ((start_ang-three_sixty)*180/Math.PI));
  41.                
  42.                 while(!done){
  43.                         pc.readAll();
  44.                         turn=.2;
  45.                         pos.setSpeed(fwd,turn);
  46.                         old_ang=pos.getYaw();
  47.                         System.out.println("pos-ninty " + Math.abs(pos.getYaw()-(startang+ninty)));
  48.                         if(Math.abs(pos.getYaw()-(startang+ninty)) < .1){
  49.                                 turn=0;
  50.                                 done=true;
  51.                         }
  52.                 }
  53.         }
  54. }