Gimbal Management

2022-06-21
No Rating

Overview

The gimbal management function of PSDK supports the simultaneous management of gimbal load devices mounted on different positions on the drone, including setting the gimbal mode, centering the gimbal, and controlling the gimbal rotation. The developer can design the control logic based on the interface of the gimbal management, so as to realize the function of precisely controlling the rotation of the designated gimbal to the corresponding angle during the flight of the drone.

Basic Concepts

Gimbal angle

gimbal joint and gimbal joint angle

The joints of the gimbal are shown in Figure 1. The gimbal joint is the structural member on the gimbal that drives the load equipment to rotate: the gimbal motor and the gimbal joint angle is the angle at which the gimbal motor rotates. This tutorial uses the body coordinate system to describe the joint angles of the gimbal.

Figure 1. Gimbal joint

gimbal attitude and gimbal attitude angle

The attitude of the gimbal is shown in Figure 2. The attitude of the gimbal is shown in Figure 2. According to the user's control instructions, the gimbal can adjust the attitude; The angle of the load device **, this angle is also called Euler angle.

Figure 2. Gimbal attitude

Gimbal control

  • control mode

    • Absolute angle control: The gimbal developed with PSDK will rotate from the current position to the specified position within the specified time according to the user's instructions.
    • Speed control: The user can control the rotation speed of the gimbal developed with PSDK.

Illustrate

  • In the angle control mode, the rotation time of the gimbal is limited by the maximum rotation speed and acceleration of the gimbal, and the actual rotation angle is limited by the limit angle of the gimbal.
  • In speed control mode, the gimbal rotates for 0.5s according to the speed specified by the user. When the gimbal rotates to the limit angle, it will stop rotating.
  • gimbal mode: Currently, the gimbal control function of PSDK supports only free mode. In this mode, when the attitude of the drone changes, the gimbal will not rotate.

gimbal status information

Applications developed using PSDK can obtain the current information on the specified gimbal. For details, please refer to PSDK API documentation.

Using the gimbal management function

1. gimbal management module initialization

If the load device developed with PSDK needs to control the gimbal, it needs to call the DjiGimbalManager_Init() interface to initialize the gimbal management module.

returnCode = DjiGimbalManager_Init();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("Init gimbal manager failed, error code: 0x%08X", returnCode);
    goto out;
}

2. Set gimbal mode

Before controlling the gimbal, you need to call the DjiGimbalManager_SetMode interface to set the working mode of the gimbal.

returnCode = DjiGimbalManager_SetMode(mountPosition, gimbalMode);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("Set gimbal mode failed, error code: 0x%08X", returnCode);
    goto out;
}

3. Control the gimbal rotation

Control the gimbal to rotate according to the expected angle and speed by calling the DjiGimbalManager_Rotate interface.

USER_LOG_INFO("Target gimbal pry = (30, 0, 0) in the body coordinate system");
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 30, 0, 0, 0.5};
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("Target gimbal pry = (30, 0, 0) failed, error code: 0x%08X", returnCode);
    goto out;
}

osalHandler->TaskSleepMs(1000);

USER_LOG_INFO("Target gimbal pry = (0, 30, 0) in the body coordinate system");
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, 30, 0, 0.5};
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("Target gimbal pry = (0, 30, 0) failed, error code: 0x%08X", returnCode);
    goto out;
}
osalHandler->TaskSleepMs(1000);

USER_LOG_INFO("Target gimbal pry = (0, 0, 30) in the body coordinate system");
rotation = (T_DjiGimbalManagerRotation) {DJI_GIMBAL_ROTATION_MODE_RELATIVE_ANGLE, 0, 0, 30, 0.5};
returnCode = DjiGimbalManager_Rotate(mountPosition, rotation);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("Target gimbal pry = (0, 0, 30) failed, error code: 0x%08X", returnCode);
    goto out;
}
osalHandler->TaskSleepMs(1000);

4. Control the gimbal back to center

Applications developed using PSDK support to rotate the pitch and yaw axes of the gimbal to the neutral position by calling the DjiGimbalManager_Reset interface.

USER_LOG_INFO("Target gimbal reset.\r\n");
returnCode = DjiGimbalManager_Reset(mountPosition);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("Reset gimbal failed, error code: 0x%08X", returnCode);
    goto out;
}

5. Get gimbal status

Developers can use the subscription data items DJI_FC_SUBSCRIPTION_TOPIC_GIMBAL_ANGLES and DJI_FC_SUBSCRIPTION_TOPIC_GIMBAL_STATUS to obtain the attitude angle and status of the gimbal at different positions.