Basic Camera Management

2022-08-01
No Rating

Overview

In order to facilitate developers to quickly develop the function of controlling cameras on DJI drones based on PSDK, DJI PSDK provides a camera management function. The interface based on camera management allows developers to set and obtain the sensitivity of multiple cameras on drones at the same time. , Aperture, Shutter, Exposure, and other parameters to control the camera to achieve functions such as taking pictures, recording videos, and pointing and zooming.

Camera management function

When using the camera management function, the developer needs to initialize the camera management function module in the PSDK first, then set the camera mode according to the actual user needs, and finally realize the required use according to the user's use logic. Functions, such as setting camera parameters or checking the status of functions, etc.

Table 1. Overview of Camera Support Feature Differences

Z30XTSXT2H20H20TH20NP1L1PSDK Camera
Set/get camera working mode
Set/get camera focus mode×××
Set/get exposure mode××××
Set/get ISO×××
set/get aperture×××
set/get shutter××××
Set/Get EV (Exposure Compensation)××××
Set/get tap scaling parameters××××××
set/get tap zoom point××××××
set/get focus××××
set/get mode for taking pictures××××
Take a single photo
Set/get interval shooting parameters×××××
Take time-lapse photos×
Set/Get Auto Bracketing Shooting Parameters×××××
Taking AEB Photos×××××
Set/get continuous shooting parameters×××××
Take burst photos××××
record video
Download file list (M300 RTK only)×××
Download media files (M300 RTK only)×××

Using the camera management function

1. Camera management module initialization

If the payload device developed with PSDK needs to control the camera function, it needs to call the DjiCameraManager_Init() interface to initialize the camera management module.

USER_LOG_INFO("--> Step 1: Init camera manager module");
DjiTest_WidgetLogAppend("--> Step 1: Init camera manager module");
returnCode = DjiCameraManager_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("Init camera manager failed, error code: 0x%08X\r\n", returnCode);
    goto exitCameraModule;
}

2. Get the camera type and version

Developers can obtain the camera type and version of the specified mount location on the drone by calling the DjiCameraManager_GetCameraType and DjiCameraManager_GetFirmwareVersion interfaces respectively.

    USER_LOG_INFO("--> Step 2: Get camera type and version");
    DjiTest_WidgetLogAppend("--> Step 2: Get camera type and version");
    returnCode = DjiCameraManager_GetCameraType(mountPosition, &cameraType);
    if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Get mounted position %d camera's type failed, error code: 0x%08X\r\n",
                       mountPosition, returnCode);
        goto exitCameraModule;
    }
    USER_LOG_INFO("Mounted position %d camera's type is %s",
                  mountPosition,
                  s_cameraTypeStrList[DjiTest_CameraManagerGetCameraTypeIndex(cameraType)].cameraTypeStr);

    returnCode = DjiCameraManager_GetFirmwareVersion(mountPosition, &firmwareVersion);
    if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
        USER_LOG_ERROR("Get mounted position %d camera's firmware version failed, error code: 0x%08X\r\n",
                       mountPosition, returnCode);
        goto exitCameraModule;
    }
    USER_LOG_INFO("Mounted position %d camera's firmware is V%d.%d.%d.%d\r\n", mountPosition,
                  firmwareVersion.firmware_version[0], firmwareVersion.firmware_version[1],
                  firmwareVersion.firmware_version[2], firmwareVersion.firmware_version[3]);

3. Set or get camera parameters

Camera management provides a series of Set or Get interfaces, you can set or get the camera parameters of the specified mount location. For example, you can get and set the ISO parameters of the camera by calling the DjiCameraManager_GetISO and DjiCameraManager_SetISO interfaces respectively.

T_DjiReturnCode returnCode;
E_DjiCameraManagerISO isoDataTemp;

returnCode = DjiCameraManager_GetISO(position, &isoDataTemp);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS &&
    returnCode != DJI_ERROR_CAMERA_MANAGER_MODULE_CODE_UNSUPPORTED_COMMAND) {
    USER_LOG_ERROR("Get mounted position %d camera's iso failed, error code: 0x%08X.",
                   position, returnCode);
    return returnCode;
}

if (isoDataTemp == isoData) {
    USER_LOG_INFO("The mounted position %d camera's iso is already what you expected.",
                  position);
    return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

returnCode = DjiCameraManager_SetISO(position, isoData);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS &&
    returnCode != DJI_ERROR_CAMERA_MANAGER_MODULE_CODE_UNSUPPORTED_COMMAND) {
    USER_LOG_ERROR("Set mounted position %d camera's iso %d failed, "
                   "error code: 0x%08X.", position, isoData, returnCode);
}

return returnCode;

4. Control the camera to perform the specified action

The developer can execute the specified camera action by calling the corresponding interface. For example, calling the DjiCameraManager_StartShootPhoto interface can control the camera at the specified location to take pictures.

/*!< start to shoot single photo */
USER_LOG_INFO("Mounted position %d camera start to shoot photo", position);
returnCode = DjiCameraManager_StartShootPhoto(position, DJI_CAMERA_MANAGER_SHOOT_PHOTO_MODE_SINGLE);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("Mounted position %d camera shoot photo failed, "
                   "error code :0x%08X", position, returnCode);
}