
Untitled
By: a guest on
May 4th, 2012 | syntax:
Java | size: 1.68 KB | hits: 19 | expires: Never
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import javaclient3.PlayerClient;
import javaclient3.Position2DInterface;
import javaclient3.SonarInterface;
import javaclient3.structures.PlayerConstants;
public class Localizer {
public static void main(String[] args) {
ArrayList<ArrayList<Double>> points =new ArrayList<ArrayList<Double>>();
PlayerClient pc;
if (args.length == 0){
pc = new PlayerClient("localhost",6665);
}else{
pc = new PlayerClient(args[0],Integer.valueOf(args[1]));
}
Position2DInterface pos = pc.requestInterfacePosition2D(0,PlayerConstants.PLAYER_OPEN_MODE);
double ninty=90 * Math.PI/180;
double turn=0.0;
double fwd=0.0;
boolean done=false;
pc.readAll();
double startang=pos.getYaw();
//System.out.println("three sixtay " + three_sixty );
SonarInterface ranger =pc.requestInterfaceSonar(0,PlayerConstants.PLAYER_OPEN_MODE);
while(pc.requestInterfaceSonar(0,PlayerConstants.PLAYER_OPEN_MODE)==null){
ranger = pc.requestInterfaceSonar(0,PlayerConstants.PLAYER_OPEN_MODE);
}
double old_ang=pos.getYaw();
double start_ang=pos.getYaw();
double ammount_turned=0.0;
System.out.println("I started at " + start_ang *180/Math.PI);
//System.out.println("start+360 "+ ((start_ang-three_sixty)*180/Math.PI));
while(!done){
pc.readAll();
turn=.2;
pos.setSpeed(fwd,turn);
old_ang=pos.getYaw();
System.out.println("pos-ninty " + Math.abs(pos.getYaw()-(startang+ninty)));
if(Math.abs(pos.getYaw()-(startang+ninty)) < .1){
turn=0;
done=true;
}
}
}
}