Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

add specific exception for time jumping backwards - #492

Merged
dirk-thomas merged 1 commit into
ros:indigo-develfrom
jowave:rospy_sleep_time_backwards
Oct 23, 2014
Merged

dirk-thomas merged 1 commit into
ros:indigo-develfrom
jowave:rospy_sleep_time_backwards

Conversation

@jowave

@jowave jowave commented Aug 19, 2014

Copy link
Copy Markdown

reason: ROS shutdown and time jumps should be distinguishable.
ROSTimeMovedBackwardsException inherits from ROSInterruptException
to preserve the API.
fixes #485

@jowave

jowave commented Aug 19, 2014

Copy link
Copy Markdown
Author

Recreated the pull request against indigo-devel.
Sorry for the inconvenience.

@ros-pull-request-builder

Copy link
Copy Markdown
Member

Can one of the admins verify this patch?

@dirk-thomas

Copy link
Copy Markdown
Member

@dirk-thomas

Copy link
Copy Markdown
Member

Can you please move the exception class to clients/rospy/src/rospy/exceptions.py where most other exceptions are defined.

Beside this minor detail the patch lgtm.

@jowave

jowave commented Sep 15, 2014

Copy link
Copy Markdown
Author

I moved the exception and updated the pull request.

@dirk-thomas

Copy link
Copy Markdown
Member

@ros-pull-request-builder

Copy link
Copy Markdown
Member

@dirk-thomas

Copy link
Copy Markdown
Member

Please update your patch to pass all unit tests. It currently breaks 145 tests.

@dirk-thomas

Copy link
Copy Markdown
Member

Please update your patch to pass all unit tests. It currently breaks 145 tests.

@ros-pull-request-builder

Copy link
Copy Markdown
Member

@jowave

jowave commented Oct 16, 2014

Copy link
Copy Markdown
Author

I have updated the patch. Apparently it passed the tests now.

@wjwwood

wjwwood commented Oct 16, 2014

Copy link
Copy Markdown
Member

+1

Comment thread clients/rospy/src/rospy/timer.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please include the time offset in the error message so that the user has a better idea how much the time jumped.

@jowave

jowave commented Oct 17, 2014

Copy link
Copy Markdown
Author

I added the time offset in the error message and a small test for the exception.

@ros-pull-request-builder

Copy link
Copy Markdown
Member

@tlind

tlind commented Oct 18, 2014

Copy link
Copy Markdown

I am worried that commit d934e53 might break existing code which is trying to catch the exception. Since there was previously no specific exception for this case, the only way of specifically catching the time-moved-backwards issue was to check the exception message, e.g.:

try:
    r.sleep()
except rospy.exceptions.ROSInterruptException as e:
    if e.message == "ROS time moved backwards":
        rospy.logwarn("Time has moved backwards (probably ROS clock has been reset)!")

However, it seems that supplying the time offset as an additional argument to the exception constructor will break that message:

>>> print rospy.exceptions.ROSInterruptException("ROS time moved backwards").message
ROS time moved backwards
>>> print rospy.exceptions.ROSInterruptException("ROS time moved backwards", -10.0).message
[empty string]

Might it be a better idea to only rospy.logerr() the time offset, and leave the exception message as-is? Or add an additional field to the exception class which contains the time offset?

EDIT: I just read that Exception.message seems to be deprecated since 2.6, though I've been using it a few times and never saw a warning anywhere. Not sure how much other code depends on it. The correct way seems to be to use e.args[0], which returns the same result in both cases.

@dirk-thomas

Copy link
Copy Markdown
Member

@tlind That is a good point.

@jowave Can you please update the new exception class to store the time offset in a member variable and keep the message of the exception as-is.

@ros-pull-request-builder

Copy link
Copy Markdown
Member

@jowave

jowave commented Oct 20, 2014

Copy link
Copy Markdown
Author

I modified the code to work with Exception.message and added a test to check for the right message.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This line should be obsolete.

@dirk-thomas

Copy link
Copy Markdown
Member

Please squash your commits after removing the unnecessary pass line.

reason: ROS shutdown and time jumps should be distinguishable.
ROSTimeMovedBackwardsException inherits from ROSInterruptException
to preserve the API.
fixes #485
@ros-pull-request-builder

Copy link
Copy Markdown
Member

@dirk-thomas

Copy link
Copy Markdown
Member

Thank you for you efforts on this. Merging...

dirk-thomas added a commit that referenced this pull request Oct 23, 2014
add specific exception for time jumping backwards
@dirk-thomas
dirk-thomas merged commit 4d2b423 into ros:indigo-devel Oct 23, 2014
@jowave

jowave commented Oct 24, 2014

Copy link
Copy Markdown
Author

You're welcome. Thank you too.

Edit: Hmm, the ros-pull-request-builder is answering. Should i not have replied to a closed pull request?

@dirk-thomas

Copy link
Copy Markdown
Member

No worries. The Jenkins check is still experimental. We hopefully can improve that in the future.

@jowave
jowave deleted the rospy_sleep_time_backwards branch November 26, 2014 07:44
if rospy.rostime.get_rostime() < initial_rostime:
raise rospy.exceptions.ROSInterruptException("ROS time moved backwards")
time_jump = (initial_rostime - rospy.rostime.get_rostime()).to_sec()
rospy.core.logerr("ROS time moved backwards: %ss", time_jump)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it really needed to log the exception? I use ROS nodes together with Gazebo, where restarting the time is quite normal, and these messages start being annoying. The previous behavior also did not log the exception.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I agree with you that the log message is not strictly necessary. On the other hand this code has been integrated over two years ago and since then been released in three ROS distributions. Since no concerns were raised in the meantime I don't see the log message as a problem either.

Please feel free to create a pull request against the latest development branch (currently lunar-devel).

peci1 added a commit to peci1/ros_comm that referenced this pull request Apr 6, 2017
The log message doesn't make sense IMO, because there is still the exception being thrown.

So the user can either catch it (and then he knows best whether it is an error or not), or he'll not catch it, and then he'll see the message printed in the stack trace.

This is a followup of comment ros#492 (comment) .

My use-case: I have a ROS node running alongside Gazebo, and resetting Gazebo always prints this error to the log, even if it is no error for me, since I expect the time to be restarted.
rsinnet pushed a commit to MisoRobotics/ros_comm that referenced this pull request Jun 19, 2017
add specific exception for time jumping backwards
sputnick1124 pushed a commit to sputnick1124/ros_comm that referenced this pull request Jul 30, 2017
The log message doesn't make sense IMO, because there is still the exception being thrown.

So the user can either catch it (and then he knows best whether it is an error or not), or he'll not catch it, and then he'll see the message printed in the stack trace.

This is a followup of comment ros#492 (comment) .

My use-case: I have a ROS node running alongside Gazebo, and resetting Gazebo always prints this error to the log, even if it is no error for me, since I expect the time to be restarted.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants