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

External clock source #69

Open
mkolodziejczyk-piap opened this issue Nov 28, 2022 · 0 comments
Open

External clock source #69

mkolodziejczyk-piap opened this issue Nov 28, 2022 · 0 comments

Comments

@mkolodziejczyk-piap
Copy link

Hi, I'm new to MOOS. I want to use time from external source (ROS). Is it enough to modify MOOSLocalTime(). Regards,

double MOOSLocalTime(bool bApplyTimeWarping)
{
#ifndef _WIN32
double dfT=0.0;
struct timeval TimeVal;
if(gettimeofday(&TimeVal,NULL)==0)
{
dfT = TimeVal.tv_sec+TimeVal.tv_usec/1000000.0;
}
else
{
//lost the will to live.....
MOOSAssert(0);
dfT =-1;
}
if(bApplyTimeWarping)
return dfT*gdfMOOSTimeWarp;
else
return dfT;
#else
if( gbWin32HPTiming )
{
static LARGE_INTEGER liStart;
static LARGE_INTEGER liPerformanceFreq;
static double dfMOOSStart;
static bool bHPTimeInitialised=false;
//to do - we should consider thread saftery here..
if(!bHPTimeInitialised)
{
//initialise with crude time
struct _timeb timebuffer;
_ftime( &timebuffer );
dfMOOSStart = timebuffer.time+ ((double)timebuffer.millitm)/1000;
QueryPerformanceCounter(&liStart);
QueryPerformanceFrequency(&liPerformanceFreq);
bHPTimeInitialised=true;
return bApplyTimeWarping ? dfMOOSStart*gdfMOOSTimeWarp :dfMOOSStart;
}
else
{
//use fancy time
LARGE_INTEGER liNow;
QueryPerformanceCounter(&liNow);
double T = dfMOOSStart+(double)(liNow.QuadPart-liStart.QuadPart)/((double)(liPerformanceFreq.QuadPart));
return bApplyTimeWarping ? T*gdfMOOSTimeWarp :T;
}
}
else
{
//user has elected to use low precision win32 timing
struct _timeb timebuffer;
_ftime( &timebuffer );
double T = timebuffer.time + ((double)timebuffer.millitm)/1000.0;
return bApplyTimeWarping ? T*gdfMOOSTimeWarp : T;
}
#endif
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant