Home > Ideas, Mindstorms > NXT Multiple Units Simple Control

NXT Multiple Units Simple Control

October 28th, 2012 Leave a comment Go to comments

A method and a program for controlling up to 7 NXT units simultaneously using Bluetooth and a standard control pad.  

I was convinced that there can be only one connection between PC and a NXT unit at a time, until Kirby00216 prompted me to run several instances of ROBOTC at the same time, each connected to a different unit. Using this method, I have created a simple control program that can be run on a number of NXT units, allowing to control all of them with a single controller – in this case, a standard USB control pad. I have used a method of reading NXT unit’s unique ID developed by Xander to allow unit-specific commands in the program. In other words, even though the same program is running on all units simultaneously, it’s possible to specify which unit is supposed to respond to which commands.

In case of my sample program provided below, there are two NXT units which I call NXT1 and NXT2, and their unique IDs are 1313750 and 911538 respectively. When you run this program on any unit, it shows the unit’s unique ID, so you can add it to the program and specify commands for that particular unit.

I only own 2 NXT units, but according to the Bluetooth specification, it’s possible to connect up to 7 units at a time to the PC this way. You can notice on the video that there are slight delays in units’ reaction when commands are being sent to two different units at the same time – this is probably caused by the PC’s outgoing Bluetooth queue. Still, this solution has a large potential, as a typical control pad with 2 joysticks and 12 buttons can be used to control 10 motors at the same time.

Control program:

#include "JoystickDriver.c"

task main () {
  long uniqueID = 0;
  TBTAddress btAddr;
  getBTAddress(btAddr);
  uniqueID = (long)btAddr[5] + ((long)btAddr[4] << 8) + ((long)btAddr[3] << 16);

  while(true)
  {
    getJoystickSettings(joystick);

    if(uniqueID == 1313750){ // NXT1 unit
      if(joy1Btn(1) == 1)
        motor[motorA] = 100;
      else
        motor[motorA] = 0;

      if(joy1Btn(2) == 1)
        motor[motorB] = 100;
      else
        motor[motorB] = 0;

      if(joy1Btn(3) == 1)
        motor[motorC] = 100;
      else
        motor[motorC] = 0;
    }

    else if(uniqueID == 911538){ // NXT2 unit
      if(joy1Btn(5) == 1)
        motor[motorA] = 100;
      else
        motor[motorA] = 0;

      if(joy1Btn(6) == 1)
        motor[motorB] = 100;
      else
        motor[motorB] = 0;

      if(joy1Btn(7) == 1)
        motor[motorC] = 100;
      else
        motor[motorC] = 0;
    }

    nxtDisplayCenteredTextLine(0, "BATTERY: %3.1fV", nImmediateBatteryLevel / (float) 1000);
    nxtDisplayCenteredTextLine(1, "UNIT: %d", uniqueID);
  }

}
									

Video:

Categories: Ideas, Mindstorms Tags:
  1. Sariel
    April 15th, 2014 at 11:12 | #1

    @Ev3fan
    I can make huge creations with multiple motors with PF system too, at a fraction of NXT’s price.

  2. Ev3fan
    April 15th, 2014 at 11:08 | #2

    Huge, fantastic creations with up to 21 motors will be possible.Come on, Sariel, buy some NXTs and start building!;)

  3. Sariel
    June 13th, 2013 at 18:08 | #3

    @FrozenEntity
    Oczywiście, że mógłbym i dokładnie to robię w moich innych skryptach. Tu chodziło mi głównie o uproszczenie prezentacji, że ten guzik = ten motor.

  4. FrozenEntity
    June 13th, 2013 at 17:15 | #4

    Siemka.

    Przejrzalem ten script do nxt, i ostrzegam ze sam nie mam nxt, ale duzo sie bawie lua i c++ wiec cos tam wiem, i wydaje mi sie ze jest dosc prymitywny. No bo skoro uzywasz do tego joysticka, to moglbys ustawic respective torque do tego jak mocno popchniesz joystick …

    Tak, wiem, uzywasz guzikow, ale to tylko pomysl 😀

    (Moj polski jest coraz gorszy bo od dawna nie mieszkam w kraju)

  5. unknown
    November 18th, 2012 at 00:40 | #5

    Sariel you should try using lejos

  6. Orzeszek
    November 15th, 2012 at 21:01 | #6

    Polak potrafi! 🙂

  7. Sariel
    October 31st, 2012 at 13:54 | #7

    @Sylca
    V3.

  8. October 31st, 2012 at 11:43 | #8

    Thanks. Which version of RobotC (I’ve got V2, and I did not see it, did I miss it?) are you using?

  9. Sariel
    October 30th, 2012 at 20:18 | #9

    @Sylca
    It comes with ROBOTC. I believe it’s compatible with all standard control pads.

  10. October 30th, 2012 at 19:18 | #10

    Hi !

    Incredible! Congratulations, as usual !

    One question: where do you find the joystick controler driver ?
    Is it compatible with any USB joystick ?

    Thanks,

    Sly

  11. NeXT-Generation
    October 28th, 2012 at 23:52 | #11

    Stepping up the complexity! Nice! I had an idea like this once, but never got around to doing it. But I did figure out that multiple instances of RobotC can be paired to a specific brick.

  12. Sariel
    October 28th, 2012 at 15:38 | #12

    @David Luders
    Why, yes, I plan to use two Bluetooth-controlled NXT units in my big bucket wheel excavator. There will be plenty of space for them 🙂

  13. David Luders
    October 28th, 2012 at 15:29 | #13

    You have been most busy lately! 🙂 Do you have any MOC in mind, in which to use these multiple NXT motors? Soon, robots will be taking over the world!

  1. No trackbacks yet.