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.
Methods
Name |
Description |
---|---|
Delete all images contained in the TcVnGevImageProvider TcCOM module receive queue and reset the corresponding omitted images counter. | |
Close the control channel to the camera. | |
Gets the reference calibration pattern points from the TcVnGevImageProvider TcCOM module (Can be set from the calibration assistant) | |
Gets the camera matrix from the TcVnGevImageProvider TcCOM module (requires intrinsic calibration parameters, e.g. set by the calibration assistant) | |
Gets the current available image (first in receive queue). | |
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. | |
Gets the current available image (first in receive queue) and its corresponding GVSP info. | |
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. | |
Gets the current available image (first in receive queue) and corresponding timestamps. | |
Gets the distortion coefficients from the TcVnGevImageProvider TcCOM module (requires intrinsic calibration parameters, e.g. set by the calibration assistant) | |
Gets the last received image from the queue. | |
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. | |
Gets the rotation matrix from the TcVnGevImageProvider TcCOM module (requires extrinsic calibration parameters, e.g. set by the calibration assistant) | |
Gets the current state of the internal camera control state machine. | |
Gets the translation vector from the TcVnGevImageProvider TcCOM module (requires extrinsic calibration parameters, e.g. set by the calibration assistant) | |
Initialize the camera to the intended state (includes sending the 'InitCameraCommands' defined in the GevImageAcquisition TcCOM module to the camera). | |
Open a control channel to the camera. | |
Reset the camera controller to initial state (might require multiple calls depending on current state, until S_OK is returned) | |
Reset the camera features to initial state (sends the 'InitCameraCommands' defined in the GevImageAcquisition TcCOM module to the camera). | |
Sets the camera matrix to the TcVnGevImageProvider TcCOM module | |
Sets the distortion coefficients to the TcVnGevImageProvider TcCOM module | |
Sets the rotation matrix to the TcVnGevImageProvider TcCOM module | |
Sets the translation vector to the TcVnGevImageProvider TcCOM module | |
Send the 'StartAcquisitionCommands' defined in the TcVnGevImageProvider TcCOM module to the camera. | |
Send the 'StopAcquisitionCommands' defined in the TcVnGevImageProvider TcCOM module to the camera. | |
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.
You can query the current state using the GetState method.
The following methods can be used to control the state machine:
- GetState
- InitializeCamera
- OpenCamera
- CloseCamera
- StartAcquisition
- StopAcquisition
- TriggerImage
- ResetCameraFeatures
- Reset
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
- FB_VN_SimpleCameraControl for cameras and file sources
- FB_VN_GevCameraControl for GigE Vision cameras
- FB_VN_FileSourceControl for file sources
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 |
- ClearImageQueue
- CloseCamera
- GetCalibPatternRef
- GetCameraMatrix
- GetCurrentImage
- GetCurrentImageUndistorted
- GetCurrentImageWithGvspInfo
- GetCurrentImageWithGvspInfoUndistorted
- GetCurrentImageWithTimestamps
- GetDistortionCoefficients
- GetLastImageFromQueue
- GetOmittedImagesNum
- GetRotationMatrix
- GetState
- GetTranslationVector
- InitializeCamera
- OpenCamera
- Reset
- ResetCameraFeatures
- SetCameraMatrix
- SetDistortionCoefficients
- SetRotationMatrix
- SetTranslationVector
- StartAcquisition
- StopAcquisition
- TriggerImage