1. Trang chủ
  2. » Công Nghệ Thông Tin

programming LEGO MINDSTORMS phần 10 pptx

43 304 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Programming LEGO MINDSTORMS
Trường học University of Aarhus
Thể loại Tài liệu
Năm xuất bản 2002
Thành phố Aarhus
Định dạng
Số trang 43
Dung lượng 611,95 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

platform-indepen-RCXPort—Java Interface to the LEGO MINDSTORMS RCX www.slewis.com/rcxport Scott Lewis’ RCXPort site for the Java interface he created for the pose of interacting with a L

Trang 1

Fred Martin’s Unofficial Questions and Answers about MIT Programmable Bricks and LEGO MINDSTORMS

Artificial Intelligence and Machine Learning (www.home.zonnet.nl/bvandam)

Bert van Dam’s site is a mine of information about artificial intelligence

in general If you find the subtle link to Miscellaneous | General Information, you will discover a whole world of LEGO projects!

MINDSTORMS RCX

RCX Internals (http://graphics.stanford.edu/~kekoa/rcx)

Kekoa Proudfoot documents all the internals of the LEGO firmware and ROM routines He made the development of firmware like legOS and pbForth possible.

Ole Caprani’s RCX Manual (www.daimi.au.dk/dArkOS/

Vaerktoejer.dir/RCX.vejledning.dir/Vejledning.html)

Ole Caprani from the University of Aarhus, Department of Computer Science, has created a very informative manual about the internals of the RCX It includes information on how the I/O ports of the microcon- troller are connected to the hardware.

MINDSTORMS RCX Sensor Input Page (www.plazaearth.com/usr/gasperi/lego.htm)

Michael Gasperi’s site describes the various sensors that can be structed; used in a leJOS environment, this is the starting point for any investigation into using sensors.The site also contains Brian Stormont’s suggestion to combine a touch sensor and a light sensor on the same

Trang 2

Languages, APIs, and Tools

Java Communications API (http://java.sun.com/products/ javacomm/index.html)

The Java Communications API can be used to write dent communications applications for MINDSTORMS robots.

platform-indepen-RCXPort—Java Interface to the LEGO MINDSTORMS RCX (www.slewis.com/rcxport)

Scott Lewis’ RCXPort site for the Java interface he created for the pose of interacting with a LEGO MINDSTORM RCX from a Java Virtual Machine.

pur-RCXJava (www.escape.com/~dario/java/rcx)

A platform-independent Java library used to develop RCX applications, developed by Dario Laverde.

Forte Tools—Forte for Java (www.sun.com/forte/ffj)

Forte is an IDE written completely in Java Forte provides a visual GUI creator, a debugger, and compilation functions—all the expected parts of

Trang 3

an IDE Forte also has the seemingly unique ability to configure the compiler and Java runtime you use.

a program you did not create can help you learn programming styles, ways to implement complex functions, or just how to better code for the RCX.

Jlint (www.ispras.ru/~knizhnik/jlint/ReadMe.htm)

Jlint is a Java version of the popular lint for C programs Jlint can be

useful, since debugging programs on the RCX, especially ones that deal with logic errors (such as an incorrect loop structures), can be difficult.

It can also detect other “assumptions” you may have made, and tells you

if they are incorrect.

An Operating System in Java for the LEGO MINDSTORMS RCX Microcontroller (www.usenix.org/publications/library/

Dave Baum’s NQC site contains the compiler and the documentation.

Bricx Command Center (http://hometown.aol.com/

johnbinder/bricxcc.htm)

Formerly known as the RCX Command Center, and based on Mark Overmars’ original source code (see LEGO Robot Pages), John Hansen’s Bricx Command Center (BricxCC) supports all the LEGO

Programmable Bricks and introduces many new and interesting features.

If you use NQC on a PC platform, this is a “must have.”

Trang 4

The site of the original RCX Command Center, a very good IDE for NQC originally developed by Mark Overmars but not updated to the current version (see Bricx Command Center).

Visual NQC (http://home.hetnet.nl/~myweb1/VisualNQC.htm)

Ronald Strijbosch’s Visual NQC has its roots in the RCX Command Center, but is completely rewritten in Visual Basic A very functional and complete IDE to NQC.

NQCEdit (http://hem.passagen.se/mickee/nqcedit)

Another front-end IDE for NQC, written by Mikael Eriksson.

Currently less sophisticated than the RCX Command Center and Visual NQC, it’s an effective and solid alternative.

NQC API Programmer’s Guide (www.cybercomm.net/

Hempel Design Group (www.hempeldesigngroup.com/lego/

■ Extremely helpful information on how to improve the reading range

of the LEGO light sensor.

■ Information about Ralph Hempel’s programmable brick FORTH (pbForth) for MINDSTORMS (www.hempeldesigngroup.com/ lego/pbFORTH/index.html).

■ Schematics and detailed instructions on how to interface R/C Servos to the RCX.

Trang 5

■ Home page of Ralph Hempel’s famous double-acting compressor.

The same site also contains his Pressure Switch (www.hempeldesigngroup.com/lego/pressureswitch/index.html).

Reactive Languages and LEGO MINDSTORMS (www.emn.fr/

WinVLL (www.research.co.jp/MindStorms/winvll/index-e.html)

A simple tool by Shigeru Makino to control and program the Micro Scout from a PC.

Trang 6

For Inspiration

Ben’s LEGO Creations (http://unite.com.au/~u11235a/lego)

Ben Williamson has created some very cool robots!

BrickBots (www.brickbots.com)

BrickBots is Richard Sutherland’s repository of building contests and best solutions.This is a nice site where you can attend “remote” chal- lenges Although the contests are no longer running on a regular basis, the current repository of contest entries provides builders with great ideas.

MindScope (http://baserv.uci.kun.nl/~smientki/Lego_Knex/ Lego_electronica/Mindscope.htm)

Stef Mientki’s graphing utility is able to continuously monitor the sors and produce a chart from the sampled values.

sen-Programming the LEGO Micro Scout (http://eaton.dhs.org/ lego)

Doug Eaton explains how to program the Micro Scout through bar codes.

Trang 7

Programming LEGO MINDSTORMS with Java Fast Track

This Appendix will provide you with a quick, yet comprehensive, review of the most important concepts covered in this book.

Appendix B

407

Trang 8

❖ Chapter 1: Introducing LEGO MINDSTORMS

The LEGO MINDSTORMS RIS Kit

 The MINDSTORMS series comes from a collaboration between the LEGO Company and the Massachusetts Institute of Technology (MIT) Media Lab that led to the creation of a “programmable brick.”

 The Robotic Invention System (RIS) is the basic kit, and the starting point for every MINDSTORMS robot of more than basic complexity.

 The RIS includes everything you need to build and program robots: the RCX unit, three sensors, two motors, an infrared (IR) tower, manuals, more than 700 TECHNIC pieces and a software CD-ROM.

RCX:The Robot’s Brain

 The RCX is a microcomputer than interfaces with input and output

devices Programs can be written on a PC and then downloaded to the unit through the IR tower.

 The RCX uses two types of memory: read-only memory (ROM) and ifiable random access memory (RAM).The latter stores both user-written programs and the system firmware, which is the RCX’s operating system.

mod- The RCX can be expanded in two ways: using a different programming software like NQC or the Java APIs, or replacing the default firmware with

a new one (legOS, pbForth, and leJOS solutions).

The RIS Software Environment

 The RIS kit contains RCX Code, which is the standard programming language from LEGO It contains tools for downloading firmware and a visual programming interface that makes writing code a very easy task.

 RCX Code is targeted at kids and beginners; its capabilities are too limited for the development of more complex robots.

RCX Bytecodes

 The RCX architecture uses an interpreter-based virtual machine to execute commands statement by statement.

Trang 9

 Opcodes, the assembly commands, are used both by the RCX’s stored programs and the IR emitting devices, like a PC with an IR tower or a remote control.

LEGO Expansion Kits

 There are other robotics kits besides the RCX-based system: CyberMaster, Scout, Micro Scout, and Code Pilot Each of these kits features only a subset

of the full RIS’ capabilities.

 Standard LEGO TECHNIC pieces can be used to expand building ties, as can sensors and other spare pieces that are available separately.

possibili- MINDSTORMS can be expanded with kits that contain sensors, motors, and special pieces Further,Vision Command (VC) is a LEGO video camera with an advanced visual recognition system that can be used to add more functionalities to your LEGO MINDSTORMS robots.

❖ Chapter 2: The Java Communications API

Overview of the Java Communications Extension API

 The Java Comm API provides the mechanism for port enumeration and ownership as well as event driven notification of change of ownership.

 Asynchronous and synchronous I/O is possible due to the standard style event-driven architecture.

Java- The SerialPort and ParallelPort classes provide a clean encapsulation for

supporting the many platforms for which the JCE API is available.

Installing and Configuring the Java Communications API

 There are three deliverables: a jar file, a properties file, and a native shared runtime library.

 Several options are available depending on use versus configuration.The simplest is to keep the three deliverable files together in the same folder so long as it is the application’s working folder.

ease-of-Chapter 1Continued

Trang 10

 There are possible version control caveats, but fortunately the API has

stabilized enough such that it’s not a big issue.

Reading and Writing to Serial Ports

 The Java Communications API comes with several simple examples that illustrate the usage of both parallel and serial ports.

 Adding event-driven notifications is straightforward using EventListeners.

 Working with the parallel ports is similar to working with any port that

extends the CommPort abstract class.

Debugging with Serial Ports:The Black Box Example

 A close look at a specific advanced Java sample program that comes with the JCE illustrates all functionality of the serial port by serving as a serial port analyzer and line monitor.

 The BlackBox sample program can be used as is as a serial proxy or sniffer tool without modifications.

 The way that the output and input streams were used in the BlackBox example can be used as the basis of custom applications that provide similar functionality.

Extending the Java Communications API

 The mechanism for adding new functionality exists via the CommDriver, CommPort and CommPortIdentifier classes.

 A step-by-step process of how a customized USB driver was implemented for use with the RCX 2.0 USB tower.

 The limitations shown include the inability to add external packages as the source for new port drivers.This would break the package naming conven-

tion of not adding to or changing the classes in the javax.comm hierarchy.

Trang 11

 The RCXPacket class wraps commands into a format that the RCX can

understand before they are sent to the tower.

 RCXCmd includes all of the standard opcodes that are used to control the RCX.These bytes are declared as static in the RCXCmd class so that they may

be called from other classes without instantiating an RCXCmd object.

 Existing RCXPort functionality does not allow for the running of Java code directly on the RCX or for high-level Java code to be compiled into byte code for downloading to the RCX.This functionality is forthcoming.

Programming the RCX Using RCXPort

 By inserting RCX commands into a Java program that runs on your PC, you can control the RCX in direct mode, provided your RCX remains within range of the IR tower for the duration of the program’s execution.

 When running programs in direct mode, there is a slight delay between commands as the data is sent from the computer’s serial port to the IR tower, then on to the RCX.

 Programming in direct mode allows for the increased power and flexibility

of the Java programming language, yet limits you to keeping the RCX within range of the tower.

Downloading Programs with RCXPort

 RCXPort also provides functionality to download byte code files to the RCX, where they are stored in random access memory (RAM) and can be

run by pressing the Run button.

 Storing programs on the RCX frees you from having to stay near the tower when running a program.

Trang 12

 Programs can be written manually in byte code, or written in a high-level language, such as ‘Not Quite C’ (NQC), then compiled into byte code.

Interfacing External Software with RCXPort

 NQC, a high-level language based on C syntax, can be compiled into byte code that is understood by RCX’s firmware.This allows you to take advantage of more advanced control structures such as loops, events and functions.

 RCXPort is capable of downloading compiled NQC byte code to the RCX.

 These programs, once stored on the RCX, can be run by themselves or called from an RCXPort-based program that is running on your personal computer.

An Advanced Example Using RCXPort

 Our example uses a hard-coded value to represent the light threshold

between two colors.This value could vary widely due to different amounts

of light and different colored candies used in your experiment.This simple branch in the code could also be used to sort the “darks” and “lights” from a bag of multicolored candies Alternatively, you could assign ranges to your different colors and check for read values that are within these ranges.

 Programs stored on the RCX can be called from Java code when

controlling the RCX in direct mode.This allows you to better control the timing of RCX operations that would otherwise be thrown off by variance

in the infrared communications.

❖ Chapter 4: Communicating

with the RCXJava API Designing an RCXJava Communications Architecture

 The use of the Java Communications API facilitates the automatic search for

an available serial port, and use of the rcx.comm package gives us USB capability in a platform-neutral manner Allowing the configuration of the port to be based on the port name improves ease-of-use.

Trang 13

 Management and encapsulation of RCX protocol details is hidden from the application user.

 The use of standard Java design patterns and Java interfaces enables us to use new and different types of ports without changing a line of code.

Overview or the RCXJava API

 The RCXJava API is an open source and extensible API.

 It supports serial, USB and new ports such as sockets.

 It lays the groundwork for a full-fledged programming environment for the RCX by using high level methods that follow the same method signature naming convention of other Java efforts like leJOS.

Using the RCXLoader Application

 The RCXLoader is an out-of-the-box utility and test tool for interfacing with the RCX.

 It provides a convenient lookup table of all the opcodes and their arguments.

 It provides the starting point or template for creating more advanced examples.

Beyond Serial Port Communications:

The RCXApplet Example

 Control of an RCX can not only be enabled from a stand-alone application but also over the Internet using a Java-enabled Web browser, providing the same GUI as one would get with the stand-alone application.

 Using RCXSocketPort, one could control a number of RCXs over a network

and the network via a proxy server.

 Use of the direct control API methods gives you the capability of creating complex frameworks similar to the visual-programming interface that comes with the LEGO MINDSTORMS kit.

Chapter 4Continued

Trang 14

Direct Control Programming for the RCX Using Java

 With direct control programming, we are using the RCX’s “brain” to pass commands from a proxy “brain” residing on a PC.There are significant advantages to programming tasks to run on the PC’s resources rather than running tasks inside the RCX.

 Tasks can run on the PC in near real time (there is a noticeable time lag).

 We can add Artificial Intelligence (AI) capabilities when programming our RCX robots Neural network programming allows an RCX to “learn” the right response to stimuli all on its own.

❖ Chapter 5: The leJOS System

Basic leJOS Usage Guidelines

 The leJOS environment (PATH, RCXTTY, LEJOS_HOME, JAVA_HOME, CLASSPATH) must be set up in order to start programming for leJOS.

 Compilation is done using lejosc, which is just a thin wrapper around javac.

 Conversion of Java class files to a leJOS binary format, and the transmission

of that format to the RCX, is done using the lejos command line tool.

The LEGO Java Operating System

 LeJOS leverages the LEGO-provided ROM code, and thus inherits tions imposed by the ROM—for instance, only eight power levels for the motors, and no sampling of sensors faster than 3 milliseconds.

limita- LeJOS gives you a common programming language (Java) and environment for the RCX.The learning curve is not as steep as other firmware replace- ments like legOS.

 A comparison to other Java environments shows the formidable ment of cramming an entire Java VM into the RCX’s 32KB of memory.

Trang 15

achieve-Overview of the leJOS Architecture

 Base classes are not part of the firmware.This is a great feature as it makes the firmware footprint smaller.

 Only classes needed by your program are actually downloaded to the RCX,

since the lejos command line tool performs a transitive closure of class graphs

of the main class.

 There is no garbage collector in leJOS—for now you have to live with that.

The future might bring you one, and hopefully you will be able to choose whether or not to include it in your program.

 A switch statement is also missing, but may be available in the future.

Using leJOS: A Simple Example

 You can read sensor values in two different ways: by polling the sensor, and

by listening for changes using an implementation of SensorListener.

 You should brake motors before changing power to ensure the power change can be noticed.This is necessary as the LEGO motor has an internal flywheel, which stores mechanical power.

An Advanced Programming Example Using leJOS

 The line-following type of robot can often become mired in a never-ending spin.Two techniques for avoiding that were presented.

Chapter 5Continued

Trang 16

 The subsumption architecture can be thought of as a design pattern for robotics programs.

Debugging leJOS Programs

 The best way to debug a leJOS program is to use the Sound and LCD

classes in unison to provide you with feedback of the robot’s state.

 Normal Java exception handling applies to leJOS, allowing you to separate code for normal operation and code for error situations.

Testing leJOS Programs

 When working out bugs, use emu-lejos and emu-lejosrun to emulate the leJOS environment on your PC.They use a text-based interface.

 When exceptions are output by the emulator, the output can be interpreted much more accurately than when displayed on the real RCX display.

❖ Chapter 7: leJOS Tools

Programming Environments for leJOS

 The command line tools provide ultimate control in terms of the options you can use, but sacrifice ease-of-use.

 GUI-based tools can simplify the use of the command-line tools, but

sacrifice some elements of control.

 Command-line tools included in the leJOS package include lejosc, lejos, lejosrun, lejosfirmdl, emu-lejos, and emu-lejosrun.

 The free IDE called Forte provides a visual GUI creator, a debugger, and compilation functions Unlike JBuilder and Eclipse, it provides the seemingly unique ability to configure the compiler and Java runtime you use.

Using the leJOS Visual Interface

 The leJOS Visual Interface (lVI) is a custom IDE especially configured for use with leJOS.

Trang 17

 The options in the Tools menu allow you to automatically compile, link, and download programs, as well as download firmware.

 After graphically setting the necessary environment variables and settings, you can create, edit, compile, and link a file.

Using a leJOS Simulator

 Simlink is designed to be an interface between Rossum’s Playhouse and the low level APIs provided by leJOS.

 The Rossum simulator has a syntax and format of its own; using its navigational and other declarations and specifications, you can create visual and non-visual elements of floor plans.

 Robot bodies in Simlink are represented as Java classes, with Rossum classes allowing you to create simple designs.

 Note that sensors and motors under simulation do not work exactly as in real life.

Additional Tips and Tools for leJOS

 Java tools like Jlint and Jad can be used on leJOS programs.

 The RCXTools package provides a clean interface to many RCX functions, while also allowing you direct control.

 The LCDText class included with RCXDirectMode can be used to test LCD words before they are downloaded to the RCX.

❖ Chapter 8: leJOS Internals

Advanced Usage of leJOS

 You can link several programs into a single binary by calling the linker with

a comma-separated list of the entry classes containing the main method.

 You can store data persistently by using thelibrary’s

josx.platform.rcx.PersistentMemoryArea class.

Chapter 7Continued

Trang 18

 You can inspect and modify the contents of the RCX’s memory by using

the methods in the library class josx.platform.rcx.Memory.

Examining leJOS Internals

 leJOS uses the standard Java compiler, but employs a leJOS-specific linker

on the host computer and a leJOS-specific virtual machine in the firmware

on the RCX.

 The linker reads the Java class files and produces a leJOS binary that can be loaded into the firmware without any modification Class, method and field names are replaced by offsets into the binary.

 The firmware contains a loader that loads the binary and a virtual machine that executes it.The virtual machine executes slightly modified Java byte code instructions.

 Threads are scheduled strictly according to priority, and round-robin within the same priority.They are preempted after a time-slice of 20 milliseconds.

 Each thread uses approximately 400 bytes of memory for its stack and other data structures.

Extending leJOS with Native Methods

 Native methods are used to interface with the hardware and with the virtual machine.

 To add a native method to the VM you need to add its signature to

common/signatures.db, and you need to provide an implementation for the RCX in rcx_impl/native.c and for the emulator in unix_impl/nativeemul.c.

 To optimize for memory you can use variables for common expressions Always test whether your optimization is better than the original.

Additional Tips and Tricks with leJOS

 You can determine the amount of free memory with the method freeMemory

in the class java.lang.Runtime.

 You can change the stack size by modifying the values in vmsrc/configure.h and recompiling the leJOS firmware.

Trang 19

❖ Chapter 9: Programming LEGO MINDSTORMS with Jini

Overview of Jini

 Jini is a Java technology built on top of RMI, enabling clients and services

to interact in a network with very little administrative overhead.

 One feature of Jini is that it is vary applicable to embedded devices, including devices like the RCX.

 The Jini Technology Starter Kit (TSK) includes all of the required jar files as

well as some service implementations such as reggie, an implementation of a

lookup service.

A Simple Jini Service Example

 We covered an example of a simple Jini service to calculate checksums and a client that made use of the service.

 The example showed how to register a service with a single known lookup service, as well as how a client could discover the registered service by querying the known lookup service.

 The service example was quite simplistic, especially in that the client actually executed the service object within its own JVM.

Proxies and Service Architectures

 Solutions that make use of Jini can be implemented according to various architectures.

 One such service architecture involves the use of a proxy object that is

registered as a service, but actually abstracts the real service and communicates with it behind the scenes.

 The proxy architecture is especially suitable when providing services for devices that are not capable of running Jini themselves.

Chapter 9Continued

Trang 20

A RCX Jini Proxy Service

 Since the RCX is not capable of running Jini itself, it is a very good date for the proxy architecture, where a proxy object would run on a machine, which would then communicate with the RCX via the infrared tower.

candi- A single machine with a single infrared link could potentially control

multiple RCXs if the firmware were modified.This would require a unique identifier to be stored in each of the RCXs’ firmware.

 Another architecture (as used in the example in this chapter) involves one infrared tower per RCX, and the proxy objects themselves storing the unique identifiers of the respective RCXs.

Using the RCX Jini Service:

Example Server and Client

 We covered a much less simplistic example that involved the networking of

a number of RCX units.

 This example showed how servers and clients could dynamically discover lookup services on a network by using multicast, and also showed the use of RMI stub objects to make method calls across a network.

 The outcome was that RCXs could interact with one another, performing a synchronized dance.

Trang 21

Index

A

AC/DC jack adapter, 6

ACodes for system sounds, 182

Add-on building elements, 24–25

addPortOwnershipListener() method, 38

AI See Artificial intelligence (AI)

Air conditioning units, 335, 356

AllMessagesListener interface in RCXJava API,

127

Analyzing data and protocols, 57

Andrews, Paul, 15, 170, 177

Apache HTTP servers, 338

API See Bluetooth Java API; Java

Communications Extension API (JCE

API); RCXJava API; RCXPort API

Apple Macintosh See Macintosh (Mac OS)

Applets

building and extending, 139–147

signing, 131

Application programming interfaces (APIs)

See Bluetooth Java API; Java

Communications Extension API (JCE

API); RCXJava API; RCXPort API

Array length, maximum, 174–175

ArrayToString(byte[] array) method, 122

Artificial intelligence (AI), 150–163

Assembly code for RCX, 20–21

Asynchronous event-based I/O, 42–43

Automatic Binding Brick, 3

AWT See Java Advanced Window Toolkit

(AWT)

B

Barcodes, 23Batteries, 16, 150

Battery class, 194

Baud rate, 45Baum, Dave, 12–13Behavior, real-time, 306–307

Behavior interface, 227–232

Big blocks, 18Binary codebuilding, 302format, 303–304Bit masks, 192–193BlackBox sample program, 57–64Blocking light sensors, 185Blocking the input stream, 42Bluetooth Java API, 67Books

Building Robots with LEGO MINDSTORMS, 5, 18, 151, 162, 277 Constructopedia manual, 4–5, 93

Design Patterns: Abstraction and Reuse of Object-Oriented Design, 220–221 Rossum User’s Guide (Simlink manual), 263 See also CD-ROMs; Companion CD-

ROM; DocumentationBraking, 131

Brick, smart or programmable See Robotics

Command Explorer (RCX)BricxCC integrated developmentenvironment (IDE), 13Broad Blue Chess Robot, 163Building applets, 139–147

Building Robots with LEGO MINDSTORMS

book, 5, 18, 151, 162, 277BuildTool, 389

Button class, 179 ButtonListener class, 179

Bytecodes See Opcodes

Ngày đăng: 13/08/2014, 15:21

TỪ KHÓA LIÊN QUAN