Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Open-Cube FW
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Cube
Open-Cube FW
Commits
e6fba080
Verified
Commit
e6fba080
authored
4 months ago
by
Jakub Vaněk
Browse files
Options
Downloads
Patches
Plain Diff
Make the EV3 color sensor calibration applicable to the EV3 color sensor
parent
caebafb8
No related branches found
Branches containing commit
No related tags found
1 merge request
!13
Make the EV3 color sensor calibration applicable to the EV3 color sensor
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/ev3/color.py
+34
-4
34 additions, 4 deletions
lib/ev3/color.py
with
34 additions
and
4 deletions
lib/ev3/color.py
+
34
−
4
View file @
e6fba080
...
...
@@ -189,9 +189,39 @@ class ColorSensor(EV3UartSensor):
else
:
# code == 0: COLOR_NONE => return None
return
None
def
calibrate
(
self
):
def
calibrate
_hw
(
self
):
"""
Calibrate the sensor
'
s RGB components and save them to sensor memory.
Send a hardware recalibration request to the sensor.
BEWARE. Do not call this unless you know what you are doing.
The calibration is intended to give the sensor an idea what a
"
100% white
"
is. Once the sensor receives the calibration
challenge, it will perform one RGB measurement. This measurement
will then be encoded into the sensor
'
s EEPROM (any previous
factory calibration will be overwritten!).
The hardware calibration affects only the following sensor modes:
- COL-REFLECT (handled by the sensor.reflection() method)
- COL-COLOR (handled by the sensor.color() method)
These are the sensor modes that perform scaling within the sensor itself.
After the calibration, the COL-REFLECT mode should return 100 %
if you keep the sensor in the same position as during calibration.
For a repeatable calibration process, it should be possible to
build a simple calibration jig. It seems that the factory LEGO
calibration makes the sensor return 100 % in COL-REFLECT when
the sensor is pointed at a 3x3 surface made of white LEGO 32523
parts from a distance of ~one Technic brick.
"""
self
.
read_raw_mode
(
ColorSensor
.
MODE_COL_CAL
)
self
.
read_raw_mode
(
ColorSensor
.
MODE_COL_CAL
)
# the sensor will send one DATA message with all zeros
self
.
write_command
(
b
'
LEGO-FAC-CAL-1
'
)
# this will allow the calibration to start
# loop until the sensor sends a new DATA message; it should contain nonzero data (the calibration is then complete)
items
=
self
.
read_raw_mode
(
ColorSensor
.
MODE_COL_CAL
)
while
items
[
0
]
==
0
:
items
=
self
.
read_raw_mode
(
ColorSensor
.
MODE_COL_CAL
)
# switch the sensor back to a mode where it will not time out
self
.
reflection
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment