You can connect a lot of different sensors to the EV3 bricks. In the following you will be introduced to the most common ones, that you are probably going to need when participating in the RoboLab.
The color sensor can measure light intensity and color values.
There are a number of modes that the sensor can use.
Make sure to pick one that is suitable for your task.
For best results, it is recommended to create a shield to cover the sensor and keep the distance between 8-12mm to the object.
Continuous, fast changes of the sensing mode can slow down your robot and may lead to instabilities or crashes. Therefore, it is recommended to stick with one.
Pretty much no sensor returns accurate colors, so we prepared an example-measurement for all sensors.
The graph resulted from moving the sensor over colors in the following order: White, Red, White, Blue, White, Black, White, Black, Yellow (unused), Black, White.
Please note that these are just examples and own measurements are very advisable.
This mode returns the estimated color. It is fairly limited as just 8 different values are distinguished.
>>> import ev3dev.ev3 as ev3 >>> cs = ev3.ColorSensor() >>> cs.mode = 'COL-COLOR' >>> cs.value() 1
In this mode the sensor returns triples of the RGB color space.
>>> import ev3dev.ev3 as ev3 >>> cs = ev3.ColorSensor() >>> cs.mode = 'RGB-RAW' >>> cs.bin_data("hhh") (354, 415, 543)
No longer handed because the ColorSensor is capable of both
The light sensor from the old LEGO MINDSTORMS NXT sets does not offer color detection but reads the grey scale values quite well.
To put it more general, it can be used for intensity measurements.
For best results, it is recommended to create a shield to cover the sensor.
This sensor supports two modes.
AMBIENT simply measures the intensity of light at the sensor, we recommend to use
REFLECT as it switches on an auxiliary LED, thus drastically increasing the quality of measurements.
>>> import ev3dev.ev3 as ev3 >>> ls = ev3.LightSensor() >>> ls.mode = 'AMBIENT' # LED is off >>> ls.ambient_light_intensity() 222.2 >>> ls.mode = 'REFLECT' # LED is on >>> ls.reflected_light_intensity() 420.0
A touch sensors simply returns if the button at its front is currently released or being pressed.
These sensors do not support any commands or modes.
>>> import ev3dev.ev3 as ev3 >>> ts = ev3.TouchSensor() >>> ts.value() 0 [press sensor] >>> ts.value() 1
The gyro sensor measures angular velocity and has to be calibrated initially. Make sure to keep the robot or sensor still while performing the initial calibration. Otherwise, you set a wrong base and so-called gyro drift will occur, rendering the measurements useless.
Due to high inaccuracy of the gyro sensor, its use is only recommended if your program is designed with fault tolerance in mind.
>>> import ev3dev.ev3 as ev3 >>> gs = ev3.GyroSensor() >>> gs.mode = 'GYRO-CAL' # calibrate to 0 twice >>> gs.mode = 'GYRO-CAL' >>> gs.mode = 'GYRO-ANG' >>> gs.value() 0 [rotate sensor] >>> gs.value() 33
internally uses ISZ-655 Single Axis Z-Gyro (dual-mass vibratory MEMS gyroscope)
integer overflow at 32k
The ultrasonic sensor can be used to detect obstacles lying ahead. Measurements can be done in centimeters or inch. It is also possible to detect other ultrasonic sensors nearby.
Please take into account that the sensor will sometimes lock up if the mode was changed too frequently (e.g. by calling
A delay of 250ms is highly recommended avoiding sensor timeouts.
>>> import ev3dev.ev3 as ev3 >>> us = ev3.UltrasonicSensor() >>> us.mode = 'US-DIST-CM' # Continuous measurement in centimeters (for inch use US-DIST-IN) >>> us.mode = 'US-SI-CM' # Single measurement in centimeters (for inch use US-SI-IN) >>> us.distance_centimeters # Not recommended 35 >>> us.value() # Prevents setting the mode again, just fetches the value 35