Interface PowerSensor

Represents any sensor that reports voltage, current, and/or power

interface PowerSensor {
    name: string;
    doCommand(command: Struct | Record<string, JsonValue>): Promise<JsonValue>;
    getCurrent(extra?: Struct): Promise<readonly [number, boolean]>;
    getPower(extra?: Struct): Promise<number>;
    getReadings(extra?: Struct): Promise<Record<string, JsonValue>>;
    getVoltage(extra?: Struct): Promise<readonly [number, boolean]>;
}

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 Current in amps and a boolean indicating whether the voltage is AC (true) or DC (false).

    Parameters

    Returns Promise<readonly [number, boolean]>

    const powerSensor = new VIAM.PowerSensorClient(
    machine,
    'my_power_sensor'
    );
    const [current, isAc] = await powerSensor.getCurrent();

    For more information, see Power Sensor API.

  • Get power in watts.

    Parameters

    Returns Promise<number>

    const powerSensor = new VIAM.PowerSensorClient(
    machine,
    'my_power_sensor'
    );
    const power = await powerSensor.getPower();

    For more information, see Power Sensor API.

  • Return the readings of a sensor.

    Parameters

    Returns Promise<Record<string, JsonValue>>

    const powerSensor = new VIAM.PowerSensorClient(
    machine,
    'my_power_sensor'
    );
    const readings = await powerSensor.getReadings();

    For more information, see Power Sensor API.

  • Get voltage in volts and a boolean indicating whether the voltage is AC (true) or DC (false).

    Parameters

    Returns Promise<readonly [number, boolean]>

    const powerSensor = new VIAM.PowerSensorClient(
    machine,
    'my_power_sensor'
    );
    const [voltage, isAc] = await powerSensor.getVoltage();

    For more information, see Power Sensor API.