Apollo: Time difference between ROS and Apollo

Created on 3 Jul 2018  Â·  5Comments  Â·  Source: ApolloAuto/apollo

Hi Guys,

Recently I have started working on Apollo. I see that Apollo time is not same as ROS time.
Could anybody please let me know difference and also the relation between ROS and Apollo time.

Thank you,
KK

CarOS Question

Most helpful comment

There are three kinds of clocks in Apollo, you can see the file apollo\modules\common\time\time.h
line 162:

static Timestamp Now() {
switch (mode()) {
case ClockMode::SYSTEM:
return SystemNow();
case ClockMode::MOCK:
return instance()->mock_now_;
case ClockMode::ROS:
return From(ros::Time::now().toSec());
default:
AFATAL << "Unsupported clock mode: " << mode();
}
return From(ros::Time::now().toSec());
}

line 198:

static void SetNow(const Duration &duration) {
Clock *clock = instance();
if (clock->mode_ != ClockMode::MOCK) {
AFATAL << "Cannot set now when clock mode is not MOCK!";
}
clock->mock_now_ = Timestamp(duration);
}

All 5 comments

There are three kinds of clocks in Apollo, you can see the file apollo\modules\common\time\time.h
line 162:

static Timestamp Now() {
switch (mode()) {
case ClockMode::SYSTEM:
return SystemNow();
case ClockMode::MOCK:
return instance()->mock_now_;
case ClockMode::ROS:
return From(ros::Time::now().toSec());
default:
AFATAL << "Unsupported clock mode: " << mode();
}
return From(ros::Time::now().toSec());
}

line 198:

static void SetNow(const Duration &duration) {
Clock *clock = instance();
if (clock->mode_ != ClockMode::MOCK) {
AFATAL << "Cannot set now when clock mode is not MOCK!";
}
clock->mock_now_ = Timestamp(duration);
}

Thank you for the response... Having hard time in understanding.. when I run apollo using bash scripts/bootstrap.sh, it would run based on ROS time or is there any difference. ?

@kk2491 The three kinds of clocks in Apollo is different in time. Your Apollo time maybe the system time, because your project maybe worked in the Linux or other system, it's not the true ROS system. That is may why your time not matched.

That just was my guess. Because I have transplanted part of the code running under Windows, found that the time does not matched, so I modified some code in time.h, set the normal time is SYSTEM time.

Others, the computing power of your device will also affect the time.

@follow123 Thank you so much for the explanation .. :-) I got it working now..

Thanks for the help guys.. I will be closing this issue ...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

freeclouds picture freeclouds  Â·  3Comments

chilihua picture chilihua  Â·  3Comments

YaoQii picture YaoQii  Â·  3Comments

Triangle001 picture Triangle001  Â·  3Comments

Wsine picture Wsine  Â·  3Comments