ReadFromNXT

Reads current state of specified motor(s) from NXT brick

Contents

Syntax

DATA = OBJ.ReadFromNXT

DATA = OBJ.ReadFromNXT(HANDLE)

[DATA1 DATA2] = OBJ.ReadFromNXT

[DATA1 DATA2] = OBJ.ReadFromNXT(HANDLE)

Description

Request the current state of the motor object OBJ from the NXT brick. NXTMotor object OBJ is not modified. DATA is a structure with property/value pairs.

If the NXTMotor object OBJ controls two motors, DATA1 and DATA2 hold the parameters of the first and the second motor respectively. If only one output argument is given, the parameters of the first motor are returned.

Use the optional parameter HANDLE to identifiy the connection to use for this command. Otherwise the default handle (see COM_SetDefaultNXT) will be used.

The returned struct contains the following fields:

Note:

The values of TachoCount and TachoLimit (which can nicely be used as progress indicators) are not guaranteed to keep being valid once motor movement has finished. They can/will be cleared by the next SendToNXT, Stop, StopMotor or maybe even DirectMotorCommand.

For advanced users: The field Position maps to the NXT firmware's register / IOmap counter RotationCount, and TachoCount maps to TachoCount as expected.

Limitations:

Apart from the previously mentioned limitation of IsRunning (return values slightly differ from what would be expected), the value of SpeedRegulation can sometimes be unexpected: The DATA struct returned by ReadFromNXT always returns the true state of the NXT's firmware registers (it's basically just a wrapper for NXT_GetOutputState). When using an NXTMotor object with SpeedRegulation = true, the regulation will only be enabled during driving. When the motor control starts braking, regulation will be disabled, and this is what ReadFromNXT shows you. So don't worry when you receive SpeedRegulation = false using this method, even though you clearly enabled speed regulation. This is by design, and the motor did in fact use speed regulation during its movement.

Examples:

  % Move motor A and show its state after 3 seconds
  motorA = NXTMotor('A', 'Power', 50);
  motorA.SendToNXT();
  pause(3);
  data = motorA.ReadFromNXT();
  % Construct a NXTMotor object on port 'A' with a power of
  % 50, TachoLimit of 1000, and send the motor settings to the NXT.
  % Show the progress of the motor movement "on the fly".

  motorA = NXTMotor('A', 'Power', 50, 'TachoLimit', 1000);
  % this example wouldn't work with 'HoldBrake'
  motorA.ActionAtTachoLimit = 'Brake';

  motorA.SendToNXT();

  % monitor during movement
  data = motorA.ReadFromNXT();
  while(data.IsRunning)
      percDone = abs(data.TachoCount / data.TachoLimit) * 100;
      disp(sprintf('Motor movement is %d % complete/n', percDone));
      data = motorA.ReadFromNXT(); % refresh
  end%while

See also

NXTMotor, SendToNXT, ResetPosition, NXT_GetOutputState,

Signature