عين#
مقدمة#
يستطيع مستشعر العين في الواقع الافتراضي اكتشاف الأجسام وتحديد لونها وسطوعها ودرجتها اللونية. كما يتيح لك ضبط نطاق الكشف وإعدادات الإضاءة للحصول على قراءات أكثر دقة.
فيما يلي قائمة بجميع الطرق المتاحة:
المُستقبِلات – قراءة وجود الكائن ولونه وسطوعه ودرجته اللونية.
near_object– تُرجع ما إذا كان مستشعر العين يكتشف وجود جسم ضمن النطاق.detect– إرجاع ما إذا كان مستشعر العين يكتشف لونًا معينًا.brightness– تُرجع كمية الضوء المنعكس من الجسم كنسبة مئوية.
دالة رد الاتصال – تشغيل التعليمات البرمجية عند اكتشاف عنصر أو فقدانه.
object_detected– يسجل دالة ليتم استدعاؤها كلما اكتشف مستشعر العين كائنًا.object_lost– يسجل دالة يتم استدعاؤها كلما فقد مستشعر العين كائنًا.
المحصلون#
near_object#
near_object تُرجع Boolean التي تُبلغ عما إذا كان مستشعر العين يكتشف وجود جسم ضمن النطاق أم لا.
True– المستشعر قريب من جسم ما.False– المستشعر ليس بالقرب من جسم ما.
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 تُرجع Boolean التي تُبلغ عما إذا كان مستشعر العين يكتشف لونًا محددًا، بناءً على قيمة اللون المكتشفة.
True— يكتشف مستشعر العين اللون المحدد.False— لا يكتشف مستشعر العين اللون المحدد.
Usage:
eye.detect(color)
حدود |
وصف |
|---|---|
|
اللون الذي يجب على مستشعر العين التحقق منه:
|
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 يعيد كمية الضوء المنعكس من الجسم كعدد عشري (float) يمثل نسبة مئوية.
نسبة أعلى تعني انعكاس المزيد من الضوء إلى مستشعر العين. نسبة أقل تعني انعكاس كمية أقل من الضوء.
Usage:
eye.brightness(units)
حدود |
وصف |
|---|---|
|
الوحدة التي تمثل السطوع: |
أتصل مرة أخرى#
object_detected#
object_detected يسجل دالة ليتم استدعاؤها كلما اكتشف مستشعر العين كائنًا جديدًا.
Usage:
eye.object_detected(callback)
حدود |
وصف |
|---|---|
|
A previously defined function that executes when the Eye Sensor detects a new object. |
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 يسجل دالة يتم استدعاؤها كلما فقد مستشعر العين كائنًا تم اكتشافه.
Usage:
eye.object_lost(callback)
حدود |
وصف |
|---|---|
|
A previously defined function that executes when the Eye Sensor loses a detected object. |
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)