DirectMotorCommand
Sends a direct command to the specified motor
Contents
Syntax
DirectMotorCommand(port, power, angle, speedRegulation, syncedToMotor, turnRatio, rampMode)
Description
DirectMotorCommand(port, power, angle, speedRegulation, syncedToMotor, turnRatio, rampMode) sends the given settings like motor port (MOTOR_A, MOTOR_B or MOTOR_C), the power (-100...100), the angle limit (also called TachoLimit), speedRegulation ('on', 'off'), syncedToMotor (MOTOR_A, MOTOR_B, MOTOR_C), turnRatio (-100...100) and rampMode ('off', 'up', 'down').
This function is basically a convenient wrapper for NXT_SetOutputState. It provides the fastest way possible to send a direct command to the motor(s) via Bluetooth or USB. Complex parameter combinations which are needed for speed regulation or synchronous driving when using NXT_SetOutputState are not necessary, this function does make sure the motor "just works". See below for examples.
Note:
When driving synced motors, it's recommended to stop the motors between consecutive direct motor command (using StopMotor) and to reset their position counters (using NXT_ResetMotorPosition).
This function is intended for the advanced user. Knowledge about the LEGO MINDSTORMS NXT Bluetooth Communication Protocol is not required, but can help to understand what this function does.
Limitations:
Generally spoken, using DirectMotorCommand together with the class NXTMotor (and its method SendToNXT) for the same motor is strongly discouraged. This function can interfer with the on-brick embedded NXC program MotorControl and could cause it to crash. It ignores whatever is happening on the NXT when sending the direct command. The only advantage is the low latency.
When using the parameter angleLimit, the motor tries to reach the desired position by turning off the power at the specified position. This will lead to overshooting of the motor (i.e. the position it stops will be too high or too low). Additionally, the LEGO firmware applies an error correction mechanism which can lead to confusing results. Please look inside the chapter "Troubleshooting" of this toolbox documentation for more details.
Examples
% let a driving robot go straight a bit. % we use motor synchronization for ports B & C: DirectMotorCommand(MOTOR_B, 60, 0, 'off', MOTOR_C, 0, 'off'); pause(5); % driving 5 seconds StopMotor(MOTOR_B, 'off'); StopMotor(MOTOR_C, 'off');
% let motor A rotate for 1000 degrees (with COAST after "braking" and % the firmware's error correction) and with speed regulation: DirectMotorCommand(MOTOR_A, 50, 1000, 'on', 'off', 0, 'off');
% this command DirectMotorCommand(MOTOR_A, 0, 0, 'off', 'off', 0, 'off'); % does exactly the same as calling StopMotor(MOTOR_A, 'off'); % or as using m = NXTMotor('A'); m.Stop('off');
See also
NXT_SetOutputState, NXT_GetOutputState, NXTMotor, SendToNXT, Stop, StopMotor,
Signature
- Author: Linus Atorf, Alexander Behrens (see AUTHORS)
- Date: 2009/08/25
- Copyright: 2007-2010, RWTH Aachen University