인코더#

소개#

encoder 클래스는 축의 회전 위치와 속도를 측정하는 광학 축 엔코더에 사용됩니다. 내부 광학 센서를 사용하여 축의 회전 거리와 속도를 감지하므로 휠 회전, 암 위치 또는 기타 메커니즘 추적에 유용합니다.

VEX 광학 샤프트 엔코더.

클래스 생성자#

encoder(
  triport::port &port );

클래스 소멸자#

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

virtual ~encoder();

매개변수#

매개변수

유형

설명

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 an encoder instance in Ports A and B
encoder EncoderA = encoder(Brain.ThreeWirePort.A);

회원 기능#

encoder 클래스에는 다음과 같은 멤버 함수가 포함됩니다.

  • setPosition — 인코더의 현재 위치를 지정된 값으로 설정합니다.

  • position — 인코더가 얼마나 회전했는지 반환합니다.

  • velocity — 인코더의 현재 회전 속도를 반환합니다.

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

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

// Create an encoder instance in Ports A and B
encoder EncoderA = encoder(Brain.ThreeWirePort.A);

setPosition#

엔코더의 현재 위치를 지정된 값으로 설정합니다. 이 기능을 사용하면 모터나 다른 메커니즘을 회전시키지 않고 추적 위치를 수동으로 설정할 수 있습니다.

Available Functions
void setPosition(
  double        value,
  rotationUnits units);

Parameters

매개변수

유형

설명

value

double

설정할 회전 위치.

units

rotationUnits

The unit that represents the position:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

이 함수는 값을 반환하지 않습니다.

position#

인코더에 연결된 샤프트가 회전한 거리를 반환합니다.

Available Functions
double position(
  rotationUnits units );

Parameters

매개변수

유형

설명

units

rotationUnits

The unit that represents the position:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

지정된 단위로 회전값을 나타내는 double 로 이루어진 double 값을 반환합니다.

velocity#

인코더의 회전 속도를 반환합니다.

Available Functions
double velocity(
  velocityUnits units );

Parameters

매개변수

유형

설명

units

velocityUnits

속도를 나타내는 단위:

  • percent pct — 퍼센트
  • rpm — 분당 회전수
  • dps — 초당 도

Return Values

지정된 단위로 속도를 나타내는 double 값을 반환합니다.