ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I believe this is due to a misunderstanding of the comment on isValid().

The documentation indeed states (here):

Returns whether or not the current time is valid. Time is valid if it is non-zero.

But "the [..] time" it refers to is not the Time instance, but "the time", as in: the global ROS time. A ROS node can use different methods to retrieve the "current time": it can use walltime, a simulation time or something else. The "valid" here essentially returns true whenever one of those sources have been selected and has been initialised properly.

0 is chosen as a sentinel value to detect when that is not the case.

It's slightly confusing that a ros::Time instance can also have a 0 value


We can also take a look at the sources (from here):

return (!g_use_sim_time) || !g_sim_time.isZero();

This essentially tells us that "time" is considered "valid" if either we're not using simulation time, or, if simulation time is being used, it's != 0.

The g_ prefixes tell us that this static method is checking globals, not ros::Time member variables.

I believe this is due to a misunderstanding of the comment on isValid().

The documentation indeed states (here):

Returns whether or not the current time is valid. Time is valid if it is non-zero.

But "the [..] time" it refers to is not the Time instance, but "the time", as in: the global ROS time. A ROS node can use different methods to retrieve the "current time": it can use walltime, a simulation time or something else. The "valid" here essentially returns true whenever one of those sources have been selected and has been initialised properly.

0 is chosen as a sentinel value to detect when that is not the case.case (as it's assumed that 0 is just not a valid value for any source of time (whether that is correct is something else)).

It's slightly confusing that a ros::Time instance can also have a 0 valuevalue and that ros::Time::isValid() is a static method of the ros::Time class.


We can also take a look at the sources (from here):

return (!g_use_sim_time) || !g_sim_time.isZero();

This essentially tells us that "time" is considered "valid" if either we're not using simulation time, or, if simulation time is being used, it's != 0.

The g_ prefixes tell us that this static method is checking globals, not ros::Time member variables.


Edit: perhaps a nice contribution would be to improve the documentation of this method and to remove the ambiguity.

I believe this is due to a misunderstanding of the comment on isValid().

The documentation indeed states (here):

Returns whether or not the current time is valid. Time is valid if it is non-zero.

But "the [..] time" it refers to is not the Time instance, but "the time", as in: the global ROS time. A ROS node can use different methods to retrieve the "current time": it can use walltime, a simulation time or something else. The "valid" here essentially returns true whenever one of those sources have been selected and has been initialised properly.

0 is chosen as a sentinel value to detect when that is not the case (as it's assumed that 0 is just not a valid value for any source of time (whether that is correct is something else)).

It's slightly confusing that a ros::Time instance can also have a 0 value and that ros::Time::isValid() is a static method of the ros::Time class.

In the code that you show:

int main(int argc, char** argv) {
    ros::init(argc, argv, "rostime_example");
    [..]
}

isValid() will return true as soon as you call ros::init(..) (as one of its duties is to initialise the time subsystem).


We can also take a look at the sources (from here):

return (!g_use_sim_time) || !g_sim_time.isZero();

This essentially tells us that "time" is considered "valid" if either we're not using simulation time, or, if simulation time is being used, it's != 0.

The g_ prefixes tell us that this static method is checking globals, not ros::Time member variables.


Edit: perhaps a nice contribution would be to improve the documentation of this method and to remove the ambiguity.

I believe this is due to a misunderstanding of the comment on isValid().

The documentation indeed states (here):

Returns whether or not the current time is valid. Time is valid if it is non-zero.

But "the [..] time" it refers to is not the Time instance, but "the time", as in: the global ROS time. A ROS node can use different methods to retrieve the "current time": it can use walltime, a simulation time or something else. The "valid" here essentially returns true whenever one of those sources have been selected and has been initialised properly.

0 is chosen as a sentinel value to detect when that is not the case (as it's assumed that 0 is just not a valid value for any source of time (whether that is correct is something else)).

It's slightly confusing that a ros::Time instance can also have a 0 value and that ros::Time::isValid() is a static method of the ros::Time class.

In the code that you show:

int main(int argc, char** argv) {
    ros::init(argc, argv, "rostime_example");
    [..]
}

isValid() will return true as soon as you call ros::init(..) (as one of its duties is to initialise the time subsystem).


We can also take a look at the sources (from here):

bool Time::isValid()
{
  return (!g_use_sim_time) || !g_sim_time.isZero();
}

This essentially tells us that "time" is considered "valid" if either we're not using simulation time, or, if simulation time is being used, it's != 0.

The g_ prefixes tell us that this static method is checking globals, not ros::Time member variables.


Edit: perhaps a nice contribution would be to improve the documentation of this method and to remove the ambiguity.

I believe this is due to a misunderstanding of the comment on isValid().

The documentation indeed states (here):

Returns whether or not the current time is valid. Time is valid if it is non-zero.

But "the [..] time" it refers to is not the Time instance, but "the time", as in: the global ROS time. time.

A ROS node can use different methods to retrieve the "current time": it can use walltime, a simulation time or something else. The "valid" here essentially returns true whenever one of those sources have been selected and has been initialised properly.

0 is chosen as a sentinel value to detect when that is not the case (as it's assumed that 0 is just not a valid value for any source of time (whether that is correct is something else)).

It's slightly confusing that a ros::Time instance can also have a 0 value and that ros::Time::isValid() is a static method of the ros::Time class.

In the code that you show:

int main(int argc, char** argv) {
    ros::init(argc, argv, "rostime_example");
    [..]
}

isValid() will return true as soon as you call ros::init(..) (as one of its duties is to initialise the time subsystem).


We can also take a look at the sources (from here):

bool Time::isValid()
{
  return (!g_use_sim_time) || !g_sim_time.isZero();
}

This essentially tells us that "time" is considered "valid" if either we're not using simulation time, or, if simulation time is being used, it's != 0.

The g_ prefixes tell us that this static method is checking globals, not ros::Time member variables.


Edit: perhaps a nice contribution would be to improve the documentation of this method and to remove the ambiguity.