Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 11.

Similar presentations


Presentation on theme: "CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 11."— Presentation transcript:

1 CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 11

2 Overview The iCommand API Motors Sensors Thread.sleep()

3 iCommand API API = Application Programming Interface See …/icommand-0.7/docs/api/index.html – Documentation for the complete iCommand library – Shows all of the different objects that you can create in order to interact with your robot. – There are different “levels of abstraction” you can use as well.

4 iCommand API Some objects/classes to review: – Library icommand.nxt LightSensor TouchSensor UltrasonicSensor Motor – Library icommand.navigation Pilot TachoNavigator

5 Working Directly with the Motors Motor.A.forward(); move whatever motor is connected to motor port A on the brick in a forward direction Motor.A.stop(); stop whatever motor is connected to motor port A on the brick

6 Sensors – TouchSensor Example TouchSensor touch = new TouchSensor(SensorPort.S1); Create a new touch sensor object and call it touch. touch is an object reference variable that allows you to “talk to” the touch sensor. Example: touch.isPressed(); //returns a boolean… //can be used in an if statement if (touch.isPressed()) { //do something } Might be better in a While loop so that it continually tests the sensor to see if its pressed: while (touch.isPressed()) { //do something } what port the sensor is connected to…

7 Touch Sensor TouchSensor touch = new TouchSensor(SensorPort.S1); Motor.A.forward();//Start A motor //Don’t do anything while the touch sensor isn’t //pressed. just loop... while (!touch.isPressed()) System.out.println("Touch Sensor Not Pressed"); Motor.A.stop(); //Stop A motor

8 Thread.sleep(int val) Tells your program to “sleep” for a certain amount of time In milliseconds public static void main (String [] args) throws Exception { Motor.A.forward(); Thread.sleep(5000); // sleep for 5 seconds Motor.B.stop(); } Needs to be added to any method that uses Thread.sleep()

9 ?


Download ppt "CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 11."

Similar presentations


Ads by Google