Connecting PC GUI To Two NXT Robots

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Connecting PC GUI To Two NXT Robots

Postby win1for » Sat Jul 10, 2010 4:00 am

Hi Guys,

I have a PC GUI application that needs to connect to two robots. One of the robot is a Folklift and the other is a Crossing. I have successfully connected to the folklift robot with this code:

Code: Select all

public boolean makeBluetoothConnection(){
      boolean connected = true;
      try{
      connected = connection.connectTo("btspp://");
      }catch(Exception ex){
         ex.printStackTrace();
      }
      if (!connected) {
         System.err.println("Failed to connect to any NXT");
         //System.exit(1);
         return connected;
      }
      this.dataInput = this.connection.getDataIn();
      this.dataOutput = this.connection.getDataOut();
      return connected;
   }


When i run my program, it uploads the code to the folklift robot. Now i want to connect to the crossing robot from the the same Gui application. The GUI application must be able to exchange info with both robots. The two robots must also communicate with each other.

I am using Eclipse: so i created a separate project folder for the folklift robot. It is in this project that i upload the folklift control program to the folklift robot.

My questions are:

1)
How can i make a Bluetooth connection to the crossing robot at the same time also from the GUI?

2)
Do i have to create a separate project folder for the crossing robot in order to upload its control program?

3)
How can i have access to the crossing robot in order to upload to it? I am asking this question to be able to upload two separate control programs to the different robots(folklift and crossing). Like i said earlier am able to upload to the folklift already.



Thanks for your help.
Last edited by win1for on Sun Jul 11, 2010 9:33 am, edited 2 times in total.
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm

Postby gloomyandy » Sat Jul 10, 2010 4:49 pm

Hi,
To connect to a particular NXT you just need to specify either the name or the address in the connection string and/or the command line. So if your nxt is called nxt1 then you can use btspp://nxt1 and nxjupload -b -n nxt1 <filename>.

It is not possible to have your PC connect to each NXT and have one of the NXTs connect to the other each NXT can only support a single in bound connection. I would suggest that the best way to make this work would be to have the PC connect to each NXT and then use it to forward messages from NXT to the other.

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

Postby win1for » Sat Jul 10, 2010 5:32 pm

Thank you soo much for your reply. I appreciate your suggestion. It sounds very good to me to implement.

I am using a Bluetooth connection and i learnt that anytime the two robots are in each others range, they can work together(exchange information). I don't know in detail how it works. I just read it. If you know how it works, then i will appreciate it if you can point me to a tutorial or give me some a little info about it.

Also my next concern is this. At the moment am able to upload the control program to the first robot. I have to also be able to upload another file(control program) to the other robot. I am asking how i can upload this file to the second robot.

For the first robot i use the ant build file from the lejos examples. This is it:


Code: Select all

<project name="zom.integrated.project.robot" default="uploadandrun">
    <description>
       Execution build file
    </description>

  <!-- set properties for this build -->
  <property environment = "env"/>
  <property file="build.properties"/>
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="main.class" value="test.RobotReceiver"/>
  <property name="binary" value="${build}/${main.class}.nxj" />
   
  <!-- deletes generated files -->
  <target name="clean" description="clean up all generated files">
     <delete dir="build"/>
  </target>

  <target name="compile" depends="clean"
        description="compile the source " >
    <!-- Compile the java code from ${src} to ${build}  -->
     <mkdir dir="${build}"/>
    <javac srcdir="${src}" destdir="${build}">
      <bootclasspath>
        <pathelement location="${nxj.classes.home}/lib/classes.jar"/>
      </bootclasspath>
    </javac>
  </target>

  <target name="link" depends="compile"
        description="link the binary " >
    <!-- Link the binary and create a signature file -->
    <java classname="js.tinyvm.TinyVM">
      <arg value="--bootclasspath"/>
      <arg path="${nxj.classes.jar}" />
      <arg value="--classpath"/>
      <arg path="${build}" />
      <arg value="--writeorder" />
      <arg value="LE" />
      <arg value="${main.class}"/>
      <arg value="-o"/>
      <arg value="${binary}"/>
      <arg value="-v"/>
      <classpath>
        <pathelement location="${nxj.jtools.jar}"/>
        <pathelement location="${nxj.commons.jar}"/>
        <pathelement location="${nxj.bcel.jar}"/>
      </classpath>
    </java>
  </target>
   
  <target name="upload" depends="link"
        description="upload the binary" >
    <java classname="lejos.pc.tools.NXJUpload" fork="true">
      <jvmarg value="-Djava.library.path=${nxj.library.path}"/>
      <jvmarg value="-Dnxj.home=${nxj.home}"/>
      <arg value="${binary}"/>
      <classpath>
        <pathelement location="${nxj.jtools.jar}"/>
        <pathelement location="${nxj.pctools.jar}"/>
         <pathelement location="${nxj.pccomm.jar}"/>
        <pathelement location="${nxj.commons.jar}"/>
        <pathelement location="${nxj.bcel.jar}"/>
         <pathelement location="${nxj.bluecove.jar}"/>
         <pathelement location="${nxj.bluecove-gpl.jar}"/>
      </classpath>
    </java>
  </target>
   
  <target name="uploadandrun" depends="link"
        description="upload and run the binary" >
    <java classname="lejos.pc.tools.NXJUpload" fork="true">
      <jvmarg value="-Djava.library.path=${nxj.library.path}"/>
      <jvmarg value="-Dnxj.home=${nxj.home}"/>
      <arg value="${binary}"/>
      <arg value="-r"/>
      <classpath>
        <pathelement location="${nxj.jtools.jar}"/>
        <pathelement location="${nxj.pctools.jar}"/>
         <pathelement location="${nxj.pccomm.jar}"/>
        <pathelement location="${nxj.commons.jar}"/>
        <pathelement location="${nxj.bcel.jar}"/>
         <pathelement location="${nxj.bluecove.jar}"/>
         <pathelement location="${nxj.bluecove-gpl.jar}"/>
      </classpath>
    </java>
  </target>

  <!--  used only for modifying the Netbeans NXJPlugin -->
    <target name="Zip for Netbeans" description="Zip the application to the sample project">
        <property name="build.classes.dir" location="/build"/>
        <property name="plugin" location="../NXJPlugin/src/nxjplugin/"/>
        <zip basedir="." destfile="${plugin}/NXJSampleProject.zip">
            <exclude name="**/build/"/>
            <exclude name="**/bin/"/>
            <exclude name="**/dist/"/>
            <exclude name="**/nbproject/private/"/>
        </zip>
    </target>
</project>



I am asking if maybe you know how to modify the build file to be able to upload to a specific robot. So that i can modify this one and use it to upload to the second robot. I need a way to specify the specific robot that i want to upload to.

If there is another way of uploading the two different files to the two robots besides the build.xml files, then i welcome that idea also.

Thanks
win1for
Novice
 
Posts: 48
Joined: Tue Mar 02, 2010 11:22 pm


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff