眼睛#
介紹#
VR眼部感應器可偵測物體並辨識其顏色、亮度和色調。它還允許您調整檢測範圍和照明設置,以獲得更準確的讀數。
以下是所有可用方法的清單:
獲取器 – 讀取物體的存在、顏色、亮度和色調。
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)
參數 |
描述 |
|---|---|
|
先前定義的 函數,當眼部感測器偵測到新物體時執行。 |
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)
參數 |
描述 |
|---|---|
|
先前定義的 函數,當眼部感測器遺失偵測到的物件時執行。 |
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)