Thursday, June 26, 2008

Multiple NXT Connections

We have faced problem establishing multiple NXTs (using iCommand library) connection with PC. The library is specifying the properties file internally; thus, when you say: nxt.open() it automatically open icommand.properties file located in your home directory or project directory.

Another problem is that commands for motors, sensors,… etc don’t specify which NXT you want to communicate. Hence, if you successfully established the connection with two robots you will have to specify which robot you want to communicate!

Therefore, to overcome this problem we establish robots connection from different main with different properties files. This required a slight change within the library code:

main -1:

private static final String PROS_1 = "icommand.properties";

public static void main(String [] args) throws InterruptedException{

//the object:

NXTCommFactory.setPROPSFNAME(PROS_2);//file properties

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

}

main- 2:

private static final String PROS_2 = "icommand2.properties";

public static void main(String [] args) throws InterruptedException{

//the object:

NXTCommFactory.setPROPSFNAME(PROS_2);//file properties

NXTCommand ob2 = new NXTCommand(); //creat instance

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

ob2.open(); //open connection

NXTCommand rob2 = ob2.getSingleton();//get the modified instance

NXTCommand.setVerify(true); //verify

NXTCommand.setSingleton(rob2); //set signleton
}

library modifications:

[class: NXTCommFactory]:

Create set/get methods for the variable PROPSFNAME. This modification will require you to import all comm classes to your package and also you have to add both bluecov Jar and comm. Jar to your project build path (if you are using Eclipse). The reset classes don’t need any modification.

If you have a better solution please share it with us :-)