Interface MovementSensor

Represents any sensor that reports information about the robot's direction, position, and/or speed.

interface MovementSensor {
    name: string;
    doCommand(command: Struct | Record<string, JsonValue>): Promise<JsonValue>;
    getAccuracy(extra?: Struct): Promise<GetAccuracyResponse>;
    getAngularVelocity(
        extra?: Struct,
    ): Promise<PlainMessage<commonApi.Vector3>>;
    getCompassHeading(extra?: Struct): Promise<number>;
    getLinearAcceleration(
        extra?: Struct,
    ): Promise<PlainMessage<commonApi.Vector3>>;
    getLinearVelocity(extra?: Struct): Promise<PlainMessage<commonApi.Vector3>>;
    getOrientation(
        extra?: Struct,
    ): Promise<PlainMessage<commonApi.Orientation>>;
    getPosition(extra?: Struct): Promise<movementSensorApi.GetPositionResponse>;
    getProperties(
        extra?: Struct,
    ): Promise<movementSensorApi.GetPropertiesResponse>;
    getReadings(extra?: Struct): Promise<Record<string, JsonValue>>;
}

Hierarchy (View Summary)

Implemented by

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' } })
    );
  • Get the accuracy of various sensors.

    Parameters

    Returns Promise<GetAccuracyResponse>

    const movementSensor = new VIAM.MovementSensorClient(
    machine,
    'my_movement_sensor'
    );
    const accuracy = await movementSensor.getAccuracy();

    For more information, see Movement Sensor API.

  • Get the compass heading, which is a number from 0-359 where 0 is North, 90 is East, 180 is South, and 270 is West.

    Parameters

    Returns Promise<number>

    const movementSensor = new VIAM.MovementSensorClient(
    machine,
    'my_movement_sensor'
    );
    const compassHeading = await movementSensor.getCompassHeading();

    For more information, see Movement Sensor API.

  • Return the readings of a sensor.

    Parameters

    Returns Promise<Record<string, JsonValue>>

    const movementSensor = new VIAM.MovementSensorClient(
    machine,
    'my_movement_sensor'
    );
    const readings = await movementSensor.getReadings();

    For more information, see Movement Sensor API.