Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DcMotor

The DC motor class provides a uniform interface for using regular DC motors with no fancy controls or feedback. This includes LEGO MINDSTORMS RCX motors and LEGO Power Functions motors.

Hierarchy

Index

Type aliases

Static CommandValue

CommandValue: "run-forever" | "run-timed" | "run-direct" | "stop"

Static PolarityValue

PolarityValue: "normal" | "inversed"

Static StopActionValue

StopActionValue: "coast" | "brake"

Constructors

constructor

  • new DcMotor(port: string): DcMotor

Properties

Protected _deviceIndex

_deviceIndex: number

connected

connected: boolean

deviceDirName

deviceDirName: string

Protected deviceIndexRegex

deviceIndexRegex: RegExp

deviceRoot

deviceRoot: string

Static overrideSysClassDir

overrideSysClassDir: string

Accessors

address

  • get address(): string
  • Returns the name of the port that this motor is connected to.

    Returns string

command

  • Sets the command for the motor. Possible values are run-forever, run-timed and stop. Not all commands may be supported, so be sure to check the contents of the commands attribute.

    Parameters

    Returns void

commandValues

  • get commandValues(): object

commands

  • get commands(): string[]
  • Returns a list of commands supported by the motor controller.

    Returns string[]

deviceIndex

  • get deviceIndex(): number

driverName

  • get driverName(): string
  • Returns the name of the motor driver that loaded this device. See the list of [supported devices] for a list of drivers.

    Returns string

dutyCycle

  • get dutyCycle(): number
  • Shows the current duty cycle of the PWM signal sent to the motor. Values are -100 to 100 (-100% to 100%).

    Returns number

dutyCycleSp

  • get dutyCycleSp(): number
  • set dutyCycleSp(value: number): void
  • Writing sets the duty cycle setpoint of the PWM signal sent to the motor. Valid values are -100 to 100 (-100% to 100%). Reading returns the current setpoint.

    Returns number

  • Writing sets the duty cycle setpoint of the PWM signal sent to the motor. Valid values are -100 to 100 (-100% to 100%). Reading returns the current setpoint.

    Parameters

    • value: number

    Returns void

polarity

polarityValues

  • get polarityValues(): object

rampDownSp

  • get rampDownSp(): number
  • set rampDownSp(value: number): void
  • Sets the time in milliseconds that it take the motor to ramp down from 100% to 0%. Valid values are 0 to 10000 (10 seconds). Default is 0.

    Returns number

  • Sets the time in milliseconds that it take the motor to ramp down from 100% to 0%. Valid values are 0 to 10000 (10 seconds). Default is 0.

    Parameters

    • value: number

    Returns void

rampUpSp

  • get rampUpSp(): number
  • set rampUpSp(value: number): void
  • Sets the time in milliseconds that it take the motor to up ramp from 0% to 100%. Valid values are 0 to 10000 (10 seconds). Default is 0.

    Returns number

  • Sets the time in milliseconds that it take the motor to up ramp from 0% to 100%. Valid values are 0 to 10000 (10 seconds). Default is 0.

    Parameters

    • value: number

    Returns void

state

  • get state(): string[]
  • Gets a list of flags indicating the motor status. Possible flags are running and ramping. running indicates that the motor is powered. ramping indicates that the motor has not yet reached the duty_cycle_sp.

    Returns string[]

stopAction

  • Sets the stop action that will be used when the motor stops. Read stop_actions to get the list of valid values.

    Parameters

    Returns void

stopActionValues

  • get stopActionValues(): object

stopActions

  • get stopActions(): string[]
  • Gets a list of stop actions. Valid values are coast and brake.

    Returns string[]

timeSp

  • get timeSp(): number
  • set timeSp(value: number): void
  • Writing specifies the amount of time the motor will run when using the run-timed command. Reading returns the current value. Units are in milliseconds.

    Returns number

  • Writing specifies the amount of time the motor will run when using the run-timed command. Reading returns the current value. Units are in milliseconds.

    Parameters

    • value: number

    Returns void

Methods

connect

  • connect(driverName: string, nameConvention?: string, propertyConstraints?: object): void
  • Parameters

    • driverName: string
    • Optional nameConvention: string
    • Optional propertyConstraints: object
      • [propertyName: string]: any

    Returns void

Protected constructPropertyPath

  • constructPropertyPath(property: string, deviceRoot?: string): string

readNumber

  • readNumber(property: string, deviceRoot?: string): number
  • Parameters

    • property: string
    • Optional deviceRoot: string

    Returns number

readProperty

  • readProperty(property: string, deviceRoot?: string): any

readString

  • readString(property: string, deviceRoot?: string): string
  • Parameters

    • property: string
    • Optional deviceRoot: string

    Returns string

readStringArray

  • readStringArray(property: string, deviceRoot?: string): string[]

readStringArrayAsType

  • readStringArrayAsType<T>(property: string, deviceRoot?: string): T[]

readStringAsType

  • readStringAsType<T>(property: string, deviceRoot?: string): T

readStringSelector

  • readStringSelector(property: string, deviceRoot?: string): string

registerEventCallback

  • registerEventCallback(callbackFunction: function, eventPredicate: function, firstTriggerOnly?: boolean, userCallbackData?: any): void
  • Parameters

    • callbackFunction: function
        • (err?: Error, userData?: any): void
        • Parameters

          • Optional err: Error
          • Optional userData: any

          Returns void

    • eventPredicate: function
        • (userData?: any): boolean
        • Parameters

          • Optional userData: any

          Returns boolean

    • Default value firstTriggerOnly: boolean = false
    • Optional userCallbackData: any

    Returns void

registerEventPromise

  • registerEventPromise(eventPredicate: function, userCallbackData?: any): Promise<any>
  • Parameters

    • eventPredicate: function
        • (userData?: any): boolean
        • Parameters

          • Optional userData: any

          Returns boolean

    • Optional userCallbackData: any

    Returns Promise<any>

set

  • set(propertyDefs: any): void
  • Parameters

    • propertyDefs: any

    Returns void

setNumber

  • setNumber(property: string, value: number): void

setProperty

  • setProperty(property: string, value: any): any

setString

  • setString(property: string, value: string): void

Generated using TypeDoc