Sensors
Work in progress…
- class nxt.sensor.Port(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Input port identifier.
The prefix is needed because a Python identifier can not start with a digit.
- S1 = 0
Sensor port 1.
- S2 = 1
Sensor port 2.
- S3 = 2
Sensor port 3.
- S4 = 3
Sensor port 4.
- class nxt.sensor.Type(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Sensor type.
- NO_SENSOR = 0
No sensor is connected.
- SWITCH = 1
Touch sensor.
- TEMPERATURE = 2
RCX temperature sensor.
- REFLECTION = 3
RCX light sensor.
- ANGLE = 4
RCX rotation sensor.
- LIGHT_ACTIVE = 5
Light sensor with light active.
- LIGHT_INACTIVE = 6
Light sensor with light off.
- SOUND_DB = 7
Sound sensor (unadjusted).
- SOUND_DBA = 8
Sound sensor (adjusted).
- CUSTOM = 9
Custom sensor (unused).
- LOW_SPEED = 10
Low speed digital sensor.
- LOW_SPEED_9V = 11
Low speed digital sensor with 9V supply voltage.
- HIGH_SPEED = 12
High speed sensor.
- COLOR_FULL = 13
NXT color sensor in full color mode (color sensor mode).
- COLOR_RED = 14
NXT color sensor with red light on (light sensor mode).
- COLOR_GREEN = 15
NXT color sensor with green light on (light sensor mode).
- COLOR_BLUE = 16
NXT color sensor in with blue light on (light sensor mode).
- COLOR_NONE = 17
NXT color sensor in with light off (light sensor mode).
- COLOR_EXIT = 18
NXT color sensor internal state.
- class nxt.sensor.Mode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Sensor mode.
- RAW = 0
Raw value, from 0 to 1023.
- BOOL = 32
Boolean value, 0 or 1.
- EDGE = 64
Count number of transitions.
- PULSE = 96
Count number of pulse.
- PERCENT = 128
Value from 0 to 100.
- CELSIUS = 160
Temperature in degree Celsius.
- FAHRENHEIT = 192
Temperature in degree Fahrenheit.
- ROTATION = 224
RCX rotation sensor mode.
- class nxt.sensor.Sensor(brick, port)
Sensor base class.
- class nxt.sensor.analog.RawReading(values)
A object holding the raw sensor values for a sensor.
- class nxt.sensor.analog.BaseAnalogSensor(brick, port)
Object for analog sensors.
- get_input_values()
Get raw sensor readings.
- Returns:
An object with the read values.
- Return type:
- reset_input_scaled_value()
Reset sensor scaled value.
This can be used to reset accumulated value for some sensor modes.
- class nxt.sensor.digital.BaseDigitalSensor(brick, port, check_compatible=True)
Object for digital sensors.
- Parameters:
check_compatible (bool) – Check sensor class match the connected sensor.
If check_compatible is
True
, queries the sensor for its name and print a warning if the wrong sensor class is used.I2C_ADDRESS is the dictionary storing name to I2C address mappings. It should be updated in every subclass. When subclassing this class, make sure to call
add_compatible_sensor()
to add compatible sensor data.- I2C_DEV = 2
- I2C_ADDRESS = {'factory_scale_divisor': (19, 'B'), 'factory_scale_factor': (18, 'B'), 'product_id': (8, '8s'), 'sensor_type': (16, '8s'), 'version': (0, '8s')}
- read_value(name)
Read one or several values from the sensor.
- Parameters:
name (str) – Name of the values to read.
- Returns:
Read values in a tuple.
- Return type:
The name parameter is an index inside I2C_ADDRESS dictionary, which gives the corresponding I2C register address and format string.
- write_value(name, value)
Write one or several values to the sensor.
The name parameter is an index inside I2C_ADDRESS dictionary, which gives the corresponding I2C register address and format string.
- get_sensor_info()
- classmethod add_compatible_sensor(version, product_id, sensor_type)
Adds an entry in the compatibility table for the sensor.
- exception nxt.sensor.digital.SearchError
- nxt.sensor.digital.find_class(info)
Returns an appropriate class.
- Parameters:
info (SensorInfo) – Information read from the sensor.
- Returns:
Class corresponding to sensor.
- Return type:
- Raises:
SearchError – When no class found.