NXTMotor

Constructs an NXTMotor object

Contents

Syntax

M = NXTMotor()

M = NXTMotor(PORT)

M = NXTMotor(PORT, 'PropName1', PropValue1, 'PropName2', PropValue2, ...)

Description

M = NXTMotor(PORT) constructs an NXTMotor object with motor port PORT and default attributes. PORT may be either the port number (0, 1, 2 or MOTOR_A, MOTOR_B, MOTOR_C) or a string specifying the port ('A', 'B', 'C'). To have two motors synchronized PORT may be a vector of two ports in ascending order.

M = NXTMotor(PORT, 'PropName1', PropValue1, 'PropName2', PropValue2, ...) constructs an NXTMotor object with motor port(s) PORT in which the given Property name/value pairs are set on the object. All properties can also be set after creation by dot-notation (see example).

Available properties are:

For a list of valid methods, see the "See also" section below.

Note:

When using a motor object with two ports set, the motors will be operated in synchronous mode. This means an internal regulation of the NXT firmware tries to move both motors at the same speed and to the same position (so that driving robots can go a straight line for example). With ActionAtTachoLimit == 'Coast' the sync mode will stay enabled during coasting, allowing for the firmware to correct the robot's position (align it straight ahead again). If you want to use those motors again, you must reset/stop the synchonization before by sending a .Stop() to the motors!

Limitations

If you send a command to the NXT without waiting for the previous motor operation to have finished, the command will be dropped (the NXT indicates this with a high and low beep tone). Use the classes method WaitFor to make sure the motor is ready for new commands, or stop the motor using the method .Stop.

The option SmoothStart in conjunction with ActionAtTachoLimit == 'Coast' is not available. As a workaround, disable SmoothStart for this mode. SmoothStart will generally only work when TachoLimit > 0 is set.

With ActionAtTachoLimit = 'Coast' and synchronous driving (two motors), the motors will stay synced after movement (even after .WaitFor() has finished). This is by design. To disable the synchonization, just use .Stop('off').

SpeedRegulation = true does not always produce the expected result. Due to internal PID regulation, the actually achieved speed can vary or oscillate when using very small values for Power. This happens especially when using the motor with a heavy load for small speeds. In this case it can be better to disable SpeedRegulation. In general, speed regulation should only be enabled if a constant rotational velocity is desired. For constant torque, better disable this feature.

Example:

      % Construct a NXTMotor object on port 'B' with a power of
      % 60, disabled speed regulation, a TachoLimit of 360 and
      % send the motor settings to the NXT brick.
      motorB = NXTMotor('B', 'Power', 60)

      motorB.SpeedRegulation     = false;
      motorB.TachoLimit          = 360;
      motorB.ActionAtTachoLimit  = 'Brake'; % this is the default anyway
      motorB.SmoothStart         = true;

      % enough setting up params, let's go!
      motorB.SendToNXT();
      % let MATLAB wait until the motor has stopped moving
      motorB.WaitFor();

      % Play tone when motor is ready to be used again
      NXT_PlayTone(400,500);
      % let's use a driving robot
      m = NXTMotor('BC', 'Power', 60);
      m.TachoLimit         = 1000;
      m.SmoothStart        = true,    % start soft
      m.ActionAtTachoLimit = 'coast'; % we want very smooth "braking", too :-)
      m.SendToNXT();                  % go!

      m.WaitFor();                    % are we there yet?

      % we're here, motors are still moving / coasting, so give the bot time!
      pause(3);

      % you can still hear the synchronization (high noisy beeping)
      % before we go back, we have to disable the synchronization quickly
      m.Stop();

      % reverse direction
      m.Power = -m.Power;
      m.SendToNXT();
      m.WaitFor();
      pause(3);
      m.Stop();

      NXT_PlayTone(500, 100); % all done

See also

SendToNXT, ReadFromNXT, WaitFor, Stop, ResetPosition, DirectMotorCommand,

Signature