NXT Multiple Units Simple Control
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);
}
}
@Ev3fan
I can make huge creations with multiple motors with PF system too, at a fraction of NXT’s price.
Huge, fantastic creations with up to 21 motors will be possible.Come on, Sariel, buy some NXTs and start building!;)
@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.
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)
Sariel you should try using lejos
Polak potrafi! 🙂
@Sylca
V3.
Thanks. Which version of RobotC (I’ve got V2, and I did not see it, did I miss it?) are you using?
@Sylca
It comes with ROBOTC. I believe it’s compatible with all standard control pads.
Hi !
Incredible! Congratulations, as usual !
One question: where do you find the joystick controler driver ?
Is it compatible with any USB joystick ?
Thanks,
Sly
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.
@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 🙂
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!