Μάτι#
Εισαγωγή#
Ο αισθητήρας VEX GO Eye Sensor μπορεί να ανιχνεύσει αντικείμενα και χρώματα. Μπορεί επίσης να αναφέρει πόσο φως αντανακλάται πίσω στον αισθητήρα και την τιμή απόχρωσης του ανιχνευμένου χρώματος.
The Eye Sensor has a light that can be turned on or off to help it see objects and colors more clearly. The Eye Sensor can also use a NEAR or FAR range to detect objects at different distances.
Ο Αισθητήρας Ματιού μπορεί να τοποθετηθεί σε διαφορετικές θέσεις ανάλογα με την έκδοση. Για παράδειγμα, η έκδοση Code Base 2.0 - Eye Forward έχει τον Αισθητήρα Ματιού στραμμένο προς τα εμπρός. Η έκδοση Code Base 2.0 - Eye Down, η έκδοση Code Base 2.0 - Eye + Electromagnet και η Super Code Base 2.0 έχουν τον Αισθητήρα Ματιού στραμμένο προς τα κάτω.
For the examples below, the configured Eye Sensor is named eye. This name is used in the examples to call Eye class methods.
Υπάρχουν πολλοί τρόποι για να κωδικοποιήσετε τον αισθητήρα ματιών. Παρακάτω είναι μια λίστα με όλες τις μεθόδους ματιών:
Μεταλλαγμένοι παράγοντες — Προσαρμόστε τις ρυθμίσεις του αισθητήρα ματιών.
set_light— Turns the Eye Sensor’s light on or off.set_range— Sets how far the Eye Sensor can detect an object.set_light_power— Sets the Eye Sensor’s light power level.
Λήπτες — Επιστρέφουν ό,τι ανιχνεύει ο αισθητήρας ματιού.
get_color— Returns the color detected by the Eye Sensor.get_hue— Returns the hue detected by the Eye Sensor.get_brightness— Returns the brightness detected by the Eye Sensor.is_object_detected— Returns whether the Eye Sensor detects an object within range.is_color_detected— Returns whether the Eye Sensor detects a specific color.
Μεταλλάκτες#
set_light#
set_light turns the Eye Sensor’s light on or off.
Usage:
eye.set_light(state)
Παράμετροι |
Περιγραφή |
|---|---|
|
The state of the Eye Sensor’s light: |
# Build Used: Super Code Base 2.0
def main():
# Turn the light on and off
while True:
eye.set_light(ON)
wait(2, SECONDS)
eye.set_light(OFF)
wait(2, SECONDS)
# Start threads — Do not delete
start_thread(main)
set_range#
set_range sets how far an object can be from the Eye Sensor before it can be detected.
Every project begins with the Eye Sensor set to FAR range by default.
Usage:
eye.set_range(distance)
Παράμετροι |
Περιγραφή |
|---|---|
|
The Eye Sensor’s object detection range. |
# Build Used: Code Base 2.0 - Eye Forward
def main():
# Drive to an object with different ranges
eye.set_range(FAR)
drivetrain.drive(FORWARD)
wait(0.2, SECONDS)
while not eye.is_object_detected():
wait(0.2, SECONDS)
drivetrain.drive_for(REVERSE, 100, MM)
# Closer detection range
eye.set_range(NEAR)
drivetrain.drive(FORWARD)
wait(0.2, SECONDS)
while not eye.is_object_detected():
wait(0.2, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
set_light_power#
set_light_power sets how bright the Eye Sensor’s light is. The light can help the Eye Sensor detect objects and colors more clearly.
Ένα υψηλότερο ποσοστό κάνει το φως πιο φωτεινό. Ένα χαμηλότερο ποσοστό κάνει το φως πιο αμυδρό.
Εάν το φως του αισθητήρα ματιού είναι σβηστό, η ρύθμιση της ισχύος φωτός πάνω από 0% θα ανάψει το φως.
Εάν το φως του αισθητήρα ματιού είναι αναμμένο, η ρύθμιση της ισχύος φωτός στο 0% θα το σβήσει.
Usage:
eye.set_light_power(value)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η φωτεινότητα στην οποία θα ρυθμιστεί το φως του αισθητήρα ματιού, από 0% έως 100%. Χρησιμοποιήστε ακέραιους αριθμούς. |
# Build Used: Super Code Base 2.0
def main():
# Turn on the light at different brightnesses
eye.set_light_power(25)
wait(2, SECONDS)
eye.set_light_power(50)
wait(2, SECONDS)
eye.set_light_power(100)
# Start threads — Do not delete
start_thread(main)
Αποκτητές#
get_color#
get_color returns the color detected by the Eye Sensor.
Αυτή η μέθοδος μπορεί να επιστρέψει:
RED— A hue value between 340° - 20°GREEN— A hue value between 75° - 154°BLUE— A hue value between 160° - 254°NONE— None of the available colors are detected.
Usage:
eye.get_color()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Super Code Base 2.0
def main():
# Stop when red is detected
drivetrain.drive(FORWARD)
while True:
if eye.get_color() == RED:
break
wait(0.2, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
get_hue#
get_hue returns the color detected by the Eye Sensor as a whole number from 0 to 359.00 degrees.
Η απόχρωση είναι ένας τρόπος περιγραφής χρώματος χρησιμοποιώντας αριθμούς γύρω από έναν χρωματικό κύκλο.

Usage:
eye.get_hue()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Code Base 2.0 - Eye Forward
def main():
# Display the hue of a pink GO piece
while True:
console.clear()
if 10 < eye.get_hue() < 40:
console.print("Pink!")
wait(0.1,SECONDS)
else:
console.print("Not pink.")
wait(0.1,SECONDS)
# Start threads — Do not delete
start_thread(main)
get_brightness#
get_brightness returns how bright the detected light is, as a whole number from 0% to 100%.
Ένα υψηλότερο ποσοστό σημαίνει ότι περισσότερο φως ανακλάται πίσω στον αισθητήρα ματιών. Ένα χαμηλότερο ποσοστό σημαίνει ότι λιγότερο φως ανακλάται πίσω.
Usage:
eye.get_brightness()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Super Code Base 2.0
def main():
# Monitor the brightness until red is detected
monitor_sensor("eye.get_brightness")
drivetrain.drive(FORWARD)
while not eye.get_color() == RED:
wait(0.2, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
is_object_detected#
is_object_detected returns a Boolean that reports whether or not the Eye Sensor detects an object within range.
True— The Eye Sensor detects an object.False— The Eye Sensor does not detect an object.
The detection range can be changed using set_range.
Usage:
eye.is_object_detected()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Build Used: Code Base 2.0 - Eye Forward
def main():
# Drive forward until an object is detected
drivetrain.drive(FORWARD)
wait(0.2, SECONDS)
while not eye.is_object_detected():
wait(0.5, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
is_color_detected#
is_color_detected returns a Boolean that reports whether the Eye Sensor detects a specified color, based on the detected hue value.
True— The Eye Sensor detects the selected color.False— The Eye Sensor does not detect the selected color.
Ο αισθητήρας ματιού λειτουργεί καλύτερα όταν το αντικείμενο είναι αρκετά κοντά για να το ανιχνεύσει και ο φωτισμός είναι καθαρός.
Usage:
eye.is_color_detected(color)
Παράμετροι |
Περιγραφή |
|---|---|
|
The color for the Eye Sensor to check:
|
# Build Used: Super Code Base 2.0
def main():
# Drive forward until a green object is detected
drivetrain.drive(FORWARD)
wait(0.2, SECONDS)
while not eye.is_color_detected(GREEN):
wait(0.5, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)