객체 센서#

소개#

물체 센서는 반사된 적외선(IR) 빛을 이용하여 물체가 가까이 있을 때 이를 감지하는 적외선 근접 센서입니다.

VEX 객체 센서.

이 페이지에서는 예시 객체 센서 이름으로 object_sensor 사용합니다. 필요에 따라 구성된 이름으로 교체하십시오.

다음은 사용 가능한 방법 목록입니다.

  • reflectivity – 물체에서 반사되는 빛의 양을 백분율로 나타내는 integer를 반환합니다.

  • is_object_detected – 객체 센서가 객체를 감지하는지 여부를 반환합니다.

  • set_threshold – 객체가 감지된 것으로 간주되기 전에 필요한 반사광의 양을 설정합니다.

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

  • object_lost – 객체 센서가 감지된 객체를 잃을 때마다 호출될 함수를 등록합니다.

  • changed – 객체 센서의 값이 변경될 때마다 호출될 함수를 등록합니다.

생성자 – 객체 센서를 수동으로 초기화합니다.

반사율#

reflectivity 물체에서 반사되는 빛의 양을 백분율로 나타내는 integer를 반환합니다.

메모:

  • 반사율 0%는 물체가 매우 어둡다는 것을 의미합니다. 센서는 3000 이상의 원시 값을 감지합니다.

  • 반사율 100%는 물체가 매우 밝다는 것을 의미합니다. 센서는 원시 값으로 0을 감지합니다.

Usage:
object_sensor.reflectivity()

매개변수

설명

이 메서드에는 매개변수가 없습니다.

# Drive forward when the reflectivity is greater than 50%.
while True:
    if object_sensor.reflectivity() > 50:
        drivetrain.drive(FORWARD)
    else:
        drivetrain.stop()
    wait(5, MSEC)

객체가 감지되었습니다#

is_object_detected 객체 감지 센서가 객체를 감지했는지 여부를 반환합니다.

  • True – 객체 센서가 객체를 감지했습니다.

  • False – 객체 센서가 객체를 감지하지 못했습니다.

Usage:
object_sensor.is_object_detected()

매개변수

설명

이 메서드에는 매개변수가 없습니다.

# Drive forward when the object sensor is detecting an object.
while True:
    if object_sensor.is_object_detected():
        drivetrain.drive(FORWARD)
    else:
        drivetrain.stop()
    wait(5, MSEC)

임계값 설정#

set_threshold 은 물체가 감지된 것으로 간주되기 전에 필요한 반사광의 양을 백분율로 설정합니다.

Usage:
object_sensor.set_threshold(value)

매개변수

설명

value

물체를 감지한 것으로 간주하는 데 필요한 반사광의 양은 0에서 100 사이의 정수로 표현됩니다.

# Set the reflectivity threshold to 50%.
object_sensor.set_threshold(50)
# Drive forward when the object sensor is detecting an object.
while True:
    if object_sensor.is_object_detected():
        drivetrain.drive(FORWARD)
    else:
        drivetrain.stop()
    wait(5, MSEC)

객체가 감지되었습니다#

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

Usage:
object_sensor.object_detected(callback, arg)

매개변수

설명

callback

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

arg

선택 사항. 콜백 함수에 전달할 인수를 포함하는 tuple. 자세한 내용은 매개변수가 있는 함수를 참조하세요.

def my_function():
  brain.screen.print("Object detected.")

# Call my_function whenever object_sensor detects an object
object_sensor.object_detected(my_function)

객체 손실#

object_lost 은 객체 센서가 감지된 객체를 놓칠 때마다 호출될 함수를 등록합니다.

Usage:
object_sensor.object_lost(callback, arg)

매개변수

설명

callback

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

arg

선택 사항. 콜백 함수에 전달할 인수를 포함하는 tuple. 자세한 내용은 매개변수가 있는 함수를 참조하세요.

def my_function():
  brain.screen.print("Object lost.")

# Call my_function whenever object_sensor loses an object
object_sensor.object_lost(my_function)

변경됨#

changed 객체 센서의 값이 변경될 때마다 호출될 함수를 등록합니다.

Usage:
object_sensor.changed(callback, arg)

매개변수

설명

callback

객체 센서의 값이 변경될 때 실행되는 이전에 정의된 함수입니다.

arg

선택 사항. 콜백 함수에 전달할 인수를 포함하는 tuple. 자세한 내용은 매개변수가 있는 함수를 참조하세요.

def my_function():
  brain.screen.print("Reflectivity changed.")

# Call my_function whenever object_sensor's value changes
object_sensor.changed(my_function)

건설업자#

Constructors are used to manually create ObjectDetector objects, which are necessary for configuring Object Sensors.

ObjectDetector#

ObjectDetector 객체 센서를 생성합니다.

Usage:
ObjectDetector(port, reverse_det)

매개변수

설명

port

객체 센서가 연결된 3선 포트:

  • EXP 브레인 – brain.three_wire_port.x 여기서 x는 포트 번호입니다.
  • 3선 확장기 – expander.a 여기서 expander 확장기 인스턴스의 이름입니다.

reverse_det

선택 사항입니다. 감지 로직을 반전시킬지 여부:

  • True – 객체가 분실되면 객체가 감지되었다고 반환하고, 객체가 감지되면 분실되었다고 반환합니다.
  • False (기본값) – 객체가 분실되면 객체가 분실되었다고 반환하고, 객체가 감지되면 감지되었다고 반환합니다.

# Create an Object Sensor in Port A
object_sensor = ObjectDetector(brain.three_wire_port.a)