Interface Servo

Represents a physical servo.

interface Servo {
    name: string;
    doCommand(command: Struct): Promise<JsonValue>;
    getPosition(extra?: Struct): Promise<number>;
    isMoving(): Promise<boolean>;
    move(angleDeg: number, extra?: Struct): Promise<void>;
    stop(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 set angle of the servo in degrees.

    Parameters

    Returns Promise<number>

    const servo = new VIAM.ServoClient(machine, 'my_servo');

    // Get the current set angle of the servo
    const pos = await servo.getPosition();

    For more information, see Servo API.

  • Return true if the servo is in motion.

    Returns Promise<boolean>

    const servo = new VIAM.ServoClient(machine, 'my_servo');

    const moving = await servo.isMoving();
    console.log('Moving:', moving);

    For more information, see Servo API.

  • Move the servo by a given angle in degrees.

    Parameters

    • angleDeg: number
    • Optionalextra: Struct

    Returns Promise<void>

    const servo = new VIAM.ServoClient(machine, 'my_servo');

    // Move the servo from its origin to the desired angle of 10 degrees
    await servo.move(10);

    // Move the servo from its origin to the desired angle of 90 degrees
    await servo.move(90);

    For more information, see Servo API.

  • Stop the servo.

    Parameters

    Returns Promise<void>

    const servo = new VIAM.ServoClient(machine, 'my_servo');

    // Move the servo from its origin to the desired angle of 10 degrees
    await servo.move(10);

    // Stop the servo. It is assumed that the servo stops moving immediately
    await servo.stop();

    For more information, see Servo API.

MMNEPVFCICPMFPCPTTAAATR