Multiple NXT's connected to the computer

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

Moderators: 99jonathan, roger, imaqine

Multiple NXT's connected to the computer

Postby ChrisB01 » Sat May 24, 2008 9:51 am

I was thinking would it be possible to have multiple nxt's connected to the computer using different com ports and all communication through one USB dongle. But if this is technically possible I can’t see how you would do it using the current version of icommand.

Thanks

Chris
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby s.k » Fri May 30, 2008 12:20 pm

well, we were able to establish 2 connections at the same time using iCommand and 2 NXT bricks via bluetooth. All what you need to do is setting new port for the other brick and some modifications to the classes of the library.
First, you should have 2 prop files for each brick. Then, at the NXTCommFactory class, add get/set methods for the PROPSFNAME and at your main class set the prop file name:
Code: Select all
NXTCommFactory.setPROPSFNAME(PROS_1);

of course you will still need to do some modifications to other classes in order to identify each singletone.
I'm sure there other ways but this one worked out with us!
s.k
New User
 
Posts: 1
Joined: Fri May 30, 2008 10:44 am
Location: United Arab Emirates

NXT's connected to the computer

Postby ChrisB01 » Sat May 31, 2008 8:01 am

I was thinking about what you said about the props files but wouldn’t it be so much easier if you used an overloaded method to start the connection something like this.

NXTCommand.open(NXTCommand.COM1,NXTCommand.RXTX)

Or even better couldn’t you use that to create an object so you could call different methods for different nxt's

NXT nxt1 = new NXT();
nxt1.open(NXTCommand.COM1,NXTCommand.RXTX)
NXT nxt2 = new NXT();
nxt2.open(NXTCommand.COM2,NXTCommand.RXTX)

nxt1.Motors.A.forward();
nxt1.Motors.C.forward();

This is just a few ideas for the next implementation of icommand but I would like to hear what people think about this.

Chris
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby asma » Wed Jun 25, 2008 8:27 pm

Hi,

we have tried to re-specify the properties file as been mentioned but that was expensive because when the two robots are running in parallel from the same main we had to specify robot each time we want to send a command!!!

Finally, we tried to run two robots from different main with different properties files and it worked fine.

check our blog: http://mindstorms2008.blogspot.com/
asma
New User
 
Posts: 5
Joined: Sat Apr 12, 2008 6:06 am

Postby janar » Thu Oct 09, 2008 7:28 am

http://mindstorms2008.blogspot.com/

Here it works in two different main.

However, if it is much more easier if we create one JAVA class for two robots and specify a prop file in constructor.

public class NXT {

Public NXT(String icommand.proffile)
{
}

OpenConnection()
{
}

CloseConnection()
{

}
}


Then I can create my robots like.

NXT robot1 = new NXT(icommand.propfile1);

NXT robot2 = new NXT(icommand.propfile2);


Is this not possible?
janar
New User
 
Posts: 8
Joined: Thu Oct 09, 2008 7:22 am

Postby janar » Thu Oct 09, 2008 7:28 am

I mean I want to run only one main.
janar
New User
 
Posts: 8
Joined: Thu Oct 09, 2008 7:22 am

Postby ChrisB01 » Thu Oct 09, 2008 3:36 pm

I don't think using ICommand you can do this as ICommand uses the static instance of the NXTCommand class meaning you can only open 1 connection. Have a look at this thread it you want to find out how to open multiple connections.

http://lejos.sourceforge.net/forum/viewtopic.php?t=1086

Chris
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby janar » Thu Oct 09, 2008 10:31 pm

Hi,

Thank you for your response.

Isn't there any way to change the library so that we can control multiple NXTs at the same time?
janar
New User
 
Posts: 8
Joined: Thu Oct 09, 2008 7:22 am

Postby janar » Fri Oct 10, 2008 1:11 am

I want to connect two NXTs from PC. I know there is a way to connect two NXTs from multiple Java applications. however, in my case I want to connecct from one java application. i have done following. but no success it. Do you gusys have any opinions?

Thanks in advance.



Code: Select all


Robot_1.java

public class Robot_1 {

   /**
    * @param args
    */
   
   private NXTCommand rob1;
   private String PROS_1;
   public Robot_1() {
      PROS_1 =  "icommand.properties1";
   }
   
   
   public void Robot_1(String propsname) {
      
      System.out.print("Setting properties file "+propsname+"\n");
   }
   

public void OpenConnection(NXTCommand ob12){
   
   NXTCommFactory.setPROPSFNAME(PROS_1);
   NXTCommand ob1 = new NXTCommand(); //creat instance

   ob1.setSingleton(ob1); //set the instance

   ob1.open(); //open connection

   NXTCommand rob1 = ob1.getSingleton();//get the modified instance

   NXTCommand.setVerify(true); //verify

   NXTCommand.setSingleton(rob1); //set signleton
   
    TestMotorStart();
   
   //return rob1;
   }
   
   public void CloseConnection(NXTCommand obj){
      TestMotorStop();
      obj.close();
      System.out.print("Robot 1 Connection Stopped/n");
      
   }
   
   private void TestMotorStart(){
      
      Motor.A.setSpeed(200);
      Motor.B.setSpeed(200);
      
      Motor.A.backward();
      Motor.B.forward();
      System.out.print("Robot 1 TestMotor Started/n");
   }
   
   private void TestMotorStop(){
      Motor.A.stop();
      Motor.B.stop();
      System.out.print("Robot 1 TestMotor Stopped/n");
      
   }

}




Robot_2.java

Code: Select all

import MyAPI.nxt.comm.NXTCommFactory;
import MyAPI.nxt.comm.NXTCommand;
import MyAPI.nxt.*;
import MyAPI.nxt.comm.*;
import MyAPI.navigation.*;

/*
import MyAPI.nxt.Motor;
import MyAPI.nxt.Sound;
import MyAPI.navigation.TachoNavigator;
import MyAPI.nxt.*;
import MyAPI.nxt.comm.*;
*/

public class Robot_2  {
   
   
   
   private NXTCommand rob2;
   private String PROS_2;
   public Robot_2() {
      //nf =  new NXTCommFactory();
      PROS_2 =  "icommand.properties2";
   }
   
   public void Robot_2(String propsname) {
      
      //nf.setPROPSFNAME(propsname);
      //NXTCommFactory.setPROPSFNAME(propsname);//file properties
      System.out.print("Setting properties file "+propsname+"\n");
   }
   

   public void OpenConnection(NXTCommand ob2){
      
      NXTCommFactory.setPROPSFNAME(PROS_2);
      NXTCommand ob1 = new NXTCommand(); //creat instance

      ob1.setSingleton(ob1); //set the instance

      ob1.open(); //open connection

      NXTCommand rob1 = ob1.getSingleton();//get the modified instance

      NXTCommand.setVerify(true); //verify

      NXTCommand.setSingleton(rob1); //set signleton
      
       TestMotorStart();
      
      //return rob1;
   }
   
   public void CloseConnection(NXTCommand obj){
      TestMotorStop();
      obj.close();
      System.out.print("Robot 2 Connection Stopped/n");
      
   }
   
   private void TestMotorStart(){
      
      Motor.A.setSpeed(200);
      Motor.B.setSpeed(200);
      
      Motor.A.forwardAllMotors();
      //Motor.A.backward();
      Motor.B.forwardAllMotors();
      System.out.print("Robot 2 TestMotor Started/n");
   }
   
   private void TestMotorStop(){
      Motor.A.stopAllMotors();
      
      Motor.B.stopAllMotors();
      System.out.print("Robot 2 TestMotor Stopped/n");
      
   }
   
   
}



Controller.java

Code: Select all



public class Controller {
   private Robot_1 robot1;
   private Robot_2 robot2;
   
   public static void main(String [] args) throws InterruptedException{
      
      robot1 = new Robot_1();
                robot2 = new Robot_2();

      robot1.OpenConnection();
      robot2.OpenConnection();

   }
}

janar
New User
 
Posts: 8
Joined: Thu Oct 09, 2008 7:22 am

Postby ChrisB01 » Fri Oct 10, 2008 2:25 pm

What you need to do it is create a modified version of the NXTCommand class but you need to make it non-static so you can create multiple instances of it, This is what I have done for my NXTCommander program. Hovever if you want to use ICommand I have not looked at this as I used the comm classes in the lejos nxj pc comm package.

Chris
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby shasan » Fri Nov 07, 2008 2:46 pm

What you need to do it is create a modified version of the NXTCommand class but you need to make it non-static so you can create multiple instances of it


What do you mean by that? Looking at the source for lejos.nxt.comm.NXTCommand it doesn't appear to me to be a static class. Am I missing something?

FWIW I'm using Lejos 0.6.
shasan
New User
 
Posts: 5
Joined: Fri Nov 07, 2008 2:21 pm
Location: Chapel Hill, NC

Postby ChrisB01 » Fri Nov 07, 2008 3:43 pm

No its not your fault, I have worded that quite badly, what I meant by "static" is there can only be one instance of the class as the constructor is private.

Chris
Last edited by ChrisB01 on Fri Nov 07, 2008 3:46 pm, edited 1 time in total.
ChrisB01
Advanced Member
 
Posts: 189
Joined: Sat Mar 15, 2008 12:19 pm
Location: UK

Postby gloomyandy » Fri Nov 07, 2008 3:45 pm

Hi,
The curent NXTCommand class follows a singleton pattern and has a private
default constructor so it is not possible to create multiple instances of it... This is what will need changing to allow multiple connections that us NXTCommand....

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

Postby lawrie » Tue Nov 11, 2008 8:21 pm

Version 0.7 which is released today has made the NXTCommand constructor public and you can create multiple instances of it.
lawrie
leJOS Team Member
 
Posts: 919
Joined: Mon Feb 05, 2007 1:27 pm


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests

more stuff