Μάτι#
Εισαγωγή#
Το ρομπότ VEX 123 διαθέτει ενσωματωμένο αισθητήρα ματιού που μπορεί να ανιχνεύσει αντικείμενα και χρώματα. Μπορεί επίσης να αναφέρει πόσο φως αντανακλάται πίσω στον αισθητήρα και την τιμή απόχρωσης του ανιχνευμένου χρώματος.
Ο αισθητήρας ματιού διαθέτει ένα φως που μπορεί να ενεργοποιηθεί ή να απενεργοποιηθεί για να βλέπει αντικείμενα και χρώματα πιο καθαρά.
Υπάρχουν πολλοί τρόποι για να κωδικοποιήσετε τον αισθητήρα ματιών. Παρακάτω είναι μια λίστα με όλες τις μεθόδους ματιών:
Μεταλλαγμένοι παράγοντες — Προσαρμόστε τις ρυθμίσεις του αισθητήρα ματιών.
set_light— Turns the Eye Sensor’s light on or off.set_light_power— Sets the Eye Sensor’s light power level.
Λήπτες — Επιστρέφουν ό,τι ανιχνεύει ο αισθητήρας ματιού.
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.is_bright— Returns whether the Eye Sensor detects a bright object.
Μεταλλάκτες#
set_light#
set_light turns the Eye Sensor’s light on or off.
Usage:
robot.eye.set_light(state)
Παράμετροι |
Περιγραφή |
|---|---|
|
The state of the Eye Sensor’s light: |
# Continuously blink the light.
while True:
robot.eye.set_light(ON)
wait(2, SECONDS)
robot.eye.set_light(OFF)
wait(2, SECONDS)
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:
robot.eye.set_light_power(value)
Παράμετροι |
Περιγραφή |
|---|---|
|
Η φωτεινότητα στην οποία θα ρυθμιστεί το φως του αισθητήρα ματιού, από 0% έως 100%. Χρησιμοποιήστε ακέραιους αριθμούς. |
# Set the light to different power levels.
robot.eye.set_light_power(25)
wait(2, SECONDS)
robot.eye.set_light_power(50)
wait(2, SECONDS)
robot.eye.set_light_power(100)
Αποκτητές#
get_hue#
get_hue returns the color detected by the Eye Sensor as a whole number from 0 to 359.00 degrees.
Η απόχρωση είναι ένας τρόπος περιγραφής χρώματος χρησιμοποιώντας αριθμούς γύρω από έναν χρωματικό κύκλο.

Usage:
robot.eye.get_hue()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Display if an object is pink.
while True:
console.clear()
if 290 < robot.eye.get_hue() < 350:
console.print("Pink!")
else:
console.print("Not pink!")
wait(0.1, SECONDS)
get_brightness#
get_brightness returns how bright the detected light is, as a whole number from 0% to 100%.
Ένα υψηλότερο ποσοστό σημαίνει ότι περισσότερο φως ανακλάται πίσω στον αισθητήρα ματιών. Ένα χαμηλότερο ποσοστό σημαίνει ότι λιγότερο φως ανακλάται πίσω.
Usage:
robot.eye.get_brightness()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Display whether a detected object is bright.
robot.eye.set_light_power(100)
robot.drive(FORWARD)
while not robot.eye.is_object_detected():
wait(0.1, SECONDS)
wait(0.1, SECONDS)
if robot.eye.get_brightness() < 70:
console.print("Object not bright.")
else:
console.print("Bright object!")
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.
Usage:
robot.eye.is_object_detected()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Stop driving after detecting an object.
robot.eye.set_light(ON)
robot.drive(FORWARD)
wait(0.1, SECONDS)
while not robot.eye.is_object_detected():
wait(0.1, SECONDS)
robot.stop()
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:
robot.eye.is_color_detected(color)
Παράμετροι |
Περιγραφή |
|---|---|
|
The color for the Eye Sensor to check:
|
# Stop driving after detecting a green object.
robot.eye.set_light(ON)
robot.drive(FORWARD)
wait(0.1, SECONDS)
while not robot.eye.is_color_detected(GREEN):
wait(0.1, SECONDS)
robot.stop()
is_bright#
is_bright returns a Boolean that reports whether the object detected by the Eye Sensor is bright.
Ένα αντικείμενο θεωρείται φωτεινό όταν αντανακλά περισσότερο από 70% φωτεινότητα πίσω στον αισθητήρα ματιού.
True— The detected object reflects more than 70% brightness.False— The detected object reflects 70% brightness or less.
Usage:
robot.eye.is_bright()
Παράμετροι |
Περιγραφή |
|---|---|
Αυτή η μέθοδος δεν έχει παραμέτρους. |
# Display whether a detected object is bright.
robot.eye.set_light_power(100)
robot.drive(FORWARD)
while not robot.eye.is_object_detected():
wait(0.1, SECONDS)
wait(0.1, SECONDS)
if robot.eye.is_bright():
console.print("Bright object!")
else:
console.print("Object not bright.")