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
e2345042
Verified
Commit
e2345042
authored
4 months ago
by
Jakub Vaněk
Browse files
Options
Downloads
Patches
Plain Diff
EV3 CS cal: move the calibration procedure to a separate program
parent
8de07304
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
Pipeline
#110534
passed
4 months ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/ev3/color.py
+0
-40
0 additions, 40 deletions
lib/ev3/color.py
programs/factory/ev3_color_cal.py
+122
-0
122 additions, 0 deletions
programs/factory/ev3_color_cal.py
with
122 additions
and
40 deletions
lib/ev3/color.py
+
0
−
40
View file @
e2345042
...
...
@@ -188,43 +188,3 @@ class ColorSensor(EV3UartSensor):
return
code
else
:
# code == 0: COLOR_NONE => return None
return
None
def
calibrate_hw
(
self
):
"""
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
)
# 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
)
# restart the sensor (after the calibration it will be stuck in the COL-CAL mode)
self
.
start_reset
()
# wait for reconnect
self
.
reflection
()
This diff is collapsed.
Click to expand it.
programs/factory/ev3_color_cal.py
0 → 100644
+
122
−
0
View file @
e2345042
"""
Perform a hardware recalibration of the EV3 Color sensor plugged into the port S1.
BEWARE. Do not run this program 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
command from this program, it will perform one RGB measurement.
This measurement will then be saved into the sensor
'
s EEPROM
(and 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.
"""
import
time
from
lib.cube
import
SH1106_I2C
from
lib.ev3
import
ColorSensor
from
lib.ev3.color
import
COLOR_SENSOR_ID
from
lib.robot_consts
import
Port
,
Sensor
,
Button
def
main
():
global
robot
display
:
SH1106_I2C
=
robot
.
display
robot
.
init_sensor
(
sensor_type
=
Sensor
.
EV3_COLOR
,
port
=
Port
.
S1
)
cs
:
ColorSensor
=
robot
.
sensors
.
light
[
Port
.
S1
]
debounce
=
False
this_calibrated
=
False
while
True
:
status_text
,
unplugged
,
ready
=
check_readiness
(
cs
,
this_calibrated
)
if
unplugged
:
this_calibrated
=
False
display
.
fill
(
0
)
display
.
text
(
"
EV3 CS cal tool
"
,
0
,
0
,
1
)
display
.
hline
(
0
,
8
,
128
,
1
)
display
.
text
(
status_text
,
0
,
10
,
1
)
if
ready
:
try
:
reading
=
cs
.
reflection
()
except
:
reading
=
-
1
pressed
=
robot
.
buttons
.
pressed
()
if
not
pressed
[
Button
.
OK
]
or
debounce
:
display
.
text
(
f
"
R:
{
reading
}
%
"
,
0
,
18
,
1
)
display
.
text
(
"
Press OK to cal
"
,
0
,
26
,
1
)
display
.
text
(
"
The scanned sur-
"
,
0
,
40
,
1
)
display
.
text
(
"
face shall later
"
,
0
,
48
,
1
)
display
.
text
(
"
return R: 100 %
"
,
0
,
56
,
1
)
display
.
show
()
if
not
pressed
[
Button
.
OK
]:
debounce
=
False
else
:
debounce
=
True
display
.
text
(
"
Calibrating...
"
,
0
,
26
,
1
)
display
.
show
()
recalibrate
(
cs
)
this_calibrated
=
True
else
:
if
unplugged
:
display
.
text
(
"
- use port S1
"
,
0
,
18
,
1
)
display
.
show
()
time
.
sleep
(
0.1
)
def
check_readiness
(
cs
:
ColorSensor
,
this_calibrated
):
is_connected
=
cs
.
is_connected
()
is_ready
=
cs
.
is_ready
()
# implies is_connected
is_cs
=
cs
.
sensor_id
()
==
COLOR_SENSOR_ID
# implies is_ready
if
is_cs
:
if
this_calibrated
:
status
=
"
S: done
"
else
:
status
=
"
S: ready
"
elif
is_ready
:
status
=
"
S: incorr. type
"
elif
is_connected
:
status
=
"
S: handshaking
"
else
:
status
=
"
S: unplugged
"
return
status
,
not
is_connected
,
is_cs
def
recalibrate
(
sensor
:
ColorSensor
):
# this will prepare the sensor; it will respond with one DATA message with all zeros
sensor
.
read_raw_mode
(
ColorSensor
.
MODE_COL_CAL
)
# this will allow the calibration to start
sensor
.
write_command
(
b
'
LEGO-FAC-CAL-1
'
)
# loop until the sensor sends a new DATA message - the calibration is then complete
# the new message should contain nonzero data
items
=
sensor
.
read_raw_mode
(
ColorSensor
.
MODE_COL_CAL
)
while
items
[
0
]
==
0
:
items
=
sensor
.
read_raw_mode
(
ColorSensor
.
MODE_COL_CAL
)
# restart the sensor (after the calibration it will be stuck in the COL-CAL mode)
sensor
.
start_reset
()
# wait for reconnect
sensor
.
reflection
()
main
()
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