Power Management

2024-06-27
No Rating

Overview

After the payload device developed based on PSDK is installed on the gimbal of the drone, the payload device can obtain higher power through power application. Therefore, the payload device using high power must support the use of low power at the same time; In case of data loss or accidental damage due to shutdown preparation, PSDK also provides the function of sending shutdown notifications.

Using power management functions

1. Pin initialization

A load device that needs to use high power needs to initialize the pins used to apply for high power on the payload device before applying for high power.

static T_PsdkReturnCode PsdkTest_HighPowerApplyPinInit(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_AHB1PeriphClockCmd(HIGH_POWER_APPLY_RCC, ENABLE);

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

    GPIO_InitStructure.GPIO_Pin = HIGH_POWER_APPLY_PIN;
    GPIO_Init(HIGH_POWER_APPLY_Port, &GPIO_InitStructure);

    return PSDK_RETURN_CODE_OK;
}

Note: Please implement the function of initializing the application for high-power pins according to the library supported by the selected development platform.

2. Develop and register a function to change the pin level state of the payload

  1. Develop a function to change the pin level state of the payload device After the developer develops the function of changing the pin level state of the payload device, it is necessary to register the function of changing the pin level state of the payload device into the specified interface.
T_DjiReturnCode DjiTest_WriteHighPowerApplyPin(E_DjiPowerManagementPinState pinState)
{
    GPIO_PinState state;

    switch (pinState) {
        case DJI_POWER_MANAGEMENT_PIN_STATE_RESET:
            state = GPIO_PIN_RESET;
            break;
        case DJI_POWER_MANAGEMENT_PIN_STATE_SET:
            state = GPIO_PIN_SET;
            break;
        default:
            USER_LOG_ERROR("pin state unknown: %d.", pinState);
            return DJI_ERROR_SYSTEM_MODULE_CODE_UNKNOWN;
    }

    HAL_GPIO_WritePin(HIGH_POWER_APPLY_PORT, HIGH_POWER_APPLY_PIN, state);

    return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}
  1. Register a function to change the pin level state After registering the function to change the pin level state of the payload device, the user can control the payload device to change the pin level state.
returnCode = DjiPowerManagement_RegWriteHighPowerApplyPinCallback(s_applyHighPowerHandler.pinWrite);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("register WriteHighPowerApplyPinCallback error.");
    return returnCode;
}

3. Apply for high power

After the payload device calls the DjiPowerManagement_ApplyHighPowerSync() interface, the payload device can apply for high power to the drone. After the high power application is completed, it can use a voltmeter and other instruments to measure the voltage of the SkyPort v2 and X-Port designated interfaces.

returnCode = DjiPowerManagement_ApplyHighPowerSync();
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("apply high power error");
    return returnCode;
}

Using shutdown notification function

The process of sending a shutdown notification from the drone is as follows:

  • When the drone gets the shutdown notification sent by the user, the drone will send a shutdown notification to the payload developed using PSDK;
  • When the payload device receives the shutdown notification sent by the drone, the payload device will complete the operations that need to be performed before shutdown, and change the shutdown preparation state;
  • When the drone obtains the status of all the payload devices being ready to shut down, it will shut down immediately.

Note: After receiving the shutdown notification for a period of time, the drone will be forced to shut down. For the specific forced shutdown time, please refer to the corresponding product model Instructions.

1. Construct shutdown state callback function

After the developer develops the function for the payload device to perform the shutdown preparation, the developer needs to register the function of the payload device to perform the shutdown preparation function in the specified interface.

static T_DjiReturnCode DjiTest_PowerOffNotificationCallback(bool *powerOffPreparationFlag)
{
    USER_LOG_INFO("aircraft will power off soon.");

    *powerOffPreparationFlag = true;

    return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
}

2. Register the callback function

After registering the function of the shutdown preparation function of the payload device, after the payload device receives the shutdown notification, it will perform the shutdown preparation action and change the shutdown preparation state of the payload device, as shown in Figure 1. Shutdown information.

// register power off notification callback function
returnCode = DjiPowerManagement_RegPowerOffNotificationCallback(DjiTest_PowerOffNotificationCallback);
if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
    USER_LOG_ERROR("register power off notification callback function error");
    return returnCode;
}

Figure 1. Shutdown Information

If you have any comments or confusion about our documentation, you can click here to give feedback and we will get back to you as soon as possible.