跳至內容
測試伺服器
開發伺服器

Encoder Control#

Encoder Control camera feature 允許您控制和監控正交編碼器。

正交編碼器也稱為增量式、旋轉式或軸式編碼器。它們通常用於必須測量運動或位置變化的自動化應用中。

Encoder Control 功能僅適用於 Basler racer 2 相機。

使用此功能#

運作原理#

Encoder Control 連接到正交編碼器(可以是旋轉式或線性式),該編碼器會產生兩個輸出訊號 A 和 B。這些也稱為相位或來源 A 和 B。這兩個訊號具有 90° 的相位差,用於追蹤編碼器的前進和後退運動方向。相位 A 和 B 是相機 Encoder Control 的輸入訊號。

下圖顯示了 Encoder Control 的典型實作方式。

典型 Encoder Control 實作

Encoder Direction of Motion#

編碼器可以向前或向後移動。為了偵測運動方向,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 Mode#

Encoder mode 控制 Encoder Control 如何計算輸入的編碼器訊號。

Four Phase Mode#

四個完全完成的訊號相位構成一個正交週期。每個完整的正交週期(即當 A 訊號緣上升時),正交編碼器計數器遞增或遞減 1。

Four Phase 模式相當穩健,允許過濾掉兩個相位之間少量的訊號抖動。

Four Phase Mode

High Resolution Mode#

在 High Resolution 模式下,每個週期的計數會變成四倍。編碼器計數器在每個訊號相位上遞增或遞減 1,即當 A 和 B 訊號緣上升和下降時。

High Resolution Mode

資訊

在 High Resolution 模式下無法進行抖動過濾。因此,不建議將 High Resolution 模式與 encoder output mode 設為 Motion 一起使用,因為兩個相位之間的抖動可能會導致連續的輸出觸發脈衝。

Encoder Output Mode#

encoder output mode 允許您設定 Encoder Control 產生有效輸出訊號的條件。提供以下 encoder output mode:

  • Motion:無論運動方向如何,都會產生輸出觸發訊號。
  • DirectionUp:在 前進 方向。系統會忽略向後的運動方向。
  • DirectionDown:在 向後 方向。系統會忽略向前的運動方向。
  • PositionUp: 在所有 新 位置中產生輸出觸發信號 前進 方向。如果 Encoder 反向,在重新通過反向開始的位置之前,將不會產生任何輸出觸發信號。
  • PositionDown: 在所有 新 位置中產生輸出觸發信號 向後 方向。如果 Encoder 反向,在重新通過反向開始的位置之前,將不會產生任何輸出觸發信號。
  • Off: 不產生輸出觸發信號。

其他 Property#

  • EncoderDivider: 決定產生 Encoder 輸出觸發信號所需的 Encoder 輸入信號數量。
  • EncoderValue: 取得 position Counter 的目前值。此 Property 為唯讀。
  • EncoderReset: 將 position Counter 的目前 Counter 值重設為 0。這也會重設並重新啟動整個 Encoder Control。信號脈衝會在重新啟動後立即開始計數。

設定 Encoder Control#

若要設定 Encoder Control:

  1. 將 EncoderSelector 參數設為 Encoder1.
  2. 將 EncoderSourceA Property 設為其中一個可用的來源信號,例如: Line2.
  3. 將 EncoderSourceB Property 設為其中一個可用的來源信號,例如: Line3.
  4. 將 EncoderMode 參數設為下列其中一個值:
  5. 將 EncoderDivider Property 設為所需的輸入信號數量。
  6. 將 EncoderOutputMode Property 設為要啟用的 output mode 類型,例如: Motion.

若要設定相機由 Encoder 信號觸發:

  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 來輕鬆設定參數。