flex_read_encoder_rtn

NI-Motion Functions

flex_read_encoder_rtn

Device Compatibility

Device Compatibility
7330
Y
7340
Y
7344
Y
7350
Y
7390
Y
NI SoftMotion Controller for CANopen—Xenus
Y
NI SoftMotion Controller for CANopen—Accelnet
Y

Read Encoder Position Return

Usage

status = flex_read_encoder_rtn(u8 boardID, u8 axisOrEncoder, i32* encoderCounts);

Purpose

Reads the position of an encoder.

Parameters

Name Type Description
boardID u8 assigned by Measurement & Automation Explorer (MAX)
axisOrEncoder u8 axis or encoder to read
encoderCounts i32* encoder position in quadrature counts

Parameter Discussion

axisOrEncoder is the axis or encoder to read. Valid values are NIMC_AXIS1 through NIMC_AXIS30 or NIMC_ENCODER1 through NIMC_ENCODER30. On motion controllers that support fewer than thirty axes, reading non-existent axes or encoders returns error –70006 (NIMC_badResourceIDOrAxisError). Refer to Axes and Encoders for axis and encoder resource IDs.

encoderCounts is the encoder position is quadrature counts.

Using This Function

This function returns the quadrature count value of the encoder selected. The encoder must be enabled, either directly through the Enable Encoders function or automatically, by being mapped to an enabled axis.

The Read Encoder Position function is typically used to read the value of an encoder that is not part of an axis. This encoder could be a master encoder used for master-slave gearing or an independent position or velocity sensor.

For reading encoders mapped to axes, you can call this function on the axis or directly on its mapped encoder. For servo axes, both approaches return the same value as the Read Position function. On stepper axes however, this function can return additional useful information.

During axis setup, you can operate the closed-loop stepper axis in open-loop mode and use this function to directly measure the counts per revolution and steps per revolution for the axis. These values must be loaded in advance for subsequent closed-loop operation. Refer to the Load Counts/Steps per Revolution function for more information.

You also can use this function to return a finer reading of position in cases where the encoder resolution greatly exceeds the step resolution of the closed-loop stepper axis.