QUATERNION subscription cannot unsubscribe and resubscribe
362 0 2023-7-24
Uploading and Loding Picture ...(0/1)
o(^-^)o
FantasticMrFox
lvl.1

Australia
Offline


We have code that basically subscribes to the E_DjiFcSubscriptionTopic::DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION

topic, unsubscribes, then resubscribes. If you do this, then the second subscription is NEVER called. The code is as follows:




```

#include "dji_psdk_drone.hpp"
#include "dji_psdk_error_handling.hpp"
#include "dji_psdk_runtime_environment.hpp"

#include <djipsdk/dji_aircraft_info.h>
#include <djipsdk/dji_core.h>
#include <djipsdk/dji_error.h>
#include <djipsdk/dji_fc_subscription.h>
#include <djipsdk/dji_flight_controller.h>
#include <djipsdk/dji_logger.h>
#include <djipsdk/dji_typedef.h>

#include <chrono>
#include <ctime>
#include <iostream>
#include <thread>

using namespace dji_psdk;
using namespace std::chrono_literals;

inline T_DjiReturnCode g_dji_callback_1(
    const uint8_t* data, uint16_t, const T_DjiDataTimestamp* timestamp
)
{
    std::cout << "GOT CALLBACK 1\n";
    return 0;
}

inline T_DjiReturnCode g_dji_callback_2(
    const uint8_t* data, uint16_t, const T_DjiDataTimestamp* timestamp
)
{
    std::cout << "GOT CALLBACK 2\n";
    return 0;
}

T_DjiUserInfo make_default_user_info()
{
    return T_DjiUserInfo{};
}

int main()
{
    ros::Time::init();
    dji_psdk::DjiPsdkRuntimeEnvironment runtime_environment{
        {{"serial_port_name", "/dev/ttyXRUSB0"}}};

    T_DjiUserInfo             userInfo = make_default_user_info();
    T_DjiAircraftInfoBaseInfo aircraftInfoBaseInfo;

    handle_psdk_call(DjiCore_Init(&userInfo));
    handle_psdk_call(DjiAircraftInfo_GetBaseInfo(&aircraftInfoBaseInfo));
    handle_psdk_call(DjiCore_SetAlias("PSDK_APPALIAS"));
    handle_psdk_call(DjiCore_ApplicationStart());
    handle_psdk_call(DjiFlightController_Init());

    std::cout << "Subscription 1\n";

    // If this is changed to DJI_FC_SUBSCRIPTION_TOPIC_VELOCITY then the whole thing
    // works as expected.
    const auto sub_to_use =
        E_DjiFcSubscriptionTopic::DJI_FC_SUBSCRIPTION_TOPIC_QUATERNION;

    handle_psdk_subscription(
        "sub specific",
        DjiFcSubscription_SubscribeTopic(
            sub_to_use, DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ, &g_dji_callback_1
        )
    );

    std::this_thread::sleep_for(1s);

    std::cout << "Unsubscribing\n";

    handle_psdk_subscription(
        "Unsubscribing default", DjiFcSubscription_UnSubscribeTopic(sub_to_use)
    );

    std::this_thread::sleep_for(1s);

    std::cout << "RESUBSCRIBING!\n";

    handle_psdk_subscription(
        "sub specific",
        DjiFcSubscription_SubscribeTopic(
            sub_to_use, DJI_DATA_SUBSCRIPTION_TOPIC_50_HZ, &g_dji_callback_2
        )
    );

    while (true) { std::this_thread::sleep_for(500ms); }

    return 0;
}



```

As specified in the code, if you use the TOPIC_VELOCITY, this works as expected. This is on PSDK 3.5 with the M350 drone.


2023-7-24
Use props
Advanced
You need to log in before you can reply Login | Register now

Credit Rules