거리 측정기#

소개#

sonar 급은 초음파 거리 측정기와 함께 사용되며, 초음파를 이용하여 가장 가까운 물체까지의 거리를 측정합니다. 초음파 펄스를 발사하고 반사되어 돌아오는 데 걸리는 시간을 측정하는 방식으로 작동합니다.

VEX EXP 거리 측정기.

클래스 생성자#

sonar(
  triport::port &port);

클래스 소멸자#

sonar 객체를 파괴하고 관련 리소스를 해제합니다.

virtual ~sonar();

매개변수#

매개변수

유형

설명

port

triport::port &

거리 측정기에서 사용하는 필수 2포트 그룹의 첫 번째 3선 포트입니다. 거리 측정기는 브레인 또는 3선 확장기의 인접한 두 포트(A-B, C-D, E-F 또는 G-H)를 사용합니다. 쌍을 이루는 첫 번째 포트(A, C, E 또는 G)를 지정해야 하며, 형식은 Brain.ThreeWirePort.X 또는 ExpanderName.X 입니다. 여기서 X 는 포트 문자입니다(예: Brain.ThreeWirePort.A 또는 Expander1.C).

예시#

// Create a sonar instance in Ports A and B
sonar RangeFinderA = sonar(Brain.ThreeWirePort.A);

회원 기능#

sonar 클래스는 다음과 같은 멤버 함수를 포함합니다.

  • foundObject — 범위 찾기가 객체를 감지했는지 여부를 반환합니다.

  • distance — 거리 측정기와 가장 가까운 감지된 객체 사이의 거리를 반환합니다.

sonar 멤버 함수를 호출하기 전에 아래와 같이 sonar 인스턴스를 생성해야 합니다.

/* This constructor is required when using VS Code.
Range Finder configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a sonar instance in Ports A and B
sonar RangeFinderA = sonar(Brain.ThreeWirePort.A);

foundObject#

거리 측정기가 시야 내에 물체를 감지했는지 여부를 반환합니다.

Available Functions
bool foundObject();

Parameters

이 함수는 매개변수를 받지 않습니다.

Return Values

거리 측정기가 물체를 감지했는지 여부를 나타내는 bool 의 부울 값을 반환합니다.

  • true — 거리 측정기가 물체를 감지했습니다.

  • false — 거리 측정기가 물체를 감지하지 못했습니다.

Examples
// Check if an object is detected.
if (RangeFinderA.foundObject()){
    // Print to screen on the brain that an object was found.
    Brain.Screen.print("object found");
}

distance#

센서가 감지한 가장 가까운 물체까지의 측정된 거리를 반환합니다.

Available Functions
double distance(
  distanceUnits units );

Parameters

매개변수

유형

설명

units

distanceUnits

거리를 나타내는 단위: inches 또는 mm.

Return Values

지정된 단위로 거리를 나타내는 double 을 반환합니다.

Examples
// Get the Range Finder distance in millimeters.
double value = RangeFinderA.distance(mm);

// Print the current distance detected by the Range Finder to the
// Brain's screen.
Brain.Screen.print(value);