跳转到内容
暂存服务器
开发服务器

Encoder Control#

通过 Encoder Control camera feature,您可以控制和监视正交编码器。

正交编码器也称为增量、旋转或轴编码器。它们通常用于必须测量运动或位置变化的自动化应用中。

Encoder Control 功能仅适用于 Basler racer 2 相机。

该功能的使用#

运作原理#

Encoder Control 与生成两个输出信号 A 和 B 的正交编码器(可以是旋转式或线性式)连接。这些信号也称为相位或源 A 和 B。这两个信号具有 90° 的相位差,用于跟踪编码器的正向和反向运动方向。相位 A 和 B 是相机编码器控制的输入信号。

下图显示了编码器控制的典型实现方式。

典型 Encoder Control 实现方式

Encoder 运动方向#

编码器可以向前或向后运动。为了检测运动方向,Encoder Control 会读取 A 和 B 信号上升沿和下降沿的顺序。

  • 正向运动方向:A 信号超前 B 信号 90° 上升。相位顺序为 1-2-3-4。
  • 反向运动方向:B 信号超前 A 信号上升。相位顺序为 4-3-2-1。

下图显示了与 A 和 B 信号的数字信号电平相对应的四个相位。

A 和 B 信号之间的关系

Position Counter#

Encoder Control 使用由 A 和 B 信号驱动的 Position Counter。计数器值在正向运动方向上递增,在反向运动方向上递减。

Position Counter 连续运行。其值表示自上次重置以来收到的传入信号数量。因此,计数器值始终反映目标对象相对于正向或反向运动当前的位置。

Encoder 模式#

Encoder Mode 控制 Encoder Control 如何计算传入的编码器信号。

四相模式#

四个完全完成的信号相位构成一个正交周期。在每个完整的正交周期中,即当 A 信号边沿上升时,正交编码器计数器递增或递减 1。

Four Phase 模式非常稳健,能够滤除两个相位之间少量的信号抖动。

四相模式

高分辨率模式#

在 High Resolution 模式下,每个周期的计数会增加四倍。在每个信号相位上,即当 A 和 B 信号边沿上升和下降时,编码器计数器递增或递减 1。

高分辨率模式

信息

在 High Resolution 模式下无法进行抖动滤波。因此,不建议将 High Resolution 模式与 encoder output mode 设为 Motion 一起使用,因为两个相位之间的抖动可能会导致连续的输出触发脉冲。

Encoder 输出模式#

Encoder Output Mode 允许您为 Encoder Control 生成有效输出信号设置条件。可用的 encoder output mode 包括:

  • Motion:无论运动方向如何,都会生成输出触发信号。
  • DirectionUp:在 正向 方向的所有位置增量处生成输出触发信号。反向运动将被忽略。
  • DirectionDown:在 反向 方向。正向运动方向将被忽略。
  • PositionUp:在所有 新 位置处生成输出触发信号,方向为 正向 。如果编码器反向,则在重新通过反向开始的位置之前,不会生成任何输出触发信号。
  • PositionDown:在所有 新 位置处生成输出触发信号,方向为 反向 。如果编码器反向,则在重新通过反向开始的位置之前,不会生成任何输出触发信号。
  • Off:不生成输出触发信号。

附加参数#

  • EncoderDivider:确定生成编码器输出触发信号所需的来自编码器的输入信号数量。
  • EncoderValue:获取位置 Counter 的当前值。此 Property 为只读。
  • EncoderReset:将位置 Counter 的当前计数值重置为 0。这同时也会重置并重新启动整个 Encoder Control。重启后会立即开始对信号脉冲进行计数。

配置 Encoder Control#

要配置 Encoder Control:

  1. 设置 EncoderSelector 将参数设置为 Encoder1.
  2. 设置 EncoderSourceA 参数设置为其中一个可用源信号,例如 Line2.
  3. 设置 EncoderSourceB 参数设置为其中一个可用源信号,例如 Line3.
  4. 设置 EncoderMode 参数设置为以下值:
  5. 设置 EncoderDivider 将 Property 设置为所需的输入信号数量。
  6. 设置 EncoderOutputMode 将 Property 设置为要启用的 output mode ,例如 Motion.

要配置相机以由编码器信号触发:

  1. 设置 TriggerSelector 将参数设置为 LineStart.
  2. 设置 TriggerMode 将参数设置为 On.
  3. 设置 TriggerSource 将参数设置为 Encoder1.

示例代码#

// Select the desired encoder selector
camera.EncoderSelector.SetValue(EncoderSelector_Encoder1)
// Select line 2 as the source signal for the A input of the encoder control
camera.EncoderSourceA.SetValue(EncoderSourceA_Line2);
// Select line 3 as the source signal for the B input of the encoder control
camera.EncoderSourceB.SetValue(EncoderSourceB_Line3);
// Select the desired encoder mode
camera.EncoderMode.SetValue(EncoderMode_FourPhase);
// Determine the number of input signals needed to generate an encoder output trigger signal
camera.EncoderDivider.SetValue(1);
// Select the desired encoder output mode
camera.EncoderOutputMode.SetValue(EncoderOutputMode_Motion);
INodeMap& nodemap = camera.GetNodeMap();
// Select the desired encoder selector
CEnumParameter(nodemap, "EncoderSelector").SetValue("Encoder1");
// Select line 2 as the source signal for the A input of the encoder control
CEnumParameter(nodemap, "EncoderSourceA").SetValue("Line2");
// Select line 3 as the source signal for the B input of the encoder control
CEnumParameter(nodemap, "EncoderSourceB").SetValue("Line3");
// Select the desired encoder mode
CEnumParameter(nodemap, "EncoderMode").SetValue("FourPhase");
// Determine the number of input signals needed to generate an encoder output trigger signal
CIntegerParameter(nodemap, "EncoderDivider").SetValue(1);
// Select the desired encoder output mode
CEnumParameter(nodemap, "EncoderOutputMode").SetValue("Motion");
// Select the desired encoder selector
camera.Parameters[PLCamera.EncoderSelector].SetValue(PLCamera.EncoderSelector.Encoder1);
// Select line 2 as the source signal for the A input of the encoder control
camera.Parameters[PLCamera.EncoderSourceA].SetValue(PLCamera.EncoderSourceA.Line2);
// Select line 3 as the source signal for the B input of the encoder control
camera.Parameters[PLCamera.EncoderSourceB].SetValue(PLCamera.EncoderSourceB.Line3);
// Select the desired encoder mode
camera.Parameters[PLCamera.EncoderMode].SetValue(PLCamera.EncoderMode.FourPhase);
// Determine the number of input signals needed to generate an encoder output trigger signal
camera.Parameters[PLCamera.EncoderDivider].SetValue(1);
// Select the desired encoder output mode
camera.Parameters[PLCamera.EncoderOutputMode].SetValue(PLCamera.EncoderOutputMode.Motion);
/* Macro to check for errors */
#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)
GENAPIC_RESULT errRes = GENAPI_E_OK;  /* Return value of pylon methods */
/* Select the desired encoder selector */
errRes = PylonDeviceFeatureFromString(hdev, "EncoderSelector", "Encoder1");
CHECK(errRes);
/* Select line 2 as the source signal for the A input of the encoder control */
errRes = PylonDeviceFeatureFromString(hdev, "EncoderSourceA", "Line2");
CHECK(errRes);
/* Select line 3 as the source signal for the B input of the encoder control */
errRes = PylonDeviceFeatureFromString(hdev, "EncoderSourceB", "Line3");
CHECK(errRes);
/* Select the desired encoder mode */
errRes = PylonDeviceFeatureFromString(hdev, "EncoderMode", "FourPhase");
CHECK(errRes);
/* Determine the number of input signals needed to generate an encoder output trigger signal */
errRes = PylonDeviceSetIntegerFeature(hdev, "EncoderDivider", 1);
CHECK(errRes);
/* Select the desired encoder output mode */
errRes = PylonDeviceFeatureFromString(hdev, "EncoderOutputMode", "Motion");
CHECK(errRes);
# Select the desired encoder selector
camera.EncoderSelector.Value = "Encoder1"
# Select line 2 as the source signal for the A input of the encoder control
camera.EncoderSourceA.Value = "Line2"
# Select line 3 as the source signal for the B input of the encoder control
camera.EncoderSourceB.Value = "Line3"
# Select the desired encoder mode
camera.EncoderMode.Value = "FourPhase"
# Determine the number of input signals needed to generate an encoder output trigger signal
camera.EncoderDivider.Value = 1
# Select the desired encoder output mode
camera.EncoderOutputMode.Value = "Motion"

您也可以使用 pylon Viewer 轻松设置参数。