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

fix rtt_now when sim clock is running on xenomai #41

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions rtt_rosclock/src/rtt_rosclock.cpp
Expand Up @@ -55,13 +55,17 @@ const ros::Time rtt_rosclock::rtt_now()
const uint64_t one_E9 = 1000000000ULL;
// NOTE: getNSecs returns wall time, getTicks returns offset time
#ifdef __XENO__
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this distinction between Xenomai and non-Xenomai builds required here at all, independent of sim time?
Wouldn't getTicks() (the else branch) work for both cases?

getTicks() => rt_timer_tsc() (if system clock is enabled in the TimeService)
getNSecs() => rt_timer_ticks2ns(rt_timer_read()) (independent of sim/system time mode)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into that next week. Thanks for the clarification !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's very true, I'm closing this PR until I provide a new one with your recommendations :)

uint64_t nsec64 = RTT::os::TimeService::Instance()->getNSecs(); //RTT::os::TimeService::Instance()->getNSecs();
uint64_t nsec64;
if(SimClockThread::GetInstance() && SimClockThread::GetInstance()->simTimeEnabled())
nsec64 = RTT::os::TimeService::ticks2nsecs(RTT::os::TimeService::Instance()->getTicks());
else
nsec64 = RTT::os::TimeService::Instance()->getNSecs();
#else
uint64_t nsec64 = RTT::os::TimeService::ticks2nsecs(RTT::os::TimeService::Instance()->getTicks()); //RTT::os::TimeService::Instance()->getNSecs();
#endif
uint32_t sec32_part = nsec64 / one_E9;
uint32_t nsec32_part = nsec64 % one_E9;
//RTT::log(RTT::Error) << "sec: " << sec32 << " nsec: " << nsec32 << RTT::endlog();
//RTT::log(RTT::Error) << "sec: " << sec32_part << " nsec: " << nsec32_part << RTT::endlog();
return ros::Time(sec32_part, nsec32_part);
}

Expand Down