src/main.java
// Main entry point - instantiate objects used and set up sensor
Main entry point - instantiate objects used and set up sensor
Main entry point - instantiate objects used and set up sensor
public static void main(String [] args) {
		int option = 0;
		Printer.printMainMenu();						
		while (option == 0)								
			option = Button.waitForAnyPress();			
		BangBangController bangbang = new BangBangController(leftMotor, rightMotor,
															 bandCenter, bandWidth, motorLow, motorHigh, usMotor);
		PController p = new PController(leftMotor, rightMotor, bandCenter, bandWidth);
		@SuppressWarnings("resource")							    
		SensorModes usSensor = new EV3UltrasonicSensor(usPort);		
		SampleProvider usDistance = usSensor.getMode("Distance");	
		float[] usData = new float[usDistance.sampleSize()];		
		Printer printer = null;										
		UltrasonicPoller usPoller = null;							
		switch(option) {
		case Button.ID_LEFT:										
			usPoller = new UltrasonicPoller(usDistance, usData, bangbang);
			printer = new Printer(option, bangbang);
			break;
		case Button.ID_RIGHT:										
			usPoller = new UltrasonicPoller(usDistance, usData, p);
			printer = new Printer(option, p);
			break;
		default:
			System.out.println("Error - invalid button");			
			System.exit(-1);
			break;
		}
		usPoller.start();
		printer.start();
		Button.waitForAnyPress();
		System.exit(0);
	}
public static void main ( String [ ] args ) { int option = 0 ; Printer . printMainMenu ( ) ; while ( option == 0 ) option = Button . waitForAnyPress ( ) ; BangBangController bangbang = new BangBangController ( leftMotor , rightMotor , bandCenter , bandWidth , motorLow , motorHigh , usMotor ) ; PController p = new PController ( leftMotor , rightMotor , bandCenter , bandWidth ) ; @ SuppressWarnings ( "resource" ) SensorModes usSensor = new EV3UltrasonicSensor ( usPort ) ; SampleProvider usDistance = usSensor . getMode ( "Distance" ) ; float [ ] usData = new float [ usDistance . sampleSize ( ) ] ; Printer printer = null ; UltrasonicPoller usPoller = null ; switch ( option ) { case Button . ID_LEFT : usPoller = new UltrasonicPoller ( usDistance , usData , bangbang ) ; printer = new Printer ( option , bangbang ) ; break ; case Button . ID_RIGHT : usPoller = new UltrasonicPoller ( usDistance , usData , p ) ; printer = new Printer ( option , p ) ; break ; default : System . out . println ( "Error - invalid button" ) ; System . exit ( - 1 ) ; break ; } usPoller . start ( ) ; printer . start ( ) ; Button . waitForAnyPress ( ) ; System . exit ( 0 ) ; }
Main entry point - instantiate objects used and set up sensor
Main entry point - instantiate objects used and set up sensor
// Set up the display on the EV3 screen // and wait for a button press.  The button // ID (option) determines what type of control to use // Setup controller objects // Setup ultrasonic sensor // Note that the EV3 version of leJOS handles sensors a bit differently. // There are 4 steps involved: // 1. Create a port object attached to a physical port (done already above) // 2. Create a sensor instance and attach to port // 3. Create a sample provider instance for the above and initialize operating mode // 4. Create a buffer for the sensor data // Because we don't bother to close this resource // usSensor is the instance // usDistance provides samples from this instance // usData is the buffer in which data are returned // Setup Printer											// This thread prints status information // in the background // Setup Ultrasonic Poller									// This thread samples the US and invokes // the selected controller on each cycle // Depending on which button was pressed, invoke the US poller and printer with the // appropriate constructor. // Bang-bang control selected // Proportional control selected // None of the above - abort // Start the poller and printer threads //Wait here forever until button pressed to terminate wallfollower