Color sensor readings py v2

From cod3v
Other languages:
English • ‎suomi

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

  1. port 1 = touch,
  2. port 2 = gyro,
  3. port 3 = color,
  4. 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/

#Sensor port convention:
#port 3 = color
#port 1 = touch, port 2 = gyro, port 3 = color, port 4 = infrared or ultrasonic.

from ev3dev2.sensor.lego import ColorSensor

from time import sleep
import os

os.system('setfont Lat15-TerminusBold14')  #Too small for my eyes!
os.system('setfont Lat15-TerminusBold32x16')  # Try this larger font
cl = ColorSensor() 

cl.calibrate_white()

while True:
    print(cl.reflected_light_intensity) 
    sleep(1)

#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.

MeetAndcodeLogo.png


Meet and Code II: Python