Color sensor readings py v2
<languages /> <translate>
Introduction
To efficiently and productivily use sensors, You need to know how they behave. Here, we test the readings on different surfaces and lines.
Robot
The idea and principle works for almost any robot thought this is tested using Asimov.
Sensors
The color sensor in reflected light intensity mode is used. The sensor convention is
- port 1 = touch,
- port 2 = gyro,
- port 3 = color,
- port 4 = infrared or ultrasonic
An Illuminating Example
Theory
To read the sensor is easy, but printing the value on a screen with a large enough font is intresting. Note that the print() -command works exactly as Python's print. There is a possibility to use Ev3-G like display command. It is shown elsewhere.
An Example Code
#!/usr/bin/env python3
# https://sites.google.com/site/ev3devpython/
<!--T:12-->
#Sensor port convention:
#port 3 = color
#port 1 = touch, port 2 = gyro, port 3 = color, port 4 = infrared or ultrasonic.
<!--T:13-->
from ev3dev2.sensor.lego import ColorSensor
<!--T:14-->
from time import sleep
import os
<!--T:15-->
os.system('setfont Lat15-TerminusBold14') #Too small for my eyes!
os.system('setfont Lat15-TerminusBold32x16') # Try this larger font
cl = ColorSensor()
<!--T:16-->
cl.calibrate_white()
<!--T:17-->
while True:
print(cl.reflected_light_intensity)
sleep(1)
<!--T:18-->
#84 is Max
#30 is Min
Exercises
1. Make a table of the reflectance of different colors and materials.
About
This course is supported by Meet and Code. The course is made in collaboration with Robotiikka- ja tiedekasvatus ry.
</translate>