Bluetooth Communication to Multiple NXT Bricks

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Bluetooth Communication to Multiple NXT Bricks

Postby Jeev » Sun Oct 21, 2007 1:15 am

Hi,

I was wondering if it would be possible to control multiple NXT bricks using iCommand?

What I am trying to do is control two motors on one brick, and two on another (4 wheel setup) brick.

It is connected to a Windows XP machine.

Would it be possible to do anything like connect each NXT brick to a different com port, and then tell the Java app to send commands to a specific com port?

Any help would be appreciated. Thanks!
Jeev
New User
 
Posts: 3
Joined: Thu Jun 28, 2007 10:53 pm

Postby bbagnall » Sat Oct 27, 2007 4:26 pm

Hi Jeev,

That's something I haven't been able to experiment with yet since I have only one brick. There was a user in the past who was going to experiment with this but I never heard back what the results were. Theoretically I think this should be possible. As you say, maybe using different ports could somehow communicate with multiple bricks. You would need to pair up multiple bricks to your computer through the operating system first I think.
User avatar
bbagnall
Site Admin
 
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm

Postby Jeev » Sun Oct 28, 2007 7:55 pm

Hi,

We were able to pair multiple bricks to the computer and set them to multiple COM Ports, but the Bluecove connection methods in iCommand automatically connect to the first brick it sees.

We also tried to use the setAddress function to specify a different MAC address to connect to, but that did not work.

Any ideas on how to get setAddress to work? Or how to get BlueCove to connect to a specific brick if multiple ones are in the area of the BT Dongle?

Thanks!
Jeev
New User
 
Posts: 3
Joined: Thu Jun 28, 2007 10:53 pm

Postby bbagnall » Sun Oct 28, 2007 10:53 pm

Hi Jeev,

Check out the source code for icommand.nxt.comm.NXTCommBluecove. There's a method in there called search() that returns all the NXT bricks it finds in the vicinity. Theoretically you could use this info to determine which brick you wanted to talk to.

Also, NXTCommand has a method called getSingleton() which returns an instance of NXTCommand, so you can send LCP (Lego Communication Protocol) commands to the brick. If you wanted to control more than one brick simultaneously in one instance of an iCommand program, you would have to expand this so you could get the appropriate instance for each brick you have.

The architecture is a bit of a Frankenstein's monster because of the way it evolved, but it should be easy to modify to your needs. If it works out, let us know and we'll add the code to the project. Keep in mind we want this to work with one brick with no additional hassle for the end user. So if your modifications make extra work for users with one brick, you should rethink the architecture.
User avatar
bbagnall
Site Admin
 
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm

Postby kirkpthompson » Thu Dec 27, 2007 2:59 am

I have another brick coming and am working on classes that provide BT COMMS between multiple pairings. I will post more when I get something concrete working.
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Postby gloomyandy » Thu Dec 27, 2007 11:18 am

Hi,
I'm in the process of re-working the NXT leJOS Bluetooth classes to support multiple concurrent connections. Not sure if you also planned on working on these if so let me know and I could let you have an early version of my code (or give you a pointer to the SF check in). I've got most parts in place now and will be testing multiple outbound connections today.

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3967
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby kirkpthompson » Thu Dec 27, 2007 5:02 pm

Cool! It sounds like you are way ahead of me. I am now just working on classes to utilize the BT send/receive with multiple elements in the array instead of just sending 1 (+2 header) at a time. I have a thread dedicated to "listen" and stuff the received data into a queue for "leisurely polling" by the implementor, with methods for the different datatypes like DataInputStream.

I would be willing to help test your classes. My other NXT should be in by early next week (hopefully before this w/e).

No sense in re-inventing the wheel....
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Postby gloomyandy » Thu Dec 27, 2007 5:58 pm

Hi,
Sounds good. Are you using the latest snapshot firmware and classes from SF? My code needs the latest firmware (the current firmware can drop packets under load and does not have the functions that are required to switch between streams). If not then we may have to wait until the next version of the firmware goes out ("real soon now...!").

All the best

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3967
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby kirkpthompson » Thu Dec 27, 2007 6:24 pm

Not yet. I did install the Tortoise SVN client and have downloaded "trunk" on 12/15/07. I saw another post explaining how to update the firmware using the latest code from SF SVN repository images. Let me see if I can find that...

ADDENDUM: Found it: http://lejos.sourceforge.net/forum/viewtopic.php?t=407
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Postby kirkpthompson » Sat Dec 29, 2007 3:40 am

I flashed the new firmware. The BT comms seem more unstable now. I added a 10ms delay between each packet send to not drop packets. The LCD seems to take less time to update so I'm thinking that the
Code: Select all
LCD.drawInt(i*256, 1, 1);
LCD.refresh();

methods were basically acting as a delay which is now much shorter.

ADDENDUM: I removed the 10ms delay and put a 2000ms delay at the end of the program and I am not dropping packets. It looks like data transfer in progress is interrupted if the java program ends before the data is completely sent.
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA

Postby PatrickLismore » Sun Feb 24, 2008 2:10 pm

I think that you can now choose which Brick to connect to by connecting on specific ports

example

first nxt on port 1
second nxt on port 2

As for the code, i have not tried i was going to look at this option for my project but i have been able to connect two nxt's together
User avatar
PatrickLismore
Active User
 
Posts: 81
Joined: Tue Oct 16, 2007 7:28 pm
Location: Prague


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 4 guests

more stuff