Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistencies between different gps and unix time conversion implementation #15499

Open
boyang9602 opened this issue Aug 9, 2024 · 0 comments
Labels
Module: Driver Indicates driver module related issues

Comments

@boyang9602
Copy link

boyang9602 commented Aug 9, 2024

Describe the bug
There are multiple implementations of GPS and UNIX time conversion in Apollo. The first is in https://github.com/ApolloAuto/apollo/blob/master/modules/common/util/time_util.h, the second is in https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/gnss/util/time_conversion.h, the third is in https://github.com/ApolloAuto/apollo/blob/master/cyber/common/time_conversion.h, the last is in https://github.com/ApolloAuto/apollo/blob/master/modules/localization/msf/common/util/time_conversion.h.

To Reproduce
Steps to reproduce the behavior:
I compared the first three implementations with GPS time 1001696182.543048

#include <iostream>
#include "time_util.h" // https://github.com/ApolloAuto/apollo/blob/master/modules/common/util/time_util.h
#include "time_conversion.h" // https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/gnss/util/time_conversion.h
#include "time_conversion_new.h" // https://github.com/ApolloAuto/apollo/blob/master/cyber/common/time_conversion.h

int main() {
    double gps_time = 1001696182.543048;
    
    // https://github.com/ApolloAuto/apollo/blob/master/modules/common/util/time_util.h
    double unix_time = TimeUtil::Gps2unix(gps_time);
    std::cout << "TimeUtil::Gps2unix\n\tGPS time: " << GLOG_TIMESTAMP(gps_time) 
              << " -> Unix time: " << GLOG_TIMESTAMP(unix_time) << std::endl;

    // https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/gnss/util/time_conversion.h
    unix_time = gps2unix(gps_time);
    std::cout << "gps2unix\n\tGPS time: " << GLOG_TIMESTAMP(gps_time) 
              << " -> Unix time: " << GLOG_TIMESTAMP(unix_time) << std::endl;

    // https://github.com/ApolloAuto/apollo/blob/master/cyber/common/time_conversion.h
    unix_time = GpsToUnixSeconds(gps_time);
    std::cout << "GpsToUnixSeconds\n\tGPS time: " << GLOG_TIMESTAMP(gps_time) 
              << " -> Unix time: " << GLOG_TIMESTAMP(unix_time) << std::endl;

    return 0;
}

There is a 2 seconds diff, between time_util.h and time_conversion.h, as shown below

(msfloc) bo@apollo:~/projects/time_conversion$ ./a.out 
TimeUtil::Gps2unix
	GPS time: 1001696182.543048024 -> Unix time: 1317660965.543047905
gps2unix
	GPS time: 1001696182.543048024 -> Unix time: 1317660967.543047905
GpsToUnixSeconds
	GPS time: 1001696182.543048024 -> Unix time: 1317660967.543047905

Which one is correct?

@daohu527 daohu527 added the Module: Driver Indicates driver module related issues label Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Module: Driver Indicates driver module related issues
Projects
None yet
Development

No branches or pull requests

2 participants