눈#

소개#

VR 아이 센서는 물체를 감지하고 색상, 밝기, 색조를 식별할 수 있습니다. 또한 감지 범위와 조명 설정을 조정하여 더욱 정확한 측정을 할 수 있습니다.

아래는 사용 가능한 모든 방법의 목록입니다.

게터 – 객체의 존재 여부, 색상, 밝기 및 색조를 읽습니다.

  • near_object – Eye Sensor가 범위 내에 있는 물체를 감지했는지 여부를 반환합니다.

  • detect – 눈 센서가 특정 색상을 감지했는지 여부를 반환합니다.

  • brightness – 물체에서 반사된 빛의 양을 백분율로 반환합니다.

콜백 함수 – 객체가 감지되거나 사라졌을 때 코드를 실행합니다.

  • object_detected – Eye Sensor가 객체를 감지할 때마다 호출될 함수를 등록합니다.

  • object_lost – Eye Sensor가 객체를 잃어버릴 때마다 호출될 함수를 등록합니다.

게터스#

near_object#

near_object Eye Sensor가 범위 내에 객체를 감지했는지 여부를 보고하는 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 감지된 색조 값을 기반으로 Eye Sensor가 지정된 색상을 감지했는지 여부를 보고하는 Boolean를 반환합니다.

  • True — 눈 센서가 선택된 색상을 감지합니다.

  • False — 눈 센서가 선택된 색상을 감지하지 못했습니다.

Usage:
eye.detect(color)

매개변수

설명

color

눈 센서가 확인할 색상:

  • 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 객체에서 반사된 빛의 양을 백분율을 나타내는 소수(float)로 반환합니다.

반사율이 높을수록 눈 센서로 반사되는 빛의 양이 많아지고, 반사율이 낮을수록 반사되는 빛의 양이 적어집니다.

Usage:
eye.brightness(units)

매개변수

설명

units

밝기를 나타내는 단위: PERCENT 퍼센트

콜백#

object_detected#

object_detected 은 눈 센서가 새로운 물체를 감지할 때마다 호출될 함수를 등록합니다.

Usage:
eye.object_detected(callback)

매개변수

설명

callback

Eye Sensor가 새 객체를 감지할 때 실행되는 이전에 정의된 함수입니다.

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 은 Eye Sensor가 감지된 객체를 놓칠 때마다 호출될 함수를 등록합니다.

Usage:
eye.object_lost(callback)

매개변수

설명

callback

Eye Sensor가 감지된 객체를 놓쳤을 때 실행되는 이전에 정의된 함수.

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)