Interface Motor

Represents a physical motor.

interface Motor {
    name: string;
    doCommand(command: Struct): Promise<JsonValue>;
    getPosition(extra?: Struct): Promise<number>;
    getProperties(extra?: Struct): Promise<Properties>;
    goFor(rpm: number, revolutions: number, extra?: Struct): Promise<void>;
    goTo(
        rpm: number,
        positionRevolutions: number,
        extra?: Struct,
    ): Promise<void>;
    isMoving(): Promise<boolean>;
    isPowered(extra?: Struct): Promise<readonly [boolean, number]>;
    resetZeroPosition(offset: number, extra?: Struct): Promise<void>;
    setPower(power: number, extra?: Struct): Promise<void>;
    setRPM(rpm: number, extra?: Struct): Promise<void>;
    stop(extra?: Struct): Promise<void>;
}

Hierarchy (View Summary, Expand)

Implemented by

Properties

name: string

The name of the resource.

Methods

  • Send/Receive arbitrary commands to the resource.

    Parameters

    • command: Struct

      The command to execute.

    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

    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

    Returns Promise<Properties>

    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.

    • Optionalextra: Struct

    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.

    • Optionalextra: Struct

    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.

    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

    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.

    • Optionalextra: Struct

    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.

    • Optionalextra: Struct

    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.

    • Optionalextra: Struct

    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

    Returns Promise<void>

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

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

    For more information, see Motor API.

MMNEPVFCICPMFPCPTTAAATR