Page 1 of 1

Motor synchronization using Direct commands

Posted: 08 Nov 2010, 21:50
by laquere
I'm trying to use 2 synchronized motors sending direct commands. I read the bluetooth documentation but I can not understand how regulation parameters works to synchronize motors.

Can any one help me?

Re: Motor synchronization using Direct commands

Posted: 09 Nov 2010, 00:15
by linusa
You prepare two parameter sets for SetOutputState, with all parameters exactly the same, except the motor. You use MODE_REGULATED, and REGMODE_SYNC. The motor on bit has to be 1 as usual, and the optional brake bit can be 1 (just use 1, you'll be fine). The RUNSTATE can as usually be RUNNING.

The "trick" is now to send the SetOutputState command to the first motor, and then to the second. Both motors will start running in sync.

It's best if both motors are turned off before (motor-on bit 0, runstate idle, regmode off, power 0), and if BlockTachoCount is reset (using ResetMotorPosition, set the "relative" parameter to true to reset BlockTachoCount).

Good explanations are found in the LEGO Mindstorms NXT "Executable File Specification" (see NXT homepage), and inside the NXC Guide PDF (see Output Module).

Re: Motor synchronization using Direct commands

Posted: 09 Nov 2010, 18:16
by afanofosc
With the enhanced NBC/NXC firmware you can do this with a single SetOutputState direct command rather than two separate ones. Just pass in one of these three combined motor constants and the enhanced NBC/NXC firmware will do the right thing.

Code: Select all

#define  OUT_AB   0x03 
#define  OUT_AC   0x04 
#define  OUT_BC   0x05 
In the standard firmware the SetOutputState direct command does accept the 0xFF value to mean "all motors". This may work if you are synchronizing A and B but C is not connected or if you are synchronizing B and C but A is not connected. I haven't tested this so I can't say for sure if it works correctly or not.

John Hansen