Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Contents

LEGO MINDSTORMS NXT Encoder

Measure encoder rotation from NXT Interactive Servo Motor

Library

Simulink Support Package for LEGO MINDSTORMS NXT Hardware

Description

This block uses the encoder in the LEGO 9842 Interactive Servo Motor to measure the rotation of the wheel in degrees. Driving the wheel forward increments the measurement, and driving the wheel in reverse decrements the measurement.

If you run a simulation of a model that contains this block without the target hardware, this block outputs zeroes. See Block Produces Zeros or Does Nothing in Simulation.

Use the Encoder

Use the Encoder block to measure encoder rotation from an NXT Interactive Servo Motor

Open the legonxtlib block library and copy the blocks shown to a new model.

Connect the Encoder block to the Motor block and the LCD block, as shown.

Double click the Motor block to open the block mask, and change the NXT brick output port parameter to B.

Connect one servo motor to Port A on the NXT brick. Connect another servo motor to Port B on the NXT brick.

Prepare and run the model on the NXT brick.

Slowly rotate the wheel of servo motor connected to Port A in each direction. Observe the servo motor connected to Port B drive in one direction and then in the other direction as you input positive or negative values. Using the input value displayed on the LCD, observe that values larger than 100 or -100 do not increase the motor speed.

In the Encoder block, experiment with changing the Reset mode parameter to Reset at each sample time, and changing the Sample time parameter to 1.

Run the model on the NXT brick again.

Observe that the block output values remain lower and reset to zero every second.

Dialog Box

NXT brick output port

Select the NXT brick output port to which the encoder is connected. The options are A, B, or C.

The LEGO 9842 Interactive Servo Motor contains both a motor and an encoder. If your model uses a Motor block and an Encoder block for the same LEGO 9842 Interactive Servo Motor, set the NXT brick output port parameter in both of those blocks to the same port.

Reset mode

Choose whether to reset the measurement value:

  • No reset — Do not reset the measurement value. Measure the total degrees of rotation.

  • Reset at each sample time — For each sample period, output the measurement value and then reset it to 0.

  • Reset by external signal — Create a block input that can reset the measurement value to 0. When you send a value other than 0 to the block input, reset the measurement value to 0. For each sample period, output the measurement value since the last reset.

Sample time

Specify how often the block reads sensor values.

Smaller values require the processor to complete the same number of instructions in less time, which can cause task overruns.

See Also

| |

External Web Sites

Was this topic helpful?