Motor synchronization using Direct commands

Discussion specific to projects ideas and support.
Post Reply
laquere
Posts: 1
Joined: 08 Nov 2010, 20:52

Motor synchronization using Direct commands

Post 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?
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: Motor synchronization using Direct commands

Post 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).
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: Motor synchronization using Direct commands

Post 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
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests