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.

GetCurrentImageWithTimestamps

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

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.

Further information

The function block FB_VN_GevCameraControl represents GigE Vision Camera objects to the full extent in the PLC. Alternatively, the function block FB_VN_SimpleCameraControl can also be used for limited access to camera objects.

This function block is not intended to be called directly. In fact, the methods contain all functionalities.

State machine

The following diagram shows the state machine. The main states are marked in blue, the transition states are gray and the error state is red. The GetState method can be used to query the state of the camera. In addition, the methods with which a state transition can be achieved and the return value to which each leads are shown. If Init Commands are present and the Initialization Auto Mode AUTOINIT_AFTER_SO has been selected, the INITIALIZING state in which the automatic initialization takes place is also briefly assumed.

FB_VN_GevCameraControl 2:

You can query the current state using the GetState method.

The following methods can be used to control the state machine:

If a method is called in a state for which it is not intended, the error code INVALIDSTATE (16#712) is returned.

HRESULT

Hex

Dec

Code

Description

16#718

1816

NOTINIT

Camera has not yet been initialized. Initialize the camera either with the method InitializeCamera or by setting the TcCOM parameter InitializationAutoMode to AUTOINIT_SO or AUTOINIT_AFTER_SO.

16#71A

1818

NOINTERFACE

The camera function block is not linked to the camera TcCOM object. Establish this link in the TwinCAT project instance under Symbol Initialization.

Application with continuous image acquisition

A state machine for placing a camera in image acquisition mode, handling error states and continuously displaying successfully captured images looks like this, for example:

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 this case, the camera can be configured to continuous image acquisition or to a hardware trigger.

Application with software trigger

A state machine for putting a camera into image acquisition mode, handling error states and triggering image acquisition via software trigger looks like this, for example:

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 this case, the camera must be configured to a software trigger (TriggerSource = software).

Related function blocks

Required License

TC3 Vision Base

System Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT V3.1.4024.54 or later

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

Tc3_Vision