Viam SDK
    Preparing search index...

    Class BaseClient

    A gRPC-web client for the Base component.

    Implements

    Index

    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' } }));
    • Get the geometries of the component in their current configuration

      Parameters

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

      Returns Promise<commonApi.Geometry[]>

      const base = new VIAM.BaseClient(machine, 'my_base');
      const geometries = await base.getGeometries();

      For more information, see Base API.

    • Return the base's properties.

      Parameters

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

      Returns Promise<baseApi.GetPropertiesResponse>

      const base = new VIAM.BaseClient(machine, 'my_base');
      const properties = await base.getProperties();

      For more information, see Base API.

    • Get the status of the resource.

      Parameters

      • callOptions: CallOptions = ...

      Returns Promise<JsonValue>

    • Return true if the base is in motion.

      Parameters

      • callOptions: CallOptions = ...

      Returns Promise<boolean>

      const base = new VIAM.BaseClient(machine, 'my_base');
      const moving = await base.isMoving();

      For more information, see Base API.

    • Move a base in a straight line by a given distance at a given speed. This method blocks until completed or cancelled.

      Parameters

      • distanceMm: number

        Distance to move, in millimeters.

      • mmPerSec: number

        Movement speed, in millimeters per second.

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

      Returns Promise<void>

      const base = new VIAM.BaseClient(machine, 'my_base');

      // Move forward 40mm at 90mm/s
      await base.moveStraight(40, 90);

      // Move backward 40mm at -90mm/s (backwards)
      await base.moveStraight(40, -90);

      For more information, see Base API.

    • Set the linear and angular power of a base from -1 to 1 in terms of power for each direction.

      Parameters

      • linear: Vector3

        Desired linear power percentage from -1 to 1.

      • angular: Vector3

        Desired angular power percentage from -1 to 1.

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

      Returns Promise<void>

      const base = new VIAM.BaseClient(machine, 'my_base');

      // Move forward at 75% power
      await base.setPower(
      { x: 0, y: 0.75, z: 0 }, // linear power
      { x: 0, y: 0, z: 0 }, // no rotation
      );

      // Move straight back at 100% power
      await base.setPower(
      { x: 0, y: -1, z: 0 }, // linear power
      { x: 0, y: 0, z: 0 }, // no rotation
      );

      // Turn counter-clockwise at 50% power
      await base.setPower(
      { x: 0, y: 0, z: 0 }, // no linear movement
      { x: 0, y: 0, z: 0.5 }, // rotate around z-axis
      );

      // Turn clockwise at 60% power
      await base.setPower(
      { x: 0, y: 0, z: 0 }, // no linear movement
      { x: 0, y: 0, z: -0.6 }, // rotate around z-axis
      );

      For more information, see Base API.

    • Set the linear and angular velocity of a base.

      Parameters

      • linear: Vector3

        Desired linear velocity in millimeters per second.

      • angular: Vector3

        Desired angular velocity in degrees per second.

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

      Returns Promise<void>

      const base = new VIAM.BaseClient(machine, 'my_base');

      // Move forward at 50mm/s while spinning 15 degrees per second to the left
      await base.setVelocity(
      { x: 0, y: 50, z: 0 }, // linear velocity in mm/s
      { x: 0, y: 0, z: 15 }, // 15 degrees per second counter-clockwise
      );

      For more information, see Base API.

    • Spin a base by a given angle at a given angular speed. This method blocks until completed or cancelled.

      Parameters

      • angleDeg: number

        Degrees to spin.

      • degsPerSec: number

        Angular speed, in degrees per second.

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

      Returns Promise<void>

      const base = new VIAM.BaseClient(machine, 'my_base');

      // Spin 10 degrees clockwise at 15 degrees per second
      await base.spin(10, 15);

      // Spin 180 degrees counter-clockwise at 20 degrees per second
      await base.spin(-180, 20);

      For more information, see Base API.

    • Stop a base

      Parameters

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

      Returns Promise<void>

      const base = new VIAM.BaseClient(machine, 'my_base');
      await base.stop();

      For more information, see Base API.