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

Rework the period standard deviation calculation in Sta… #1361

Merged
merged 1 commit into from
Apr 27, 2018
Merged

Rework the period standard deviation calculation in Sta… #1361

merged 1 commit into from
Apr 27, 2018

Conversation

deng02
Copy link
Contributor

@deng02 deng02 commented Apr 9, 2018

…tisticsLoggger.

Fixes #1360

msg.period_stddev += ros::Duration(t.toSec() * t.toSec());
try
{
msg.period_stddev += ros::Duration(t.toSec() * t.toSec());
Copy link
Member

Choose a reason for hiding this comment

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

The result of this temporary result might clearly exceeding the value range of 32 bit. But in the following lines it is divided and then the sqrt is being computed which would bring the value back into a valid range.

Therefore I would suggest to way this value is being computed rather than catching the error and skipping the input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I will rework this.

{
msg.period_stddev = ros::Duration(period_stddev);
}
catch(std::runtime_error& e)
Copy link
Member

Choose a reason for hiding this comment

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

With the updated math in which cases do you expect this to happen?

Copy link
Contributor Author

@deng02 deng02 Apr 26, 2018

Choose a reason for hiding this comment

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

Short answer is never :) The slightly longer mathematial answer that I worked out for my own curiosity is that in a scenario where there are 4 samples where the first 3 arrive within nanoseconds of each other (effectively making the first 2 periods 0) and the 4th arrives much later, the 4th sample would have to arrive 5579326178 seconds or 177 years later. And I won't be around then to deal with the exception. Thanks for pointing this out, I will remove the guard.

@deng02 deng02 changed the title Add try/catch around the period standard deviation calculation in Sta… Rework the period standard deviation calculation in Sta… Apr 26, 2018
@dirk-thomas dirk-thomas changed the base branch from lunar-devel to melodic-devel April 27, 2018 18:30
@dirk-thomas
Copy link
Member

Thank you for the patch.

The CI failure on Melodic is due to a know compiler warning which requires a new pluginlib release. So merging anyway.

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

Successfully merging this pull request may close these issues.

2 participants