Class EncoderClient

A gRPC-web client for the Encoder component.

Implements

Constructors

Properties

callOptions: CallOptions = ...
name: string

The name of the resource.

Methods

  • Send/Receive arbitrary commands to the resource.

    Parameters

    • command: Struct | Record<string, JsonValue>

      The command to execute. Accepts either a Struct or a plain object, which will be converted automatically.

    • callOptions: CallOptions = ...

    Returns Promise<JsonValue>

    // Plain object (recommended)
    const result = await resource.doCommand({
    myCommand: { key: 'value' },
    });

    // Struct (still supported)
    import { Struct } from '@viamrobotics/sdk';

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

    Parameters

    • positionType: PositionType = EncoderPositionType.UNSPECIFIED

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

    • extra: {} = {}
    • callOptions: CallOptions = ...

    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.

  • Return the encoder's properties.

    Parameters

    • extra: {} = {}
    • callOptions: CallOptions = ...

    Returns Promise<encoderApi.GetPropertiesResponse>

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

    // Get whether the encoder returns position in ticks or degrees
    const properties = await encoder.getProperties();

    For more information, see Encoder API.

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

    Parameters

    • extra: {} = {}
    • callOptions: CallOptions = ...

    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.