Now that I am able to connect to my NXT via Bluetooth is time to try to communicate with it. I don't have 2 NXT's so what I focused on was communicating between a PC and the NXT brick. Since I know Java, I looked for a Java library that was able to accomplish this. iCommand is a sub-project of leJOS and it was the first thing I tried. I downloaded iCommand 0.7 and tried to make the sample programs work. To my surprise, the bluecove jar mentioned in the docs was missing but I was able to find it in an older version: 0.6. I asked on the leJOS forum why is this and was told that iCommand is not supported anymore.
Anyway, after I installed the missing jar and I set the classpath, I was able to run most of the sample programs that came with it with great results. It was a real breakthrough and I was very happy! However, none of the samples were showing how to send a message to the NXT and receive some message back. After quite a lot of digging, I found out there are 2 ways of communicating with the NXT: one is Direct Commands (basically, your code on the PC sends a command to the NXT that is interpreted directly by the firmware), the other is sending/receiving messages to/from specific mailboxes (sometimes named queues in some libraries I found). To test the communication, I got a very simple NXC program from Daniele Benedettelli's tutorial at bricxcc site (page 43) that is supposed to receive a message from another NXT and send a response message back.
Because I was able to use iCommand successfully, I figured next step was to use it to send a message to the NXT. Unfortunately, it didn't work. Later I found out in the leJOS forum what I already mentioned: that iCommand is not supported anymore. Indeed, looking in the source code for NXTCommand class that is supposed to handle the communication, messageRead and messageWrite are marked UNTESTED. It looks to me that they should work but they didn't and without being able to get some help, I moved on.
Next try: use the newer code in the leJOS project. I installed it and tried some sample code that I found, again without any success. A response to my question in the leJOS forum revealed that leJOS uses streams to talk to the NXT and not mailboxes. The solution is to install the leJOS firmware on the NXT and use streams. This didn't sound too bad but I didn't want to get too deep in proprietary firmware and communication stuff so I abandoned the idea.
Looking around I found several libraries that seemed able to use mailboxes, a comprehensive list is here on Team Hassenplug's site. I decided that if Java didn't work, maybe I should try C# (which I don't know but it is close to Java as far as I know) so I decided to try MindSqualls (another alternative seems to be NXT# but the website was down every time I tried).
So, it is MindSqualls' turn. But about this, in a later post.
Celebrating MINDSTORMS with a Remix - Part 3
-
The ROBOTMAK3RS continued their celebration of the 25th Anniversary of
MINDSTORMS through these Fall and Winter remix projects. Each ROBOTMAK3R
was taske...
1 year ago
No comments:
Post a Comment