Interface Encoder

Represents a physical encoder.

interface Encoder {
    name: string;
    doCommand(command: Struct): Promise<JsonValue>;
    getPosition(
        positionType?: PositionType,
        extra?: Struct,
    ): Promise<readonly [number, PositionType]>;
    getProperties(extra?: Struct): Promise<encoderApi.GetPropertiesResponse>;
    resetPosition(extra?: Struct): Promise<void>;
}

Hierarchy (View Summary, Expand)

Implemented by

Properties

name: string

The name of the resource.

Methods

  • Send/Receive arbitrary commands to the resource.

    Parameters

    • command: Struct

      The command to execute.

    Returns Promise<JsonValue>

    const result = await resource.doCommand({
    name: 'myCommand',
    args: { key: 'value' },
    });
  • Return the current position either in relative units (ticks away from a zero position) or absolute units (degrees along a circle).

    Parameters

    • OptionalpositionType: PositionType

      The type of position the encoder returns (ticks or degrees)

    • Optionalextra: Struct

    Returns Promise<readonly [number, PositionType]>

    const encoder = new VIAM.EncoderClient(machine, 'my_encoder');

    // Get the position of the encoder in ticks
    const [position, posType] = await encoder.getPosition(
    EncoderPositionType.POSITION_TYPE_TICKS_COUNT
    );
    console.log('The encoder position is currently', position, posType);

    For more information, see Encoder API.

  • Set the current position of the encoder as the new zero position.

    Parameters

    Returns Promise<void>

    const encoder = new VIAM.EncoderClient(machine, 'my_encoder');

    // Reset the zero position of the encoder
    await encoder.resetPosition();

    For more information, see Encoder API.

MMNEPVFCICPMFPCPTTAAATR