Sensor

class Sensor(varargin)
List of methods:

Information given in this section can be used to configure a sensor’s measurements. For example the Touch-Sensor is capable of either detecting whether it is being pushed, or count the number of pushes. In order to change it’s mode and hence it’s return values, an EV3 object has to be created and connected beforehand. Assuming the physical sensor has been connected to sensor port 1 of the physical brick, the mode change is done as follows:

Example:
    //initialization:
    brick = EV3()
    brick.connect('usb')

    //changing mode of sensor:
    brick.sensor1.mode = DeviceMode.Touch.Bumps

The available modes to a given sensor are described in the Attributes section.

Notes

  • You don’t need to create instances of this class. The EV3-class automatically creates instances for each sensor port, and you can work with them via the EV3-object.
  • The Sensor-class represents sensor ports, not individual sensors!
  • When an input argument of a method is marked as optional, the argument needs to be ‘announced’ by a preceding 2nd argument, which is a string containing the name of the argument. For example, Motor.setProperties may be given a power-parameter. The syntax would be as follows: brickObject.motorA.setProperties(‘power’, 50);
mode

Sensor mode in which the value will be read. By default, mode is set to DeviceMode.Default.Undefined. See also type. [WRITABLE]
Once a physical sensor is connected to the port and the physical Brick is connected to the EV3-object, the allowed mode and the default mode for a Sensor-object are the following (depending on the sensor type):

  • Touch-Sensor:
    • DeviceMode.Touch.Pushed [Default]
      • Output: 0: not pushed, 1: pushed
    • DeviceMode.Touch.Bumps
      • Output: n: number of times being pushed
  • Ultrasonic-Sensor:
    • DeviceMode.UltraSonic.DistCM [Default]
      • Output: distance in cm
      • Note: actively creates ultrasonic sound
    • DeviceMode.UltraSonic.DistIn
      • Output: distance in inches
      • Note: actively creates ultrasonic sound
    • DeviceMode.UltraSonic.Listen
      • Output: distance in cm
      • Note: ONLY listens to other sources (sensors) of ultrasonic sound
  • Color-Sensor:
    • DeviceMode.Color.Reflect [Default]
      • Output: value in range 0% to 100% brightness
    • DeviceMode.Color.Ambient
      • Output: value in range 0% to 100% brightness
    • DeviceMode.Color.Col
      • Output: none, black, blue, green. yellow, red, white, brown
  • Gyro-Sensor:
    • DeviceMode.Gyro.Angular [Default]
      • Note: value appears to be rising indefinitely, even in resting position
    • DeviceMode.Gyro.Rate
      • Output: rotational speed [degree/s]. Expect small offset in resting position
  • Infrared-Sensor:
    • DeviceMode.InfraRed.Prox [Default]
      • Note: currently not recognized
    • DeviceMode.InfraRed.Seek
    • DeviceMode.InfraRed.Remote
  • NXTColor-Sensor:
    • DeviceMode.NXTColor.Reflect [Default]
      • Output: value in range 0% to 100% brightness
    • DeviceMode.NXTColor.Ambient
      • Output: value in range 0% to 100% brightness
    • DeviceMode.NXTColor.Color
      • Output: value representing color: 1-black, 2-blue, 3-green, 4-yellow, 5-red, 6-white, 7-brown
    • DeviceMode.NXTColor.Green
      • Output: value in range 0% to 100% of green reflectivity
    • DeviceMode.NXTColor.Blue
      • Output: value in range 0% to 100% of blue reflectivity
    • DeviceMode.NXTColor.Raw
      • Note: obsolete, functionality available in other modes. Also not working properly. Returning 1 value instead of 3
  • NXTLight-Sensor:
    • DeviceMode.NXTLight.Reflect [Default]
      • Output: value in range 0% to 100% brightness
    • DeviceMode.NXTLight.Ambient
      • Output: value in range 0% to 100% brightness
  • NXTSound-Sensor:
    • DeviceMode.NXTSound.DB [Default]
      • Output: value in decibel
    • DeviceMode.NXTSound.DBA
      • Output: value in dba weighted according to human hearing
  • NXTTemperature-Sensor
    • DeviceMode.NXTTemperature.C [Default]
      • Output: value in Celsius
    • DeviceMode.NXTTemperature.F
      • Output: value in Fahrenheit
  • NXTTouch-Sensor:
    • DeviceMode.NXTTouch.Pushed [Default]
      • Output: 0: not pushed, 1: pushed
    • DeviceMode.NXTTouch.Bumps
      • Output: n: number of times pressed and released
  • NXTUltraSonic-Sensor:
    • DeviceMode.NXTUltraSonic.CM [Default]
      • Output: distance in cm
    • DeviceMode.NXTUltraSonic.IN
      • Output: distance in inches
  • HTAccelerometer-Sensor:
    • DeviceMode.HTAccelerometer.Acceleration [Default]
    • DeviceMode.HTAccelerometer.AccelerationAllAxes
      • Note: Not working properly. Returning 1 value instead of 6
  • HTCompass-Sensor:
    • DeviceMode.HTCompass.Degrees [Default]
      • Note: ‘Error’ mode assigned, value still appears to be correct.
      • Output: 0 to 180 degree. 45° being north, 90° east etc
  • HTColor-Sensor:
    • DeviceMode.HTColor.Col [Default]
      • Output: value representing color: 0-black, 1-purple, 2-blue, 3-cyan, 4-green, 5-green/ yellow, 6-yellow, 7-orange, 8-red, 9-magenta, 10-pink, 11-low saturation blue, 12-low saturation green, 13-low saturation yellow, 14-low saturation orange, 15-low saturation red, 16-low saturation pink, 17-white
    • DeviceMode.HTColor.Red
      • Output: value in range 0 to 255 of red reflectivity
    • DeviceMode.HTColor.Green
      • Output: value in range 0 to 255 of green reflectivity
    • DeviceMode.HTColor.Blue
      • Output: value in range 0 to 255 of blue reflectivity
    • DeviceMode.HTColor.White
      • Output: value in range 0 to 255 of white reflectivity
    • DeviceMode.HTColor.Raw
      • Note: obsolete, color values available in other modes. Also not working properly. Returning 1 value instead of 3
    • DeviceMode.HTColor.Nrm,
      • Note: obsolete, normalized values available in other modes. Also not working properly. Returning 1 value instead of 4
    • DeviceMode.HTColor.All
      • Note: obsolete, all values available in other modes. Also not working properly. Returning 1 value instead of 4
Type:DeviceMode.{Type}
debug

Debug turned on or off. In debug mode, everytime a command is passed to the sublayer (‘communication layer’), there is feedback in the console about what command has been called. [WRITABLE]

Type:bool
value

Value read from hysical sensor. What the value represents depends on mode. [READ-ONLY]

Type:numeric
type

Type of physical sensor connected to the port. Possible types are: [READ-ONLY]

  • DeviceType.NXTTouch
  • DeviceType.NXTLight
  • DeviceType.NXTSound
  • DeviceType.NXTColor
  • DeviceType.NXTUltraSonic
  • DeviceType.NXTTemperature
  • DeviceType.LargeMotor
  • DeviceType.MediumMotor
  • DeviceType.Touch
  • DeviceType.Color
  • DeviceType.UltraSonic
  • DeviceType.Gyro
  • DeviceType.InfraRed
  • DeviceType.HTColor
  • DeviceType.HTCompass
  • DeviceType.HTAccelerometer
  • DeviceType.Unknown
  • DeviceType.None
  • DeviceType.Error
Type:DeviceType
reset(sensor)

Resets sensor value.

Notes

  • Has not been thoroughly tested but seems to work as expected
setProperties(sensor, varargin)

Sets multiple Sensor properties at once using MATLAB’s inputParser.

Parameters:
  • debug (bool) – [OPTIONAL]
  • mode (DeviceMode.{Type}) – [OPTIONAL]
Example:
    brick = EV3()
    brick.connect('bt', 'serPort', '/dev/rfcomm0');

    % use the following line:
    brick.sensor1.setProperties('debug', 'on', 'mode', DeviceMode.Color.Ambient);

    % Instead of:
    brick.sensor1.debug = 'on';
    brick.sensor1.mode = DeviceMode.Color.Ambient;