跳转到内容

Precision Time Protocol#

相机的 Precision Time Protocol (PTP) 功能可让您同步同一网络中的多个 GigE 相机。

IEEE 1588标准定义了该协议。Basler 相机支持 IEEE 1588-2008,也称为 PTP 版本 2。

信息

PTP 同步的精度在很大程度上取决于您的网络硬件和设置。为了获得最高精度,请选择高质量的网络硬件、使用支持 PTP 的网络交换机,并向您的网络添加一个带有 GPS 接收器的外部 PTP 时钟设备。

该功能的使用#

为什么使用 PTP#

Precision Time Protocol (PTP) 功能使相机可以使用以下功能(如果可用):

运作原理#

通过 PTP,多台设备(例如相机)会自动与网络中找到的最准确的时钟(称为主时钟或最佳主时钟)同步。

该协议使网络中的系统可以执行以下操作:

  • 与主时钟同步,即,将本地时钟尽可能精确地设置为主时钟的时间。
  • 与主时钟同步,即,将本地时钟的频率调整为主时钟的频率。您希望两台设备上 1 秒钟的持续时间尽可能保持相同。

主时钟由几个条件决定。最高优先级的条件是设备的优先级 1 设置。

时间戳同步#

The basic concept of the Precision Time Protocol (IEEE 1588) is based on the exchange of PTP messages. These messages allow the slave clocks to synchronize their timestamp value with the timestamp value of the master clock. For Basler cameras, this means that their TimestampLatchValue parameter values will be as identical as possible. The precision highly depends on your network hardware and setup.

如果网络中没有设备同步到协调世界时间(例如 TAI 或 UTC),网络将以任意时标模式 (ARB) 运行。在此模式下,epoch 是任意的,因为它不受绝对时间的限制。时标是相对的,仅在此网络中有效。

信息

  • IEEE 1588 定义了用于存储和传输时间信息的 80 位时间戳。因为 GigE Vision 使用 64 位时间戳,所以 PTP 时间戳映射到 GigE Vision 的 64 位时间戳。
  • 如果支持 PTP 的设备在没有其他支持 PTP 的设备的网络中运行,则该设备不会调整其本地时钟。其本地时钟的精度与不支持 PTP 的设备相同。
  • 有关 Precision Time Protocol 的更多信息,请参见 GigE 网络白皮书中的同步和实时:多相机应用

启用 PTP 时钟同步#

开启相机电源时,始终禁用 PTP。如果要使用 PTP,必须自行启用。

要启用 PTP:

  1. 如果要将外部设备用作主时钟(例如 GPS 接收器),请将外部设备配置为主时钟。
    Basler 建议将 ANNOUNCE 间隔设为 2 秒,将 SYNC 间隔设为 0.5 秒。
  2. 确保要通过 PTP 同步的所有相机均已正确配置
  3. On all cameras that you want to synchronize via PTP, set the GevIEEE1588 parameter to true.
  4. 等待全部 PTP 网络设备已充分同步。根据您的网络设置,这可能需要几秒钟或几分钟。
    您可以通过检查设备的 PTP 时钟同步状态来确定何时同步设备。

现在,您可以使用启用 PTP 的相机功能

信息

在 ace Classic/U/L 相机上,启用 PTP 时钟同步会将相机的内部滴答频率从 125 MHz(= 8 ns 滴答持续时间)更改为 1 GHz(= 1 ns 滴答持续时间)。包间隔帧传输延迟参数值会自动调整。
在其他相机上,滴答频率始终为 1 GHz。

配置 PTP 时钟同步#

根据您的相机型号,可以使用以下设置:

优先级 1#

在启用 PTP 的网络中,主时钟由几个条件决定。最重要的条件是设备的“优先级 1”设置。具有最低“优先级 1”设置的网络设备是主时钟。

On ace 2 cameras, you can change the Priority 1 setting to force a camera to be the master clock, or to prevent a camera from being the master clock. To do so, set the BslPtpPriority1 parameter to a value between 0 (highest priority) and 255 (lowest priority).

其他相机上,“优先级 1”设置预设为 128,无法更改。

信息

有关主时钟标准的更多信息,请参见 IEEE 1588-2008 规范的条款 7.6.2.2。

PTP 延迟机制#

延迟测量机制定义了如何在网络内发送和接收 PTP 延迟测量消息。PTP 标准定义了两种机制:端到端(E2E,也称为“延迟请求-响应”)和点对点 (P2P)。有关更多信息,请参见本文

On ace 2 cameras, you can change the delay measurement mechanism. To do so, set the BslPtpProfile parameter to DelayRequestResponseDefaultProfile (default) or PeerToPeerDefaultProfile.

其他相机上,延迟测量机制预设为端到端,无法更改。

信息

  • 在大多数情况下,请使用端到端延迟测量。仅当整个网络都设置为点对点延迟测量时,才使用点对点。这意味着所有交换机和路由器都启用了 PTP,并且所有 PTP 设备都配置为点对点通信。
  • 使用点对点延迟测量时,以下限制适用:

网络模式#

网络模式设置定义了如何在网络内传输 PTP 消息。

On ace 2 cameras, you can change the network mode. To do so, set the BslPtpNetworkMode parameter to one of the following values:

  • Multicast: PTP messages are sent to all devices in the local network that are configured for PTP multicasting. This is the default mode and sufficient for most use cases.
  • Hybrid: PTP messages are sent using multicast and unicast messages. This saves network load because fewer messages have to be processed. For more information, see this article.
  • 单播:PTP 消息被发送到本地网络中的一个或多个指定设备。其他设备无法接收 PTP 消息。
    要配置单播,请执行以下操作:
    1. Make sure that the BslPtpNetworkMode is set to Unicast.
    2. Set the BslPtpUcPortAddrIndex parameter to 0.
    3. Set the BslPtpUcPortAddr parameter to the IP address of the first receiving device.
    4. Increase the BslPtpUcPortAddrIndex parameter by 1.
    5. Set the BslPtpUcPortAddr parameter to the IP address of the next receiving device.
    6. 对涉及的所有 PTP 设备重复步骤 3 和 4。

其他相机上,网络模式预设为多播。但是,这些相机也可以接收单播消息并做出相应响应。

信息

使用单播模式时,涉及的所有设备都必须支持单播协商。一些 PTP 实现不使用单播协商,因此与 Basler 相机不兼容。

PTP 管理#

PTP 管理协议可让您通过管理消息读取任何 PTP 设备的设置,即无需使用 pylon API。如果允许,也可以写入设置。

ace 2 相机上,可以启用或禁用 PTP 管理。为此:

  1. 启用 PTP 时钟同步
  2. 设置 BslPtpManagementEnable 参数设置为以下值:
    • true: You can read settings (GET), write settings (SET), and execute commands (COMMAND) using management messages with the message IDs listed below.
    • false (default): The PTP Management Protocol is disabled, and settings can neither be read nor written.

其他相机上,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

  1. INITIALIZE 命令可重置时钟速度。

  2. 仅当相应的设备用作超级主时钟时才能设置。

有关这些属性的默认值和范围的信息,请参见 IEEE 1588-2008 规范附录 J。

一步或两步时钟#

此设置定义为需要出口 timestamp 的任何 PTP 事件消息生成多少条消息:

  • 一步操作中,发送一条消息。该消息包括消息数据和出口 timestamp。
  • 两步操作中,发送两条消息。第一条消息包括消息数据。第二条消息包括出口 timestamp。

有关更多信息,请参见本文

On ace 2 cameras, two-step operation is disabled by default. If another PTP device in the network explicitly requires two-step event messages, you can enable them by setting the BslPtpTwoStep parameter to true.

其他相机上,始终启用两步操作。

检查 PTP 时钟同步的状态#

要检查 PTP 时钟同步的状态,您必须使用 pylon API。

一个典型的 PTP 状态检查实现包含以下步骤:

  1. Execute the GevIEEE1588DataSetLatch command.
    The command allows you to take a "snapshot" of the camera's current PTP state. The "snapshot" implementation ensures that all parameter values in the latched data set refer to exactly the same point in time.
  2. Wait until the GevIEEE1588Status parameter value is no longer Initializing.
  3. 从设备读取以下参数值,具体取决于相机型号:

    • On ace 2 cameras, read the PtpServoStatus parameter from all slave cameras. If the parameter value is Locked, the respective device should be sufficiently synchronized. If you need a more refined status check, follow the "other cameras" procedure below instead.
    • On other cameras, read the GevIEEE1588OffsetFromMaster parameter value from all slave cameras until the highest offset from master is below a certain threshold (according to your requirements, e.g., 1 millisecond).
      Due to the fact that the clock is continuously adjusted by a control mechanism, the offset is not decreasing monotonically. Basler recommends that you check the maximum GevIEEE1588OffsetFromMaster parameter value within a given time window:

      PTP 相对于主振幅的偏移

  4. 重复步骤 1 和 2,直到设备充分同步。

锁存数据集内包含什么?#

After executing the GevIEEE1588DataSetLatch command, you can read the following parameter values from the device:

  • GevIEEE1588ClockId: Indicates the unique ID of the current PTP device (the "clock ID").
  • GevIEEE1588OffsetFromMaster: Indicates the estimated temporal offset between the master clock and the clock of the current PTP device in ticks (1 tick = 1 nanosecond).
  • GevIEEE1588ParentClockId: Indicates the clock ID of the PTP device that currently serves as the master clock (the "parent clock ID").
  • GevIEEE1588Status: Indicates the state of the current PTP device, e.g., whether it is a master or a slave clock. The returned values match the PTP port state enumeration (Initializing, Faulty, Disabled, Listening, Pre_Master, Master, Passive, Uncalibrated, and Slave). For more information, refer to the pylon API documentation and the IEEE 1588-2008 specification.
  • GevIEEE1588StatusLatched: If this parameter is available, Basler recommends using it instead of the GevIEEE1588Status parameter. This is because the GevIEEE1588Status parameter is not tied to the GevIEEE1588DataSetLatch command. Therefore, if you read multiple PTP-related values from a device, the device state will not relate to the same point in time as the other values.
附加参数#

On ace 2 cameras, after executing the PtpDataSetLatch command, you can read the following additional parameter values from the device:

  • BslPtpDelayMechanism: Indicates the delay mechanism used by the PTP network. A value of E2E indicates that the Delay Request-Response mechanism is used. A value of P2P indicates that the peer-to-peer mechanism is used.
  • PtpClockAccuracy: Indicates the expected accuracy of the PTP device clock when it is or becomes the grandmaster. On Basler cameras, the expected accuracy is preset to Unknown. This is because Basler cameras don't synchronize to a coordinated world time, e.g., UTC.
  • PtpGrandmasterClockID: Indicates the clock ID of the PTP device that currently serves as the grandmaster clock.
  • PtpServoStatus: Indicates the state of the clock servo, i.e., the state of the PTP clock synchronization. If the state is Locked, the clock of the current device is successfully synchronized with the master clock. In all other cases, the state is Unknown.

示例代码#

ace 2 相机#
// ** 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.
其他相机#
// Enable PTP on the current device
camera.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.
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.
// Enable PTP on the current device
camera.Parameters[PLCamera.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. */
# Enable PTP on the current device
camera.GevIEEE1588.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.

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