How about adding a really powerful extension to your NXT? I'm refering to your PC.
NXTender is a program that your run on your PC and which lets your NXT control your PC. This program allows the NXT to send keyboard and mouse events to the PC (simulating a keyboard or a mouse), to request that events from a joystick connected to the PC be sent to the NXT, to open windows on the PC and to display data in them, and so on (the so-on part is currently just a wish).
To be productive and to have fun, NXT builders should be programming the NXT, not the PC.
In my first two NXT-PC projects (the NXT as a remote two-key keyboard and the joystick-controlled ultrasonic explorer), I designed a custom communication protocol for each project and wrote a custon PC-side program for each. I quickly realized that this is pretty hard. For example, if your program sends both text messages to the NXT and numbers (say joystick positions), then it's best to send them to different mailboxes on the NXT. So your NXT program and your PC program must be coordinated in terms of the mailboxes that are used for each type of data. As you add or remove things that are sent, you must keep changing both programs.
I decided to create a PC-side program that will allow you to contoll the NXT-PC interaction from the NXT side alone. This would allow NXT builders who are not proficient PC programmers to use the PC as an extension of the NXT. It's a powerful extension, given the computational power of PC and the range of things that connect to them (joysticks, keyboards, mice, printers, scanners, cameras, cup warmers, and anything connected to the internet).
Let's take joystick input as an example. With NXTender, if your NXT wants joystick input, it tells the PC to send joystick events to the NXT, and it tells the PC which events it wants to listen to (say, only Y-axis and button events) and in which mailboxes it wants to receive them. This means that you can control all the relevant details of the NXT-PC interaction from your NXT program.
Let's take radar-style displays as another example. With NXTender, the NXT can tell the PC to open a radar window on the desktop, it can tell the PC to display dots at certain angles and distances from the center of the window, it can tell the PC to clear the dots from the window (for the next scan), and it can tell the PC to close the window. Thee window is not always there; it's there only when the NXT wants it there.
Suppose you want to build a NXT robot that will control a USB cup warmer or lamp connected to your PC. Can you do this with NXTender? No, this require some custom programming that will control these devices. The standard version of NXTender does not know how to controll them. But I have tried to make it as easy as possible to add this custom code to NXTender.
NXTender controls the PC using a set of modules called plugins. Each plugin is responsible for responding to NEXT messages that start with a certain word. For example, in the standard version of NXTender the keyboard plugin responds when the NXT sends a command like KBD LEFT, but the radar plugin responds when the NXT sends the command RADAR OPEN.
What a plugin does in response to a message is entirely up to the plugin. It can do whatever it wants on the PC, and it can send messages back to the NXT.
So to controll your cup warmer from the NXT, you will have to write a NXTender plugin that responds to commands starting with, say, CUP-WARMER, and that actually controls your cup warmer. How easy or hard it is depends on your programming skills and on how difficult it is to control a particular device from a PC program, but it's easier than writing a complete program that interacts with the NXT, because NXTender takes care of the details of the NXT-PC communications. NXTender also allows you to easily build NXT creations that interact with multiple devices on the PC. For example, if your NXT creation needs both joystick input and to contol the cup warmer, then you only need to implement the cup-warmer plugin; the joystick plugin is built in.
Requirements: Windows with java 1.5 or later (also called java
5.0) installed. Sorry folks, it currently only works on windows. You
can check your version of java by giving the command java
-version
on the Windows command
line.
Download the zip file
and unpack its contents into some
directory, say C:\Program Files\NXtender
. Now
either
cd C:\Program
Files\NXtender
), and run NXTender
,
or C:\Program
Files\NXtender
. If you packed it elsewhere, you will need
to change the
properties of the shortcut.Now you need to pair your NXT with the PC via bluetooth. I always do the pairing from the XNT.
Finally, you need to tell NXTender on which serial port the NXT is connected. Right-click on the Bluethooth icon on the tray, select Advanced Configuration, then the Local Services tab, and note the name of the serial port (it's COM14 on my PC). Now right-click on the NXTender icon in the tray, and select the correct port number from the list. It should appaer in the list. You only have to do this once; NXTender remembers this port number for ever.
To stop NXTender, right-click on the icon try and select Exit.
Troubleshooting: if you try to connect to the correct port and
you get an error message, it might be caused by a running NXTender that
is still connected to the serial port but has already closed the tray
icon. (If this happens, then it's a bug in NXTender.) Open the task
manager and kill the running NXTender process, which will be
called java.exe
.
There are only three rules that you should know about using NXTender when you create your NXT program:
Here are the links to the documentation of the built-in plugins and the user-contributed plugins.
NXTender is an open-source project. It is freely distributed with its source code (everything is in the zip file), and you are welcome and encouraged to contribute to it. There are two main ways to contribute to NXTender:
How creative are you? I'm announcing a NXTender challenge: to design and build the best Lego mouse-replacement device (it could be a Lego mouse, trackball, trackpoint, trackpad, whatever, as long as it can function well as a mouse). I've done the PC-side programming for you, now you build the Lego thing.
sivantoledo.nxt.NXTender.Plugin
:public static abstract class Plugin {
// irrelevant private fields
// The name argumet is the command prefix, such as KBD
public Plugin(String name) {
plugins.put(name,this);
}
/*
* You must implement
* public static Plugin
getInstance(sivantoledo.nxt.Sender sender)
* otherwise your plugin will not load.
*/
public abstract void process(String command);
public abstract void close(); // shut down all threads etc.
}
public abstract class Sender {
public abstract void send(byte mailbox, String s, boolean important);
public abstract void send(byte mailbox, int i, boolean important);
public abstract void send(byte mailbox, boolean b, boolean important);
/*
* The following methods all send an important message.
*/
public void send(byte mailbox, String s) { send(mailbox, s, true); }
public void send(byte mailbox, int i) { send(mailbox, i, true); }
public void send(byte mailbox, boolean b) { send(mailbox, b, true); }
public abstract void flushQueue(byte mailbox);
public abstract void flushAllQueues();
}
org.superobots.nxtender.cupwarmer.CupWarmer.jar
.plugins
directory of NXTender.Sender
class has been improved to tell
NXTender whether it is allowed to drop messages or not and to flush the
queue of old undelivered messages. There are also two new plugins, BEEP
(to send a beep, useful for testing), and PING, for measuring the
performance of Bluetooth communication. I also added capability to use
the PC as a master and the NXT as a slave, but it is commented out
(included in the sources but not in the binary version) becasue it is
hard to use without loosing messages.© 2006, Sivan Toledo