Μάτι#

Εισαγωγή#

Ο αισθητήρας VR Eye μπορεί να ανιχνεύσει αντικείμενα και να αναγνωρίσει το χρώμα, τη φωτεινότητα και την απόχρωση τους. Σας επιτρέπει επίσης να προσαρμόσετε το εύρος ανίχνευσης και τις ρυθμίσεις φωτισμού για πιο ακριβείς μετρήσεις.

Παρακάτω είναι μια λίστα με όλες τις διαθέσιμες μεθόδους:

Λήψη δεδομένων – Ανάγνωση παρουσίας, χρώματος, φωτεινότητας και απόχρωσης αντικειμένων.

  • near_object – Returns whether the Eye Sensor detects an object within range.

  • detect – Returns whether the Eye Sensor detects a specific color.

  • brightness – Returns the amount of light reflected from the object as a percent.

Επανάκληση – Εκτέλεση κώδικα όταν εντοπιστεί ή χαθεί ένα αντικείμενο.

  • object_detected – Registers a function to be called whenever the Eye Sensor detects an object.

  • object_lost – Registers a function to be called whenever the Eye Sensor loses an object.

Αποκτητές#

near_object#

near_object returns a Boolean that reports whether or not the Eye Sensor detects an object within range.

  • True – The sensor is near an object.

  • False – The sensor is not near an object.

Usage:
eye.near_object()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

def main():
    # Stop driving when Eye Sensor is 
    # near an object
    drivetrain.drive(FORWARD)
    while True:
        if front_eye.near_object():
            drivetrain.stop()
        wait(5, MSEC)

# VR threads — Do not delete
vr_thread(main)

detect#

detect 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.detect(color)

Παράμετροι

Περιγραφή

color

The color for the Eye Sensor to check for:

  • BLUE
  • GREEN
  • NONE
  • RED
def main():
    # Stop the robot if the Eye Sensor 
    # detects red
    drivetrain.turn(RIGHT)
    while True:
        if front_eye.detect(RED):
            drivetrain.stop()
        wait(5, MSEC)

# VR threads — Do not delete
vr_thread(main)

brightness#

brightness returns the amount of light reflected from the object as a decimal (float) representing a percent.

Ένα υψηλότερο ποσοστό σημαίνει ότι περισσότερο φως ανακλάται πίσω στον αισθητήρα ματιών. Ένα χαμηλότερο ποσοστό σημαίνει ότι λιγότερο φως ανακλάται πίσω.

Usage:
eye.brightness(units)

Παράμετροι

Περιγραφή

units

The unit that represents the brightness: PERCENT

Επανάκληση#

object_detected#

object_detected registers a function to be called whenever the Eye Sensor detects a new object.

Usage:
eye.object_detected(callback)

Παράμετροι

Περιγραφή

callback

Μια προηγουμένως καθορισμένη συνάρτηση που εκτελείται όταν ο αισθητήρας ματιού ανιχνεύει ένα νέο αντικείμενο.

def detected():
    # Display a message
    drivetrain.stop()
    brain.print("object detected")
    wait(0.5,SECONDS)
    brain.clear()

def main():
    # Drive until an object is detected
    drivetrain.drive(FORWARD)
    front_eye.object_detected(detected)

# VR threads — Do not delete
vr_thread(main)

object_lost#

object_lost registers a function to be called whenever the Eye Sensor loses a detected object.

Usage:
eye.object_lost(callback)

Παράμετροι

Περιγραφή

callback

Μια προηγουμένως καθορισμένη συνάρτηση που εκτελείται όταν ο αισθητήρας ματιού χάνει ένα ανιχνευμένο αντικείμενο.

def lost():
    # Display a message
    drivetrain.stop()
    brain.print("object lost")
    wait(0.5,SECONDS)
    brain.clear()

def main():
    # Back away from an object
    drivetrain.drive(REVERSE)
    front_eye.object_lost(lost)

# VR threads — Do not delete
vr_thread(main)