Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
5th Annual Robofest 2004 Informational Meeting Mar. 20, 2004 Chan Jin Chung Ali Khazaal Jason Lo Computer Science Lawrence Technological University chung 1 Agenda • Introduction to Robofest and Game Rules Go to www.robofest.net and click on Announcement link Tech Resource link • 9:15am: NQC Installation and Basics • 10:45am: Java, LeJos, Eclipse setup • Announcements chung 2 NQC installation • You must install RIS or RoboLab software to install the drivers for your IR tower. • Tech Resource or CD-ROM given today • Bricxcc 3.3.7.7 chung 3 NQC • NQC complier – David Baum • Brick Command Center (bricxcc) – IDE tool • Tutorial: www.robofest.net TechResource chung 4 The first NQC program task main() { OnFwd(OUT_A); OnFwd(OUT_B); Wait(400); // 4 sec OnRev(OUT_A+OUT_B); Wait(400); Off(OUT_A+OUT_B); } chung 5 Control Structures • • • • • chung repeat(n) while if if else do while 6 Using variables #define TURN_TIME int move_time; 85 // define a variable task main() { move_time = 20; // set the initial value repeat(50) { OnFwd(OUT_A+OUT_C); Wait(move_time); // use the variable for sleeping OnRev(OUT_C); Wait(TURN_TIME); move_time += 5; // increase the variable } Off(OUT_A+OUT_C); } chung 7 Sensors task main() { SetSensor(SENSOR_1,SENSOR_TOUCH); OnFwd(OUT_A+OUT_C); until (SENSOR_1 == 1); Off(OUT_A+OUT_C); } chung 8 A Simple Line Following #define THRESHOLD 40 chung task main() { SetSensor(SENSOR_2,SENSOR_LIGHT); OnFwd(OUT_A+OUT_C); while (true) { if (SENSOR_2 > THRESHOLD) { OnRev(OUT_C); Wait(10); // make smooth movement until (SENSOR_2 <= THRESHOLD); OnFwd(OUT_A+OUT_C); } } } 9 Why Java? • Write once, run anywhere • Professional OO software development • AP exam from C++ to Java, 2004- chung 10 Install Java, LeJos, and Eclipse! Acknowledgement: Based on web page created by Jason Chien-Tai and updated by Tim Cahoon, a robofest coach 1. Install RCX or Robolab software to install the drivers for your Infrared Tower. RCX v1.X only supports the serial tower. RCX 2.x supports both the serial and USB versions of the Tower (You can skip this step if you have already installed RCX or Robolab) 2. Download Java J2SE SDK from http://java.sun.com/j2se/1.4.2/download.html Install the program by running it. This may take 4-5 minutes to install. (Windows 98 users may need to use the older 1.3.x version if there errors installing the newest version) chung 11 3. Dowload leJOS from 4. 5. 6. 7. chung http://lejos.sourceforge.net/download.html (Start with Version 2.xx) Extract downloaded leJOS ZIP file to a directory (eg.C:\lejos) When doing the unzip, specify unzip to C:\. The zip file will build the lejos directory for you. Download eclipse from http://www.eclipse.org/downloads/index.php (With Latest Release Start with Version 2.xx) Extract downloaded eclipse ZIP file to a directory (eg. C:\eclipse) When doing the unzip, specify unzip to C:\. The zip file will build the eclipse directory for you. Download the following zip-bundle org.lejos_1.0.2.zip 12 8. Unzip it into your eclipse plugin directory. (The files go into c:\eclipse\plugins ) 9. Start eclipse by double-clicking eclipse.exe under C:\eclipse (Double-click again if eclipse is not started) HINT: Make a shortcut for eclipse and put it on your desktop. 10. When eclipse is running, go to the leJOS preference page, using Window->Preferences->Lejos page or Lejos>Preferences. chung 13 • Lejos Installation Directory = C:\lejos (where you installed Lejos files) RCX comm port = com1, com1, USB (depends on how infrared tower is connected) Data Transfer Rate = fast, slow (select fast. If you have problems try slow) • If lejos is not listed on the bar (with file, edit, source, etc..) at the top of eclipse, the lejos plugins were not put in the right directory. ( eclipse\plugins is where the files go). Exit eclipse and redo step 8 again. chung 14 How to write a LeJos Java Program using Eclispe • Create a project: File -> New -> Project • Highlight leJOS Project and click Next (or double click leJOS Project) • Type in your Project Name and Click on Finish • Create a Java class file: File -> New -> Other; double click on Class • Type a Java class name; check public static void main() and click on Finish chung 15 chung 16 Compile, download, and run • Save the file (compile is done) • Select: leJOS -> firmware download (for the first time run, takes more than 5 min) • Select: leJOS -> bytecode download to download your program • Press the green Run button to execute your program chung 17 Announcement 1010 4-3-03: RCX code and RoboLab Workshop 4-17-03 Warm-up Competition at Cranbrook Institute of Science. Only for 10 teams We need referees! chung 18