Viam SDK
    Preparing search index...

    Interface Servo

    Represents a physical servo.

    interface Servo {
        name: string;
        doCommand(command: Struct | Record<string, JsonValue>): Promise<JsonValue>;
        getPosition(extra?: Struct): Promise<number>;
        getStatus(): Promise<JsonValue>;
        isMoving(): Promise<boolean>;
        move(angleDeg: number, extra?: Struct): Promise<void>;
        stop(extra?: Struct): Promise<void>;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    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.

      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 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.