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

Encoder Control#

透過 Encoder Control camera feature,您可以控制並監控正交編碼器(quadrature encoder)。

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

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:不會產生輸出觸發訊號。

其他參數#

  • EncoderDivider:決定產生 Encoder 輸出觸發訊號所需的 Encoder 輸入訊號數量。
  • EncoderValue:取得 Counter 的目前值。此 Property 為唯讀。
  • EncoderReset:將 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 來輕鬆設定參數。