The time of the drone system slightly differs from the GPS time

Completed

Comments

19 comments

  • DJI Developer Support
    Hello, unfortunately, currently you can only use PSDK on the onboard device to synchronize the time to the drone. Which model are you using?
    0
    Comment actions Permalink
  • Takuma Watanabe

    Hello, thank you for your reply. Here are my development environment.

     

    Drone: Matrice 350 RTK

    Toolchain: Keil MDK v5.40.0.3 with compiler v5.25.2.0

    Adapter Board: Payload SDK Development Kit 2.0

    Onboard Device 1: STM32F4Discovery, connected to the adapter board through UART to receive RTK positioning data from the drone

    Onboard Device 2: Raspberry Pi 4 Model B, connected to the STM32F4Discovery through UART, to receive and store the positioning data from the STM32F4Discovery to the SD card of the Raspberry Pi, and to collect the measured data from the following sensor module. The system clock is adjusted using a third-party GPS receiver module.

    Onboard Device 3: Sensor (millimeter-wave FMCW radar) module, connected to the Raspberry Pi through USB-C cable, I need to precisely know the drone time when this sensor starts sensing

     

    I have understood that the GPS time cannot be used to synchronize the drone time. Is it possible to use the Time Synchronization function of the Payload SDK on Linux platform (Raspberry Pi)? If it is possible, the STM32F4Discovery board is no longer necessary. I'm using this board because the sample code of the time synchronization and positioning are only for the FreeRTOS platform. The following article says that "When developing on Linux, you cannot use the sample directly. You need to adapt it to the platform in the PPS callback part (5.16.4 Development Notes). " However, I cannot figure out how to do it. It would be great help if there is the working sample code for Linux platforms.

     

    https://sdk--forum-dji-net.translate.goog/hc/zh-cn/articles/7025264281241-5-16-%E6%97%B6%E9%97%B4%E5%90%8C%E6%AD%A5-time-sync?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=ja&_x_tr_pto=wapp

    https://sdk--forum-dji-net.translate.goog/hc/zh-cn/articles/7024246057625-5-14-%E7%B2%BE%E5%87%86%E5%AE%9A%E4%BD%8D-positioning?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=ja&_x_tr_pto=wapp 

    0
    Comment actions Permalink
  • DJI Developer Support
    Hello, sorry, maybe due to the problem of translation software, you want to synchronize the time of the payload device with the time of the drone, right? The time of the drone is actually obtained through GPS communication. When you synchronize the time of the drone, you also synchronize the GPS time to a certain extent. For the modification in LINUX, you can refer to the attached picture.
    0
    Comment actions Permalink
  • Takuma Watanabe

    Thank you for your reply.

    >Hello, sorry, maybe due to the problem of translation software, you want to synchronize the time of the payload device with the time of the drone, right?

    Yes.

    >The time of the drone is actually obtained through GPS communication.

    But as I said before, the drone time is about 10 seconds faster than the actual GPS time.

    >For the modification in LINUX, you can refer to the attached picture.

    Sorry, I cannot see the attached picture. Where can I find that?

     

    0
    Comment actions Permalink
  • DJI Developer Support
    Hello, regarding the picture, you can refer to here. As for the drone being 10 seconds faster than GPS, we have confirmed that this is processed by the flight control end, so this may not be corrected on the SDK side, unfortunately: https://pan-sec.djicorp.com/s/SJ5zYYPqzW3YmmE
    0
    Comment actions Permalink
  • Takuma Watanabe

    Hello, thank you so much for the pictures. Is it possible to provide complete working sample source files?

    0
    Comment actions Permalink
  • DJI Developer Support
    Hello, unfortunately, only the image files are currently available (previously provided to other developers for reference). Regarding the source code, we need to confirm with the R&D team. If a large number of developers consult us, we will make it into a tutorial.
    0
    Comment actions Permalink
  • Takuma Watanabe

    Hello, I successfully built my code modified based on the provided picture. However, I have got the following error. It seems that the PPS signal was received correctly. Do you identify what the problem is?
    Could you please provide the content of "system_init()" function in "image (3).png?"

    [0.010][core]-[Info]-[DjiCore_Init:106) Payload SDK Version : V3.9.0-beta.0-build.2044
    [0.375][adapter]-[Info]-[DjiAccessAdapter_Init:231) Identify aircraft series is Matrice 350 Series
    [0.375][adapter]-[Info]-[DjiAccessAdapter_Init:264) Identify mount position type is Payload Port Type
    [0.380][adapter]-[Info]-[DjiAccessAdapter_Init:365) Identity uart0 baudrate is 460800 bps
    [0.400][adapter]-[Info]-[DjiPayloadNegotiate_Init:243) Waiting payload negotiate finished.
    [1.400][adapter]-[Info]-[DjiPayloadNegotiate_Init:247) No need wait negotiate finished
    [1.409][core]-[Info]-[DjiIdentityVerify_UpdatePolicy:474) Updating dji sdk policy file...
    [2.409][core]-[Info]-[DjiIdentityVerify_UpdatePolicy:482) Update dji sdk policy file successfully
    [3.483][infor]-[Info]-[DjiAircraftInfo_GetAdapterSerialNumber:806) Get serial number of Skyport V2 or X-Port is 39CDM6M0010070
    [3.485][core]-[Info]-[DjiCore_Init:174) Identify AircraftType = Matrice 350 RTK, MountPosition = Payload Port NO1, SdkAdapterType = Skyport V2
    [4.090][core]-[Info]-[DjiCore_ApplicationStart:238) Start dji sdk application
    [4.116][time_sync]-[Info]-[DjiTimeSync_ApplyPpsAsyncCallback:593) apply pps success.
    [4.181][time_sync]-[Info]-[DjiTimeSync_PushAppTimeHandle:111) Current time: 2024.09.25 14:46:15.
    [4.334][time_sync]-[Info]-[DjiTimeSync_ApplyAircraftTimestampAsyncCallback:663) apply aircraft timestamp success.
    [5.413][user]-[Warn]-[TimeSyncRTK_GetNewestPpsTriggerLocalTimeUs:228) pps have not been triggered.
    [5.413][time_sync]-[Error]-[DjiTimeSync_ReceiveAircraftTimestampHandle:481) System is busy. Suggestion : Please try again later. (Details:) Callback function return error. Please check this function in users provided.
    [5.413][linker]-[Error]-[DjiCommand_DealCmd:889) cmd handle failure, cmdset = 0x0f, cmdid = 0x74
    [5.542][time_sync]-[Error]-[DjiTimeSync_TransferToAircraftTime:307) Payload have not synchronised time. Please call DjiTimeSync_RegGetNewestPpsTriggerTimeCallback interface to register GetNewestPpsTriggerLocalTimeUsCallback callback function before transferring time, and please check hardware connection / software configure of PPS signal and RTK signal to ensure PPS signal is[5.542][user]-[Error]-[DjiTest_TimeSyncTask:162) transfer to aircraft time error: 0x000000E4.
    [5.544][user]-[Info]-[TimeSyncRTK_PpsSignalResponseInit:215) pps signal response init success.
    [5.575][infor]-[Info]-[DjiAircraftInfo_NotifyMobileAppInfoHandle:715) Set mobile app info, language is Japanese, screen type is Big Screen
    [6.354][user]-[Info]-[TimeSyncRTK_ppsIrpHandle:179)  === get localtime: 1727243177.173 us
    [6.484][time_sync]-[Error]-[DjiTimeSync_ReceiveAircraftTimestampHandle:499) aircraft timestamp package is invalid, local: 6484000, trigger: 1727243177000173, difference: -597593293.
    [6.484][linker]-[Error]-[DjiCommand_DealCmd:889) cmd handle failure, cmdset = 0x0f, cmdid = 0x74
    [6.542][time_sync]-[Error]-[DjiTimeSync_TransferToAircraftTime:307) Payload have not synchronised time. Please call DjiTimeSync_RegGetNewestPpsTriggerTimeCallback interface to register GetNewestPpsTriggerLocalTimeUsCallback callback function before transferring time, and please check hardware connection / software configure of PPS signal and RTK signal to ensure PPS signal is[6.542][user]-[Error]-[DjiTest_TimeSyncTask:162) transfer to aircraft time error: 0x000000E4.
    [7.354][user]-[Info]-[TimeSyncRTK_ppsIrpHandle:179)  === get localtime: 1727243178.99 us
    [7.423][time_sync]-[Error]-[DjiTimeSync_ReceiveAircraftTimestampHandle:499) aircraft timestamp package is invalid, local: 7423000, trigger: 1727243178000099, difference: -597654219.
    [7.423][linker]-[Error]-[DjiCommand_DealCmd:889) cmd handle failure, cmdset = 0x0f, cmdid = 0x74
    [7.543][time_sync]-[Error]-[DjiTimeSync_TransferToAircraftTime:307) Payload have not synchronised time. Please call DjiTimeSync_RegGetNewestPpsTriggerTimeCallback interface to register GetNewestPpsTriggerLocalTimeUsCallback callback function before transferring time, and please check hardware connection / software configure of PPS signal and RTK signal to ensure PPS signal is[7.543][user]-[Error]-[DjiTest_TimeSyncTask:162) transfer to aircraft time error: 0x000000E4.
    [8.354][user]-[Info]-[TimeSyncRTK_ppsIrpHandle:179)  === get localtime: 1727243179.106 us
    [8.419][time_sync]-[Error]-[DjiTimeSync_ReceiveAircraftTimestampHandle:499) aircraft timestamp package is invalid, local: 8419000, trigger: 1727243179000106, difference: -597658226.
    [8.419][linker]-[Error]-[DjiCommand_DealCmd:889) cmd handle failure, cmdset = 0x0f, cmdid = 0x74
    [8.543][time_sync]-[Error]-[DjiTimeSync_TransferToAircraftTime:307) Payload have not synchronised time. Please call DjiTimeSync_RegGetNewestPpsTriggerTimeCallback interface to register GetNewestPpsTriggerLocalTimeUsCallback callback function before transferring time, and please check hardware connection / software configure of PPS signal and RTK signal to ensure PPS signal is[8.543][user]-[Error]-[DjiTest_TimeSyncTask:162) transfer to aircraft time error: 0x000000E4.

    0
    Comment actions Permalink
  • DJI Developer Support
    Hello, you can see that Callback function return error. Please check this function in users provided. This error is because the callback information is incorrect and cannot be synchronized. You can check whether the callback information is the same as that in the sample. Please do not completely copy the image we provide, because the implementation of the image is based on the PSDK 3.3 version. The current PSDK version has changed a lot, and some interfaces may not be applicable.
    0
    Comment actions Permalink
  • Takuma Watanabe

    Thank you for your reply.

    >Please do not completely copy the image we provide, because the implementation of the image is based on the PSDK 3.3 version.
    I have compared the provided image with the original sample code, but the code in the image seems to be correctly implemented. Sorry but I can't figure out how to modify it. Could you please provide more detailed information?

    What I have done are:
    1) Add the following code to the end of "test_time_sync.c"

    /* Step 1 */
    static void TimeSyncRTK_ppsIrpHandle(void)
    {
        struct timeval tv;

        if(gettimeofday(&tv, NULL) == 0) {
            s_ppsNewestTriggerLocalTimeUs = (uint64_t)tv.tv_sec*1000000 + (uint64_t)tv.tv_usec;
            USER_LOG_INFO(" === get localtime: %u.%u us", tv.tv_sec, tv.tv_usec);
        }
        else {
            s_ppsNewestTriggerLocalTimeUs = 0;
        }
    }

    /* Step 2 */
    static T_DjiReturnCode TimeSyncRTK_setupPiIrq(void)
    {
        /* Step 2.1 */
        if (wiringPiSetup() == -1) {
            USER_LOG_ERROR("wiringPi setup error");
            return DJI_RETURN_CODE_ERR_UNKNOWN;
        }
        /* Step 2.2 */
        const int ppsPin = 4;

        pinMode(ppsPin, INPUT);
        pullUpDnControl(ppsPin, PUD_DOWN);

        /* Step 2.3 */
        if (wiringPiISR(ppsPin, INT_EDGE_RISING, TimeSyncRTK_ppsIrpHandle) < 0) {
            USER_LOG_ERROR("wiringPi interrupt register error");
            return DJI_RETURN_CODE_ERR_UNKNOWN;
        }

        return DJI_RETURN_CODE_OK;
    }

    /* Step 3 */
    T_DjiReturnCode TimeSyncRTK_PpsSignalResponseInit(void)
    {
        if (TimeSyncRTK_setupPiIrq() != DJI_RETURN_CODE_OK) {
            return DJI_RETURN_CODE_ERR_UNKNOWN;
        }
        USER_LOG_INFO("pps signal response init success.");

        return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
    }

    /* Step 4 */
    T_DjiReturnCode TimeSyncRTK_GetNewestPpsTriggerLocalTimeUs(uint64_t *localTimeUs)
    {
        if (localTimeUs == NULL) {
            USER_LOG_ERROR("input pointer is null.");
            return DJI_ERROR_SYSTEM_MODULE_CODE_INVALID_PARAMETER;
        }
        if (s_ppsNewestTriggerLocalTimeUs == 0) {
            USER_LOG_WARN("pps have not been triggered.");
            return DJI_ERROR_SYSTEM_MODULE_CODE_BUSY;
        }
        *localTimeUs = s_ppsNewestTriggerLocalTimeUs;

        return DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS;
    }

    2) Add the following code before "while(1)" loop in the main function in "main.c"

        /* Time Sync. Step 1 */
        T_DjiTestTimeSyncHandler timeSyncHandler = {
            .PpsSignalResponseInit = TimeSyncRTK_PpsSignalResponseInit,
            .GetNewestPpsTriggerLocalTimeUs = TimeSyncRTK_GetNewestPpsTriggerLocalTimeUs
        };
        DjiTest_TimeSyncRegHandler(&timeSyncHandler);

        /* Time Sync. Step 2 */
        returnCode = DjiTest_TimeSyncStartService();
        if (returnCode != DJI_ERROR_SYSTEM_MODULE_CODE_SUCCESS) {
            USER_LOG_ERROR("time sync init error");
        }

    "DjiTest_TimeSyncTask" function in "test_time_sync.c" is not changed because the code in the image seems same as those in the original sample code.

    0
    Comment actions Permalink
  • DJI Developer Support
    Hello, it seems that there is no problem with your process. During the use, have you ensured the RTK data convergence? Because we found that there is a prompt in the log that the aircraft time acquisition failed, which means that your RTK convergence may be abnormal.
    0
    Comment actions Permalink
  • Takuma Watanabe

    Hello, I have tried a similar outdoor experiment confirming that the RTK data was converged (FIX solution, using D-RTK2 mobile station). However, again I have got the similar error (aircraft timestamp package is invalid). Could you please tell me other possible cause for this error?

    0
    Comment actions Permalink
  • DJI Developer Support
    Hello, we have confirmed that the most common problem is RTK non-convergence. If you still have saved logs, you can export the logs to us and we will further confirm the cause for you. How to export aircraft logs/parameter logs
    0
    Comment actions Permalink
  • Takuma Watanabe

    Hello, I have uploaded the exported log file on Dropbox and the link is given in the previous post which is now pending approval. If you cannot see the link, please tell me where to upload my log file.

    0
    Comment actions Permalink
  • DJI Developer Support
    Hi, we are sorry, we may not be able to access the data, please upload the log file here: https://pan-sec.djicorp.com/s/LHQggJj5WZ9fmxg We will check it as soon as possible.
    0
    Comment actions Permalink
  • Takuma Watanabe

    Sorry, the system says that I don't have authorization to upload the file. Could you please give me a permission to upload the file? I also uploaded my log file to the following Google Drive link. Please try to use this.

    https://drive.google.com/file/d/12C3BrL1lwghfp1gOmoXx_JiluVUYFI9u/view?usp=sharing

    0
    Comment actions Permalink
  • DJI Developer Support
    Hello, we tried your link, unfortunately, it cannot be accessed, and it prompts us that there is an access error. Please re-upload it here: https://pan-sec.djicorp.com/s/LHQggJj5WZ9fmxg We have re-checked the permissions.
    0
    Comment actions Permalink
  • Takuma Watanabe

    I have successfully uploaded the log file to the provided link. Thank you very much.

    0
    Comment actions Permalink
  • DJI Developer Support
    Hello, we noticed that your rtk status is normal, so you can focus on checking whether the time record is inconsistent, which will also cause time synchronization failure. It is recommended to refer to the following to print out the time for comparison to check: 1. Print localTimeUs in the PsdkTest_TimeSyncGetNewestPpsTriggerLocalTimeUs function in the test_time_sync.c file 2. The result of localTimeUs of PsdkTest_GetNewestPpsTriggerLocalTimeUs in the pps.c file is saved in a txt file 3. Print s_ppsNewestTriggerLocalTimeMs in PPS at the same time Compare these three data to see if there is any abnormality.
    0
    Comment actions Permalink

Please sign in to leave a comment.