Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Sensor

The sensor class provides a uniform interface for using most of the sensors available for the EV3. The various underlying device drivers will create a lego-sensor device for interacting with the sensors.

Sensors are primarily controlled by setting the mode and monitored by reading the value<N> attributes. Values can be converted to floating point if needed by value<N> / 10.0 ^ decimals.

Since the name of the sensor<N> device node does not correspond to the port that a sensor is plugged in to, you must look at the address attribute if you need to know which port a sensor is plugged in to. However, if you don't have more than one sensor of each type, you can just look for a matching driver_name. Then it will not matter which port a sensor is plugged in to - your program will still work.

Hierarchy

Index

Constructors

constructor

  • new Sensor(port?: string, driverNames?: string[] | string): Sensor

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 the sensor is connected to, e.g. ev3:in1. I2C sensors also include the I2C address (decimal), e.g. ev3:in1:i2c8.

    Returns string

command

  • set command(value: string): void
  • Sends a command to the sensor.

    Parameters

    • value: string

    Returns void

commands

  • get commands(): string[]
  • Returns a list of the valid commands for the sensor. Returns -EOPNOTSUPP if no commands are supported.

    Returns string[]

decimals

  • get decimals(): number
  • Returns the number of decimal places for the values in the value<N> attributes of the current mode.

    Returns number

deviceIndex

  • get deviceIndex(): number

driverName

  • get driverName(): string
  • Returns the name of the sensor device/driver. See the list of [supported sensors] for a complete list of drivers.

    Returns string

mode

  • get mode(): string
  • set mode(value: string): void
  • Returns the current mode. Writing one of the values returned by modes sets the sensor to that mode.

    Returns string

  • Returns the current mode. Writing one of the values returned by modes sets the sensor to that mode.

    Parameters

    • value: string

    Returns void

modes

  • get modes(): string[]
  • Returns a list of the valid modes for the sensor.

    Returns string[]

numValues

  • get numValues(): number
  • Returns the number of value<N> attributes that will return a valid value for the current mode.

    Returns number

units

  • get units(): string
  • Returns the units of the measured value for the current mode. May return empty string

    Returns string

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

getFloatValue

  • getFloatValue(valueIndex: number): number
  • Parameters

    • valueIndex: number

    Returns number

getValue

  • getValue(valueIndex: number): number
  • Parameters

    • valueIndex: number

    Returns number

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