FB_VN_GevCameraControl

This FB provides the basic functionality to control a GigE Vision camera and access its calibration data.

Do not call the main FB directly. Only use the available methods.

FB_VN_GevCameraControl 1: Methods

Name

Description

ClearImageQueue

Delete all images contained in the TcVnGevImageProvider TcCOM module receive queue and reset the corresponding omitted images counter.

CloseCamera

Close the control channel to the camera.

GetCalibPatternRef

Gets the reference calibration pattern points from the TcVnGevImageProvider TcCOM module (Can be set from the calibration assistant)

GetCameraMatrix

Gets the camera matrix from the TcVnGevImageProvider TcCOM module (requires intrinsic calibration parameters, e.g. set by the calibration assistant)

GetCurrentImage

Gets the current available image (first in receive queue).

GetCurrentImageUndistorted

Gets the current available image (first in receive queue) with undistortion applied. Incompatible with pixel formats that contain an encoding, e.g. a Bayer pattern. Requires intrinsic calibration parameters in the TcVnGevImageProvider TcCOM module, e.g. set by the calibration assistant.

GetCurrentImageWithGvspInfo

Gets the current available image (first in receive queue) and its corresponding GVSP info.

GetCurrentImageWithGvspInfoUndistorted

Gets the current available image (first in receive queue) with its corresponding GVSP info and undistortion applied. Incompatible with pixel formats that contain an encoding, e.g. a Bayer pattern. Requires intrinsic calibration parameters in the TcVnGevImageProvider TcCOM module, e.g. set by the calibration assistant.

GetDistortionCoefficients

Gets the distortion coefficients from the TcVnGevImageProvider TcCOM module (requires intrinsic calibration parameters, e.g. set by the calibration assistant)

GetLastImageFromQueue

Gets the last received image from the queue.

GetOmittedImagesNum

Gets the number of omitted images since the last call of ClearImageQueue(). If the image receive queue in the TcVnGevImageProvider TcCOM module is full and a new image arrives, the first one in the queue will be deleted and the omitted counter is increased.

GetRotationMatrix

Gets the rotation matrix from the TcVnGevImageProvider TcCOM module (requires extrinsic calibration parameters, e.g. set by the calibration assistant)

GetState

Gets the current state of the internal camera control state machine.

GetTranslationVector

Gets the translation vector from the TcVnGevImageProvider TcCOM module (requires extrinsic calibration parameters, e.g. set by the calibration assistant)

InitializeCamera

Initialize the camera to the intended state (includes sending the 'InitCameraCommands' defined in the GevImageAcquisition TcCOM module to the camera).

OpenCamera

Open a control channel to the camera.

Reset

Reset the camera controller to initial state (might require multiple calls depending on current state, until S_OK is returned)

ResetCameraFeatures

Reset the camera features to initial state (sends the 'InitCameraCommands' defined in the GevImageAcquisition TcCOM module to the camera).

SetCameraMatrix

Sets the camera matrix to the TcVnGevImageProvider TcCOM module

SetDistortionCoefficients

Sets the distortion coefficients to the TcVnGevImageProvider TcCOM module

SetRotationMatrix

Sets the rotation matrix to the TcVnGevImageProvider TcCOM module

SetTranslationVector

Sets the translation vector to the TcVnGevImageProvider TcCOM module

StartAcquisition

Send the 'StartAcquisitionCommands' defined in the TcVnGevImageProvider TcCOM module to the camera.

StopAcquisition

Send the 'StopAcquisitionCommands' defined in the TcVnGevImageProvider TcCOM module to the camera.

TriggerImage

Send the 'SoftwareTriggerCommands' defined in the TcVnGevImageProvider TcCOM module to the camera.

Weiterführende Informationen

Der Funktionsblock FB_VN_GevCameraControl repräsentiert GigE Vision Camera Objekte im vollen Umfang in der SPS. Alternativ kann für einen beschränkten Zugriff auf Kamera Objekte auch der Funktionsblock FB_VN_SimpleCameraControl genutzt werden.

Dieser Funktionsblock ist nicht dafür gedacht, direkt aufgerufen zu werden. Vielmehr enthalten die Methoden sämtliche Funktionalität.

Zustandsautomat

Die nachfolgende Grafik zeigt den Zustandsautomaten. Die Hauptzustände sind dabei blau gekennzeichnet, die Übergangszustände grau und der Error-Zustand rot. In welchem Zustand sich die Kamera befindet, kann über die Methode GetState abgefragt werden. Zudem ist dargestellt, mit welchen Methoden ein Zustandsübergang erreicht werden kann und zu welchem Rückgabewert dieser jeweils führt. Wenn Init Commands vorhanden sind und der InitializationAutoMode AUTOINIT_AFTER_SO ausgewählt wurde, wird auch kurzzeitig der State INITIALIZING angenommen, in dem die automatische Initialisierung erfolgt.

FB_VN_GevCameraControl 2:

Den aktuellen Zustand können Sie mit der Methode GetState abfragen.

Zur Steuerung des Zustandsautomaten können folgende Methoden verwendet werden:

Wenn eine Methode in einem Zustand aufgerufen wird, für den sie nicht gedacht ist, wird der Fehlercode INVALIDSTATE (16#712) zurückgegeben.

HRESULT

Hex

Dec

Code

Beschreibung

16#718

1816

NOTINIT

Kamera wurde noch nicht initialisiert. Initialisieren Sie die Kamera entweder mit der Methode InitializeCamera oder indem Sie den TcCOM-Parameter InitializationAutoMode auf AUTOINIT_SO oder AUTOINIT_AFTER_SO setzen.

16#71A

1818

NOINTERFACE

Der Kamera-Funktionsblock ist nicht mit dem Kamera-TcCOM-Objekt verknüpft. Stellen Sie diese Verknüpfung in der TwinCAT Projektinstanz unter Symbol Initialization her.

Anwendung mit kontinuierlichem Bildeinzug

Ein Zustandsautomat, um eine Kamera in den Bildaufnahme-Modus zu bringen, Fehlerzustände zu behandeln und kontinuierlich erfolgreich aufgenommene Bilder anzuzeigen, sieht z. B. so aus:

VAR
    hr              :   HRESULT;
    ipImageIn       :   ITcVnImage;
    ipImageInDisp   :   ITcVnDisplayableImage;
    fbCameraControl :   FB_VN_GevCameraControl;
    eCameraState    :   ETcVnCameraState;
    nNewImageCounter:   UINT;
END_VAR

eCameraState :=  fbCameraControl.GetState();

// CameraControl is in error state, so try to reset the camera connection
IF eCameraState = TCVN_CS_ERROR THEN
    hr :=  fbCameraControl.Reset();

// Camera not yet initialized
ELSIF eCameraState < TCVN_CS_INITIALIZED THEN
    hr :=  fbCameraControl.InitializeCamera();

// Camera not yet opened
ELSIF eCameraState < TCVN_CS_OPENED THEN
    hr := fbCameraControl.OpenCamera();

// Camera not yet streaming
ELSIF eCameraState < TCVN_CS_ACQUIRING THEN
    hr := fbCameraControl.StartAcquisition();

// Camera streaming
ELSIF eCameraState = TCVN_CS_ACQUIRING THEN
    hr := fbCameraControl.GetCurrentImage(ipImageIn);

    // Check if new Image was received
    IF SUCCEEDED(hr) AND ipImageIn <> 0 THEN
        nNewImageCounter := nNewImageCounter + 1;

        // Place to call vision algorithms
        hr := F_VN_TransformIntoDisplayableImage(ipImageIn, ipImageInDisp, hr);
    END_IF

END_IF

In diesem Fall kann die Kamera auf kontinuierliche Bild-Akquise oder auf einen Hardwaretrigger konfiguriert werden.

Anwendung mit Softwaretrigger

Ein Zustandsautomat, um eine Kamera in den Bildaufnahme-Modus zu bringen, Fehlerzustände zu behandeln und per Softwaretrigger eine Bildaufnahme anzutriggern, sieht z. B. so aus:

VAR
    hr              :   HRESULT;
    ipImageIn       :   ITcVnImage;
    ipImageInDisp   :   ITcVnDisplayableImage;
    fbCameraControl :   FB_VN_GevCameraControl;
    eCameraState    :   ETcVnCameraState;
    nNewImageCounter:   UINT;
    bTrigger        :   BOOL := TRUE;
END_VAR

eCameraState :=  fbCameraControl.GetState();

// CameraControl is in error state, so try to reset the camera connection
IF eCameraState = TCVN_CS_ERROR THEN
    hr :=  fbCameraControl.Reset();

// Camera trigger image
ELSIF eCameraState = TCVN_CS_TRIGGERING THEN
    hr := fbCameraControl.TriggerImage();

// Camera not yet initialized
ELSIF eCameraState < TCVN_CS_INITIALIZED THEN
    hr :=  fbCameraControl.InitializeCamera();

// Camera not yet opened
ELSIF eCameraState < TCVN_CS_OPENED THEN
    hr := fbCameraControl.OpenCamera();

// Camera not yet streaming
ELSIF eCameraState < TCVN_CS_ACQUIRING THEN
    hr := fbCameraControl.StartAcquisition();

// Camera streaming
ELSIF eCameraState = TCVN_CS_ACQUIRING THEN

    IF bTrigger THEN
        hr := fbCameraControl.TriggerImage();
        IF SUCCEEDED(hr) THEN
            bTrigger := FALSE;
        END_IF
    ELSE
        hr := fbCameraControl.GetCurrentImage(ipImageIn);

        // Check if new Image was received
        IF SUCCEEDED(hr) AND ipImageIn <> 0 THEN
            nNewImageCounter := nNewImageCounter + 1;

            // Trigger next image
            bTrigger := TRUE;

            // Place to call vision algorithms
            hr := F_VN_TransformIntoDisplayableImage(ipImageIn, ipImageInDisp, hr);
        END_IF
    END_IF

END_IF

In diesem Fall muss die Kamera auf einen Softwaretrigger (TriggerSource = Software) konfiguriert werden.

Verwandte Funktionsblöcke

Required License

TC3 Vision Base

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1. 4024.44 or later

PC or CX (x64) with PL50, e.g. Intel 4-core Atom CPU

Tc3_Vision