编码器#

介绍#

光学轴编码器用于测量轴的旋转位置和速度。它利用内部光学传感器检测轴的旋转角度和速度,因此可用于跟踪车轮旋转、机械臂位置或其他机械装置。

VEX 光学轴编码器。

This page uses encoder_a as the example Optical Shaft Encoder name. Replace it with your own configured name as needed.

以下是可用方法列表:

  • set_position – Sets the encoder’s current position to a specific value.

  • reset_position – Sets the encoder’s current position to 0.

  • position – Returns how far the encoder has rotated.

  • velocity – Returns the current rotational speed of the encoder.

构造函数 - 手动初始化和配置光学轴编码器。

  • Encoder – Create an Optical Shaft Encoder.

设置位置#

set_position sets the encoder’s current position to a specified value.

Usage:
encoder_a.set_position(position, units)

范围

描述

位置

将编码器位置设置为一个数字。

单位

Optional. The unit to set the position with:

  • DEGREES (default)
  • TURNS

# Set the encoder's position to 3 turns
encoder_a.set_position(3, TURNS)

重置位置#

reset_position sets the encoder’s current position to 0.

Usage:
encoder_a.reset_position()

参数

描述

此方法没有参数。

位置#

position returns how far the shaft connected to the encoder has rotated.

Usage:
encoder_a.position(units)

参数

描述

单位

Optional. The unit to return the position with:

  • DEGREES (default) – Returns an integer
  • TURNS – Returns a float.

速度#

velocity returns the rotational speed of the encoder as a float.

Usage:
encoder_a.velocity(units)

范围

描述

单位

Optional. The unit to return the velocity with:

  • RPM (default) – Rotations per minute
  • VelocityUnits.DPS – Degrees per second.

构造函数#

Constructors are used to manually create Encoder objects, which are necessary for configuring an Optical Shaft Encoder outside of VEXcode.

Encoder#

Encoder creates an Optical Shaft Encoder.

Usage:
Encoder(port)

范围

描述

port

The first of the two 3-Wire Ports that the Optical Shaft Encoder is connected to:

  • On the V5 BrainPorts.PORTx where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create an Optical Shaft Encoder in Port A and B
encoder_a = Encoder(brain.three_wire_port.a)