1 / 9

CSE 1341 Honors

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

asta
Download Presentation

CSE 1341 Honors

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 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 }

  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(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()

  9. ?

More Related