Sei sulla pagina 1di 98
Programming LEGO Mindstorms NXT robots. Macrofaculty profiled documents. Programming Lego Mindstorms NXT with Java.

Programming LEGO Mindstorms NXT robots.

Macrofaculty profiled documents.

Mindstorms NXT robots. Macrofaculty profiled documents. Programming Lego Mindstorms NXT with Java. LeJOS NXJ Virtual

Programming Lego Mindstorms NXT with Java. LeJOS NXJ Virtual Machine.

Legal notes

© 2008,2011 Silesian University of Technology, Gliwice, Poland, Ph. D. Piotr Czekalski

This document is copyrighted. Copying, lending, distribution and redistribution on author's permission only.

This document contains noncommercial, educational content only thus cannot be utilized as a part of of any commercial business.

Author of this document assures that has made efforts to achieve correctness of the contents of this document as well as tried to provide latest and most modern review of the related technology on the hardware, software and programming methods. However it is obvious that author cannot guarantee the content not to contain some minor or major mistakes or shortcomings, mostly because of rapid popularity on the subject, changes of legal state, changes in current knowledge and trends, hardware and software updates, etc. This document is provided as is with no warranty of any kind and cannot be a subject of any claims on the content nor author.

Author kindly requests all users of this document to provide information on any mistakes or shortcomings in this documents “pro publico bono”. As this document can exist in many versions it is necessary to check doubtful content versus latest release of this document.

Any trademarks used in this document may be copyrighted by appropriate owners, particularly:

LEGO, the LEGO logo, DUPLO, BIONICLE, MINDSTORMS, the BELVILLE, CLIKITS, KNIGHTS’ KINGDOM and EXO-FORCE logos, the Brick and Knob configurations and the Minifigure is a trademark of the LEGO Group.

Microsoft, Robotics Studio, .NET logo, Visual Studio, ActiveX and Windows is a trademark of the Microsoft Corporation.

Java, JDK and JAVA logo is a trademark of the Oracle Corp.

ageia PhysX is a trademark of the nVIDIA Corporation.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

2

Plan of the presentation Changing original LEGO firmware to the LeJOS NXJ Java virtual machine.

Plan of the presentation

Plan of the presentation Changing original LEGO firmware to the LeJOS NXJ Java virtual machine. Preparing

Changing original LEGO firmware to the LeJOS NXJ Java virtual machine.Plan of the presentation Preparing Eclipse environment to build LeJOS native autonomous programs. LeJOS API brief

Preparing Eclipse environment to build LeJOS native autonomous programs.LEGO firmware to the LeJOS NXJ Java virtual machine. LeJOS API brief reference with samples. Version

LeJOS API brief reference with samples.environment to build LeJOS native autonomous programs. Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

3

Part 1 Installing LeJOS firmware. Running sample test program. Version 1.53 | 20th November 2011

Part 1

Part 1 Installing LeJOS firmware. Running sample test program. Version 1.53 | 20th November 2011 Ph.D.

Installing LeJOS firmware.Part 1 Running sample test program. Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Running sample test program.Part 1 Installing LeJOS firmware. Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski 4

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

4

LeJOS NXJ New firmware replaces genuine LEGO (reversible operation). Dedicated compiler and linker (imports it's

LeJOS NXJ

LeJOS NXJ New firmware replaces genuine LEGO (reversible operation). Dedicated compiler and linker (imports it's own
LeJOS NXJ New firmware replaces genuine LEGO (reversible operation). Dedicated compiler and linker (imports it's own

New firmware replaces genuine LEGO (reversible operation).LeJOS NXJ Dedicated compiler and linker (imports it's own java.lang.* libraries). A set of utilities to

Dedicated compiler and linker (imports it's own java.lang.* libraries).New firmware replaces genuine LEGO (reversible operation). A set of utilities to work with NXT Brick.

A set of utilities to work with NXT Brick.and linker (imports it's own java.lang.* libraries). API covers both Genuine LEGO and 3 r d

API covers both Genuine LEGO and 3 r d party components (sensors, servos, comm., etc.). rd party components (sensors, servos, comm., etc.).

It is Open Source project.3 r d party components (sensors, servos, comm., etc.). Current version 0.9.0 beta (16 t h

Current version 0.9.0 beta (16 t h May 2011) th May 2011)

Formerly API was for RCX (RIS) now NXT.project. Current version 0.9.0 beta (16 t h May 2011) LeJOS powered robot „Jitter” flew on

LeJOS powered robot „Jitter” flew on International Space Station in 2001 ;-).t h May 2011) Formerly API was for RCX (RIS) now NXT. Version 1.53 | 20th

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

5

What is needed to work with LeJOS & Java? LEGO Mindstorms Edu/Retail NXT Software. libusb-win32

What is needed to work with

What is needed to work with LeJOS & Java? LEGO Mindstorms Edu/Retail NXT Software. libusb-win32 filter

LeJOS & Java?

What is needed to work with LeJOS & Java? LEGO Mindstorms Edu/Retail NXT Software. libusb-win32 filter

LEGO Mindstorms Edu/Retail NXT Software.What is needed to work with LeJOS & Java? libusb-win32 filter driver (not for x64). Java

libusb-win32 filter driver (not for x64).LeJOS & Java? LEGO Mindstorms Edu/Retail NXT Software. Java SE SDK (JDK). Apache Ant (optional). Eclipse

Java SE SDK (JDK).NXT Software. libusb-win32 filter driver (not for x64). Apache Ant (optional). Eclipse (optional but recommended).

Apache Ant (optional).libusb-win32 filter driver (not for x64). Java SE SDK (JDK). Eclipse (optional but recommended). USB cable

Eclipse (optional but recommended).(not for x64). Java SE SDK (JDK). Apache Ant (optional). USB cable Bluecove library (jar file)

USB cableApache Ant (optional). Eclipse (optional but recommended). Bluecove library (jar file) for iCommand remote access (

Bluecove library (jar file) for iCommand remote access (warning iCommand is obsolete now ). warning iCommand is obsolete now).

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

6

Setup procedure. LEGO Mindstorms Edu/Retail Software Dedicated setup. Java SDK http://java.sun.com/ Dedicated setup.

Setup procedure.

Setup procedure. LEGO Mindstorms Edu/Retail Software Dedicated setup. Java SDK http://java.sun.com/ Dedicated setup.

LEGO Mindstorms Edu/Retail SoftwareSetup procedure. Dedicated setup. Java SDK http://java.sun.com/ Dedicated setup. Apache Ant

Setup procedure. LEGO Mindstorms Edu/Retail Software Dedicated setup. Java SDK http://java.sun.com/ Dedicated setup.

Dedicated setup.

Dedicated setup.Software Dedicated setup. Java SDK http://java.sun.com/ Apache Ant http://ant.apache.org/bindownload.cgi Unpack

Apache Ant http://ant.apache.org/bindownload.cgi Unpack to the designated folder. http://ant.apache.org/bindownload.cgi Unpack to the designated folder.

LeJOS http://lejos.sourceforge.net/nxj-downloads.php Dedicated setup (also ZIP available). http://lejos.sourceforge.net/nxj-downloads.php Dedicated setup (also ZIP available).

LibUSB http://libusb-win32.sourceforge.net/#downloads Dedicated setup. Extra procedure for Windows 7/Vista exists,
LibUSB http://libusb-win32.sourceforge.net/#downloads Dedicated setup. Extra procedure for Windows 7/Vista exists,
LibUSB http://libusb-win32.sourceforge.net/#downloads Dedicated setup. Extra procedure for Windows 7/Vista exists,

Dedicated setup. Extra procedure for Windows 7/Vista exists, not for x64.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

7

Setup procedure (cont.). Environment variables: – NXJ_HOME – LeJOS folder, i.e: c:\Program Files\LeJOS NXJ or

Setup procedure (cont.).

Setup procedure (cont.). Environment variables: – NXJ_HOME – LeJOS folder, i.e: c:\Program Files\LeJOS NXJ or
Setup procedure (cont.). Environment variables: – NXJ_HOME – LeJOS folder, i.e: c:\Program Files\LeJOS NXJ or

Environment variables:

NXJ_HOME – LeJOS folder, i.e: c:\Program Files\LeJOS NXJ or C:\Program Files (x86)\leJOS NXJ (on x64)

JAVA_HOME – JDK setup folder (must be JDK instead of JRE) (warning: for x64 Windows OSes – JDK have to be x86 anyway)

ANT_HOME – Ant scripts folder, i.e.: c:\apache-ant-1.8.2ant

PATH - %NXJ_HOME%\bin;%JAVA_HOME%\bin;%ANT_HOME %\bin;%PATH%

iCommand extra settings (remote controlled mode, obsolete):

CLASSPATH - .;C:\icommand-

0.7\dist\icommand.jar;C:\icommand-

0.7\dist\bluecove-2.1.0.jar;

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

8

Setup procedure (cont.). Installing NXJ firmware into the NXT Intelligent Brick: – Brick have to

Setup procedure (cont.).

Setup procedure (cont.). Installing NXJ firmware into the NXT Intelligent Brick: – Brick have to be

Installing NXJ firmware into the NXT Intelligent Brick:

Brick have to be connected over USB, detected (drivers installed) and ready.

cmd: > nxjflash or nxjflashg

Sometime manual entering into firmware update mode is necessary (press hardware reset button for few seconds – see image below).

NXJ can be replaced with genuine firmware again (the NXJ firmware flashing is reversible procedure) using LEGO Mindstorms Edu/Retail NXT software

procedure) using LEGO Mindstorms Edu/Retail NXT software 9 – NXT Intelligent Brick allows up to about
9
9

NXT Intelligent Brick allows up to about 100 updates to the firmware.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

Setup procedure (cont.). Run sample program: – Cmd:> cd %NXJ_HOME%\samples\View (Lejos v 0.6) – Cmd:>

Setup procedure (cont.).

Setup procedure (cont.). Run sample program: – Cmd:> cd %NXJ_HOME%\samples\View (Lejos v 0.6) – Cmd:> cd

Run sample program:Setup procedure (cont.). – Cmd:> cd %NXJ_HOME%\samples\View (Lejos v 0.6) – Cmd:> cd

Cmd:> cd %NXJ_HOME%\samples\View (Lejos v 0.6)

Cmd:> cd %USERPROFILE%\leJOSNXJProjects\samples\View (v 0.7 and newer)

Cmd:> nxjc View.java

Cmd:> nxj -r -u View

Allows to watch NXT(NXJ) robot state:– Cmd:> nxjc View.java – Cmd:> nxj -r -u View View sensor values. View servomotors state.

View sensor values.nxj -r -u View Allows to watch NXT(NXJ) robot state: View servomotors state. View system state.

View servomotors state.Allows to watch NXT(NXJ) robot state: View sensor values. View system state. Version 1.53 | 20th

View system state.robot state: View sensor values. View servomotors state. Version 1.53 | 20th November 2011 Ph.D. Eng.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

10

Part 2 Configuring Eclipse to compile autonomous projects for NXJ. Creating a project for NXJ.

Part 2

Part 2 Configuring Eclipse to compile autonomous projects for NXJ. Creating a project for NXJ. Configuring

Configuring Eclipse to compile autonomous projects for NXJ.

Creating a project for NXJ.Configuring Eclipse to compile autonomous projects for NXJ. Configuring three exteral tools (compile, upload, browse NXT

Configuring three exteral tools (compile, upload, browse NXT brick contents) to work with NXT directly from Eclipse IDE.autonomous projects for NXJ. Creating a project for NXJ. Version 1.53 | 20th November 2011 Ph.D.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

11

Configuring Eclipse. Eclipse http://www.eclipse.org/downloads/ Follow instructions available on-line (currently just

Configuring Eclipse.

Configuring Eclipse. Eclipse http://www.eclipse.org/downloads/ Follow instructions available on-line (currently just

Follow instructions available on-line (currently just unpack).Eclipse. Eclipse http://www.eclipse.org/downloads/ Preparing Eclipse to compile for NXJ: Create project:

Preparing Eclipse to compile for NXJ:instructions available on-line (currently just unpack). Create project: Version 1.53 | 20th November 2011 Ph.D. Eng.

Create project:just unpack). Preparing Eclipse to compile for NXJ: Version 1.53 | 20th November 2011 Ph.D. Eng.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski 12
Ph.D. Eng. Piotr Czekalski
12
Configuring Eclipse (cont.). Project details. Watch carefully project location (Project layout section) because external

Configuring Eclipse (cont.).

Configuring Eclipse (cont.). Project details. Watch carefully project location (Project layout section) because external
Configuring Eclipse (cont.). Project details. Watch carefully project location (Project layout section) because external

Project details.

Configuring Eclipse (cont.). Project details. Watch carefully project location (Project layout section) because external

Watch carefully project location (Project layout section) because external tools configuration depends on it.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski 13
Ph.D. Eng. Piotr Czekalski
13
Configuring Eclipse (cont.). Configure classpath for NXJ: Project->Properties: Java Build Path/Libraries. [Add

Configuring Eclipse (cont.).

Configuring Eclipse (cont.). Configure classpath for NXJ: Project->Properties: Java Build Path/Libraries. [Add
Configure classpath for NXJ: Project->Properties: Java Build Path/Libraries. [Add External JARs]: <LeJOS
Configure classpath for
NXJ:
Project->Properties:
Java Build
Path/Libraries.
[Add External JARs]:
<LeJOS path>
Version 1.53 | 20th November 2011
Ph.D. Eng. Piotr Czekalski
14
Configuring Eclipse (cont.). Configure NXJ compile command: Run->External Tools->External Tools Configurations:

Configuring Eclipse (cont.).

Configuring Eclipse (cont.). Configure NXJ compile command: Run->External Tools->External Tools Configurations:

Configure NXJ compile command:

Run->ExternalConfiguring Eclipse (cont.). Configure NXJ compile command: Tools->External Tools Configurations: Program/[New]. Use

Tools->External

Tools

Configurations:

Program/[New].Run->External Tools->External Tools Configurations: Use IDE variables. Watch *.java files location (project root

Use IDE variables.

Watch *.java files location (project root or subfolders).

Ph.D. Eng. Piotr Czekalski 15
Ph.D. Eng. Piotr Czekalski
15

Version 1.53 | 20th November 2011

Configuring Eclipse (cont.). Configure upload to NXT brick command: Run->External Tools->External

Configuring Eclipse (cont.).

Configuring Eclipse (cont.). Configure upload to NXT brick command: Run->External Tools->External
Configure upload to NXT brick command:

Configure upload to NXT brick command:

Run->ExternalConfigure upload to NXT brick command: Tools->External Tools Configurations: Program/[New]. Use IDE variables.

Tools->External

Tools

Configurations:

Program/[New].Configure upload to NXT brick command: Run->External Tools->External Tools Configurations: Use IDE variables.

Use IDE variables.

Use IDE variables.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski 16
Ph.D. Eng. Piotr Czekalski
16
Configuring Eclipse (cont.). Configure browse NXT Intelligent Brick contents: Run->External Tools->External Tools

Configuring Eclipse (cont.).

Configuring Eclipse (cont.). Configure browse NXT Intelligent Brick contents: Run->External Tools->External Tools
Configuring Eclipse (cont.). Configure browse NXT Intelligent Brick contents: Run->External Tools->External Tools

Configure browse NXT Intelligent Brick contents:

Run->External(cont.). Configure browse NXT Intelligent Brick contents: Tools->External Tools Configurations: Program/[New].

Tools->External

Tools

Configurations:

Program/[New].Run->External Tools->External Tools Configurations: Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski 17
Ph.D. Eng. Piotr Czekalski
17
Simple test program. ● import lejos.nxt.*; ● ● public class HelloWorld { – public static

Simple test program.

Simple test program. ● import lejos.nxt.*; ● ● public class HelloWorld { – public static void

import lejos.nxt.*;

public class HelloWorld {

public static void main (String[] aArg)

throws Exception

{

LCD. clear (); LCD. drawString ("Welcome !", 1, 1);

Button. waitForPress ();

}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

18

Compiling and running. Mark the source file to compile (required!). Program starting procedure: 1.Compile. 2.Upload

Compiling and running.

Compiling and running. Mark the source file to compile (required!). Program starting procedure: 1.Compile. 2.Upload to
Mark the source file to compile (required!).

Mark the source file to compile (required!).

Program starting procedure:

Program starting procedure:

1.Compile.

2.Upload to NXT.

Program starting procedure: 1.Compile. 2.Upload to NXT. 3.Run using nxjbrowse or directly from the firmware menu.
3.Run using nxjbrowse or directly from the firmware menu. Version 1.53 | 20th November 2011
3.Run using nxjbrowse or
directly from the firmware
menu.
Version 1.53 | 20th November 2011
Ph.D. Eng. Piotr Czekalski
19
Other method (preffered). Using LeJOS plugin for Eclipse: Installation procedure. Configuration procedure. Sample project.

Other method (preffered).

Other method (preffered). Using LeJOS plugin for Eclipse: Installation procedure. Configuration procedure. Sample project.
Other method (preffered). Using LeJOS plugin for Eclipse: Installation procedure. Configuration procedure. Sample project.

Using LeJOS plugin for Eclipse:

Installation procedure.Other method (preffered). Using LeJOS plugin for Eclipse: Configuration procedure. Sample project. Version 1.53 | 20th

Configuration procedure.Using LeJOS plugin for Eclipse: Installation procedure. Sample project. Version 1.53 | 20th November 2011 Ph.D.

Sample project.Eclipse: Installation procedure. Configuration procedure. Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

20

Installing LeJOS plugin for Eclipse. Run Eclipse, click [menu]: Help->Install New Software. Paste the following

Installing LeJOS plugin for Eclipse.

Run Eclipse, click [menu]:Installing LeJOS plugin for Eclipse. Help->Install New Software. Paste the following link and click Add:

Help->Install New Software.

Paste the following link and click Add:Run Eclipse, click [menu]: Help->Install New Software. http://lejos.sourceforge.net/tools/eclipse/plugin/nxj/ Mark

Mark both checkboxes (leJOS NXJ*) click [Next] and follow a wizard.Add: http://lejos.sourceforge.net/tools/eclipse/plugin/nxj/ Installing may take some time as it requires a bunch of

Installing may take some time as it requires a bunch of dependency packages.checkboxes (leJOS NXJ*) click [Next] and follow a wizard. Restart Eclipse. Observe an integrated help context

Restart Eclipse.some time as it requires a bunch of dependency packages. Observe an integrated help context for

Observe an integrated help context for LeJOS available in Eclipse now.it requires a bunch of dependency packages. Restart Eclipse. Version 1.53 | 20th November 2011 Ph.D.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

help context for LeJOS available in Eclipse now. Version 1.53 | 20th November 2011 Ph.D. Eng.
21
21
Configuring LeJOS plugin for Eclipse. LeJOS plugin is aware of NXJ location path, thus needs

Configuring LeJOS plugin for Eclipse.

LeJOS plugin is aware of NXJ location path, thus needs some configuration.Configuring LeJOS plugin for Eclipse. Click [menu]: Window->Preferences, choose leJOS NXJ then paste leJOS NXJ root

Click [menu]: Window->Preferences, choose leJOS NXJ then paste leJOS NXJ root installation directory: Version
Click [menu]:
Window->Preferences,
choose leJOS NXJ then paste
leJOS NXJ root installation
directory:
Version 1.53 | 20th November 2011
Ph.D. Eng. Piotr Czekalski
22
Using LeJOS plugin for Eclipse. Using plugin one may flash the firmware as required –

Using LeJOS plugin for Eclipse.

Using plugin one may flash the firmware as required – click [Menu]->leJOS NXJ->Upload Firmware (if still required).Using LeJOS plugin for Eclipse. To create a new project, simply create a new Java project,

To create a new project, simply create a new Java project, then right-click in Package
To create a new project, simply create
a new Java project, then right-click in
Package Explorer and select
leJOS NXJ->
Convert to leJOS NXJ Project:
Write and compile as in any
regular Java application.
When ready, right-click the project
and choose
Upload Program to the NXT Brick.
The Console shall write something
similar to:
project <name> now is a
leJOS NXJ project
Version 1.53 | 20th November 2011
Ph.D. Eng. Piotr Czekalski
23
Add some extra tools. ● LeJOS comes with bunch of valuable tools. Those may be

Add some extra tools.

LeJOS comes with bunch of valuable tools. Those may be configured as Eclipse External Tools, i.e.:

nxjbrowse – NXJ brick file explorerThose may be configured as Eclipse External Tools, i.e.: nxjmonitor – a remote program monitor –

nxjmonitor – a remote program monitor – allows to browse sensor input and servomotor output values almost realtime (well, not in fact – too slow for most applications), also draws tracing message (useful). Works over Bluetooth connection.External Tools, i.e.: nxjbrowse – NXJ brick file explorer nxjdataviewer – data logger downloader and presentation

nxjdataviewer – data logger downloader and presentation tool (both BT & usb)tracing message (useful). Works over Bluetooth connection. nxjconsoleviewer – RConsole output (graphical tool)

nxjconsoleviewer – RConsole output (graphical tool)logger downloader and presentation tool (both BT & usb) nxjconsole – as above but command line

nxjconsole – as above but command lineusb) nxjconsoleviewer – RConsole output (graphical tool) nxjcontrol – combines above in one + some extra

nxjcontrol – combines above in one + some extra features(graphical tool) nxjconsole – as above but command line nxjdebug – debugger no longer exists, replaced

nxjdebug – debugger no longer exists, replaced by nxjconsolenxjcontrol – combines above in one + some extra features The tools include trace and debugging,

The tools include trace and debugging, also nxjbrowse tool.– debugger no longer exists, replaced by nxjconsole Procedure same as configuring compiler and linker using

Procedure same as configuring compiler and linker using external tools.The tools include trace and debugging, also nxjbrowse tool. Version 1.53 | 20th November 2011 Ph.D.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

24

LeJOS API. Three modes (two remote, one autonomous): – Remote for LCP: lejos.pc.comm , lejos.nxt,lejos.robotics,

LeJOS API.

LeJOS API. Three modes (two remote, one autonomous): – Remote for LCP: lejos.pc.comm , lejos.nxt,lejos.robotics,
LeJOS API. Three modes (two remote, one autonomous): – Remote for LCP: lejos.pc.comm , lejos.nxt,lejos.robotics,

Three modes (two remote, one autonomous):

Remote for LCP: lejos.pc.comm,

lejos.nxt,lejos.robotics, lejos.geom

Remote iCommand API: icommand.navigation, icommand.nxt, icommand.nxtcomm, icommand.vision (obsolete) icommand.navigation, icommand.nxt, icommand.nxtcomm, icommand.vision(obsolete)

Autonomous:icommand.nxt, icommand.nxtcomm, icommand.vision (obsolete) – java.awt, java.io, java.lang, java.util, java.awt –

java.awt, java.io, java.lang, java.util, java.awt

Micro edition: javax.bluetooth, javax.microedition.io, javax.microedition.lcdui

Other: lejos.devices, lejos.robotics.navigation, lejos.nxt, lejos.nxt.comm, lejos.nxt.debug, lejos.nxt.remote, lejos.rcxcomm, lejos.robotics.subsumption, lejos.util, lejos.robotics

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

25

LeJOS API reference. lejos.nxt.* all classes related to the sensors, NXT buttons & sound, actuators

LeJOS API reference.

LeJOS API reference. lejos.nxt.* all classes related to the sensors, NXT buttons & sound, actuators (servos),

lejos.nxt.* all classes related to the sensors, NXT buttons & sound, actuators (servos), 3 r d all classes related to the sensors, NXT buttons & sound, actuators (servos), 3 rd party included partially. Interfaces, abstract classes and RCX compatibility API (sensors, motors).

classes and RCX compatibility API (sensors, motors). lejos.nxt.addon all 3 r d party sensors and servos

lejos.nxt.addon all 3 rd party sensors and servos (generally those not included in LEGO NXT kit), RCX sensors and motors support

lejos.nxt.comm communication with NXT over USB & Bluetooth (Lego Communication Protocol implementation included). communication with NXT over USB & Bluetooth (Lego Communication Protocol implementation included).

lejos.nxt.remote remote managing other NXT over Bluetooth (LCP included). remote managing other NXT over Bluetooth (LCP included).

lejos.nxt.debug brings debugging capabilities. brings debugging capabilities.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

26

LeJOS API reference (cont.). lejos.addon.gps GPS support classes. lejos.util utility classes, mostly for debugging and

LeJOS API reference (cont.).

LeJOS API reference (cont.). lejos.addon.gps GPS support classes. lejos.util utility classes, mostly for debugging and

lejos.addon.gps GPS support classes. GPS support classes.

lejos.util utility classes, mostly for debugging and tracing, i.e. asserts, data loggers, watches, timers, recycled classes, utility classes, mostly for debugging and tracing, i.e. asserts, data loggers, watches, timers, recycled classes, button click counters, etc.

lejos.addon.keyboard SPP (over BT) keyboard

support classes.

javax.bluetooth Java bluetooth support compatibility classes. Java bluetooth support compatibility classes.

javax.microedition J2ME compatibility classes. Current version implements I/O, LCD UI and JSR- 179 location API. J2ME compatibility classes. Current version implements I/O, LCD UI and JSR- 179 location API.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

27

LeJOS API reference (cont). lejos.robotics.navigation navigators & pilots. lejos.robotics.subsumption Support for

LeJOS API reference (cont).

LeJOS API reference (cont). lejos.robotics.navigation navigators & pilots. lejos.robotics.subsumption Support for

lejos.robotics.navigation navigators & pilots.

lejos.robotics.subsumption Support for subsumption architecture (behavioral programming).

lejos.robotics.localization Support for Monte Carlo & Particle Filtering based position tracking of a robot.

lejos.robotics.mapping Support for loadable / definable maps of object, works with lejos.robotics.navigation package to provide deterministic range to an object located on the map.

lejos.robotics.objectdetection Object (feature, when on map) detection broker. Capable to notify one listener based on multiple sensor readings (i.e. range / touch sensor wall detection).

lejos.robotics.pathfinding various path finding algorithms with respect to the map obstacles.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

28

LeJOS API reference (cont.). lejos.geom geometric shape support for robotics using flat coordinates. lejos.charset

LeJOS API reference (cont.).

LeJOS API reference (cont.). lejos.geom geometric shape support for robotics using flat coordinates. lejos.charset

lejos.geom geometric shape support for robotics using flat coordinates. geometric shape support for robotics using flat coordinates.

lejos.charset character sets encoder / decoder (Latin1 / UTF8 supported) character sets encoder / decoder (Latin1 / UTF8 supported)

lejos.io lejos specific stream reader / writer classes – native support for java.io lejos specific stream reader / writer classes – native support for java.io

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

29

lejos.nxt.* package reference. Basic components, most common use when compiling for NXT Intelligent Brick: Common

lejos.nxt.* package reference.

lejos.nxt.* package reference. Basic components, most common use when compiling for NXT Intelligent Brick: Common solution
lejos.nxt.* package reference. Basic components, most common use when compiling for NXT Intelligent Brick: Common solution

Basic components, most common use when compiling for NXT Intelligent Brick:

Common solution part.most common use when compiling for NXT Intelligent Brick: Different and exceptional cases. Version 1.53 |

Different and exceptional cases.compiling for NXT Intelligent Brick: Common solution part. Version 1.53 | 20th November 2011 Ph.D. Eng.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

30

LCD – text mode. Static class LCD. Text mode 16 cols (X: 0 Methods: 15)

LCD – text mode.

LCD – text mode. Static class LCD. Text mode 16 cols (X: 0 Methods: 15) x

Static class LCD.LCD – text mode. Text mode 16 cols (X: 0 Methods: 15) x 8 rows (Y:

Text mode 16 cols (X: 0LCD – text mode. Static class LCD. Methods: 15) x 8 rows (Y: 0 7) public

Methods:LCD – text mode. Static class LCD. Text mode 16 cols (X: 0 15) x 8

15)

x 8 rows (Y: 0

7)

public static drawString(String str, int x, int y);LCD. Text mode 16 cols (X: 0 Methods: 15) x 8 rows (Y: 0 7) public

public static drawString(String str, int x, int y, boolean invert); - inverted text - inverted text

public static drawInt(int i, int x, int y); - left aligned, uses as many characters as necessary - left aligned, uses as many characters as necessary

public static drawInt(int i, int places, int x, int y); - right aligned, uses provided number of characters - right aligned, uses provided number of characters

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

31

LCD – text mode (cont.). Methods: public static drawChar(char c, int x, int y, boolean

LCD – text mode (cont.).

LCD – text mode (cont.). Methods: public static drawChar(char c, int x, int y, boolean invert);

Methods:LCD – text mode (cont.). public static drawChar(char c, int x, int y, boolean invert); public

public static drawChar(char c, int x, int y, boolean invert);LCD – text mode (cont.). Methods: public static clear(); Sample: Version 1.53 | 20th November 2011

public static clear();static drawChar(char c, int x, int y, boolean invert); Sample: Version 1.53 | 20th November 2011

Sample: Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski 32
Sample:
Version 1.53 | 20th November 2011
Ph.D. Eng. Piotr Czekalski
32
LCD – graphics mode. Graphics mode 100 px (X: 0 Class: 99) x 64 px

LCD – graphics mode.

LCD – graphics mode. Graphics mode 100 px (X: 0 Class: 99) x 64 px (Y:

Graphics mode 100 px (X: 0LCD – graphics mode. Class: 99) x 64 px (Y: 0 63) javax.microedition.lcdui.Graphics; Methods (general description):

Class:LCD – graphics mode. Graphics mode 100 px (X: 0 99) x 64 px (Y: 0

99)

x 64 px (Y: 0

63)

javax.microedition.lcdui.Graphics;

Methods (general description):99) x 64 px (Y: 0 63) javax.microedition.lcdui.Graphics; Draw lines, arcs, figures, images, Strings, Ints, Chars

Draw lines, arcs, figures, images, Strings, Ints, CharsMethods (general description): Drawing style and fill can be provided. Version 1.53 | 20th

Drawing style and fill can be provided.Draw lines, arcs, figures, images, Strings, Ints, Chars Version 1.53 | 20th November 2011 Ph.D. Eng.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

33

LCD – streamed mode. Console style drawing – bottom line, scrolls up history entries Class:

LCD – streamed mode.

LCD – streamed mode. Console style drawing – bottom line, scrolls up history entries Class: lejos.nxt.LCDOutputStream;

Console style drawing – bottom line, scrolls up history entriesLCD – streamed mode. Class: lejos.nxt.LCDOutputStream; Method (general description): public void write(int c); - writes

Class:style drawing – bottom line, scrolls up history entries lejos.nxt.LCDOutputStream; Method (general description):

lejos.nxt.LCDOutputStream;

Method (general description):scrolls up history entries Class: lejos.nxt.LCDOutputStream; public void write(int c); - writes a low-order 8 bits

public void write(int c); - writes a low-order 8 bits (byte) to output stream (console) – the remaining 24 - writes a low-order 8 bits (byte) to output stream (console) – the remaining 24 high-order bits are abandoned.

Other java.io.OutputStream methods like: close, flush and so one.– the remaining 24 high-order bits are abandoned. Version 1.53 | 20th November 2011 Ph.D. Eng.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

34

NXT Intelligent Brick buttons. 4 static fields to identify buttons Common methods: public final boolean

NXT Intelligent Brick buttons.

NXT Intelligent Brick buttons. 4 static fields to identify buttons Common methods: public final boolean isPressed();

4 static fields to identify buttonsNXT Intelligent Brick buttons. Common methods: public final boolean isPressed(); public final void

Common methods:Brick buttons. 4 static fields to identify buttons public final boolean isPressed(); public final void

public final boolean isPressed();buttons. 4 static fields to identify buttons Common methods: public final void waitForPressAndRelease(); static int

public final void waitForPressAndRelease();buttons Common methods: public final boolean isPressed(); static int waitForPress(); public void

static int waitForPress();isPressed(); public final void waitForPressAndRelease(); public void addButtonListener(ButtonListener aListener); -

public void addButtonListener(ButtonListener aListener); - up to 4 delegates each - up to 4 delegates each

static int readButtons(); - low level function – reads using bit mask: - low level function – reads using bit mask:

ENTER=0x01, LEFT=0x02, RIGHT=0x04, ESC=0x08

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

35

Sample: NXT Intelligent Brick buttons (cont.). ● import lejos.nxt.*; ● public class ButtonPresses ● {
Sample: NXT Intelligent Brick buttons (cont.). ● import lejos.nxt.*; ● public class ButtonPresses ● {

Sample:

NXT Intelligent Brick

Sample: NXT Intelligent Brick buttons (cont.). ● import lejos.nxt.*; ● public class ButtonPresses ● { ●

buttons (cont.).

Sample: NXT Intelligent Brick buttons (cont.). ● import lejos.nxt.*; ● public class ButtonPresses ● { ●

import lejos.nxt.*;

public class ButtonPresses

{

void public static void main (String[] args)

throws Exception

{

while (true) {

LCD. clear ();

If (Button. ENTER .isPressed()) LCD.drawString ("ENTER",0,0);

if (Button. ESCAPE .isPressed()) LCD. drawString ("ESCAPE",0,0);

if (Button. LEFT .isPressed()) LCD. drawString ("LEFT",0,0);

if (Button. RIGHT .isPressed()) LCD.drawString ("RIGHT",0,0);

}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

36

Sample: NXT Intelligent Brick buttons (cont.). ● import lejos.nxt.*; ● public class ButtonTest ● {
Sample: NXT Intelligent Brick buttons (cont.). ● import lejos.nxt.*; ● public class ButtonTest ● {

Sample:

NXT Intelligent Brick

Sample: NXT Intelligent Brick buttons (cont.). ● import lejos.nxt.*; ● public class ButtonTest ● { ●

buttons (cont.).

Sample: NXT Intelligent Brick buttons (cont.). ● import lejos.nxt.*; ● public class ButtonTest ● { ●

import lejos.nxt.*;

public class ButtonTest

{

void public static void main (String[] args)

throws Exception

{

Button. ENTER .waitForPressAndRelease();

LCD. drawString ("Finished", 3, 4);

Thread. sleep (2000);

}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

37

Class: Power source monitoring. lejos.nxt.Battery; Methods: static float getVoltage(); static int getVoltageMilliVolt();

Class:Power source monitoring. lejos.nxt.Battery; Methods: static float getVoltage(); static int getVoltageMilliVolt(); Sample:

Power source monitoring.

Class: Power source monitoring. lejos.nxt.Battery; Methods: static float getVoltage(); static int getVoltageMilliVolt();

lejos.nxt.Battery;

Methods:Class: Power source monitoring. lejos.nxt.Battery; static float getVoltage(); static int getVoltageMilliVolt(); Sample:

static float getVoltage();Class: Power source monitoring. lejos.nxt.Battery; Methods: static int getVoltageMilliVolt(); Sample: import lejos.nxt.*;

static int getVoltageMilliVolt();lejos.nxt.Battery; Methods: static float getVoltage(); Sample: import lejos.nxt.*; public class BatteryTest {

Sample:static float getVoltage(); static int getVoltageMilliVolt(); import lejos.nxt.*; public class BatteryTest { void main

import lejos.nxt.*;

public class BatteryTest {

void main (String[] args) throws Exception {

LCD. drawString ("Battery: " + Battery. getVoltage (),0,0);

Thread.sleep (2000);

}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

38

Class: Sound (by brick speaker). lejos.nxt.Sound; Methods: public static void systemSound(boolean aQueued, int aCode);

Class:Sound (by brick speaker). lejos.nxt.Sound; Methods: public static void systemSound(boolean aQueued, int aCode); Acode=(0:

Sound (by brick speaker).

Class: Sound (by brick speaker). lejos.nxt.Sound; Methods: public static void systemSound(boolean aQueued, int aCode);

lejos.nxt.Sound;Class: Sound (by brick speaker). Methods: public static void systemSound(boolean aQueued, int aCode); Acode=(0: short

Methods:Class: Sound (by brick speaker). lejos.nxt.Sound; public static void systemSound(boolean aQueued, int aCode); Acode=(0:

public static void systemSound(boolean aQueued, int aCode);Class: Sound (by brick speaker). lejos.nxt.Sound; Methods: Acode=(0: short beep, 1: double beep, 2: descending, 3:

public static void systemSound(boolean aQueued, int aCode); Acode=(0: short beep, 1: double beep, 2: descending, 3:

Acode=(0: short beep, 1: double beep, 2:

descending, 3: ascending)

public static void beep();short beep, 1: double beep, 2: descending, 3: ascending) public static void twoBeeps(); public static void

public static void twoBeeps();2: descending, 3: ascending) public static void beep(); public static void beepSequence(); public static void

public static void beepSequence();public static void beep(); public static void twoBeeps(); public static void beepSequenceUp(); public static void

public static void beepSequenceUp();static void twoBeeps(); public static void beepSequence(); public static void buzz(); Version 1.53 | 20th November

public static void buzz();void beepSequence(); public static void beepSequenceUp(); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

39

Sound (by brick speaker). Sample: ● import lejos.nxt.*; ● public class Tune { ● private

Sound (by brick speaker).

Sound (by brick speaker). Sample: ● import lejos.nxt.*; ● public class Tune { ● private static
Sound (by brick speaker). Sample: ● import lejos.nxt.*; ● public class Tune { ● private static

Sample:

import lejos.nxt.*;

public class Tune {

private static final short [] note = {

2349,115, 0,5, 1760,165, 0,35, 1760,28, 0,13, 1976,23,

0,18, 1760,18, 0,23, 1568,15, 0,25, 1480,103, 0,18, 1175,180, 0,20, 1760,18,

0,23, 1976,20, 0,20, 1760,15, 0,25, 1568,15, 0,25, 2217,98, 0,23, 1760,88,

0,33, 1760,75, 0,5, 1760,20, 0,20, 1760,20, 0,20, 1976,18, 0,23, 1760,18,

0,23, 2217,225, 0,15, 2217,218};

void public static void main(String [] args) {

for(int i=0;i< note .length; i+=2) {

final short w = note [i+1];

final int n = note [i];

if (n != 0) Sound. playTone (n, w*10);

try { Thread.sleep (w*10); } catch (InterruptedException e) {}

}}}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

40

Touch sensor. Class: TouchSensor class instance with port; Constructor: public TouchSensor(ADSensorPort port); Common

Touch sensor.

Touch sensor. Class: TouchSensor class instance with port; Constructor: public TouchSensor(ADSensorPort port); Common

Class:Touch sensor. TouchSensor class instance with port; Constructor: public TouchSensor(ADSensorPort port); Common methods:

Touch sensor. Class: TouchSensor class instance with port; Constructor: public TouchSensor(ADSensorPort port); Common

TouchSensor class instance with port;

Constructor:Touch sensor. Class: TouchSensor class instance with port; public TouchSensor(ADSensorPort port); Common methods: public

public TouchSensor(ADSensorPort port);Class: TouchSensor class instance with port; Constructor: Common methods: public boolean isPressed(); Version 1.53 |

Common methods:port; Constructor: public TouchSensor(ADSensorPort port); public boolean isPressed(); Version 1.53 | 20th November

public TouchSensor(ADSensorPort port); Common methods: public boolean isPressed(); Version 1.53 | 20th November

public boolean isPressed();

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

41

Sample: Touch sensor (cont.). ● import lejos.nxt.*; ● public class TouchTest { – void public
Sample: Touch sensor (cont.). ● import lejos.nxt.*; ● public class TouchTest { – void public

Sample:

Touch sensor (cont.).

Sample: Touch sensor (cont.). ● import lejos.nxt.*; ● public class TouchTest { – void public static

import lejos.nxt.*;

public class TouchTest {

void public static main(String [] args) { throws Exception

{

TouchSensor touch = new TouchSensor(SensorPort. S1);

while (!touch.isPressed());

LCD.drawString(„Finished”, 3, 4);

Thread.sleep(2000);

}

}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

42

Class: Light sensor. – LightSensor class instance with port; Constructor: public LightSensor(ADSensorPort port);

Class:Light sensor. – LightSensor class instance with port; Constructor: public LightSensor(ADSensorPort port); Methods: void

Light sensor.

Class: Light sensor. – LightSensor class instance with port; Constructor: public LightSensor(ADSensorPort port);

LightSensor class instance with port;

Constructor:Light sensor. – LightSensor class instance with port; public LightSensor(ADSensorPort port); Methods: void

public LightSensor(ADSensorPort port);– LightSensor class instance with port; Constructor: Methods: void setFloodlight(boolean bOn); public int

Methods:port; Constructor: public LightSensor(ADSensorPort port); void setFloodlight(boolean bOn); public int readValue();

void setFloodlight(boolean bOn);Constructor: public LightSensor(ADSensorPort port); Methods: public int readValue(); public int readNormalizedValue();

public int readValue();port); Methods: void setFloodlight(boolean bOn); public int readNormalizedValue(); void calibrateHigh(); void

public int readNormalizedValue();void setFloodlight(boolean bOn); public int readValue(); void calibrateHigh(); void calibrateLow(); void setHigh(int

void calibrateHigh(); void calibrateLow();public int readValue(); public int readNormalizedValue(); void setHigh(int high); void setLow(int low); int getHigh();

void setHigh(int high); void setLow(int low);void calibrateHigh(); void calibrateLow(); int getHigh(); int getLow(); Version 1.53 | 20th November

int getHigh(); int getLow();void setHigh(int high); void setLow(int low); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

43

Sample: Light sensor (cont.). ● import lejos.nxt.*; ● public class LightTest { ● void main
Sample: Light sensor (cont.). ● import lejos.nxt.*; ● public class LightTest { ● void main

Sample:

Light sensor (cont.).

Sample: Light sensor (cont.). ● import lejos.nxt.*; ● public class LightTest { ● void main (String[]

import lejos.nxt.*;

public class LightTest {

void main (String[] args)

throws Exception

{

LightSensor light = new LightSensor(SensorPort. S1);

while (true) {

LCD. drawInt (light.readValue(), 4, 0, 0);

LCD. drawInt (light.readNormalizedValue(), 4, 0, 1);

LCD. drawInt (SensorPort. S1 .readRawValue(), 4, 0, 2);

LCD. drawInt (SensorPort. S1 .readValue(), 4, 0, 3);

Thread.sleep(2000);

}

}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

44

Sound sensor. Class: – SoundSensor class instance with port; Constructor: public SoundSensor(ADSensorPort port); public

Sound sensor.

Sound sensor. Class: – SoundSensor class instance with port; Constructor: public SoundSensor(ADSensorPort port); public

Class:Sound sensor. – SoundSensor class instance with port; Constructor: public SoundSensor(ADSensorPort port); public

SoundSensor class instance with port;

Constructor:sensor. Class: – SoundSensor class instance with port; public SoundSensor(ADSensorPort port); public

public SoundSensor(ADSensorPort port);– SoundSensor class instance with port; Constructor: public SoundSensor(ADSensorPort port, boolean bDBA);

public SoundSensor(ADSensorPort port, boolean bDBA);port; Constructor: public SoundSensor(ADSensorPort port); Methods: int readValue(); void setDBA(boolean dba); Version

Methods:port); public SoundSensor(ADSensorPort port, boolean bDBA); int readValue(); void setDBA(boolean dba); Version 1.53 |

int readValue();SoundSensor(ADSensorPort port, boolean bDBA); Methods: void setDBA(boolean dba); Version 1.53 | 20th November 2011

void setDBA(boolean dba);port, boolean bDBA); Methods: int readValue(); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

45

Samples: Sound sensor (cont.). ● import lejos.nxt.*; ● public class SoundScope { ● void main
Samples: Sound sensor (cont.). ● import lejos.nxt.*; ● public class SoundScope { ● void main

Samples:

Sound sensor (cont.).

Samples: Sound sensor (cont.). ● import lejos.nxt.*; ● public class SoundScope { ● void main (String[]

import lejos.nxt.*;

public class SoundScope {

void main (String[] args) throws Exception {

SoundSensor light = new SoundSensor(SensorPort. S1 );

while (!Button.ESCAPE.isPressed()) {

LCD. clear ();

for(int i=0;i<100;i++)

LCD. setPixel (1,i,60 - (sound.readValue()/2));

Thread.sleep(20);

}

}

}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

46

Ultrasound distance sensor. Class: – UltrasonicSensor class instance with I2C port; Constructor: public

Ultrasound distance sensor.

Ultrasound distance sensor. Class: – UltrasonicSensor class instance with I2C port; Constructor: public

Class:Ultrasound distance sensor. – UltrasonicSensor class instance with I2C port; Constructor: public

UltrasonicSensor class instance with I2C port;

Constructor:Class: – UltrasonicSensor class instance with I2C port; public UltrasonicSensor(I2CPort port); Methods: int

public UltrasonicSensor(I2CPort port);UltrasonicSensor class instance with I2C port; Constructor: Methods: int getDistance(); void ping(); int

Methods:port; Constructor: public UltrasonicSensor(I2CPort port); int getDistance(); void ping(); int readDistances(int []

int getDistance();Constructor: public UltrasonicSensor(I2CPort port); Methods: void ping(); int readDistances(int [] distances); int

void ping();UltrasonicSensor(I2CPort port); Methods: int getDistance(); int readDistances(int [] distances); int continuous();

int readDistances(int [] distances);port); Methods: int getDistance(); void ping(); int continuous(); Version 1.53 | 20th November 2011 Ph.D.

int continuous();void ping(); int readDistances(int [] distances); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

47

Ultrasound distance sensor (cont.). Sample: ● import lejos.nxt.*; ● public class SonicTest { ● void

Ultrasound distance sensor (cont.).

Ultrasound distance sensor (cont.). Sample: ● import lejos.nxt.*; ● public class SonicTest { ● void
Ultrasound distance sensor (cont.). Sample: ● import lejos.nxt.*; ● public class SonicTest { ● void

Sample:

import lejos.nxt.*;

public class SonicTest {

void main(String[] args) throws Exception {

UltrasonicSensor sonic = new

UltrasonicSensor(SensorPort. S1 );

while(!Button. ESCAPE .isPressed()) {

LCD. clear ();

LCD. drawInt (sonic.getDistance(), 0, 3);

}

}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

48

NXT Interactive Servomotor. Class: Motor class; (Motor.A, Motor.B, Motor.C) Methods: void flt(); void forward(); void

NXT Interactive Servomotor.

NXT Interactive Servomotor. Class: Motor class; (Motor.A, Motor.B, Motor.C) Methods: void flt(); void forward(); void

Class:NXT Interactive Servomotor. Motor class; (Motor.A, Motor.B, Motor.C) Methods: void flt(); void forward(); void backward();

Motor class; (Motor.A, Motor.B, Motor.C)NXT Interactive Servomotor. Class: Methods: void flt(); void forward(); void backward(); int getActualSpeed(); float

Methods:Servomotor. Class: Motor class; (Motor.A, Motor.B, Motor.C) void flt(); void forward(); void backward(); int

void flt();Class: Motor class; (Motor.A, Motor.B, Motor.C) Methods: void forward(); void backward(); int getActualSpeed(); float

void forward(); void backward();class; (Motor.A, Motor.B, Motor.C) Methods: void flt(); int getActualSpeed(); float getBasePower(); int

int getActualSpeed();Methods: void flt(); void forward(); void backward(); float getBasePower(); int getLimitAngle(); int getMode();

float getBasePower();void forward(); void backward(); int getActualSpeed(); int getLimitAngle(); int getMode(); int getPower(); int

int getLimitAngle();void backward(); int getActualSpeed(); float getBasePower(); int getMode(); int getPower(); int getSpeed(); int

int getMode();getActualSpeed(); float getBasePower(); int getLimitAngle(); int getPower(); int getSpeed(); int getStopAngle(); Version

int getPower();float getBasePower(); int getLimitAngle(); int getMode(); int getSpeed(); int getStopAngle(); Version 1.53 | 20th

int getSpeed();int getLimitAngle(); int getMode(); int getPower(); int getStopAngle(); Version 1.53 | 20th November 2011 Ph.D.

int getStopAngle();int getMode(); int getPower(); int getSpeed(); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

49

NXT Interactive Servomotor (cont.). Methods: int getTachoCount(); void resetTachoCount(); boolean isMoving(); boolean

NXT Interactive Servomotor (cont.).

NXT Interactive Servomotor (cont.). Methods: int getTachoCount(); void resetTachoCount(); boolean isMoving(); boolean
NXT Interactive Servomotor (cont.). Methods: int getTachoCount(); void resetTachoCount(); boolean isMoving(); boolean

Methods:

int getTachoCount();NXT Interactive Servomotor (cont.). Methods: void resetTachoCount(); boolean isMoving(); boolean isRotating(); boolean

void resetTachoCount();Servomotor (cont.). Methods: int getTachoCount(); boolean isMoving(); boolean isRotating(); boolean

boolean isMoving();Methods: int getTachoCount(); void resetTachoCount(); boolean isRotating(); boolean isRegulating(); void lock();

boolean isRotating();getTachoCount(); void resetTachoCount(); boolean isMoving(); boolean isRegulating(); void lock(); void

boolean isRegulating();resetTachoCount(); boolean isMoving(); boolean isRotating(); void lock(); void regulateSpeed(boolean yes); void

void lock();isMoving(); boolean isRotating(); boolean isRegulating(); void regulateSpeed(boolean yes); void reverseDirection();

void regulateSpeed(boolean yes);boolean isRotating(); boolean isRegulating(); void lock(); void reverseDirection(); void rotate(int angle);

void reverseDirection();void lock(); void regulateSpeed(boolean yes); void rotate(int angle); //blokujące void rotate(int angle,

void rotate(int angle); //blokującevoid regulateSpeed(boolean yes); void reverseDirection(); void rotate(int angle, boolean immediate); void rotateTo(int

void rotate(int angle, boolean immediate);reverseDirection(); void rotate(int angle); //blokujące void rotateTo(int angle); void rotateTo(int angle, boolean

void rotateTo(int angle);//blokujące void rotate(int angle, boolean immediate); void rotateTo(int angle, boolean immediate); Version 1.53 |

void rotateTo(int angle, boolean immediate);angle, boolean immediate); void rotateTo(int angle); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

50

NXT Interactive Servomotor (cont.). Methods: void setBrakePower(int pwr); void setPower(int power); void setSpeed(int

NXT Interactive Servomotor (cont.).

NXT Interactive Servomotor (cont.). Methods: void setBrakePower(int pwr); void setPower(int power); void setSpeed(int
NXT Interactive Servomotor (cont.). Methods: void setBrakePower(int pwr); void setPower(int power); void setSpeed(int

Methods:

void setBrakePower(int pwr);NXT Interactive Servomotor (cont.). Methods: void setPower(int power); void setSpeed(int speed); // stopni/min. void

void setPower(int power);Servomotor (cont.). Methods: void setBrakePower(int pwr); void setSpeed(int speed); // stopni/min. void stop(); void

void setSpeed(int speed); // stopni/min.void setBrakePower(int pwr); void setPower(int power); void stop(); void smoothAcceleration(boolean yes); Version

void stop();power); void setSpeed(int speed); // stopni/min. void smoothAcceleration(boolean yes); Version 1.53 | 20th

void smoothAcceleration(boolean yes);void setSpeed(int speed); // stopni/min. void stop(); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

51

NXT Interactive Servomotor (cont.). Sample: ● import lejos.nxt.*; ● public class HelloWorld { ● public

NXT Interactive Servomotor (cont.).

NXT Interactive Servomotor (cont.). Sample: ● import lejos.nxt.*; ● public class HelloWorld { ● public static
NXT Interactive Servomotor (cont.). Sample: ● import lejos.nxt.*; ● public class HelloWorld { ● public static

Sample:

import lejos.nxt.*;

public class HelloWorld {

public static void main(String [] args) {

Motor. B .resetTachoCount();

Motor. C .resetTachoCount();

while (!Button. ENTER .isPressed()) {

LCD. drawInt (Motor. B .getTachoCount(), 1, 1);

LCD. drawInt (Motor. C .getTachoCount(), 1, 2);

try {

Thread. sleep (100);

LCD. clear ();

}

catch(InterruptedException e){}

}}}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

52

NXT Interactive Servomotor (cont.). Sample (cont.): ● ( ) ● Motor.B.setSpeed(720);// 2 RPM ●

NXT Interactive Servomotor (cont.).

NXT Interactive Servomotor (cont.). Sample (cont.): ● ( ) ● Motor.B.setSpeed(720);// 2 RPM ●
NXT Interactive Servomotor (cont.). Sample (cont.): ● ( ) ● Motor.B.setSpeed(720);// 2 RPM ●

Sample (cont.):

(

)

Motor.B.setSpeed(720);// 2 RPM

Motor.C.setSpeed(720);

Motor.B.forward();

Motor.C.forward();

Thread.sleep (1000); //to trzeba obłożyć musi być Try-catch żeby skompilować

Motor.A.stop();

Motor.C.stop();

Motor.A.regulateSpeed(true);

Motor.A.rotateTo( 360);

Motor.A.rotate(-720,true);

while(Motor.A.isRotating()){};

int angle = Motor.A.getTachoCount(); // should be -360

(

)

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

53

3 r d party sensors (base) lejos.nxt.addon Sensors other than I2C use A/D port (

3 rd party sensors (base)

lejos.nxt.addon

3 r d party sensors (base) lejos.nxt.addon Sensors other than I2C use A/D port ( ADSensorPort
3 r d party sensors (base) lejos.nxt.addon Sensors other than I2C use A/D port ( ADSensorPort
3 r d party sensors (base) lejos.nxt.addon Sensors other than I2C use A/D port ( ADSensorPort
3 r d party sensors (base) lejos.nxt.addon Sensors other than I2C use A/D port ( ADSensorPort

Sensors other than I2C use A/D port (ADSensorPort ) and have dedicated classes, not inheriting common base class (but object , as ADSensorPort) and have dedicated classes, not inheriting common base class (but object, as all classes do).

All I2C sensors inherit from I2CSensor . I2CSensor.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

54

I2C: 3 r d party sensors (base). – I2CSensor class instance with I2C port; Constructor:

I2C:3 r d party sensors (base). – I2CSensor class instance with I2C port; Constructor: public

3 rd party sensors (base).

I2C: 3 r d party sensors (base). – I2CSensor class instance with I2C port; Constructor: public
I2C: 3 r d party sensors (base). – I2CSensor class instance with I2C port; Constructor: public
I2C: 3 r d party sensors (base). – I2CSensor class instance with I2C port; Constructor: public

I2CSensor class instance with I2C port;

Constructor:sensors (base). – I2CSensor class instance with I2C port; public UltrasonicSensor(I2CPort port); Methods: int

public UltrasonicSensor(I2CPort port);– I2CSensor class instance with I2C port; Constructor: Methods: int getData(int register, byte[] buf, int len);

Methods:port; Constructor: public UltrasonicSensor(I2CPort port); int getData(int register, byte[] buf, int len); int

int getData(int register, byte[] buf, int len);Constructor: public UltrasonicSensor(I2CPort port); Methods: int sendData(int register, byte value); int sendData(int

int sendData(int register, byte value);Methods: int getData(int register, byte[] buf, int len); int sendData(int register, byte[] buf, int len); void

int sendData(int register, byte[] buf, int len);buf, int len); int sendData(int register, byte value); void setAddress(int addr); // 7-bit I2CPort getPort();

void setAddress(int addr); // 7-bitvalue); int sendData(int register, byte[] buf, int len); I2CPort getPort(); String getProductID(); String

I2CPort getPort(); String getProductID(); String getSensorType(); String getVersion();byte[] buf, int len); void setAddress(int addr); // 7-bit Version 1.53 | 20th November 2011 Ph.D.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

55

Compass sensor. Both HiTechnic & Mindsensors: – CompassSensor class instance with I2C port; Constructor: public

Compass sensor.

Compass sensor. Both HiTechnic & Mindsensors: – CompassSensor class instance with I2C port; Constructor: public

Both HiTechnic & Mindsensors:Compass sensor. – CompassSensor class instance with I2C port; Constructor: public CompassSensor(I2CPort port); Methods:

CompassSensor class instance with I2C port;

Constructor:– CompassSensor class instance with I2C port; public CompassSensor(I2CPort port); Methods: float

public CompassSensor(I2CPort port);CompassSensor class instance with I2C port; Constructor: Methods: float getDegrees(); //0.1 grade accuracy clockwise

Methods:I2C port; Constructor: public CompassSensor(I2CPort port); float getDegrees(); //0.1 grade accuracy clockwise float

float getDegrees(); //0.1 grade accuracy clockwiseConstructor: public CompassSensor(I2CPort port); Methods: float getDegreesCartesian; // counterwise void

float getDegreesCartesian; // counterwiseMethods: float getDegrees(); //0.1 grade accuracy clockwise void resetCartesianZero(); void startCalibration(); // min.

void resetCartesianZero();accuracy clockwise float getDegreesCartesian; // counterwise void startCalibration(); // min. 20s/per turn, Mindsensors

void startCalibration(); // min. 20s/per turn, Mindsensors min. 2 turns, HiTechinc: 1.5 to 2// counterwise void resetCartesianZero(); void stopCalibration(); Version 1.53 | 20th November 2011

void stopCalibration();20s/per turn, Mindsensors min. 2 turns, HiTechinc: 1.5 to 2 Version 1.53 | 20th November 2011

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

56

Sample: Compass sensor. import lejos.nxt.*; import lejos.nxt.addon.*; public class Compass { public static void
Sample: Compass sensor. import lejos.nxt.*; import lejos.nxt.addon.*; public class Compass { public static void

Sample:

Compass sensor.

Sample: Compass sensor. import lejos.nxt.*; import lejos.nxt.addon.*; public class Compass { public static void

import lejos.nxt.*;

import lejos.nxt.addon.*;

public class Compass {

public static void main(String [] args) {

CompassSensor cs = new CompassSensor(SensorPort.S4);

Motor. B .setSpeed(60); Motor. B .forward();

float stopnie=cs.getDegrees();

while (stopnie>1) {

LCD. clear (); LCD. drawInt((int)stopnie, 1, 1);

stopnie=cs.getDegrees();

}

Motor. B .stop(); LCD.clear ();

LCD. drawString ("Znalazlem polnoc!", 1, 2);

try { Button. ENTER .waitForPressAndRelease(); }

catch(InterruptedException e){}}

}

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

57

Tilt / acceleration. HiTechnic: – AccelHTSensor; Constructor: public AccelHTSensor(I2CPort port); public

Tilt / acceleration.

Tilt / acceleration. HiTechnic: – AccelHTSensor; Constructor: public AccelHTSensor(I2CPort port); public

HiTechnic:Tilt / acceleration. – AccelHTSensor; Constructor: public AccelHTSensor(I2CPort port); public AccelHTSensor(I2CPort

AccelHTSensor;

Constructor:Tilt / acceleration. HiTechnic: – AccelHTSensor; public AccelHTSensor(I2CPort port); public AccelHTSensor(I2CPort port,

public AccelHTSensor(I2CPort port);/ acceleration. HiTechnic: – AccelHTSensor; Constructor: public AccelHTSensor(I2CPort port, int address); Methods:

public AccelHTSensor(I2CPort port, int address);Constructor: public AccelHTSensor(I2CPort port); Methods: int getXAccel(); int getXTilt(); int getYAccel();

Methods:port); public AccelHTSensor(I2CPort port, int address); int getXAccel(); int getXTilt(); int getYAccel(); int

int getXAccel(); int getXTilt();public AccelHTSensor(I2CPort port, int address); Methods: int getYAccel(); int getYTilt(); int getZAccel(); int

int getYAccel(); int getYTilt();int address); Methods: int getXAccel(); int getXTilt(); int getZAccel(); int getZTilt(); Version 1.53 | 20th

int getZAccel(); int getZTilt();int getXTilt(); int getYAccel(); int getYTilt(); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

58

Tilt / acceleration. Mindsensors: – AccelMindSensor; Constructor: public AccelMindSensor(I2CPort port); public

Tilt / acceleration.

Tilt / acceleration. Mindsensors: – AccelMindSensor; Constructor: public AccelMindSensor(I2CPort port); public

Mindsensors:Tilt / acceleration. – AccelMindSensor; Constructor: public AccelMindSensor(I2CPort port); public

AccelMindSensor;

Constructor:Tilt / acceleration. Mindsensors: – AccelMindSensor; public AccelMindSensor(I2CPort port); public

public AccelMindSensor(I2CPort port);Mindsensors: – AccelMindSensor; Constructor: public AccelMindSensor(I2CPort port, int address); Methods:

public AccelMindSensor(I2CPort port, int address);Constructor: public AccelMindSensor(I2CPort port); Methods: int getXAccel(); int getXTilt(); int getYAccel();

Methods:port); public AccelMindSensor(I2CPort port, int address); int getXAccel(); int getXTilt(); int getYAccel(); int

int getXAccel(); int getXTilt();public AccelMindSensor(I2CPort port, int address); Methods: int getYAccel(); int getYTilt(); int getZAccel(); int

int getYAccel(); int getYTilt();int address); Methods: int getXAccel(); int getXTilt(); int getZAccel(); int getZTilt(); Version 1.53 | 20th

int getZAccel(); int getZTilt();int getXTilt(); int getYAccel(); int getYTilt(); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

59

Class: Gyro sensor. – GyroSensor class instance with port; Constructor: public GyroSensor(AdSensorPort port); Methods:

Class:Gyro sensor. – GyroSensor class instance with port; Constructor: public GyroSensor(AdSensorPort port); Methods: int

Gyro sensor.

Class: Gyro sensor. – GyroSensor class instance with port; Constructor: public GyroSensor(AdSensorPort port); Methods:

GyroSensor class instance with port;

Constructor:Class: Gyro sensor. – GyroSensor class instance with port; public GyroSensor(AdSensorPort port); Methods: int

public GyroSensor(AdSensorPort port);– GyroSensor class instance with port; Constructor: Methods: int readValue(); void setOffset(int offset);

Methods:port; Constructor: public GyroSensor(AdSensorPort port); int readValue(); void setOffset(int offset); Requires

int readValue();Constructor: public GyroSensor(AdSensorPort port); Methods: void setOffset(int offset); Requires setting the offset to

void setOffset(int offset);GyroSensor(AdSensorPort port); Methods: int readValue(); Requires setting the offset to provide accurate results

Requires setting the offset to provide accurate results (offset can be measured during runtime).port); Methods: int readValue(); void setOffset(int offset); DirectionFinder based on gyro (keeps heading): public

DirectionFinder based on gyro (keeps heading):accurate results (offset can be measured during runtime). public GyroDirectionFinder Version 1.53 | 20th November 2011

runtime). DirectionFinder based on gyro (keeps heading): public GyroDirectionFinder Version 1.53 | 20th November 2011

public GyroDirectionFinder

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

60

HiTechnic color sensor. Class: – ColorSensorHT class instance with I2C port; Constructor: public ColorSensorHT(I2CPort

HiTechnic color sensor.

HiTechnic color sensor. Class: – ColorSensorHT class instance with I2C port; Constructor: public ColorSensorHT(I2CPort

Class:HiTechnic color sensor. – ColorSensorHT class instance with I2C port; Constructor: public ColorSensorHT(I2CPort port);

ColorSensorHT class instance with I2C port;

Constructor:Class: – ColorSensorHT class instance with I2C port; public ColorSensorHT(I2CPort port); Methods: Color

public ColorSensorHT(I2CPort port);ColorSensorHT class instance with I2C port; Constructor: Methods: Color getColor(); - returns RGB at once in

Methods:I2C port; Constructor: public ColorSensorHT(I2CPort port); Color getColor(); - returns RGB at once in Color class

Color getColor(); - returns RGB at once in Color class returns RGB at once in Color class

int getBlue/Green/Red();Color getColor(); - returns RGB at once in Color class int getColorIndexNumber();int getColorID(); int getMode();

int getColorIndexNumber();int getColorID();returns RGB at once in Color class int getBlue/Green/Red(); int getMode(); int getRGBNormalized(int color); int

int getMode();int getColorIndexNumber();int getColorID(); int getRGBNormalized(int color); int getRGBRaw(int color);

int getRGBNormalized(int color);int getColorIndexNumber();int getColorID(); int getMode(); int getRGBRaw(int color); int initBlackLevel(); int

int getRGBRaw(int color);int getMode(); int getRGBNormalized(int color); int initBlackLevel(); int initWhiteBalance(); Version 1.53 |

int initBlackLevel(); int initWhiteBalance();int getRGBNormalized(int color); int getRGBRaw(int color); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

61

Class: HiTechnic angle sensor. – AngleSensor class instance with I2C port; Constructor: public ColorSensor(I2CPort

Class:HiTechnic angle sensor. – AngleSensor class instance with I2C port; Constructor: public ColorSensor(I2CPort port);

HiTechnic angle sensor.

Class: HiTechnic angle sensor. – AngleSensor class instance with I2C port; Constructor: public ColorSensor(I2CPort

AngleSensor class instance with I2C port;

Constructor:angle sensor. – AngleSensor class instance with I2C port; public ColorSensor(I2CPort port); public ColorSensor(I2CPort

public ColorSensor(I2CPort port);– AngleSensor class instance with I2C port; Constructor: public ColorSensor(I2CPort port, int mode); public

public ColorSensor(I2CPort port, int mode);I2C port; Constructor: public ColorSensor(I2CPort port); public ColorSensor(I2CPort port, int address, int mode, int

public ColorSensor(I2CPort port, int address, int mode, int type);port); public ColorSensor(I2CPort port, int mode); Methods: calibrateAngle() getAccAngle() - read accumulated

Methods:ColorSensor(I2CPort port, int address, int mode, int type); calibrateAngle() getAccAngle() - read accumulated angle

calibrateAngle()port, int address, int mode, int type); Methods: getAccAngle() - read accumulated angle getAngle() - read

getAccAngle() - read accumulated angle read accumulated angle

getAngle() - read current angle read current angle

getRPM() - read current rotation speed read current rotation speed

resetAccAngle() - reset the accumulated angle count reset the accumulated angle count

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

62

Other sensors (briefly). IR Seeker (HiTechnic)IR source directional scanner: – IRSeeker class instance with I2C

Other sensors (briefly).

Other sensors (briefly). IR Seeker (HiTechnic)IR source directional scanner: – IRSeeker class instance with I2C port;

IR Seeker (HiTechnic)IR source directional scanner:Other sensors (briefly). – IRSeeker class instance with I2C port; – IRSeekerV2 class instance with I2C

IRSeeker class instance with I2C port;

IRSeekerV2 class instance with I2C port;

Optical distance meter (Mindsensors):with I2C port; – IRSeekerV2 class instance with I2C port; – OpticalDistanceSensor class instance with I2C

OpticalDistanceSensor class instance with I2C port;

NXTCam (Mindsensors):– OpticalDistanceSensor class instance with I2C port; – NXTCam class instance with I2C port; Sony PSP2

NXTCam class instance with I2C port;

Sony PSP2 controller interface PSP-NX (Mindsensors):(Mindsensors): – NXTCam class instance with I2C port; PSPNXController class with regular SensorPort; Version 1.53

port; Sony PSP2 controller interface PSP-NX (Mindsensors): PSPNXController class with regular SensorPort; Version 1.53

PSPNXController class with regular SensorPort;

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

63

Other sensors (briefly). PFLink – power functions over Mindsensors NRLink- Nx: – PFMate I2C –

Other sensors (briefly).

Other sensors (briefly). PFLink – power functions over Mindsensors NRLink- Nx: – PFMate I2C – control

PFLink – power functions over Mindsensors NRLink- Nx:Other sensors (briefly). – PFMate I2C – control LEGO Power Functions IR receiver – PFMateMotor –

PFMate I2C – control LEGO Power Functions IR receiver

PFMateMotor – Motor class for PFMate

PFMotorPort – Motorport class for PFMate

Mindsensors line leader sensor for black / white lines:for PFMate – PFMotorPort – Motorport class for PFMate – NXTLineLeader I2C Mindsensors NXTMMX motor multiplexer:

NXTLineLeader I2C

Mindsensors NXTMMX motor multiplexer:sensor for black / white lines: – NXTLineLeader I2C – NXTMMX / MMXRegulatedMotor / NXTMMXMotor Version

NXTMMX / MMXRegulatedMotor / NXTMMXMotor

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

64

Other sensors (briefly). Codatex RFID sensor: – RFIDSensor I2C HiTechnic EOPD (Electro Optical Proximity Detector)

Other sensors (briefly).

Other sensors (briefly). Codatex RFID sensor: – RFIDSensor I2C HiTechnic EOPD (Electro Optical Proximity Detector) –

Codatex RFID sensor:Other sensors (briefly). – RFIDSensor I2C HiTechnic EOPD (Electro Optical Proximity Detector) – capable to detect

RFIDSensor I2C

HiTechnic EOPD (Electro Optical Proximity Detector) – capable to detect very small distance changes, spotlight independent:sensors (briefly). Codatex RFID sensor: – RFIDSensor I2C – EOPD ADSensorPort Dexter Industries dGPS sensor: –

EOPD ADSensorPort

Dexter Industries dGPS sensor:changes, spotlight independent: – EOPD ADSensorPort – GPSSensor I2C Firgelli linear actuators (motor+encoder

GPSSensor I2C

Firgelli linear actuators (motor+encoder based) various models:Dexter Industries dGPS sensor: – GPSSensor I2C – LinearActuator MotorPort Version 1.53 | 20th November

LinearActuator MotorPort

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

65

Other sensors (briefly). Mindsensors RTC: – RealTimeClock I2C Mindsensors touch sensors multiplexer: – TouchMUX

Other sensors (briefly).

Other sensors (briefly). Mindsensors RTC: – RealTimeClock I2C Mindsensors touch sensors multiplexer: – TouchMUX

Mindsensors RTC:Other sensors (briefly). – RealTimeClock I2C Mindsensors touch sensors multiplexer: – TouchMUX ADSensorPort Version

RealTimeClock I2C

Mindsensors touch sensors multiplexer:sensors (briefly). Mindsensors RTC: – RealTimeClock I2C – TouchMUX ADSensorPort Version 1.53 | 20th November 2011

TouchMUX ADSensorPort

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

66

Other sensors (briefly) (cont.). Multiplexer interface for RCX motors (Mindsensors): – RCXMotorMultiplexer class

Other sensors (briefly) (cont.).

Other sensors (briefly) (cont.). Multiplexer interface for RCX motors (Mindsensors): – RCXMotorMultiplexer class
Other sensors (briefly) (cont.). Multiplexer interface for RCX motors (Mindsensors): – RCXMotorMultiplexer class

Multiplexer interface for RCX motors (Mindsensors):

RCXMotorMultiplexer class instance with I2C port;

– RCXMotorMultiplexer class instance with I2C port; Single motor of RCX motor multiplexer: RCXPlexedMotorPort

Single motor of RCX motor multiplexer:

RCXPlexedMotorPort class instance;

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

67

RCX sensors connected to the NXT over accessory cable. RCX Light Sensor: RCXLightSensor class instance,

RCX sensors connected to the

RCX sensors connected to the NXT over accessory cable. RCX Light Sensor: RCXLightSensor class instance, using

NXT over accessory cable.

RCX sensors connected to the NXT over accessory cable. RCX Light Sensor: RCXLightSensor class instance, using

RCX Light Sensor:RCX sensors connected to the NXT over accessory cable. RCXLightSensor class instance, using LegacySensorPort class; RCX

RCXLightSensor class instance, using LegacySensorPort class;connected to the NXT over accessory cable. RCX Light Sensor: RCX Motor: RCXMotor class instance, using

RCX Motor:RCXLightSensor class instance, using LegacySensorPort class; RCXMotor class instance, using BasicMotorPort class; RCX

RCXMotor class instance, using BasicMotorPort class;class instance, using LegacySensorPort class; RCX Motor: RCX Rotation Sensor: – RCXRotationSensor class instance,

RCX Rotation Sensor:Motor: RCXMotor class instance, using BasicMotorPort class; – RCXRotationSensor class instance, using

RCXRotationSensor class instance, using LegacySensorPort class;

RCX Temperature Sensor:class instance, using LegacySensorPort class; – RCXTemperatureSensor class instance, using

RCXTemperatureSensor class instance, using LegacySensorPort class;

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

68

NXT to NXT remote connections. LCP compatible firmware Master Slave Allows to manage other NXTs

NXT to NXT remote connections.

NXT to NXT remote connections. LCP compatible firmware Master Slave Allows to manage other NXTs through
LCP compatible firmware Master
LCP compatible
firmware
Master

Slave

Allows to manage other NXTs through NXT.remote connections. LCP compatible firmware Master Slave Communication over BT. NXTs have to be paired. Package:

Communication over BT.Master Slave Allows to manage other NXTs through NXT. NXTs have to be paired. Package: lejos.nxt.remote

NXTs have to be paired.to manage other NXTs through NXT. Communication over BT. Package: lejos.nxt.remote LCP compatible firmware 6 9

Package:through NXT. Communication over BT. NXTs have to be paired. lejos.nxt.remote LCP compatible firmware 6 9

lejos.nxt.remote

LCP compatible firmware
LCP compatible
firmware

69

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

NXT to NXT remote connections. Communicates with other NXT using LCP protocol. Supports sensors (class

NXT to NXT remote connections.

NXT to NXT remote connections. Communicates with other NXT using LCP protocol. Supports sensors (class RemoteSensorPort

Communicates with other NXT using LCP protocol.NXT to NXT remote connections. Supports sensors (class RemoteSensorPort ): ADSensorPort, BasicSensorPort, I2CPort,

Supports sensors (class RemoteSensorPort ): RemoteSensorPort):

ADSensorPort, BasicSensorPort, I2CPort, NXTProtocol and SensorConstants.

Support motors (class RemoteMotorPort ): RemoteMotorPort):

BasicMotorPort, NXTProtocol, TachoMotorPort,Encoder.

A similar to autonomous mode API – class RemoteNXT – supports almost all features of remote NXT over Bluetooth and LCP protocol. RemoteNXT – supports almost all features of remote NXT over Bluetooth and LCP protocol.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

70

Creating user menu on NXT brick. lejos.util package Class: TextMenu class instance Constructors: public TextMenu(String[]

Creating user menu on NXT brick.

Creating user menu on NXT brick. lejos.util package Class: TextMenu class instance Constructors: public TextMenu(String[]

lejos.util package package

Class:Creating user menu on NXT brick. lejos.util package TextMenu class instance Constructors: public TextMenu(String[]

TextMenu class instanceCreating user menu on NXT brick. lejos.util package Class: Constructors: public TextMenu(String[] items); public

Constructors:brick. lejos.util package Class: TextMenu class instance public TextMenu(String[] items); public TextMenu(String[]

public TextMenu(String[] items);package Class: TextMenu class instance Constructors: public TextMenu(String[] items, int topRow); public

public TextMenu(String[] items, int topRow);instance Constructors: public TextMenu(String[] items); public TextMenu(String[] items, int topRow, String title);

public TextMenu(String[] items, int topRow, String title);items); public TextMenu(String[] items, int topRow); Methods: int select(); int select(int startIdx); int

Methods:public TextMenu(String[] items, int topRow, String title); int select(); int select(int startIdx); int select(int

int select();TextMenu(String[] items, int topRow, String title); Methods: int select(int startIdx); int select(int startInd, int

int select(int startIdx);items, int topRow, String title); Methods: int select(); int select(int startInd, int timeout); Version 1.53 |

int select(int startInd, int timeout);title); Methods: int select(); int select(int startIdx); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

71

Creating user menu on NXT brick (cont.). Methods: String[] getItems(); void setItems(String[] items); void setTitle(String

Creating user menu on NXT brick

Creating user menu on NXT brick (cont.). Methods: String[] getItems(); void setItems(String[] items); void setTitle(String

(cont.).

Creating user menu on NXT brick (cont.). Methods: String[] getItems(); void setItems(String[] items); void setTitle(String

Methods:Creating user menu on NXT brick (cont.). String[] getItems(); void setItems(String[] items); void setTitle(String title);

String[] getItems();Creating user menu on NXT brick (cont.). Methods: void setItems(String[] items); void setTitle(String title); void quit();

void setItems(String[] items);menu on NXT brick (cont.). Methods: String[] getItems(); void setTitle(String title); void quit(); // przydatne dla

void setTitle(String title);Methods: String[] getItems(); void setItems(String[] items); void quit(); // przydatne dla innego wątku void

void quit(); // przydatne dla innego wątkuvoid setItems(String[] items); void setTitle(String title); void resetTimeout(); When pressing Esc select returns -1,

void resetTimeout();title); void quit(); // przydatne dla innego wątku When pressing Esc select returns -1, when canceled

When pressing Esc select returns -1, when canceled by quit() returns -2. select returns -1, when canceled by quit() returns -2.

Select is a blocking call, quit() can be called by other thread asynchronously. is a blocking call, quit() can be called by other thread asynchronously.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

72

Class: PID controller - lejos.util. – PIDController; Constructor: public PIDController(int setpoint); Methods:

Class:PID controller - lejos.util. – PIDController; Constructor: public PIDController(int setpoint); Methods: doPID(int

PID controller - lejos.util.

Class: PID controller - lejos.util. – PIDController; Constructor: public PIDController(int setpoint); Methods:

PIDController;

Constructor:Class: PID controller - lejos.util. – PIDController; public PIDController(int setpoint); Methods: doPID(int

public PIDController(int setpoint);controller - lejos.util. – PIDController; Constructor: Methods: doPID(int processVariable) – PID calculation for

Methods:Constructor: public PIDController(int setpoint); doPID(int processVariable) – PID calculation for single

doPID(int processVariable) – PID calculation for single iteration PID calculation for single iteration

freezeIntegral(boolean status)

getPIDParam(int paramID)for single iteration freezeIntegral(boolean status) setPIDParam(int paramID, float value) Version 1.53 | 20th

setPIDParam(int paramID, float value)freezeIntegral(boolean status) getPIDParam(int paramID) Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

73

Class: Reading NXT brick settings. Settings class . Method: static Properties getProperties(); static String

Class:Reading NXT brick settings. Settings class . Method: static Properties getProperties(); static String getProperty(String

Reading NXT brick settings.

Class: Reading NXT brick settings. Settings class . Method: static Properties getProperties(); static String

Settings class. .

Method:Class: Reading NXT brick settings. Settings class . static Properties getProperties(); static String getProperty(String

static Properties getProperties();Class: Reading NXT brick settings. Settings class . Method: static String getProperty(String key, String defaultValue);

static String getProperty(String key, String defaultValue);Settings class . Method: static Properties getProperties(); static void getProperty(String key, String Value); Version

static void getProperty(String key, String Value);static String getProperty(String key, String defaultValue); Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

74

Cooperation over Bluetooth. 75 Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Cooperation over Bluetooth.

Cooperation over Bluetooth. 75 Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski
Cooperation over Bluetooth. 75 Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski
75
75

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

Cooperation over Bluetooth (cont.). The other device must provide Bluetooth SPP service (Serial Port Profile

Cooperation over Bluetooth (cont.).

Cooperation over Bluetooth (cont.). The other device must provide Bluetooth SPP service (Serial Port Profile over
Cooperation over Bluetooth (cont.). The other device must provide Bluetooth SPP service (Serial Port Profile over

The other device must provide Bluetooth SPP service (Serial Port Profile over Bluetooth).Cooperation over Bluetooth (cont.). All classes and interfaces are available in lejos.nxt.comm package. Stream

All classes and interfaces are available in lejos.nxt.comm package. lejos.nxt.comm package.

Stream definitions available in java.io java.io

Both stream and packed communication possible.package. Stream definitions available in java.io Base classes: Bluetooth / BTConnection LCP / LCPBTResponder

Base classes:in java.io Both stream and packed communication possible. Bluetooth / BTConnection LCP / LCPBTResponder / LCPResponder

Bluetooth / BTConnectionBoth stream and packed communication possible. Base classes: LCP / LCPBTResponder / LCPResponder USB / USBConnection

LCP / LCPBTResponder / LCPResponderpossible. Base classes: Bluetooth / BTConnection USB / USBConnection RS485 / RS485Connection – BitBus

USB / USBConnectionBluetooth / BTConnection LCP / LCPBTResponder / LCPResponder RS485 / RS485Connection – BitBus Network, port 4

RS485 / RS485Connection – BitBus Network, port 4 – BitBus Network, port 4

Rconsole – for tracing – for tracing

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

76

Tracing and monitoring. Program execution can be traced on the PC over Bluetooth connection almost

Tracing and monitoring.

Tracing and monitoring. Program execution can be traced on the PC over Bluetooth connection almost realtime.

Program execution can be traced on the PC over Bluetooth connection almost realtime.Tracing and monitoring. Run LCPBTResponder thread on the NXT brick and NXT Monitor tool at the

Run LCPBTResponder thread on the NXT brick and NXT Monitor tool at the PC. LCPBTResponder thread on the NXT brick and NXT Monitor tool at the PC.

Sample (NXJ part):thread on the NXT brick and NXT Monitor tool at the PC. LCPBTResponder lcpThread = new

NXT brick and NXT Monitor tool at the PC. Sample (NXJ part): LCPBTResponder lcpThread = new

LCPBTResponder lcpThread = new LCPBTResponder();

lcpThread.setDaemon(true);

lcpThread.start();

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

77

Debugging. LeJOS NXJ provides basic support for handling critical situations and finding errors: Runtime exception

Debugging.

Debugging. LeJOS NXJ provides basic support for handling critical situations and finding errors: Runtime exception

LeJOS NXJ provides basic support for handling critical situations and finding errors:Debugging. Runtime exception handling, Debugging over USB. NXJ supports most of standard Java exceptions. Remote debugging

Runtime exception handling,support for handling critical situations and finding errors: Debugging over USB. NXJ supports most of standard

Debugging over USB.situations and finding errors: Runtime exception handling, NXJ supports most of standard Java exceptions. Remote

NXJ supports most of standard Java exceptions.errors: Runtime exception handling, Debugging over USB. Remote debugging requires to communicate with a PC computer

Remote debugging requires to communicate with a PC computer by:over USB. NXJ supports most of standard Java exceptions. Calling one following methods in NXJ program:

Calling one following methods in NXJ program:debugging requires to communicate with a PC computer by: public static void open(int timeout); public static

public static void open(int timeout);computer by: Calling one following methods in NXJ program: public static void open(); Running debugger on

public static void open();in NXJ program: public static void open(int timeout); Running debugger on PC (nxjdebug) (nxjconsole). Version 1.53

static void open(int timeout); public static void open(); Running debugger on PC (nxjdebug) (nxjconsole). Version 1.53

Running debugger on PC (nxjdebug) (nxjconsole).

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

78

Debugging (cont.). Send text to the debugger: public static void out(String s); Close connection with

Debugging (cont.).

Debugging (cont.). Send text to the debugger: public static void out(String s); Close connection with PC

Send text to the debugger:Debugging (cont.). public static void out(String s); Close connection with PC debugger: public static void close();

public static void out(String s);Debugging (cont.). Send text to the debugger: Close connection with PC debugger: public static void close();

Close connection with PC debugger:Send text to the debugger: public static void out(String s); public static void close(); Version 1.53

public static void close();void out(String s); Close connection with PC debugger: Version 1.53 | 20th November 2011 Ph.D. Eng.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

79

Advanced programming techniques. Programming using pilot and navigator classes. Subsumption programming with behaviours

Advanced programming

Advanced programming techniques. Programming using pilot and navigator classes. Subsumption programming with behaviours

techniques.

Advanced programming techniques. Programming using pilot and navigator classes. Subsumption programming with behaviours

Programming using pilot and navigator classes.Advanced programming techniques. Subsumption programming with behaviours implementation, hierarchy and cooperation.

Subsumption programming with behaviours implementation, hierarchy and cooperation.techniques. Programming using pilot and navigator classes. Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

80

Navigator classes lejos.robotics.navigation pack. Generally for Tribots, however servomotor ports can be defined freely.
Navigator classes lejos.robotics.navigation pack. Generally for Tribots, however servomotor ports can be defined freely.

Navigator classes

Navigator classes lejos.robotics.navigation pack. Generally for Tribots, however servomotor ports can be defined freely.

lejos.robotics.navigation pack.

Generally for Tribots, however servomotor ports can be defined freely.Navigator classes lejos.robotics.navigation pack. Supports abstract/high level creation of the robot moves. Programming

Supports abstract/high level creation of the robot moves.for Tribots, however servomotor ports can be defined freely. Programming of movements by high level navigator

Programming of movements by high level navigator classes (implement Navigator); Navigator);

SimpleNavigator (acutally useless, obsolete) TachoNavigator; CompassNavigator;

Uses Pilot or CompassPilot classes to execute desired robot movment and to identify XY localisation. Pilot or CompassPilot classes to execute desired robot movment and to identify XY localisation.

Warning for the inertia of movements, according to thedesired robot movment and to identify XY localisation. physical phenomenas (see theory vs practice) Version 1.53

physical phenomenas (see theory vs practice)

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

81

Subsumption programming. lejos.robotics.subsumption pack. High level definition of the robot behaviour. Pro's: clear

Subsumption programming.

Subsumption programming. lejos.robotics.subsumption pack. High level definition of the robot behaviour. Pro's: clear

lejos.robotics.subsumption pack.

High level definition of the robot behaviour.Subsumption programming. lejos.robotics.subsumption pack. Pro's: clear and well organized code, clear relations among

Pro's:pack. High level definition of the robot behaviour. clear and well organized code, clear relations among

clear and well organized code, clear relations among behaviours,High level definition of the robot behaviour. Pro's: separates behaviours from the low level action

separates behaviours from the low level action implementation,and well organized code, clear relations among behaviours, very easy extension by new behaviours Flaws: longer

very easy extension by new behavioursbehaviours from the low level action implementation, Flaws: longer project startup time (at the beginning), hard

Flaws:action implementation, very easy extension by new behaviours longer project startup time (at the beginning), hard

longer project startup time (at the beginning),implementation, very easy extension by new behaviours Flaws: hard to identify all possibilities, template based project

hard to identify all possibilities,Flaws: longer project startup time (at the beginning), template based project organisation (may be pro), difficult

template based project organisation (may be pro),time (at the beginning), hard to identify all possibilities, difficult debugging. Version 1.53 | 20th November

difficult debugging.template based project organisation (may be pro), Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

82

Subsumption programming. Behaviour class must implement lejos.robotics.subsumption.Behavior interface. Interface methods

Subsumption programming.

Subsumption programming. Behaviour class must implement lejos.robotics.subsumption.Behavior interface. Interface methods

Behaviour class must implement lejos.robotics.subsumption.Behavior interface. lejos.robotics.subsumption.Behavior interface.

Interface methods to implement (obligatory):implement lejos.robotics.subsumption.Behavior interface. void action(); // main behaviour actions void supress();

void action(); // main behaviour actions // main behaviour actions

void supress(); // stop/brake – executed to stop action(); // stop/brake – executed to stop action();

Won't finish until action(); stops, thus developer must ensure to make action(); safely interruptable by it's own.

boolean takeControl(); // tests, if the action shall be executed. // tests, if the action shall be executed.

takeControl(); // tests, if the action shall be executed. Version 1.53 | 20th November 2011 Ph.D.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

83

Subsumption programming. Arbitrator class ensures checking if behaviour shall be executed and calling appropriate actions:

Subsumption programming.

Subsumption programming. Arbitrator class ensures checking if behaviour shall be executed and calling appropriate actions:

Arbitrator class ensures checking if behaviour shall be executed and calling appropriate actions:Subsumption programming. lejos.robotics.subsumption.Arbitrator Constructor: Arbitrator(Behavior[] behaviors); //

lejos.robotics.subsumption.Arbitrator

Constructor:appropriate actions: lejos.robotics.subsumption.Arbitrator Arbitrator(Behavior[] behaviors); // start(); need to be

Arbitrator(Behavior[] behaviors); // start(); need to be called afterwards

behaviors); // start(); need to be called afterwards void start(); Arbitrator circulates over behaviours with

void start();

Arbitrator circulates over behaviours with respect to their priority and checks if execution condition is true for takeControl(); takeControl();

behaviors table index is a priority of the behaviour. table index is a priority of the behaviour.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

84

Subsumption programming. If two behaviours are ready to execute, only the higher priority one is

Subsumption programming.

Subsumption programming. If two behaviours are ready to execute, only the higher priority one is executed.

If two behaviours are ready to execute, only the higher priority one is executed.Subsumption programming. Arbitrator is singlethreaded ! Can loose some environment / sensor events because interaction can

Arbitrator is singlethreaded !ready to execute, only the higher priority one is executed. Can loose some environment / sensor

Can loose some environment / sensor events because interaction can disappear before behaviour receives control to check execution condition. Execution buffering is necessary then (foolproof takeControl() method). takeControl() method).

When higher level behaviour occurs, the lower level behaviour's supress() method is called to break it. supress() method is called to break it.

One behaviour is never executed one by one. If during next check the same behaviour is still active, next lower priority behaviour is being executed.behaviour's supress() method is called to break it. Version 1.53 | 20th November 2011 Ph.D. Eng.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

85

Threads, events, delegates. A dedicated for listeners exists so called „listener thread” (starts if at

Threads, events, delegates.

Threads, events, delegates. A dedicated for listeners exists so called „listener thread” (starts if at least

A dedicated for listeners exists so called „listener thread” (starts if at least a one delegate has been declared):Threads, events, delegates. Button Listeners, Sensor Port Listeners. Provides non-blocking, asynchronous port, button and

Button Listeners,(starts if at least a one delegate has been declared): Sensor Port Listeners. Provides non-blocking, asynchronous

Sensor Port Listeners.least a one delegate has been declared): Button Listeners, Provides non-blocking, asynchronous port, button and sensor

Provides non-blocking, asynchronous port, button and sensor processing using events and delegates.has been declared): Button Listeners, Sensor Port Listeners. A dedicated thread („regulator thread”) exists for every

A dedicated thread („regulator thread”) exists for every Interactive Servomotor that ensures command execution in an asychronous way.button and sensor processing using events and delegates. Bluetooth class runs separated thread for communication.

Bluetooth class runs separated thread for communication. class runs separated thread for communication.

Timer class runs separate thread also. class runs separate thread also.

One can create own threads and daemons (inherited from Thread base class). Beware locks and parallel jobs! Thread base class). Beware locks and parallel jobs!

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

86

Threads, events, delegates (cont.). Sample: ● import lejos.nxt.*; ● public class ListenForButtons ● { –

Threads, events, delegates (cont.).

Threads, events, delegates (cont.). Sample: ● import lejos.nxt.*; ● public class ListenForButtons ● { –
Threads, events, delegates (cont.). Sample: ● import lejos.nxt.*; ● public class ListenForButtons ● { –

Sample:

import lejos.nxt.*;

public class ListenForButtons

{

public static void main (String[] args)

{

Button.ENTER .addButtonListener(new ButtonListener() {

public void buttonPressed(Button b) {

LCD. drawString ("ENTER pressed",0,0);

}

public void buttonReleased(Button b) {

}

}

LCD. clear (); ();

}

});

while (true);

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

87

Threads, events, delegates (cont.). Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski 8

Threads, events, delegates (cont.).

Threads, events, delegates (cont.). Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski 8 8
Threads, events, delegates (cont.). Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski 8 8

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

Threads, events, delegates (cont.). Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski 8 8

88

Remote PC-NXJ programming. iCommand iCommand is currently obsolete, as replaced by LEJOS NXJ however still

Remote PC-NXJ programming.

iCommand

Remote PC-NXJ programming. iCommand iCommand is currently obsolete, as replaced by LEJOS NXJ however still provide
Remote PC-NXJ programming. iCommand iCommand is currently obsolete, as replaced by LEJOS NXJ however still provide

iCommand is currently obsolete, as replaced by LEJOS NXJ however still provide remote controlled environment even if LEJOS is efficient but autonomous.

environment even if LEJOS is efficient but autonomous. LCP compatible firmware needed (NXJ or Genuine v.

LCP compatible firmware needed (NXJ or Genuine v. 1.05 or later).

firmware needed (NXJ or Genuine v. 1.05 or later). Firmware acts as communication broker between PC
firmware needed (NXJ or Genuine v. 1.05 or later). Firmware acts as communication broker between PC

Firmware acts as communication broker between PC and NXT brick.

acts as communication broker between PC and NXT brick. Main algorithm is executed on the PC
acts as communication broker between PC and NXT brick. Main algorithm is executed on the PC

Main algorithm is executed on the PC using PC Java virtual machine (JRE) (Windows/Linux/Mac OS).acts as communication broker between PC and NXT brick. Packages icommand.* (since Lejos 0.8 it is

Packages icommand.* (since Lejos 0.8 it is „dead”) icommand.*(since Lejos 0.8 it is „dead”)

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

89

Remote PC-NXJ programming. iCommand (cont.). Latest iCommand library 0.7 (8 th May 2009) Unpack to

Remote PC-NXJ programming.

iCommand (cont.).

Remote PC-NXJ programming. iCommand (cont.). Latest iCommand library 0.7 (8 th May 2009) Unpack to the
Remote PC-NXJ programming. iCommand (cont.). Latest iCommand library 0.7 (8 th May 2009) Unpack to the

Latest iCommand library 0.7 (8 th May 2009) (8 th May 2009)

Unpack to the desired folder (c:\ best) Copy Bluecove< >.jar to the < >\icommand\dist\
Unpack to the desired folder (c:\ best)
Copy Bluecove<
>.jar
to the
<
>\icommand\dist\

Modify system environment classpath variable to contain at least:

.;C:\icommand\dist\icommand.jar;

C:\icommand\dist\bluecove.jar;

Latest BlueCove library 2.1.0 (8 th May 2009) (8 th May 2009)

Install procedureLatest BlueCove library 2.1.0 (8 th May 2009) Version 1.53 | 20th November 2011 Ph.D. Eng.

BlueCove library 2.1.0 (8 th May 2009) Install procedure Version 1.53 | 20th November 2011 Ph.D.
BlueCove library 2.1.0 (8 th May 2009) Install procedure Version 1.53 | 20th November 2011 Ph.D.
BlueCove library 2.1.0 (8 th May 2009) Install procedure Version 1.53 | 20th November 2011 Ph.D.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

90

Remote PC-NXJ programming. iCommand (cont.). NXT and PC have to be paired and trusted. COM

Remote PC-NXJ programming.

iCommand (cont.).

Remote PC-NXJ programming. iCommand (cont.). NXT and PC have to be paired and trusted. COM port
Remote PC-NXJ programming. iCommand (cont.). NXT and PC have to be paired and trusted. COM port

NXT and PC have to be paired and trusted.Remote PC-NXJ programming. iCommand (cont.). COM port (outgoing to the NXT) have to be installed (usually

iCommand (cont.). NXT and PC have to be paired and trusted. COM port (outgoing to the

COM port (outgoing to the NXT) have to be installed (usually identified by „Dev B”).iCommand (cont.). NXT and PC have to be paired and trusted. COM port above have to

COM port above have to be configured with Bluecove library icommand.properties file, containing i.e.: NXTCOMM=COM4 line and provide nxt.btaddress when working with

line and provide nxt.btaddress when working with multiple robots BT-visible. Above works with Microsoft
line and provide nxt.btaddress when working with multiple robots BT-visible. Above works with Microsoft
line and provide nxt.btaddress when working with multiple robots BT-visible. Above works with Microsoft

multiple robots BT-visible.

Above works with Microsoft Windows XP, WIDCOMM or genuine Microsoft Bluetooth stack. Other stacks and OS may need RXTX library utility.nxt.btaddress when working with multiple robots BT-visible. Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

91

Remote PC-NXJ programming. iCommand (cont.). icommand.nxt package like lejos.nxj but limited. icommand.navigation

Remote PC-NXJ programming.

iCommand (cont.).

Remote PC-NXJ programming. iCommand (cont.). icommand.nxt package like lejos.nxj but limited. icommand.navigation
Remote PC-NXJ programming. iCommand (cont.). icommand.nxt package like lejos.nxj but limited. icommand.navigation

icommand.nxt package like lejos.nxj but limited.

(cont.). icommand.nxt package like lejos.nxj but limited. icommand.navigation package like lejos.robotics.navigation

icommand.navigation package like lejos.robotics.navigation but limited

package like lejos.robotics.navigation but limited icommand.nxt.comm package like lejos.nxj.comm but really

icommand.nxt.comm package like lejos.nxj.comm but really small part implemented

like lejos.nxj.comm but really small part implemented icommand.vision pack for environment image recognition

icommand.vision pack for environment image recognition using PC webcams (not related to the Mindsensor's NXTCam).

PC webcams (not related to the Mindsensor's NXTCam). Version 1.53 | 20th November 2011 Ph.D. Eng.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

92

Remote PC-NXJ programming. lejos.nxt.remote. Provides a low level access to the remote NXT using LCP.

Remote PC-NXJ programming.

lejos.nxt.remote.

Remote PC-NXJ programming. lejos.nxt.remote. Provides a low level access to the remote NXT using LCP. OutputValues
Remote PC-NXJ programming. lejos.nxt.remote. Provides a low level access to the remote NXT using LCP. OutputValues

Provides a low level access to the remote NXT using LCP.Remote PC-NXJ programming. lejos.nxt.remote. OutputValues class, motors: (i.e. Motor.B.Forward) Sensor reading class –

OutputValues class, motors: (i.e. Motor.B.Forward)
OutputValues class,
motors: (i.e. Motor.B.Forward)

Sensor reading class – InputValues InputValues

Actuators / output:

Sensor reading class – InputValues Actuators / output: RemoteMotor class, three instances of RemoteMotorSensor
Sensor reading class – InputValues Actuators / output: RemoteMotor class, three instances of RemoteMotorSensor

RemoteMotor class, three instances of

Actuators / output: RemoteMotor class, three instances of RemoteMotorSensor class. Helper classes: NXTCommand –
Actuators / output: RemoteMotor class, three instances of RemoteMotorSensor class. Helper classes: NXTCommand –
Actuators / output: RemoteMotor class, three instances of RemoteMotorSensor class. Helper classes: NXTCommand –

RemoteMotorSensor class.

Helper classes: NXTCommand – low level communication, RemoteBattery, DeviceInfo, FileInfo, FirmwareInfo.

RemoteBattery, DeviceInfo, FileInfo, FirmwareInfo . Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr Czekalski

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

93

Remote PC-NXJ programming. LeJOS PC API. LeJOS PC API is designed for Oracle / Sun

Remote PC-NXJ programming.

LeJOS PC API.

Remote PC-NXJ programming. LeJOS PC API. LeJOS PC API is designed for Oracle / Sun Java
Remote PC-NXJ programming. LeJOS PC API. LeJOS PC API is designed for Oracle / Sun Java

LeJOS PC API is designed for Oracle / Sun Java classes.jar libraries.Remote PC-NXJ programming. LeJOS PC API. Subset of autonomous packages, similar programing and behaviour. Firmware acts

Subset of autonomous packages, similar programing and behaviour.API is designed for Oracle / Sun Java classes.jar libraries. Firmware acts as communication broker between

Firmware acts as communication broker between PC and NXT brick (using LCP).of autonomous packages, similar programing and behaviour. Main algorithm is executed on the PC using PC

Main algorithm is executed on the PC using PC Java virtual machine (JRE) (Windows/Linux/Mac OS).communication broker between PC and NXT brick (using LCP). Works with almost any firmware that supports

Works with almost any firmware that supports LCP (in theory).using PC Java virtual machine (JRE) (Windows/Linux/Mac OS). 94 Version 1.53 | 20th November 2011 Ph.D.

with almost any firmware that supports LCP (in theory). 94 Version 1.53 | 20th November 2011
94
94

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

Remote PC-NXJ programming. LeJOS PC API (cont.). Packages: lejos.nxt – genuine NXT sensors, servos. lejos.nxt.addon

Remote PC-NXJ programming.

LeJOS PC API (cont.).

Remote PC-NXJ programming. LeJOS PC API (cont.). Packages: lejos.nxt – genuine NXT sensors, servos. lejos.nxt.addon -

Packages:

Remote PC-NXJ programming. LeJOS PC API (cont.). Packages: lejos.nxt – genuine NXT sensors, servos. lejos.nxt.addon -
Remote PC-NXJ programming. LeJOS PC API (cont.). Packages: lejos.nxt – genuine NXT sensors, servos. lejos.nxt.addon -

lejos.nxt – genuine NXT sensors, servos. – genuine NXT sensors, servos.

lejos.nxt.addon - 3 r d party sensors, motors, multiplexers and so on. - 3 rd party sensors, motors, multiplexers and so on.

lejos.nxt.remote – NXT2NXT communication over Bluetooth protocol (managed from PC through other brick).

Bluetooth protocol (managed from PC through other brick). lejos.pc.comm – Bluetooth and USB communication interface

lejos.pc.comm – Bluetooth and USB communication interface – Bluetooth and USB communication interface

lejos.util (partially different from autonomous implementation) (partially different from autonomous implementation)

lejos.geom(partially different from autonomous implementation) 95 Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr

95
95

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

Remote PC-NXJ programming. LeJOS PC API (cont.). Packages: lejos.robotics – hal for other „robotics” packages

Remote PC-NXJ programming.

LeJOS PC API (cont.).

Remote PC-NXJ programming. LeJOS PC API (cont.). Packages: lejos.robotics – hal for other „robotics” packages
Remote PC-NXJ programming. LeJOS PC API (cont.). Packages: lejos.robotics – hal for other „robotics” packages
Remote PC-NXJ programming. LeJOS PC API (cont.). Packages: lejos.robotics – hal for other „robotics” packages

Packages:

lejos.robotics – hal for other „robotics” packages lejos.robotics.localization lejos.robotics.mapping lejos.robotics.navigation lejos.robotics.objectdetection lejos.robotics.pathfinding

lejos.robotics.objectdetection lejos.robotics.pathfinding 96 Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr
lejos.robotics.objectdetection lejos.robotics.pathfinding 96 Version 1.53 | 20th November 2011 Ph.D. Eng. Piotr
96
96

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

Literature Maximum LEGO NXT: Building Robots with Java Brains, Brian Bagnall, 2007. On-line: LeJOS Tutorial,

Literature

Literature Maximum LEGO NXT: Building Robots with Java Brains, Brian Bagnall, 2007. On-line: LeJOS Tutorial,

Maximum LEGO NXT: Building Robots with Java Brains, Brian Bagnall, 2007.Literature On-line: LeJOS Tutorial, http://lejos.sourceforge.net/nxt/nxj/tutorial/index.htm , August 2011. On-line: NXJ

2011.

On-line: NXJ API, http://lejos.sourceforge.net/nxt/nxj/api/index.html , August 2011. http://lejos.sourceforge.net/nxt/nxj/api/index.html, August 2011.

On-line: PC NXJ API: http://lejos.sourceforge.net/nxt/pc/api/index.html , August 2011. http://lejos.sourceforge.net/nxt/pc/api/index.html, August 2011.

On-line: iCommand API: http://lejos.sourceforge.net/nxt/icommand/api/index.html , December 2010. http://lejos.sourceforge.net/nxt/icommand/api/index.html, December 2010.

Version 1.53 | 20th November 2011

Ph.D. Eng. Piotr Czekalski

97

This is the end. Thank you for your attention. Version 1.53 | 20th November 2011
This is the end.
Thank you for your
attention.
Version 1.53 | 20th November 2011
Ph.D. Eng. Piotr Czekalski
98