Precision Time Protocol#
IEEE 1588 標準定義了該協定。Basler 相機支援 IEEE 1588-2008(也稱為 PTP Version 2)。
資訊
PTP 同步的精確度很大程度上取決於您的網路硬體與設定。為了達到最高精確度,請選擇高品質的網路硬體、使用支援 PTP 的網路交換器,並在您的網路中加入配備 GPS 接收器的外部 PTP 時脈裝置。
使用此功能#
為什麼使用 PTP#
Precision Time Protocol (PTP) 功能可讓相機在可用時使用以下功能:
運作原理#
透過 PTP,多個裝置(例如相機)會自動與網路中精度最高時脈(稱為主時脈或最佳主時脈)進行同步。
該協定可讓網路內的系統執行以下操作:
- 與主時脈同步,即盡可能精確地將本機時脈設為主時脈的時間。
- 與主時脈調頻,即將本機時脈的頻率調整為主時脈的頻率。您會希望兩個裝置上「一秒」的持續時間盡可能完全相同。
主時脈由多個條件決定。優先權最高的條件是裝置的 Priority 1 設定。
Timestamp 同步#
Precision Time Protocol (IEEE 1588) 的基本概念是基於 PTP 訊息的交換。這些訊息可讓從屬時脈同步其 時間戳記 值與主時脈的 Timestamp 值。對於 Basler 相機而言,這意味著其 TimestampLatchValue Property 值將盡可能保持一致。精確度很大程度上取決於您的網路硬體和設定。
如果網路中的沒有任何裝置與協調世界時(例如 TAI 或 UTC)同步,網路將在任意時間尺度模式 (ARB) 下運作。在此模式下,時期(epoch)是任意的,因為它不繫結至絕對時間。時間尺度是相對的,且僅在此網路中有效。
資訊
- IEEE 1588 定義了用於儲存和傳輸時間資訊的 80-bit Timestamp。由於 GigE Vision 使用 64-bit Timestamp,因此 PTP Timestamp 會對應至 GigE Vision 的 64-bit Timestamp。
- 在沒有其他 PTP 啟用裝置的網路中運作的 PTP 啟用裝置不會校準其本機時脈。其本機時脈的精確度與未啟用 PTP 的裝置相同。
- 如需有關 Precision Time Protocol 的詳細資訊,請參閱 Synchronous and in Real Time: Multi-Camera Applications in the GigE Network 白皮書。
啟用 PTP 時鐘同步#
相機開機時,PTP 預設為停用。如果您想要使用 PTP,則必須啟用它。
若要啟用 PTP:
- 如果您想要使用外部裝置作為主時脈(例如 GPS 接收器),請將該外部裝置設定為主時脈。
Basler 建議將 ANNOUNCE 間隔設為 2 秒,SYNC 間隔設為 0.5 秒。 - 請確保所有您希望透過「PTP 」進行同步的攝影機均已正確設定。
- 在所有您希望透過PTP 進行同步的攝影機上,請設定
GevIEEE1588參數設為true. - 請等待所有PTP 網路裝置完成充分同步。根據您的網路設定,此過程可能需要幾秒鐘或幾分鐘。
您可透過檢查PTP 時鐘同步狀態,來判斷裝置何時已完成同步。
現在,您可以使用支援「PTP 」功能的相機功能。
資訊
在 aceClassic/U/L 相機上,啟用PTP 時鐘同步功能會將相機的內部時鐘頻率從 125 MHz(即 8 ns 時鐘週期)變更為 1 GHz(即 1 ns 時鐘週期)。「封包間延遲」與「幀傳輸延遲」參數的數值會自動調整。
在其他相機上,時鐘頻率始終為 1 GHz。
設定 PTP 時鐘同步#
根據您的相機型號,可使用以下設定:
Priority 1#
在啟用了 PTP 的網路中,主時鐘由多個條件決定。最重要的條件是裝置的 Priority 1 設定。具有最低 Priority 1 設定的網路裝置為主時鐘。
在 ace 2 與 dart M 相機,您可以變更 Priority 1 設定以強制相機成為主時鐘,或防止相機成為主時鐘。若要這樣做,請將 BslPtpPriority1 參數設為 0(最高優先順序)到 255(最低優先順序)之間的值。
在其他相機上,Priority 1 設定預設為 128 且無法變更。
資訊
如需有關主時鐘條件的詳細資訊,請參閱 IEEE 1588-2008 規範第 7.6.2.2 節。
PTP 延遲機制#
延遲量測機制定義了如何在網路內傳送與接收 PTP 延遲量測訊息。PTP 標準定義了兩種機制:端對端(E2E,又稱「延遲請求-回應」)與點對點(P2P)。如需詳細資訊,請參閱這篇文章。
在 ace 2 與 dart M 相機,您可以變更延遲量測機制。若要這樣做,請將 BslPtpProfile 參數設為 DelayRequestResponseDefaultProfile (預設)或 PeerToPeerDefaultProfile.
在其他相機上,延遲量測機制預設為端對端且無法變更。
資訊
網路模式#
網路模式設定定義了 PTP 訊息如何在網路內傳輸。
在 ace 2 相機,您可以變更網路模式。若要這樣做,請將 BslPtpNetworkMode 參數設為下列其中一個值:
Multicast:PTP 訊息會傳送至本機網路中所有設定為 PTP 多點傳送的裝置。這是預設模式,足以應付大多數的使用情境。Hybrid:PTP 訊息會使用多點傳送和單點傳送訊息來傳送。這可減少需要處理的訊息數量,進而節省網路負載。如需詳細資訊,請參閱 這篇文章.Unicast: PTP 訊息會傳送至本機網路中的一個或多個指定設備。其他設備無法接收 PTP 訊息。
若要設定單點傳播 (unicast):- 請確保
BslPtpNetworkMode且Unicast. - 將
BslPtpUcPortAddrIndex參數設為 0。 - 將
BslPtpUcPortAddr參數設為第一個接收裝置的 IP 位址。 - 將
BslPtpUcPortAddrIndex參數增加 1。 - 將
BslPtpUcPortAddr參數設為下一個接收裝置的 IP 位址。 - 對於所有相關的 PTP 設備,重複步驟 3 和 4。
- 請確保
在其他相機上,網路模式預設為多點傳播 (multicast)。不過,這些相機也可以接收單點傳播 (unicast) 訊息並做出相應回應。
資訊
使用單點傳播 (unicast) 模式時,所有相關設備都必須支援單點傳播 (unicast) 協商。某些 PTP 實作不支援單點傳播 (unicast) 協商,因此與 Basler 相機不相容。
PTP 管理#
PTP 管理協定允許您透過管理訊息讀取任何 PTP 設備的設定,也就是說,無需使用 pylon API。如果允許,也可以寫入設定。
在ace 2 and dart M cameras上,您可以啟用或停用 PTP 管理。若要這樣做:
- 啟用 PTP 時鐘同步。
- 將
BslPtpManagementEnable參數設為下列其中一個值:true: 您可以使用包含以下訊息 ID 的管理訊息來讀取設定 (GET)、寫入設定 (SET) 以及執行命令 (COMMAND) 如下所列.false(預設):PTP 管理協定已停用,且無法讀取或寫入設定。
在其他相機上,PTP 管理始終處於啟用狀態,且預設為唯讀存取。
支援的管理訊息#
| 管理訊息 ID | 支援的操作 |
|---|---|
| NULL_MANAGEMENT | GET, SET |
| CLOCK_DESCRIPTION | GET |
| USER_DESCRIPTION | GET, SET |
| INITIALIZE | COMMANDa |
| DEFAULT_DATA_SET | GET |
| CURRENT_DATA_SET | GET |
| PARENT_DATA_SET | GET |
| TIME_PROPERTIES_DATA_SET | GET |
| PORT_DATA_SET | GET |
| PRIORITY1 | GET, SET |
| PRIORITY2 | GET, SET |
| DOMAIN | GET |
| SLAVE_ONLY | GET |
| LOG_ANNOUNCE_INTERVAL | GET, SET |
| ANNOUNCE_RECEIPT_TIMEOUT | GET, SET |
| LOG_SYNC_INTERVAL | GET, SET |
| VERSION_NUMBER | GET |
| ENABLE_PORT | COMMAND |
| DISABLE_PORT | COMMAND |
| TIME | GET, SETb |
| CLOCK_ACCURACY | GET, SET |
| UTC_PROPERTIES | GET, SET |
| TRACEABLE_PROPERTIES | GET, SET |
| TIMESCALE_PROPERTIES | GET, SET |
| UNICAST_NEGOTIATION_ENABLE | GET |
| ACCEPTABLE_MASTER_TABLE | GET, SET |
| ACCEPTABLE_MASTER_TABLE_ENABLED | GET, SET |
| ACCEPTABLE_MASTER_MAX_TABLE_SIZE | GET |
| DELAY_MECHANISM | GET, SET |
| LOG_MIN_PDELAY_REQ_INTERVAL | GET, SET |
-
INITIALIZE 命令會重設時脈速度。
-
僅當對應的裝置作為主時脈 (grandmaster clock) 時才能設定。
如需這些屬性的預設值與範圍的相關資訊,請參閱 IEEE 1588-2008 規範附錄 J。
單步或雙步時鐘#
此設定定義了針對需要發送 Timestamp 的任何 PTP 事件訊息要產生多少訊息:
- 在一步式 (one-step) 作業中,會發送一則訊息。該訊息包含訊息資料與發送 Timestamp。
- 在兩步式 (two-step) 作業中,會發送兩則訊息。第一則訊息包含訊息資料。第二則訊息包含發送 Timestamp。
如需詳細資訊,請參閱這篇文章。
在 ace 2 與 dart M 相機,兩步式作業預設為停用。如果網路中的其他 PTP 裝置明確要求兩步式事件訊息,您可以透過設定以下項目來啟用它們: BslPtpTwoStep 參數設為 true.
在其他相機上,兩步式作業一律為啟用。
檢查 PTP 時鐘同步的狀態#
若要檢查 PTP 時脈同步狀態,您必須使用 pylon API 開發您自己的檢查方法。
PTP 狀態檢查的典型實作包含下列步驟:
- 執行
GevIEEE1588DataSetLatch命令。
此命令允許您對相機目前的 PTP 狀態進行「快照」。此「快照」實作可確保 已鎖存資料集中的所有參數值 皆指向完全相同的時間點。 - 等待直到
GevIEEE1588Status參數值不再為Initializing. -
根據相機型號,從裝置讀取下列參數值:
- 在 ace 2 與 dart M 相機,從所有從屬相機讀取
PtpServoStatus參數。如果參數值為Locked,則各自的裝置應已充分同步。如果您需要更精確的狀態檢查,請改為遵循下方的「其他相機」程序。 -
在 其他相機,從所有從屬相機讀取
GevIEEE1588OffsetFromMaster來自所有從屬相機的參數值,直到主時脈的最大偏移低於特定閾值(根據您的需求,例如 1 毫秒)。
由於時脈持續由控制機制進行調整,因此偏移並不會單調遞減。Basler 建議您檢查特定時間窗口內的最大GevIEEE1588OffsetFromMaster參數值:
- 在 ace 2 與 dart M 相機,從所有從屬相機讀取
-
重複步驟 1 和 2,直到裝置充分同步為止。
鎖存資料集中包含什麼?#
執行 GevIEEE1588DataSetLatch 指令後,您可以從裝置讀取下列參數值:
GevIEEE1588ClockId:指出目前 PTP 裝置的唯一 ID(「時脈 ID」)。GevIEEE1588OffsetFromMaster:指出主時脈與目前 PTP 裝置時脈之間以 Tick 為單位的估計時間差(1 tick = 1 奈秒)。GevIEEE1588ParentClockId:指出目前作為主時脈的 PTP 裝置之時脈 ID(「父時脈 ID」)。GevIEEE1588Status:指出目前 PTP 裝置的狀態,例如它是主時脈還是從屬時脈。傳回的值符合 PTP 連接埠狀態列舉(Initializing、Faulty、Disabled、Listening、Pre_Master、Master、Passive、Uncalibrated 與 Slave)。如需詳細資訊,請參閱 pylon API 文件以及 IEEE 1588-2008 規範.GevIEEE1588StatusLatched:如果此參數可用,Basler 建議使用它來取代GevIEEE1588Status參數。這是因為GevIEEE1588Status參數並未繫結至GevIEEE1588DataSetLatch指令。因此,如果您從裝置讀取多個與 PTP 相關的值,裝置狀態將不會與其他值對應至同一個時間點。
其他參數#
在 ace 2 與 dart M 相機,執行 PtpDataSetLatch 指令後,您可以從裝置讀取下列額外的參數值:
BslPtpDelayMechanism:指出 延遲機制 由 PTP 網路使用。值為E2E表示使用延遲請求-回應機制。值為P2P表示使用點對點機制。PtpClockAccuracy:指出 PTP 裝置時脈在作為或成為主時脈(Grandmaster)時的預期準確度。在 Basler 相機上,預期準確度預設為Unknown。這是因為 Basler 相機不會與世界協調時間(例如 UTC)進行同步。PtpGrandmasterClockID:指出目前作為主時脈(Grandmaster clock)的 PTP 裝置之時脈 ID。PtpServoStatus:指出時脈伺服器的狀態,即 PTP 時脈同步的狀態。如果狀態為Locked,則目前裝置的時脈已成功與主時脈同步。在所有其他情況下,狀態為Unknown.
外部連結#
- 端對端與點對端(時間同步部落格)
- Hybrid Mode PTP:混合多播與單播(時間同步部落格)
- IEEE 1588-2008 規範(IEEE 標準協會)
- 單步還是雙步?(時間同步部落格)
- Precision Time Protocol(維基百科)
- 白皮書:同步與即時:GigE 網路中的多鏡頭應用(Basler)
範例程式碼#
ace 相機#
// ** Configure PTP **
// Set Priority 1 to 128
camera.BslPtpPriority1.SetValue(128);
// Enable end-to-end delay measurement
camera.BslPtpProfile.SetValue(BslPtpProfile_DelayRequestResponseDefaultProfile);
// Set the network mode to unicast
camera.BslPtpNetworkMode.SetValue(BslPtpNetworkMode_Unicast);
// Set the IP address of the first unicast device to 192.168.10.12
// (0xC0 = 192, 0xA8 = 168, 0x0A = 10, 0x0C = 12)
camera.BslPtpUcPortAddrIndex.SetValue(0);
camera.BslPtpUcPortAddr.SetValue((0xC0A80A0C);
// Enable PTP Management Protocol
camera.BslPtpManagementEnable.SetValue(true);
// Disable two-step operation
camera.BslPtpTwoStep.SetValue(false);
// ** Enable PTP on the current device **
camera.PtpEnable.SetValue(true);
// To check the status of the PTP clock synchronization,
// implement your own check method here.
// For guidelines, see "Checking the Status of
// the PTP Clock Synchronization" in this topic.
INodeMap& nodemap = camera.GetNodeMap();
// ** Configure PTP **
// Set Priority 1 to 128
CIntegerParameter(nodemap, "BslPtpPriority1").SetValue(128);
// Enable end-to-end delay measurement
CEnumParameter(nodemap, "BslPtpProfile").SetValue("DelayRequestResponseDefaultProfile");
// Set the network mode to unicast
CEnumParameter(nodemap, "BslPtpNetworkMode").SetValue("Unicast");
// Set the IP address of the first unicast device to 192.168.10.12
// (0xC0 = 192, 0xA8 = 168, 0x0A = 10, 0x0C = 12)
CIntegerParameter(nodemap, "BslPtpUcPortAddrIndex").SetValue(0);
CIntegerParameter(nodemap, "BslPtpUcPortAddr").SetValue(0xC0A80A0C);
// Enable PTP Management Protocol
CBooleanParameter(nodemap, "BslPtpManagementEnable").SetValue(true);
// Disable two-step operation
CBooleanParameter(nodemap, "BslPtpTwoStep").SetValue(false);
// ** Enable PTP on the current device **
CBooleanParameter(nodemap, "PtpEnable").SetValue(true);
// To check the status of the PTP clock synchronization,
// implement your own check method here.
// For guidelines, see "Checking the Status of
// the PTP Clock Synchronization" in this topic.
// ** Configure PTP **
// Set Priority 1 to 128
camera.Parameters[PLCamera.BslPtpPriority1].SetValue(128);
// Enable end-to-end delay measurement
camera.Parameters[PLCamera.BslPtpProfile].SetValue(PLCamera.BslPtpProfile.DelayRequestResponseDefaultProfile);
// Set the network mode to unicast
camera.Parameters[PLCamera.BslPtpNetworkMode].SetValue(PLCamera.BslPtpNetworkMode.Unicast);
// Set the IP address of the first unicast device to 192.168.10.12
// (0xC0 = 192, 0xA8 = 168, 0x0A = 10, 0x0C = 12)
camera.Parameters[PLCamera.BslPtpUcPortAddrIndex].SetValue(0);
camera.Parameters[PLCamera.BslPtpUcPortAddr].SetValue(0xC0A80A0C);
// Enable PTP Management Protocol
camera.Parameters[PLCamera.BslPtpManagementEnable].SetValue(true);
// Disable two-step operation
camera.Parameters[PLCamera.BslPtpTwoStep].SetValue(false);
// ** Enable PTP on the current device **
camera.Parameters[PLCamera.PtpEnable].SetValue(true);
// To check the status of the PTP clock synchronization,
// implement your own check method here.
// For guidelines, see "Checking the Status of
// the PTP Clock Synchronization" in this topic.
/* 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 */
/* ** Configure PTP ** */
/* Set Priority 1 to 128 */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslPtpPriority1", 128);
CHECK(errRes);
/* Enable end-to-end delay measurement */
errRes = PylonDeviceFeatureFromString(hdev, "BslPtpProfile", "DelayRequestResponseDefaultProfile");
CHECK(errRes);
/* Set the network mode to unicast */
errRes = PylonDeviceFeatureFromString(hdev, "BslPtpNetworkMode", "Unicast");
CHECK(errRes);
/* Set the IP address of the first unicast device to 192.168.10.12 */
/* (0xC0 = 192, 0xA8 = 168, 0x0A = 10, 0x0C = 12) */
errRes = PylonDeviceSetIntegerFeature(hdev, "BslPtpUcPortAddrIndex", 0);
CHECK(errRes);
errRes = PylonDeviceSetIntegerFeature(hdev, "BslPtpUcPortAddr", 0xC0A80A0C);
CHECK(errRes);
/* Enable PTP Management Protocol */
errRes = PylonDeviceSetBooleanFeature(hdev, "BslPtpManagementEnable", 1);
CHECK(errRes);
/* Disable two-step operation */
errRes = PylonDeviceSetBooleanFeature(hdev, "BslPtpTwoStep", 0);
CHECK(errRes);
/* ** Enable PTP on the current device ** */
errRes = PylonDeviceSetBooleanFeature(hdev, "PtpEnable", 1);
CHECK(errRes);
/* To check the status of the PTP clock synchronization, */
/* implement your own check method here. */
/* For guidelines, see "Checking the Status of */
/* the PTP Clock Synchronization" in this topic. */
# ** Configure PTP **
# Set Priority 1 to 128
camera.BslPtpPriority1.Value = 128
# Enable end-to-end delay measurement
camera.BslPtpProfile.Value = "DelayRequestResponseDefaultProfile"
# Set the network mode to unicast
camera.BslPtpNetworkMode.Value = "Unicast"
# Set the IP address of the first unicast device to 192.168.10.12
# (0xC0 = 192, 0xA8 = 168, 0x0A = 10, 0x0C = 12)
camera.BslPtpUcPortAddrIndex.Value = 0
camera.BslPtpUcPortAddr.Value = 0xC0A80A0C
# Enable PTP Management Protocol
camera.BslPtpManagementEnable.Value = True
# Disable two-step operation
camera.BslPtpTwoStep.Value = False
# ** Enable PTP on the current device **
camera.PtpEnable.Value = True
# To check the status of the PTP clock synchronization,
# implement your own check method here.
# For guidelines, see "Checking the Status of
# the PTP Clock Synchronization" in this topic.
其他相機#
INodeMap& nodemap = camera.GetNodeMap();
// Enable PTP on the current device
CBooleanParameter(nodemap, "GevIEEE1588").SetValue(true);
// To check the status of the PTP clock synchronization,
// implement your own check method here.
// For guidelines, see "Checking the Status of
// the PTP Clock Synchronization" in this topic.
/* 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 */
/* Enable PTP on the current device */
errRes = PylonDeviceSetBooleanFeature(hdev, "GevIEEE1588", 1);
CHECK(errRes);
/* To check the status of the PTP clock synchronization, */
/* implement your own check method here. */
/* For guidelines, see "Checking the Status of */
/* the PTP Clock Synchronization" in this topic. */
您也可以使用 pylon Viewer 來輕鬆設定參數。