import Robot.*;

public class ClassNameHere {

	private Microbot    robot = new Microbot("COM1");
	
	Location points[]=new Location[2];
	

	//COMPILER GENERATED CODE; DO NOT MODIFY
	Location PLACE = new Location(8.07,0.0,0.1,-90.0,0.0,"PLACE");
	Location A = new Location(5.43,-3.53,-0.05,-90.0,-32.57,"A");
	Location B = new Location(5.48,3.47,-0.07,-90.0,39.84,"B");
	Location MEET = new Location(14.414023326711678,-1.6203651031891415,9.105013009970863,0.23437500000000133,92.109375,"MEET");
	Location H = new Location(10.347607972056487,-0.7182376949570931,8.832700547064771,-7.031250000000002,80.625,"H");
	//COMPILER GENERATED CODE; DO NOT MODIFY

	public ClassNameHere() {
		points[0]=A;
		points[1]=B;
		int cycles=4;
		
		robot.signal(-1);
		robot.delay(4);
		
		robot.move(H);
		
		for (int i=0;i<cycles;i++) {
			movePointToPoint(0,1);
			if (robot.getInputBit(7)==1) sidetrack();
			movePointToPoint(1,0);
			if (robot.getInputBit(7)==1) sidetrack();
		};
		//sidetrack();
		
		robot.move(H);
		robot.ready();
		robot.closePort();
	}
	
	private void movePointToPoint(int from, int to) {
		robot.appro(points[from],3);
		robot.movet(points[from],2);
		robot.grasp();
		robot.appro(points[from],3);
		robot.appro(points[to],3);
		robot.move(points[to]);
		robot.open();
		robot.appro(points[to],3);
		robot.grasp();
	}
	
	private void sidetrack() {
		robot.move(H);
		robot.open();
		robot.move(MEET);
		robot.close(0.6);
		robot.signal(1);
		robot.delay(2);
		robot.move(H);
		robot.move(PLACE);
		robot.open();
		robot.signal(-1);
		robot.move(H);
		robot.grasp();
	}
	
	public static void main(String args[]) {new ClassNameHere();};

}
