90 likes | 197 Views
CSE 1341 Honors. Professor Mark Fontenot Southern Methodist University Note Set 11. Overview. The iCommand API Motors Sensors Thread.sleep (). iCommand API. API = Application Programming Interface See …/icommand-0.7/docs/api/index.html
E N D
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 11
Overview • The iCommand API • Motors • Sensors • Thread.sleep()
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.
iCommand API • Some objects/classes to review: • Library icommand.nxt • LightSensor • TouchSensor • UltrasonicSensor • Motor • Library icommand.navigation • Pilot • TachoNavigator
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
Sensors – TouchSensor Example what port the sensor is connected to… 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 }
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
Thread.sleep(intval) • 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()