multiple NXT's

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

multiple NXT's

Postby TurretGun » Mon Dec 08, 2008 3:20 pm

Hi, For a school project I'm trying to connect multiple NXT's to my laptop, and give them all a name to address them with eg. Move or Gun. I've been looking through the forums, and í ahve found some things, but not the multiple NXT's, especcially not with 0.7.

How should i approach this? i just need that to get started, we're trying to make a turret gun with motion dtection via webcam, and an authorisation module to turn it off remotely. i'll post some pieces of code when we have it working :-)

Thanks, T
TurretGun
New User
 
Posts: 5
Joined: Mon Dec 08, 2008 3:15 pm

Postby Machiel » Mon Dec 08, 2008 3:24 pm

Have you programed before in java?
WHAAAAAAAA!
I have skype: Machiel.veldkamp ADD ME! :D
Machiel
Novice
 
Posts: 60
Joined: Tue Sep 09, 2008 11:36 am
Location: Netherlands

Postby TurretGun » Mon Dec 08, 2008 3:36 pm

lol yes, we worked with the NXT's in the last project too, and we have Java lessons every week, I may seem retarded, but i just can't figure it out >.>
TurretGun
New User
 
Posts: 5
Joined: Mon Dec 08, 2008 3:15 pm

Postby lawrie » Wed Dec 10, 2008 11:09 am

You should not have any problem communicating with multiple NXTs as long as you use lejos.pc.comm rather than iCommand.

You need to decide how you want to communicate from the PC to the NXT. You have a choice between using the LEGO Communication Protocol (which is used by the standard LEGO firmware and iCommand) or using Java streams. Java streams are much more flexible. To use streams, look at samples like BTSend and BTReceive.

If you want to use LCP you can connect a nxtCommand object to each NXT and send commands to it. Version 0.7 lets you do this - 0.6 didn't.

If you want to communicate from one NXT to another you have the same choice between LCP and streams. Look at the BTConnect sample for how to use streams.

You can use LCP from one NXT to another but the support for this is limited. See the RemoteNXTTest sample.

Version 0.8 should have better support for all this but you can do it quite easily with 0.7.

For version 0.8 I have started a NXJControl utility that combines our current set of GUI utilities into one and adds extra functions to it. It can keep simultaneous connections to multiple NXTs. At 0.8 Bluetooth connections to the NXT will be faster as we cache the addresses of NXTs in a properties file, so we don't have to keep doing Bluetooth inquiries. Version 0.8 will also include support for all of what iCommand currently does and a bit more. This will allow you to run some leJOS NXJ programs remotely from the PC by just recompiling them with pccomm.jar instead of classes.jar. Finally 0.8 will have RS485 support which will allow very fast connection from one NXT to another.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Postby TurretGun » Wed Dec 10, 2008 1:20 pm

Maybe we should have been clearer, we have lejos, and the plan was to use that all along. with USB btw. I want to do: nxtComm.open(nxtInfo[0]) but I want to replace nxtInfo[0] with my own information, but I don't know what to place in there. I have the addresses for my NXT's, but can I just put those in the array?

open(NXTInfo nxt)
Connect to a NXT found by a search or created from mname and address.

ohwyeah, small typo there btw. so should the array be :
NXTInfo [0] = NXT;
NXTInfo [1] = 00165306DBC4; ?

T.
TurretGun
New User
 
Posts: 5
Joined: Mon Dec 08, 2008 3:15 pm

Postby TurretGun » Wed Dec 10, 2008 2:20 pm

ohw I fiddled with it, and I tried this :

Code: Select all
NXTInfo henk=new NXTInfo("NXT", "00165306DBC4") ; and then
try {
      nxtComm.open(henk);
   } catch (NXTCommException e) {
      System.out.println("Exception in open");
   }

but I get the error: device is not valid. what did I do wrong?

T.
TurretGun
New User
 
Posts: 5
Joined: Mon Dec 08, 2008 3:15 pm

Postby Machiel » Wed Dec 10, 2008 2:48 pm

This is what I have there:
Code: Select all
public Remote()
   {
      
      try {
         nxtComm = NXTCommFactory.createNXTComm(2);
      } catch (NXTCommException e) {System.out.println("Error 1");}
      nxtInfo = new NXTInfo("NXT","00:16:53:03:67:69");
   }


and:

Code: Select all
private class Connector extends Thread
   {
      public Connector()
      {
         start();
      }
      
      public void run()
      {
         connectStatus = CONNECTING;
         try {
             nxtComm.open(nxtInfo);
             OutputStream os = nxtComm.getOutputStream();
             dos = new DataOutputStream(os);
             InputStream is = nxtComm.getInputStream();
             dis = new DataInputStream(is);
             connected = true;
             connectStatus = CONN_SUCCESS;
             sendCommand(ACTIVE);
         }
         catch (NXTCommException e)
         {
            connectStatus = CONN_FAILURE;
         }
      }
   }
WHAAAAAAAA!
I have skype: Machiel.veldkamp ADD ME! :D
Machiel
Novice
 
Posts: 60
Joined: Tue Sep 09, 2008 11:36 am
Location: Netherlands

Postby lawrie » Wed Dec 10, 2008 9:44 pm

The "device is not valid" is not an error, but just some diagnostics that was left in. It should not stop the connection from working.

You should be able to connect to multiple NXTs using USB either by doing a search by name that will return a NXTInfo structure that you can open, or by constructing the NXTInfo with the name and address as you are doing. The NXTInfo name and address constructor is a bit inconsistent as it assumes that connections by address are only used for Bluetooth and sets the protocol to BLUETOOTH. This is because early versions of leJOS did not support connecting by address using USB. However if you NXTComm is a USB one created by :

NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.USB);

then the protocol set in the NXTInfo will be ignored.

This has all been tidied up for the 0.8 release.
lawrie
leJOS Team Member
 
Posts: 922
Joined: Mon Feb 05, 2007 1:27 pm

Postby TurretGun » Thu Dec 11, 2008 2:27 pm

weee! ok, I have multiple connections, multiple NXT's, and i can choose where to send what information. That's progress :-P

I'm now working with this:

Code: Select all
      
try {
      beweeg = NXTCommFactory.createNXTComm(NXTCommFactory.USB);
      Cam = NXTCommFactory.createNXTComm(NXTCommFactory.USB);
   } catch (NXTCommException e)
   {
      System.out.println("Failure to load comms driver");
   }

NXTInfo TurretCam = new NXTInfo( "NXT", "00165302D893");
   NXTInfo TurretMove =new NXTInfo("NXT", "00165306DBC4") ;
   
   
   try {
      Cam.open(TurretCam);
   } catch (NXTCommException e) {
      System.out.println("Exception in open");
   }
   
   try {
      beweeg.open(TurretMove);
   } catch (NXTCommException e) {
      System.out.println("Exception in open");
   }


It feels redundant, could I just make 1 NxtComm, and then just call open twice, with different info? I tried that, but then you obviously just have 1 name to make streams on, and I want to make a different stream to a different NXT. Should I keep it like this, or is there a shortcut?

ohw, if i run it like this, it works but I get some weird output:
device is not valid
Found nxt name NXT address 00165302D893
Found nxt name NXT address 00165306DBC4
device is not valid
Found nxt name NXT address 00165306DBC4
Found nxt name Unknown address 00165302D893

and after that it just does what i told it to do, in this case, the USBsend sample.

T.
TurretGun
New User
 
Posts: 5
Joined: Mon Dec 08, 2008 3:15 pm


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff