Top Banner
15-9-2015 1 HTHT Science 2 Society Minor Module 1: From Idea to Prototype Robotics: NXT, Programming Prof. Frank van der Velde Cognitive Psychology & Ergonomics (CPE) CTIT
77

Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Jun 24, 2018

Download

Documents

trinhthu
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

15-9-2015 1

HTHT Science 2 Society Minor Module 1: From Idea to Prototype

Robotics: NXT, Programming

Prof. Frank van der Velde

Cognitive Psychology

& Ergonomics (CPE)

CTIT

Page 2: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Overview

2

Mindstorms NXT 2.0: • Robot types • Programming • Installation

21 September: Ing Fjodor van Slooten will give a hands-on lecture on the NXT IO (Application Development and Design) Horstring Noord, N208 ([email protected]) (This lecture is strongly based on his presentations) At another time: Dr. Vicky Charisi will present a one-hour talk on child-robot interaction.

Page 3: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

What is Lego Mindstorms NXT 2.0?

Technical Lego + “Computer” + Sensors + Actuators

Different robot types possible

3

Page 4: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Brick

Lego Brick NXT

Ports for motors

Ports for sensors

4

Page 5: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Lego Brick NXT

5

256 Kb memory Display 100x64 Speaker

Page 6: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Lego Brick NXT

6

Battery: will be empty Charge battery at least 30 min Continue charging battery during session.

Page 7: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Sensors NXT

Licht sensor Detects light intensity environment And reflection infrared sender

Ultrasonic sensor Determines distances with ultrasound waves

Sound sensor Records sound level (not microphone!)

Touch sensor Responds to: Pressing Release Touch

7

start

Page 8: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Ultrasonic sensor NXT

8

Ultrasonic sensor does not always operate on port 4! Sensor value is visible when

NXT is linked.

Page 9: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Color sensors NXT

9

Lego ColorSensor

HiTechnicColorSensor

RGB

Page 10: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Servo Motors NXT

Tachometer for build-in Rotation

Sensor Motor core Build-in gearing

Attaching a wheel

10

Page 11: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Drag and drop programming 11

Page 12: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Drag and drop programming 12

Common: • Move • Record/Play • Sound • Display • Wait • Loop • Switch

Page 13: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Drag and drop programming 13

Action: • Motor • Sound • Display • Send message • Color lamp

Page 14: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Drag and drop programming 14

Sensor: • Touch • Sound • Light • Ultrasonic • NXT button • Rotation • Timer • Receive message • Color sensor

Page 15: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Drag and drop programming 15

Flow: • Wait • Loop • Switch • Stop

Page 16: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Drag and drop programming 16

Data: • Logic • Math • Compare • Range • Random • Variable • Constant

Page 17: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Drag and drop programming 17

Advanced: • Number to text • Text • Keep alive • File access • Calibrate • Reset motor • Bluetooth connection

Page 18: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Configuration screen:

start

Textual commentary: what program is doing (do this!) 18

Page 19: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Configuration screen:

start Wait 2 sec

19

Page 20: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

start Wait 2 sec

Configuration screen:

Move forward

20

Page 21: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

start Wait 2 sec

Configuration screen:

Move forward Move backward

21

Page 22: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

start Wait 2 sec Move forward Move backward

Store program

22

Page 23: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Transferring program to brick (PC and NXT need to be linked)

Using either: • USB • Bluetooth

Download and start program

23

Stop

Page 24: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Repeating program parts is usually not good programming!

Repeat program 3 times:

24

Page 25: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Example: (see “educatieve_bijlage_nxt_binnenstebuiten.pdf”)

Instead, use a ‘loop’ by inserting repeat block

Configuration screen:

25

Page 26: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

Help gives information on programming

26

Page 27: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

27

Programming NXT Example: present sensor values on screen

• (Light) sensor block • Number-to-Text block • Display block

Then: Connection with Data Wire

After that: place in Loop

Page 28: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

28

Programming NXT Example: present sensor values on screen

Loop (Infinite)

Complete palette

Page 29: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

29

Programming NXT Example: move along wall

Steering parameter gets result calculation

First:

Robot moves straight ahead?

Tip: drive slowly, need time for processing sensor information.

NXT button

Page 30: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

30

Programming NXT

Example: avoiding collision (Bumper car)

Yes: drive back a bit and make turn (try other direction)

Is Touch sensor pressed? Driving straight ahead

Page 31: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

31

Programming NXT

Example: using NXT buttons

Switch block (conditional, if .. then)

Condition: True or False

True

False

Page 32: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

32

Programming NXT

Example: wait until Enter button is pressed

Page 33: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

33

Programming NXT

Example: using variables

Menu: Edit > Manage variables Variabele name, type

Page 34: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

34

Programming NXT

Example: using variables

Advanced example

Decision: is TurnOn True?

Value variable enters Decision via data wire

TurnOn=False

MotorRunning=True

Page 35: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

35

Programming NXT

Example: multiple tasks

• Tasks in sequence • Disadvantage: if something happens in one task, it could be ignored in other

Task 1 Task 2

Loop

Page 36: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

36

Programming NXT

Example: multiple tasks

• Tasks simultanously • Disadvantage: programming more difficult • E.g., cannot just use same sensor • Solution: variables

Task 1

Task 2 Pull ends to make connections

Page 37: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

37

Programming NXT

Example: using timer

There are 3 timers. Start with 0 at beginning of program

Have 5 sec passed?

Reset timer

Timer 1

Page 38: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

38

Programming NXT

Example: using timer

Is someone gone for longer as 30 sec?

Task 1

Reset timer if close So, timer runs as long as far away

Keep repeating loop

Page 39: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

39

Programming NXT

Example: using timer

Is someone gone for longer as 30 sec?

Task 1

Use result (logical) comparison to see if timer has ‘turned on’ (if 30 sec have passed)

Reset timer

Task 2 Keep repeating loop

Timer passed: play sound

and reset timer

Page 40: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

40

For using Lego software: Possibly Java firmware installed on NXT Install also Lego Firmware on NXT Zip-file, map lego\firmware\1.31 See INSTALLATIE.TXT

Page 41: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

41

Programming NXT

More complicated and flexible programming: • Use programming language LeJOS. • Based on JAVA, suited for NXT

Software and documentation can be found on Website APPLICATIEBOUW http://module4.io.utwente.nl/applicatiebouw/

Lectures (Dutch)

Download

Page 43: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

43

Unpack zip file

See info:

Page 44: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Programming NXT

44

Unpack zip file

See info:

Page 45: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Building robots

45

Unpack zip file

See info:

Lego parts:

Page 46: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

46

Unpack zip file

See info:

Working with Lego parts:

Lego parts: Box Box is owned by the UT. Use is carefully! Use lock for the box! Check content of box Fill in list: http://module4.io.utwente.nl/aftekenlijst/ If parts are missing: Mail Fjodor van Slooten

Building robots

Page 47: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Robot examples

47

Unpack zip file

See info:

Ultrasonic sensor: detects object

Instructions for building this robot

Sound sensor: reacts to commands

Touch sensor: detects object

between claws

Claws to grasp and transport

object

Light sensor: stay within area

Page 48: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Robot examples

48

Castor Bot

Instructions for building this robot: nxtprograms.com

Page 49: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Robot examples

49

Castor Bot

Instructions for building this robot: nxtprograms.com

Page 50: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Robot examples

50

Castor Bot

Instructions for building this robot: nxtprograms.com

Simple design

Extra sensors can be

added easily

Two separately

driving wheels

Assistance wheel

Page 51: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Robot examples

51

Robot Arm

Instructions for building this robot: nxtprograms.com

Page 52: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Robot examples

52

Instructions for building this robot: nxtprograms.com

Turns around

an axis

Moves up and down

Robot Gripper: Grabbing and moving object

Light sensor detects colour of object

Claw can open and close

Touch sensor detects presence of object

Page 53: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Robot examples

Information about robots can be found in: • In Lego software: building guides • Zip file Applicatiebouw • nxtprograms.com • Books (contact Fjodor van Slooten,

Horstring Noord, N208 ([email protected])

53

Page 54: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

See: See: “Installatie” (For Mac and Windows) Windows: Start script install.bat by right clicking mouse. Choose Run as Administrator. You need the following programmes (in this order!) - Java Development Kit (JDK), 32 bits versie - Eclipse IDE for Java Developers, 32 bits versie - Lego Mindstorms NXT software - LeJOS - Eclipse plugin voor LeJOS

http://module4.io.utwente.nl/applicatiebouw/index.php?dir=download

54

Page 55: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Java Development Kit (JDK) Go to Unpacket Zip map To map 'Java'. Dubbelclick on: jdk-8u45-windows-i586.exe Wizard installs JDK and Java Runtime environment (JRE, version 8) Installation via Next (a number of times) Close

Installation of programmes

55

Page 56: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

56

Eclipse: IDE

Page 57: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

57

Eclipse: IDE

Eclipse can run without installation For this copy the folder Eclipse to: "C:\Program Files (x86)" or "C:\Program Files". Doubleclick on Eclipse to see its content Click on file “eclipse.exe”with right mousebutton Select "Send to > Desktop (create shortcut)"

Page 58: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

58

Start Eclipse: First time program asks for making a Workspace Use your Documents folder "Make New folder". Give distinctive name eg. “EclipseWorkspace”. Activate option "Use this as the default ..." OK.

Page 59: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

After OK:

59

You can click this away to start using Eclipse

Page 60: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

60

Lego Mindstorms NXT software Start by activating setup.exe in folder 'Lego\LegoMindstorms2.0'. Ignore ‘wrong Windows-version’ or ‘lack of memory’ (continue with Next) After installation install 2 updates: Install first patch 2.0f3 in folder Lego\2.0f3_patch via setup.exe in that folder. Install latest version Lego Mindstorms NXT driver in folder Lego\driver_1.1.3 via setup.exe in that folder

Page 61: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

61

LeJOS installation: Remove old version with uninstall.exe (then restart computer) Driver of Lego Mindstorms NXT must be installed (see previous slide) Installation of LeJOS: doubleclick leJOS_NXJ_0.9.1beta-3_win32_setup.exe in folder 'LeJOS' After Next select Java Development Kit. Select latest version (jdk1.7.0_51 or higher).

Page 62: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

62

LeJOS installation: Location: standard Continue with Next

Page 63: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

63

LeJOS installation: Select "Sample and Example Projects" Leave other options as they are Continue with Next.

Page 64: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

LeJOS installation: In other screens leave it as it is. Continue with Next (a number of times) Press Install to start installation.

64

Page 65: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

65

LeJOS installation: After installation start NXJ Flash utility by selecting "Launch NXJ Flash utility" Press Finish If LeJOS firmware is not on NXT, install with NXJ Flash utility: Connect NXT to computer and turn it on Wait until driver is installed. Press button 'Flash LeJOS firmware'. After 'Ok' en 'Yes' LeJOS firmware is installed on NXT More information (Dutch) In file TIPS.txt (in folder 'LeJOS‘)

Page 66: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

Eclipse plugin for LeJOS Is ‘enclosed’ in Eclipse (based on ZIP-file Applicatiebouw) Hence installation of the plugin is not needed. Ckeck and control the options of the Eclipse plugin for LeJOS: Select in Eclipse: Window > Preferences from menu Then select "LeJOS NXJ". If under NXJ_HOME you find the folder where LeJOS geinstalleerd is installed, the plugin is fine.

66

Page 67: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

Eclipse plugin for LeJOS Otherwise: Browse to find path to LeJOS (NXJ_HOME). This is folder where LeJOS is installed. Is usually: C:\Program Files\LeJOS NXJ or C:\Program Files (x86)\LeJOS NXJ

67

Page 68: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

Installation of programmes

Eclipse plugin for LeJOS After installation you find the LeJOS icon in menu bar of Eclipse

68

Page 69: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

See: http://www.lejos.org/nxt/nxj/tutorial/Preliminaries/UsingEclipse.htm

Go the "File" menu of Eclipse and select "New" and then "Project...""

69

Page 70: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

See: http://www.lejos.org/nxt/nxj/tutorial/Preliminaries/UsingEclipse.htm

Then:

Two options:

70

Page 71: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

This opens the wizard for creating new leJOS PC projects:

71

Enter name e.g., NewPCProject (but use more informative names for yourself) Press Finish

Page 72: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

In Eclipse, you will see your new project: NewPCProject And JAR files from Libraries (JAR: Java Archive)

72

Page 73: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

Right click the src folder and select "New" and then "Class" in the context menu

73

"Src“: folder where the project's source files are located. In a Java project, src folder and its sub folders hold the .java files.

Page 74: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

This opens the wizard for creating new Java classes

74

Press Finish: Editor opens You can type in program

The package name com.mydomain (lowercase!) corresponds to the DNS domain "mydomain.com". Make sure to chose appropriate names.

Source folder name: NewPCProject

Package name (= namespace)

File name: HelloWorld

Page 75: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

Example program ”HelloWorld.java”

75

Notice order: • package

• import (if any)

• class

• void main

Appear when opening file (except import) File name = class name + .java

Page 76: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

Example program ”HelloWorld.java”

76

Run program: right-click on the class which contains the main method. Select "Run As"→"Java Application" in the context menu.

Page 77: Robotics: NXT, Programming - Universiteit Twente · Robotics: NXT, Programming ... Textual commentary: what program is doing (do this!) 18 . Programming NXT ... Robot examples 47

New LeJOS project in Eclipse

Example program ”HelloWorld.java”

77

Run program: Output on the local console in Eclipse.