Encoder Component

The encoder component provides an API for getting the position of a motor or a joint in ticks or degrees.

If you have hardware or software that provides the position of a motor or joint, use an encoder component.

Encoder components are often used in conjunction with a motor, and are sometimes even built directly into motors. Encoders can also be mounted on a passive joint or other rotating object to keep track of the joint angle.

The encoder component supports:

  • Incremental encoders, which can measure the speed and direction of rotation in relation to a given reference point like a starting point. These encoders output two phases. Based on the sequence and timing of these phases, it is determined how far something has turned and in which direction. Each phase output goes to a different pin on the board.
  • Single phase or single pin “pulse output” encoders, which measure the position relative to the starting position but not the direction.
  • Absolute encoders, which provide the absolute position of a rotating shaft, without requiring a reference point.

Configuration

To use an encoder, you need to add it to your machine’s configuration.

Go to your machine’s CONFIGURE page, and add a model that supports your encoder.

The following list shows the available encoder models. For additional configuration information, click on the model name:

Model
Description
ModelDescription
incrementalA two phase encoder, which can measure the speed and direction of rotation in relation to a given reference point
singleA single pin “pulse output” encoder which returns its relative position but no direction

API

The encoder API supports the following methods:

Method NameDescriptionviam-micro-server Support
GetPositionGet the current position of the encoder in ticks or degrees.

ResetPositionSet the current position of the encoder to be the new zero position.

GetPropertiesGet a list of all the position types that are supported by a given encoder.

GetGeometriesGet all the geometries associated with the encoder in its current configuration, in the frame of the encoder.

ReconfigureReconfigure this resource.

DoCommandExecute model-specific commands that are not otherwise defined by the component API.

GetResourceNameGet the ResourceName for this encoder with the given name.

CloseSafely shut down the resource and prevent further use.

Troubleshooting

If your encoder is not working as expected, follow these steps:

  1. Check your machine logs on the LOGS tab to check for errors.
  2. Review your encoder model’s documentation to ensure you have configured all required attributes.
  3. Check that all wires are securely attached to the correct pins.
  4. Click on the TEST panel on the CONFIGURE or CONTROL tab and test if you can use the encoder there.

If none of these steps work, reach out to us on the Community Discord and we will be happy to help.

Next steps

For general configuration, development, and usage info, see:

You can also use the encoder component with the following services: