Skip to main content

Basic Camera Functions

Overview

To meet developers' needs for controlling camera payloads, PSDK provides interfaces for camera operations such as photo capture, video recording, zooming, and focusing. Developers must first implement functions such as photo capture, video recording, and metering, and then register them using the PSDK camera interfaces to develop a fully functional camera payload. With Autel Robotics drones and mobile apps developed based on MSDK, users can control camera payloads developed using PSDK to perform specified actions and retrieve information and resources from the payload.

  • Basic Functions: Set camera mode, capture photos, record videos, retrieve camera state, manage SD card
  • Advanced Functions: Zoom, metering, focus

Basic Concept Introduction

1. Camera Modes

Before using camera-related functions, the camera payload must be set to the appropriate mode. Different modes define the operational logic of the camera payload when performing specific tasks:

  • Photo Mode: In this mode, the user can trigger the camera payload to capture photos.
  • Video Mode: In this mode, the user can trigger the camera payload to record videos.
  • Playback Mode: In this mode, the user can play or download media files stored on the payload via the mobile app.

Note:

  • The camera can only perform actions specific to the current mode. For example, in video mode, it can only record videos and cannot capture photos.

2. Photo Mode

The camera payloads developed with PSDK support the following photo modes:

  • Single Shot: After sending the capture command, the camera will take a single photo.
  • Burst Mode: After sending the capture command, the camera will continuously take the specified number of photos. Currently, it supports burst shots of 2/3/5/7/10/14 photos.
  • Timed Capture: After sending the capture command, the camera will capture photos at specified time intervals for a set number of shots.
    • The interval photo count range is [2,255]. If 255 is selected, the camera will continue taking photos until the StopShootPhoto interface is called.

3. Focus Mode

  • Auto Focus (AF): In auto focus mode, the camera payload calculates the focus result based on the image status (diffuse emission) obtained from the optical sensor, achieving clear focus.
  • Manual Focus (MF): In manual focus mode, the user can adjust the focus ring to achieve a clear image.
  • AFC: The camera focus mode is set to continuous auto-focus, which is supported only by firmware version v01.03.00 or higher for Mavic Pro, X4S camera, Mavic 2 Zoom camera, and Mavic 2 Pro camera.

4. Focus Point

When controlling the camera payload to focus, the focus point must first be set. The value of this focus point is the aspect ratio of the current focus point in the camera's view.

  • In auto focus mode, developers need to define the camera's focusing strategy and set the focus point (this focus point is also referred to as the "target point").
  • In manual focus mode, the user can adjust the focus point as needed to obtain the desired image.

image

5. Focus Ring

For Camera payloads with a zoom ring (optical zoom) developed using PSDK , the focus ring value can be set by calling the SetFocusRingValue interface:

  • The default focus ring value is 0, which represents the maximum and minimum possible focal distances.
  • When the focus ring value is not 0, the user can set the focus ring value according to the actual parameters of the camera.

6. Focus Assistant

  • In AF and MF modes, the focus assistant uses digital zoom to enlarge the user-specified focus area. By calling the SetFocusAssistantSettings interface, the status of the focus assistant can be set. Using the focus assistant, users can check the focus quality of the camera payload.

7. Zoom Modes

  • Optical Zoom: Achieved by changing the structure of the optical lens. The larger the optical zoom factor, the farther the object that can be captured; conversely, the closer it is.
  • Digital Zoom: The processor uses a specific algorithm to change the area of each pixel on the sensor to achieve digital zoom.
  • Continuous Zoom: The camera payload controls the lens to move in a specified direction at a specified speed. First, the camera payload performs optical zoom. When the optical zoom reaches its limit, digital zoom is applied to achieve continuous zoom. The current zoom factor = current optical zoom factor × current digital zoom factor.
  • Point Zoom: After the user specifies a target point, the camera payload developed with PSDK controls the gimbal to position the target at the center of the frame and zoom in on the image according to the preset zoom factor.

8. Zoom Directions

  • ZOOM_IN: Decrease the zoom factor, bringing the image from far to near.
  • ZOOM_OUT: Increase the zoom factor, moving the image from near to far.

9. Zoom Speed

  • SLOWEST: Zoom at the slowest speed
  • SLOW: Zoom at a slower speed
  • MODERATELY_SLOW: Zoom at a slightly slower speed than normal
  • NORMAL: Zoom at normal speed
  • MODERATELY_FAST: Zoom at a slightly faster speed than normal
  • FAST: Zoom at a faster speed
  • FASTEST: Zoom at the fastest speed

10. Metering Modes

  • Average Metering: Calculates the average brightness of the entire image by analyzing the overall light level, suitable for evenly lit photo scenes.
  • Center-Weighted Metering: Measures the light in the central area of the image sensor, suitable for photos with a framed composition.
  • Spot Metering: Measures the light within a range centered around a specified point, as shown in the image. This method provides accurate metering results, ensuring the correct exposure of the specified object. It is suitable for shooting in complex lighting conditions.

image

Using Basic Camera Functions

Developers should implement functions such as setting the camera mode, capturing photos, and recording videos for camera payloads according to actual application needs and the selected development platform. These functions should be constructed based on the T_UAVCameraCommonHandler structure provided by the PSDK. After registering the camera function handlers to the designated interfaces in the PSDK, users can control the camera payload developed with PSDK via Autel Robotics drones or mobile apps developed based on MSDK to perform the corresponding actions.

    // Retrieve the current state of the payload system
s_commonHandler.GetSystemState = GetSystemState;
// Implement the function to set the mode of the camera payload
s_commonHandler.SetMode = SetMode;
s_commonHandler.GetMode = GetMode;
// Implement the function to start or stop video recording
s_commonHandler.StartRecordVideo = StartRecordVideo;
s_commonHandler.StopRecordVideo = StopRecordVideo;
// Implement the function to start or stop photo capture
s_commonHandler.StartShootPhoto = StartShootPhoto;
s_commonHandler.StopShootPhoto = StopShootPhoto;
// Implement the function to set the photo capture feature of the camera payload
s_commonHandler.SetShootPhotoMode = SetShootPhotoMode;
s_commonHandler.GetShootPhotoMode = GetShootPhotoMode;
s_commonHandler.SetPhotoBurstCount = SetPhotoBurstCount;
s_commonHandler.GetPhotoBurstCount = GetPhotoBurstCount;
s_commonHandler.SetPhotoTimeIntervalSettings = SetPhotoTimeIntervalSettings;
s_commonHandler.GetPhotoTimeIntervalSettings = GetPhotoTimeIntervalSettings;
// Implement the SD card management feature
s_commonHandler.GetSDCardState = GetSDCardState;
s_commonHandler.FormatSDCard = FormatSDCard;

Basic Function Initialization

When using PSDK to develop camera functions for payloads, the camera module must be initialized and camera-related functions must be registered.

1. Camera Function Module Initialization

Before using camera-related functions, you must call the UAVPayloadCamera_Init interface to initialize the camera payload and ensure it operates correctly.

T_UAVReturnCode returnCode;

// Initialize the camera function module
returnCode = UAV_Camera_Init();
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Init camera function module failed, error code: 0x%08X", returnCode);
}

2. Register Camera Payload Basic Functions

After developers implement functions such as setting the camera mode, capturing photos, and recording videos for the camera payload, they need to register these basic camera functions through UAVPayloadCamera_RegCommonHandler.

returnCode = UAVPayloadCamera_RegCommonHandler(commonHandler);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("Init camera function module failed, error code: 0x%08X", returnCode);
}

Using SD Card Management Features

Note:

  • Camera payloads developed using X-Port need to implement the functionality for storing media files and register this functionality to the PSDK specified interfaces. The storage card on X-Port only supports storing X-Port log information and cannot store media files generated by the payload.
  • This tutorial uses an emulated SD card management feature as an example to explain how to use the PSDK SD card management functionality. To develop payloads with SD card management features, please use the system interfaces of the payload to implement SD card management.

SD Card Module Initialization

To use the SD card management functionality, developers must first develop and register functions to operate the SD card. By initializing the SD card management module, you can obtain the state information of the SD card.

    /* Init the SDcard parameters */
s_cameraSDCardState.isInserted = true;
s_cameraSDCardState.isVerified = true;
s_cameraSDCardState.totalSpaceInMB = SDCARD_TOTAL_SPACE_IN_MB;
s_cameraSDCardState.remainSpaceInMB = SDCARD_TOTAL_SPACE_IN_MB;
s_cameraSDCardState.availableCaptureCount = SDCARD_TOTAL_SPACE_IN_MB / SDCARD_PER_PHOTO_SPACE_IN_MB;
s_cameraSDCardState.availableRecordingTimeInSeconds = SDCARD_TOTAL_SPACE_IN_MB / SDCARD_PER_SECONDS_RECORD_SPACE_IN_MB;

Get the Current State of the SD Card

The control program of the payload developed with PSDK can call the GetSDCardState interface to obtain the current state of the SD card on the payload. Users can view the SD card state information of the payload through mobile apps developed with MSDK.

// Function to estimate the remaining number of photos and available video recording time.
if (s_cameraState.isRecording) {
s_cameraState.currentVideoRecordingTimeInSeconds++;
s_cameraSDCardState.remainSpaceInMB =
s_cameraSDCardState.remainSpaceInMB - SDCARD_PER_SECONDS_RECORD_SPACE_IN_MB;
if (s_cameraSDCardState.remainSpaceInMB > SDCARD_TOTAL_SPACE_IN_MB) {
s_cameraSDCardState.remainSpaceInMB = 0;
s_cameraSDCardState.isFull = true;
}
}
// Get the state of the SD card
static T_UAVReturnCode GetSDCardState(T_UAVCameraSDCardState *sdCardState)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

memcpy(sdCardState, &s_cameraSDCardState, sizeof(T_UAVCameraSDCardState));

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Using the SD Card Formatting Feature

The control program of a payload developed with PSDK can call the FormatSDCard interface to trigger SD card formatting on the payload. Users can view the SD card state and initiate formatting operations through a mobile app developed with MSDK, as shown in Fig. 1. SD Card Management Feature.

static T_UAVReturnCode FormatSDCard(void)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

USER_LOG_INFO("format sdcard");

memset(&s_cameraSDCardState, 0, sizeof(T_UAVCameraSDCardState));
s_cameraSDCardState.isInserted = true;
s_cameraSDCardState.isVerified = true;
s_cameraSDCardState.totalSpaceInMB = SDCARD_TOTAL_SPACE_IN_MB;
s_cameraSDCardState.remainSpaceInMB = SDCARD_TOTAL_SPACE_IN_MB;
s_cameraSDCardState.availableCaptureCount = SDCARD_TOTAL_SPACE_IN_MB / SDCARD_PER_PHOTO_SPACE_IN_MB;
s_cameraSDCardState.availableRecordingTimeInSeconds =
SDCARD_TOTAL_SPACE_IN_MB / SDCARD_PER_SECONDS_RECORD_SPACE_IN_MB;

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Using Mode Setting Feature

The control program of a payload developed with PSDK can call the SetMode and GetMode interfaces to set the camera mode. This allows the user to switch the working mode of the camera payload, as shown in Fig. 2. Set Camera Mode.

static T_UAVReturnCode GetSystemState(T_UAVCameraSystemState *systemState)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

*systemState = s_cameraState;

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode SetMode(E_UAVCameraMode mode)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

s_cameraState.cameraMode = mode;
USER_LOG_INFO("set camera mode:%d", mode);

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

T_UAVReturnCode UAVTest_CameraGetMode(E_UAVCameraMode *mode)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

*mode = s_cameraState.cameraMode;

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Using the Photo Capture Feature

Note:

  • Before using the photo capture feature, the user must set the camera payload to photo mode via a mobile app developed with MSDK.
  • When taking photos, the payload developed with PSDK will return the photo capture status to the mobile app developed with MSDK (e.g., to trigger a shutter sound on the app).

Set the Photo Capture Mode of the Camera Payload

The control program of a payload developed with PSDK can call the SetShootPhotoMode and GetShootPhotoMode interfaces to set and retrieve the photo capture mode of the camera payload. Users can also set and retrieve the photo capture mode through a mobile app developed with MSDK.

static T_UAVReturnCode SetShootPhotoMode(E_UAVCameraShootPhotoMode mode)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

s_cameraShootPhotoMode = mode;
USER_LOG_INFO("set shoot photo mode:%d", mode);

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode GetShootPhotoMode(E_UAVCameraShootPhotoMode *mode)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

*mode = s_cameraShootPhotoMode;

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);\
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Control Single Photo Capture

The control program of a payload developed with PSDK can call the StartShootPhoto and StopShootPhoto interfaces to control the camera payload to capture a single photo. Users can also trigger single photo capture through a mobile app developed with MSDK.

static T_UAVReturnCode StartShootPhoto(void)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

USER_LOG_INFO("start shoot photo");
s_cameraState.isStoring = true;

if (s_cameraShootPhotoMode == UAV_CAMERA_SHOOT_PHOTO_MODE_SINGLE) {
s_cameraState.shootingState = UAV_CAMERA_SHOOTING_SINGLE_PHOTO;
} else if (s_cameraShootPhotoMode == UAV_CAMERA_SHOOT_PHOTO_MODE_BURST) {
s_cameraState.shootingState = UAV_CAMERA_SHOOTING_BURST_PHOTO;
} else if (s_cameraShootPhotoMode == UAV_CAMERA_SHOOT_PHOTO_MODE_INTERVAL) {
s_cameraState.shootingState = UAV_CAMERA_SHOOTING_INTERVAL_PHOTO;
s_cameraState.isShootingIntervalStart = true;
s_cameraState.currentPhotoShootingIntervalTimeInSeconds = s_cameraPhotoTimeIntervalSettings.timeIntervalSeconds;
}

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode StopShootPhoto(void)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

USER_LOG_INFO("stop shoot photo");
s_cameraState.shootingState = UAV_CAMERA_SHOOTING_PHOTO_IDLE;
s_cameraState.isStoring = false;
s_cameraState.isShootingIntervalStart = false;

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Control Burst Photo Capture

The control program of a payload developed with PSDK can call the SetPhotoBurstCount and GetPhotoBurstCount interfaces to control burst photo capture on the camera payload. Users can set the number of burst shots and control the camera payload to capture the specified number of photos through a mobile app developed with MSDK.

static T_UAVReturnCode SetPhotoBurstCount(E_UAVCameraBurstCount burstCount)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

s_cameraBurstCount = burstCount;
USER_LOG_INFO("set photo burst count:%d", burstCount);

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode GetPhotoBurstCount(E_UAVCameraBurstCount *burstCount)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

*burstCount = s_cameraBurstCount;

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Control Timed Photo Capture

The control program of a payload developed with PSDK can call the SetPhotoTimeIntervalSettings and GetPhotoTimeIntervalSettings interfaces to control timed photo capture on the camera payload. Users can set the photo interval and control the camera payload to capture photos at specified time intervals through a mobile app developed with MSDK.

static T_UAVReturnCode SetPhotoTimeIntervalSettings(T_UAVCameraPhotoTimeIntervalSettings settings)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

s_cameraPhotoTimeIntervalSettings.captureCount = settings.captureCount;
s_cameraPhotoTimeIntervalSettings.timeIntervalSeconds = settings.timeIntervalSeconds;
USER_LOG_INFO("set photo interval settings count:%d seconds:%d", settings.captureCount,
settings.timeIntervalSeconds);
s_cameraState.currentPhotoShootingIntervalCount = settings.captureCount;

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode GetPhotoTimeIntervalSettings(T_UAVCameraPhotoTimeIntervalSettings *settings)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

memcpy(settings, &s_cameraPhotoTimeIntervalSettings, sizeof(T_UAVCameraPhotoTimeIntervalSettings));

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Photo Capture State Management

When the “Capture” button is clicked in a mobile app developed with MSDK, the camera payload developed with PSDK should perform the photo capture, photo storage, and memory state update operations within a custom time window (e.g., 0.5 seconds) in a separate thread.

Confirm Photo Capture State

After completing the photo capture action, the camera payload developed with PSDK needs to retrieve its current photo capture state.

if (s_cameraState.shootingState != PSDK_CAMERA_SHOOTING_PHOTO_IDLE &&
photoCnt++ > TAKING_PHOTO_SPENT_TIME_MS_EMU / (1000 / PAYLOAD_CAMERA_EMU_TASK_FREQ)) {
s_cameraState.isStoring = false;
s_cameraState.shootingState = PSDK_CAMERA_SHOOTING_PHOTO_IDLE;
photoCnt = 0;
}

Store Photo

After capturing a photo, the camera payload developed with PSDK stores the photo taken by the camera on the memory card on the camera payload.

  • Store photos taken by the camera payload in single shot mode
if (s_cameraShootPhotoMode == UAV_CAMERA_SHOOT_PHOTO_MODE_SINGLE) {
s_cameraSDCardState.remainSpaceInMB =
s_cameraSDCardState.remainSpaceInMB - SDCARD_PER_PHOTO_SPACE_IN_MB;
s_cameraState.isStoring = false;
s_cameraState.shootingState = UAV_CAMERA_SHOOTING_PHOTO_IDLE;
}
  • Store photos taken by the camera payload in burst mode
else if (s_cameraShootPhotoMode == UAV_CAMERA_SHOOT_PHOTO_MODE_BURST) {
s_cameraSDCardState.remainSpaceInMB =
s_cameraSDCardState.remainSpaceInMB - SDCARD_PER_PHOTO_SPACE_IN_MB * s_cameraBurstCount;
s_cameraState.isStoring = false;
s_cameraState.shootingState = UAV_CAMERA_SHOOTING_PHOTO_IDLE;
}
  • Store photos taken by the camera payload in timed photo capture mode
else if (s_cameraShootPhotoMode == UAV_CAMERA_SHOOT_PHOTO_MODE_INTERVAL) {
if (isStartIntervalPhotoAction == true) {
s_cameraState.isStoring = false;
s_cameraState.shootingState = UAV_CAMERA_SHOOTING_PHOTO_IDLE;
s_cameraSDCardState.remainSpaceInMB =
s_cameraSDCardState.remainSpaceInMB - SDCARD_PER_PHOTO_SPACE_IN_MB;
}
}

Check Storage Space

To ensure that the SD card in the camera payload has sufficient storage space to save photos or videos after the camera payload performs a photo capture action, it is recommended to add a function for checking SD card storage space in the camera payload developed with PSDK.

  • Check the remaining SD card storage space after the camera payload performs single and burst photo captures.
if (s_cameraSDCardState.remainSpaceInMB > SDCARD_TOTAL_SPACE_IN_MB) {
s_cameraSDCardState.remainSpaceInMB = 0;
s_cameraSDCardState.isFull = true;
}
  • Check the remaining SD card storage space after the camera payload performs timed photo capture
if (s_cameraShootPhotoMode == UAV_CAMERA_SHOOT_PHOTO_MODE_INTERVAL) {
if (isStartIntervalPhotoAction == true) {
s_cameraState.isStoring = false;
s_cameraState.shootingState = UAV_CAMERA_SHOOTING_PHOTO_IDLE;
s_cameraSDCardState.remainSpaceInMB =
s_cameraSDCardState.remainSpaceInMB - SDCARD_PER_PHOTO_SPACE_IN_MB;
}
}

Using the Video Recording Feature

Note:

  • The camera payload cannot capture photos or perform metering while recording videos.
  • Developers can set default values for parameters such as ISO, exposure, and focus during video recording, based on user requirements.
  • Before using the video recording feature of the camera payload, the user needs to set the camera payload's mode to video mode via a mobile app developed with MSDK.

Control Camera Video Recording

The control program of a payload developed with PSDK can call the StartRecordVideo and StopRecordVideo interfaces to control the camera payload to record video. Users can also control the camera payload's video recording via a mobile app developed with MSDK.

static T_UAVReturnCode StartRecordVideo(void)
{
T_UAVReturnCode UAVStat;
T_UAVReturnCode returnCode = UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

UAVStat = osalHandler->MutexLock(s_commonMutex);
if (UAVStat != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", UAVStat);
return UAVStat;
}

if (s_cameraState.isRecording != false) {
USER_LOG_ERROR("camera is already in recording state");
returnCode = UAV_ERROR_SYSTEM_MODULE_CODE_NONSUPPORT_IN_CURRENT_STATE;
goto out;
}

s_cameraState.isRecording = true;
USER_LOG_INFO("start record video");

out:
UAVStat = osalHandler->MutexUnlock(s_commonMutex);
if (UAVStat != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", UAVStat);
return UAVStat;
}

return returnCode;
}

static T_UAVReturnCode StopRecordVideo(void)
{
T_UAVReturnCode UAVStat;
T_UAVReturnCode returnCode = UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

UAVStat = osalHandler->MutexLock(s_commonMutex);
if (UAVStat != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", UAVStat);
return UAVStat;
}

if (s_cameraState.isRecording != true) {
USER_LOG_ERROR("camera is not in recording state");
returnCode = UAV_ERROR_SYSTEM_MODULE_CODE_NONSUPPORT_IN_CURRENT_STATE;
goto out;
}

s_cameraState.isRecording = false;
s_cameraState.currentVideoRecordingTimeInSeconds = 0;
USER_LOG_INFO("stop record video");

out:
UAVStat = osalHandler->MutexUnlock(s_commonMutex);
if (UAVStat != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", UAVStat);
return UAVStat;
}

return returnCode;
}

Video Recording State Update

By default, the control program of a camera payload developed with PSDK updates the camera state at a frequency of 10 Hz.

Note: After video recording starts, the mobile app developed with MSDK will display the current recording duration. When the camera stops recording, the timer will reset to 0.

if (s_cameraState.isRecording) {
s_cameraState.currentVideoRecordingTimeInSeconds++;
s_cameraSDCardState.remainSpaceInMB =
s_cameraSDCardState.remainSpaceInMB - SDCARD_PER_SECONDS_RECORD_SPACE_IN_MB;
if (s_cameraSDCardState.remainSpaceInMB > SDCARD_TOTAL_SPACE_IN_MB) {
s_cameraSDCardState.remainSpaceInMB = 0;
s_cameraSDCardState.isFull = true;
}
}

static T_UAVReturnCode GetSystemState(T_UAVCameraSystemState *systemState)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

*systemState = s_cameraState;

returnCode = osalHandler->MutexUnlock(s_commonMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Implementing the Focus Feature

Developers should implement focus-related functions for the camera payload according to the selected development platform and the actual requirements of their industry application. These functions should be constructed based on the T_UAVCameraFocusHandler structure provided in the PSDK. After registering the focus functions to the designated PSDK interface, users can control the camera payload to focus through a mobile app developed with MSDK.

    //Implement the function to set the focus mode
s_focusHandler.SetFocusMode = SetFocusMode;
s_focusHandler.GetFocusMode = GetFocusMode;
// Implement the function to set the focus target
s_focusHandler.SetFocusTarget = SetFocusTarget;
s_focusHandler.GetFocusTarget = GetFocusTarget;
// Implement the function to set the focus ring value
s_focusHandler.SetFocusRingValue = SetFocusRingValue;
s_focusHandler.GetFocusRingValue = GetFocusRingValue;

Using the Focus Feature

Register Focus Function

After implementing the focus functionality of the camera payload, developers need to register it using UAVPayloadCamera_RegFocusHandler, allowing users to control the camera payload to focus via a mobile app developed with MSDK.

    returnCode = UAVPayloadCamera_RegFocusHandler(&s_focusHandler);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("camera register adjustable focal point handler error:0x%08llX", returnCode);
return returnCode;
}

Set Focus Mode

The control program of a payload developed with PSDK can call the SetFocusMode and GetFocusMode interfaces to set the focus mode of the camera payload. Users can switch the focus mode of the camera payload accordingly.

static T_UAVReturnCode SetFocusMode(E_UAVCameraFocusMode mode)
{
USER_LOG_INFO("set focus mode:%d", mode);
s_cameraFocusMode = mode;

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode GetFocusMode(E_UAVCameraFocusMode *mode)
{
*mode = s_cameraFocusMode;

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Set Focus Target

The control program of a payload developed with PSDK can call the SetFocusTarget and GetFocusTarget interfaces to set the focus target of the camera payload. Users can set or retrieve the focus target of the camera payload through a mobile app developed with MSDK.

static T_UAVReturnCode SetFocusTarget(T_UAVCameraPointInScreen target)
{
USER_LOG_INFO("set focus target x:%.2f y:%.2f", target.focusX, target.focusY);
memcpy(&s_cameraFocusTarget, &target, sizeof(T_UAVCameraPointInScreen));

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode GetFocusTarget(T_UAVCameraPointInScreen *target)
{
memcpy(target, &s_cameraFocusTarget, sizeof(T_UAVCameraPointInScreen));

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Set Focus Ring

The control program of a payload developed with PSDK can call the SetFocusRingValue, GetFocusRingValue, and GetFocusRingValueUpperBound interfaces to set the focus ring value of the camera payload. Users can set or retrieve the current value and maximum value of the focus ring of the camera payload through a mobile app developed with MSDK.

static T_UAVReturnCode SetFocusRingValue(uint32_t value)
{
USER_LOG_INFO("set focus ring value:%d", value);
s_cameraFocusRingValue = value;

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode GetFocusRingValue(uint32_t *value)
{
*value = s_cameraFocusRingValue;

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Implementing the Metering Feature

Developers should implement metering-related functions for the camera payload based on the selected development platform and the actual requirements of their industry application. These functions should be constructed according to the T_UAVCameraExposureMeteringHandler structure defined in the PSDK. After registering the metering functions to the designated PSDK interface, users can control the camera payload to perform metering through a mobile app developed with MSDK.

    // Implement the function to set the metering mode
s_exposureMeteringHandler.SetMeteringMode = SetMeteringMode;
s_exposureMeteringHandler.GetMeteringMode = GetMeteringMode;
// Implement the function to control the payload to perform metering
s_exposureMeteringHandler.SetSpotMeteringTarget = SetSpotMeteringTarget;
s_exposureMeteringHandler.GetSpotMeteringTarget = GetSpotMeteringTarget;

Using the Metering Feature

Register Metering Function

After implementing the metering functionality of the camera payload, developers need to register it using PsdkPayloadCamera_RegExposureMeteringHandler. Once registered through the designated interface, users can control the camera payload to perform metering via a mobile app developed with MSDK, as shown in Fig. 2. Metering Feature.

    returnCode = UAVPayloadCamera_RegExposureMeteringHandler(&s_exposureMeteringHandler);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("camera register exposure metering handler error:0x%08llX", returnCode);
return returnCode;
}

Set Metering Mode

The control program of a payload developed with PSDK can call the SetMeteringMode and GetMeteringMode interfaces to set or retrieve the metering mode of the camera payload. Users can view the metering mode of the payload through a mobile app developed with MSDK, as shown in Fig. 3. Spot Metering and Fig. 4. Center-Weighted Metering.

static T_UAVReturnCode SetMeteringMode(E_UAVCameraMeteringMode mode)
{
USER_LOG_INFO("set metering mode:%d", mode);
s_cameraMeteringMode = mode;

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode GetMeteringMode(E_UAVCameraMeteringMode *mode)
{
*mode = s_cameraMeteringMode;

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Set Metering Target

After the camera payload calls the SetSpotMeteringTarget and GetSpotMeteringTarget interfaces, a mobile app developed with MSDK can set or retrieve the metering target of the camera payload.

static T_UAVReturnCode SetSpotMeteringTarget(T_UAVCameraSpotMeteringTarget target)
{
USER_LOG_INFO("set spot metering area col:%d row:%d", target.col, target.row);
memcpy(&s_cameraSpotMeteringTarget, &target, sizeof(T_UAVCameraSpotMeteringTarget));

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

static T_UAVReturnCode GetSpotMeteringTarget(T_UAVCameraSpotMeteringTarget *target)
{
memcpy(target, &s_cameraSpotMeteringTarget, sizeof(T_UAVCameraSpotMeteringTarget));

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Implementing the Zoom Feature

Developers should implement zoom-related functions for the camera payload according to the selected development platform and the actual requirements of their industry application. These functions should be constructed based on the T_UAVCameraTapZoomHandler structure defined in the PSDK. After registering the zoom functions to the designated PSDK interface, users can control the camera payload to perform zoom operations through a mobile app developed with MSDK.

    // Implement the function to control the payload to perform digital zoom
s_digitalZoomHandler.SetDigitalZoomFactor = SetDigitalZoomFactor;
s_digitalZoomHandler.GetDigitalZoomFactor = GetDigitalZoomFactor;
// Implement the function to control the payload to perform optical zoom
s_opticalZoomHandler.SetOpticalZoomFocalLength = SetOpticalZoomFocalLength;
s_opticalZoomHandler.GetOpticalZoomFocalLength = GetOpticalZoomFocalLength;
s_opticalZoomHandler.GetOpticalZoomFactor = GetOpticalZoomFactor;
s_opticalZoomHandler.GetOpticalZoomSpec = GetOpticalZoomSpec;
s_opticalZoomHandler.StartContinuousOpticalZoom = StartContinuousOpticalZoom;
s_opticalZoomHandler.StopContinuousOpticalZoom = StopContinuousOpticalZoom;

Using the Zoom Feature

Register Zoom Function

After implementing the zoom functionality for the camera payload, developers need to register each zoom function through the designated registration interface. By calling the specified interface, the payload developed with PSDK can control the camera payload to perform zoom operations, enabling users to control the zoom of the camera payload via a mobile app developed with MSDK.

  • Register digital zoom functionality
returnCode = UAVPayloadCamera_RegDigitalZoomHandler(&s_digitalZoomHandler);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("camera register digital zoom handler error:0x%08llX", returnCode);
return returnCode;
}
  • Register optical zoom functionality
returnCode = UAVPayloadCamera_RegOpticalZoomHandler(&s_opticalZoomHandler);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("camera register optical zoom handler error:0x%08llX", returnCode);
return returnCode;
}

Using the Digital Zoom Feature

The control program of a payload developed with PSDK can call the SetDigitalZoomFactor and GetDigitalZoomFactor interfaces to control the payload to perform digital zoom. Users can control the camera payload's digital zoom via a mobile app developed with MSDK, while also retrieving the digital zoom factor of the payload.

static T_UAVReturnCode SetDigitalZoomFactor(UAV_f32_t factor)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

USER_LOG_INFO("set digital zoom factor:%.2f", factor);
s_cameraDigitalZoomFactor = factor;

returnCode = osalHandler->MutexUnlock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

T_UAVReturnCode UAVTest_CameraGetDigitalZoomFactor(UAV_f32_t *factor)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

*factor = s_cameraDigitalZoomFactor;

returnCode = osalHandler->MutexUnlock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Using the Optical Zoom Feature

The control program of a payload developed with PSDK can call the SetOpticalZoomFocalLength and GetOpticalZoomFocalLength interfaces to control the payload to perform optical zoom. Users can control the camera payload to perform optical zoom via a mobile app developed with MSDK, while also retrieving the optical zoom factor of the payload.

  • Set the focal length of the optical zoom camera
static T_UAVReturnCode SetOpticalZoomFocalLength(uint32_t focalLength)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

USER_LOG_INFO("set optical zoom focal length:%d", focalLength);
s_isOpticalZoomReachLimit = false;
s_cameraDigitalZoomFactor = ZOOM_DIGITAL_BASE_FACTOR;
s_cameraOpticalZoomFocalLength = ZOOM_OPTICAL_FOCAL_MIN_LENGTH;

returnCode = osalHandler->MutexUnlock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

T_UAVReturnCode UAVTest_CameraGetOpticalZoomFactor(UAV_f32_t *factor)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

//Formula:factor = currentFocalLength / minFocalLength
*factor = (UAV_f32_t) s_cameraOpticalZoomFocalLength / ZOOM_OPTICAL_FOCAL_MIN_LENGTH;

returnCode = osalHandler->MutexUnlock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
  • Retrieve the zoom factor of the camera payload After obtaining the current optical focal length of the camera payload, the zoom factor can be calculated using the formula: Zoom factor = Current focal length ÷ Minimum focal length.
T_UAVReturnCode UAVTest_CameraGetOpticalZoomFactor(UAV_f32_t *factor)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

//Formula:factor = currentFocalLength / minFocalLength
*factor = (UAV_f32_t) s_cameraOpticalZoomFocalLength / ZOOM_OPTICAL_FOCAL_MIN_LENGTH;

returnCode = osalHandler->MutexUnlock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
  • Retrieve the range of optical zoom
static T_UAVReturnCode GetOpticalZoomSpec(T_UAVCameraOpticalZoomSpec *spec)
{
spec->maxFocalLength = ZOOM_OPTICAL_FOCAL_MAX_LENGTH;
spec->minFocalLength = ZOOM_OPTICAL_FOCAL_MIN_LENGTH;
spec->focalLengthStep = ZOOM_OPTICAL_FOCAL_LENGTH_STEP;

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

Using Continuous Zoom Feature

The control program of a payload developed with PSDK can call the StartContinuousOpticalZoom and StopContinuousOpticalZoom interfaces to control the payload to start or stop performing continuous zoom. Users can control the camera payload to execute continuous zoom via a mobile app developed with MSDK.

  • Control the camera payload to start zooming
static T_UAVReturnCode StartContinuousOpticalZoom(E_UAVCameraZoomDirection direction, E_UAVCameraZoomSpeed speed)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

USER_LOG_INFO("start continuous optical zoom direction:%d speed:%d", direction, speed);
s_isStartContinuousOpticalZoom = true;
s_cameraZoomDirection = direction;
s_cameraZoomSpeed = speed;

returnCode = osalHandler->MutexUnlock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
  • Control the camera payload to stop zooming
static T_UAVReturnCode StopContinuousOpticalZoom(void)
{
T_UAVReturnCode returnCode;
T_UAVOsalHandler *osalHandler = UAVPlatform_GetOsalHandler();

returnCode = osalHandler->MutexLock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("lock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

USER_LOG_INFO("stop continuous optical zoom");
s_isStartContinuousOpticalZoom = false;
s_cameraZoomDirection = UAV_CAMERA_ZOOM_DIRECTION_OUT;
s_cameraZoomSpeed = UAV_CAMERA_ZOOM_SPEED_NORMAL;

returnCode = osalHandler->MutexUnlock(s_zoomMutex);
if (returnCode != UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
USER_LOG_ERROR("unlock mutex error: 0x%08llX.", returnCode);
return returnCode;
}

return UAV_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
  • Control the camera payload to perform continuous zoom
if (s_isStartContinuousOpticalZoom == true) {
tempDigitalFactor = s_cameraDigitalZoomFactor;
tempFocalLength = (int32_t) s_cameraOpticalZoomFocalLength;
if (s_isOpticalZoomReachLimit == false) {
if (s_cameraZoomDirection == UAV_CAMERA_ZOOM_DIRECTION_IN) {
tempFocalLength += ((int) s_cameraZoomSpeed - UAV_CAMERA_ZOOM_SPEED_SLOWEST + 1) * ZOOM_OPTICAL_FOCAL_LENGTH_CTRL_STEP;
} else if (s_cameraZoomDirection == UAV_CAMERA_ZOOM_DIRECTION_OUT) {
tempFocalLength -= ((int) s_cameraZoomSpeed - UAV_CAMERA_ZOOM_SPEED_SLOWEST + 1) * ZOOM_OPTICAL_FOCAL_LENGTH_CTRL_STEP;
}

if (tempFocalLength > ZOOM_OPTICAL_FOCAL_MAX_LENGTH) {
s_isOpticalZoomReachLimit = true;
tempFocalLength = ZOOM_OPTICAL_FOCAL_MAX_LENGTH;
}

if (tempFocalLength < ZOOM_OPTICAL_FOCAL_MIN_LENGTH) {
tempFocalLength = ZOOM_OPTICAL_FOCAL_MIN_LENGTH;
}
} else {
if (s_cameraZoomDirection == UAV_CAMERA_ZOOM_DIRECTION_IN) {
tempDigitalFactor += (UAV_f32_t) ZOOM_DIGITAL_STEP_FACTOR;
} else if (s_cameraZoomDirection == UAV_CAMERA_ZOOM_DIRECTION_OUT) {
tempDigitalFactor -= (UAV_f32_t) ZOOM_DIGITAL_STEP_FACTOR;
}

if (tempDigitalFactor > (UAV_f32_t) ZOOM_DIGITAL_MAX_FACTOR) {
tempDigitalFactor = (UAV_f32_t) ZOOM_DIGITAL_MAX_FACTOR;
}

if (tempDigitalFactor < (UAV_f32_t) ZOOM_DIGITAL_BASE_FACTOR) {
s_isOpticalZoomReachLimit = false;
tempDigitalFactor = ZOOM_DIGITAL_BASE_FACTOR;
}
}
s_cameraOpticalZoomFocalLength = (uint16_t) tempFocalLength;
s_cameraDigitalZoomFactor = tempDigitalFactor;
}