Class MotorClient

A gRPC-web client for the Motor component.

Implements

Constructors

Properties

callOptions: CallOptions = ...
name: string

The name of the resource.

Methods

  • Send/Receive arbitrary commands to the resource.

    Parameters

    • command: Struct

      The command to execute.

    • callOptions: CallOptions = ...

    Returns Promise<JsonValue>

    const result = await resource.doCommand({
    name: 'myCommand',
    args: { key: 'value' },
    });
  • Return the position of the motor relative to its zero position. Raise an error if position reporting is not supported.

    Parameters

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

    Returns Promise<number>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Get the current position of the motor
    const position = await motor.getPosition();
    console.log('Position:', position);

    For more information, see Motor API.

  • Return the motor's properties.

    Parameters

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

    Returns Promise<{ positionReporting: boolean }>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Report a dictionary mapping optional properties to whether it is supported by
    // this motor
    const properties = await motor.getProperties();
    console.log('Properties:', properties);

    For more information, see Motor API.

  • Turn the motor at a specified speed for either a specified number of revolutions or indefinitely. Raise an error if position reporting is not supported.

    Parameters

    • rpm: number

      Speed in revolutions per minute.

    • revolutions: number

      Number of revolutions relative to the motor's starting position. If this value is 0, this will run the motor at the given rpm indefinitely. If this value is nonzero, this will block until the number of revolutions has been completed or another operation comes in.

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

    Returns Promise<void>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Turn the motor 7.2 revolutions at 60 RPM
    await motor.goFor(60, 7.2);

    For more information, see Motor API.

  • Move the motor to a specific position relative to its home position at a specified speed. Raise an error if position reporting is not supported.

    Parameters

    • rpm: number

      Speed in revolutions per minute.

    • positionRevolutions: number

      Number of revolutions relative to the motor's home position.

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

    Returns Promise<void>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Turn the motor to 8.3 revolutions from home at 75 RPM
    await motor.goTo(75, 8.3);

    For more information, see Motor API.

  • Return true if the motor is in motion.

    Parameters

    • callOptions: CallOptions = ...

    Returns Promise<boolean>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Check whether the motor is currently moving
    const moving = await motor.isMoving();
    console.log('Moving:', moving);

    For more information, see Motor API.

  • Return true if the motor is on.

    Parameters

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

    Returns Promise<readonly [boolean, number]>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Check whether the motor is currently running
    const [isPowered, powerPct] = await motor.isPowered();
    console.log('Powered:', isPowered);
    console.log('Power percentage:', powerPct);

    For more information, see Motor API.

  • Set the current position of the motor as the new zero position, offset by a given position. Raise an error if position reporting is not supported.

    Parameters

    • offset: number

      Position from which to offset the current position.

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

    Returns Promise<void>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Set the current position as the new home position with no offset
    await motor.resetZeroPosition(0.0);

    For more information, see Motor API.

  • Set the percentage of the motor's total power that should be employed.

    Parameters

    • power: number

      A value between -1 and 1 where negative values indicate a backwards direction and positive values a forward direction.

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

    Returns Promise<void>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Set the power to 40% forwards
    await motor.setPower(0.4);

    For more information, see Motor API.

  • Move the motor indefinitely at a specified speed. Raise an error if position reporting is not supported.

    Parameters

    • rpm: number

      Speed in revolutions per minute.

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

    Returns Promise<void>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Spin the motor at 75 RPM
    await motor.setRPM(75);

    For more information, see Motor API.

  • Turn the motor off.

    Parameters

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

    Returns Promise<void>

    const motor = new VIAM.MotorClient(machine, 'my_motor');

    // Stop the motor
    await motor.stop();

    For more information, see Motor API.

MMNEPVFCICPMFPCPTTAAATR