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

Making repeated state publication optional #595

Merged
merged 2 commits into from
Oct 7, 2020

Conversation

ayrton04
Copy link
Collaborator

@ayrton04 ayrton04 commented Sep 18, 2020

Addresses #574.

As far as how this will behave, if the filter publishes a state with time t, and we later get a measurement with stamp < t, we'll still integrate that measurement and correct our state internally, but we won't publish a state that includes that correction until the next publication cycle after t.

This may get its base changed to a new noetic-devel branch.

@@ -991,20 +995,21 @@ namespace RobotLocalization
"\ntransform_timeout is " << tfTimeout_.toSec() <<
"\nfrequency is " << frequency_ <<
"\nsensor_timeout is " << filter_.getSensorTimeout() <<
"\ntwo_d_mode is " << (twoDMode_ ? "true" : "false") <<
"\nsmooth_lagged_data is " << (smoothLaggedData_ ? "true" : "false") <<
"\ntwo_d_mode is " << std::boolalpha << twoDMode_ <<
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, I printed out the new param here using boolalpha, and thought I might as well pick up the others.

// If we're trying to publish with the same time stamp, it means that we had a measurement get inserted into the
// filter history, and our state estimate was updated after it was already published. As of ROS Noetic, TF2 will
// issue warnings whenever this occurs, so we make this behavior optional.
corrected_data = (!permitCorrectedPublication_ && lastPublishedStamp_ == filteredPosition.header.stamp);
Copy link
Collaborator

Choose a reason for hiding this comment

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

lastPublishedStamp_ == filteredPosition.header.stamp I don't think that works, because what if its older than just the last update. If you have something with substantial latency (100ms) but your filter is spinning at 100hz, then it could be much older than last, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So I'm thinking aloud here. The filter history handles this situation:

  • In the first cycle, the filter has four measurements to process. They have timestamps 1, 2, 4, and 5. They get processed, and we publish a state with timestamp 5.
  • In the second cycle, the filter receives only a measurement with timestamp 3. It rewinds history to the posterior state after measurement 2 was fused, and then processes 3, 4, and 5 again. Then it publishes a state with timestamp 5. This creates the issue in question, and is solved by this PR.

Now let's go over your scenario, or at least what I think you are saying.

  • In the first cycle, the filter has four measurements to process. They have timestamps 1, 2, 4, and 5. They get processed, and we publish a state with timestamp 5.
  • In the second cycle, the filter has four measurements to process. They have timestamps 6, 7, 8, and 9. They get processed, and we publish a state with timestamp 9.
  • In the third cycle, the filter receives only a measurement with timestamp 3. It rewinds history to the posterior state after measurement 2 was fused, and then processes 3, 4, 5, 6, 7, 8, and 9 again. Then it publishes a state with stamp 9 again. This also causes the issue, and is solved by this PR.

The filter was never publishing the updated state as it processed the history. It was rewinding, inserting, and processing all the way up to the latest measurement, then publishing. So I think checking the latest publication should work?

Note that in both of those cases, anyone listening to tf will get the exact same behavior before and after this change: the first transform published won't get updated when the second one arrives. It's just that in Noetic, we also get yelled at. :)

There is a third case.

  • In the first cycle, the filter has four measurements to process. They have timestamps 1, 2, 4, and 5. They get processed, and we publish a state with timestamp 5.
  • In the second cycle, the filter has two measurements to process. They have timestamps 3 and 6. The filter rewinds history to the posterior state after measurement 2 was fused, and then processes 3, 4, 5, and 6, and publishes the state with timestamp 6. This is obviously not an issue.

Anyway, I will readily admit that I might be totally missing your point, and I apologize if so. Can you provide an example?

Copy link
Collaborator

@SteveMacenski SteveMacenski Sep 21, 2020

Choose a reason for hiding this comment

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

OK, I wasn't sure where filteredPosition's stamp was from, I didn't know that it would already be, at this point, rewinded back up to the latest message in all cases. That works.

I might just make it a little more error proof with lastPublishedStamp_ >= filteredPosition.header.stamp. I agree it shouldn't matter, but I think it makes syntactically more clear why this is being checked (or why they might be equal). I feel like a native reader can pull more from that than ==.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that situation should never happen, but it also won't hurt to change it, and I agree with the increased clarity.

@SteveMacenski
Copy link
Collaborator

Shouldn't this be targeted only onto noetic and foxy? I don't think this issue affects melodic

@@ -174,6 +174,10 @@ If *true*, the state estimation node will publish the transform from the frame s
^^^^^^^^^^^^^^^^^^^^^
If *true*, the state estimation node will publish the linear acceleration state. Defaults to *false*.

~permit_corrected_publication
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any "new in XYZ distro" marker we can do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we just make a noetic-devel and then change this PR to target that? Then we don't have to worry about that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah

}

// Retain the last published stamp so we can detect repeated transforms in future cycles
lastPublishedStamp_ = filteredPosition.header.stamp;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be in the if statement, or else you could update based on a corrected_data update.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the earlier suggestion about >= notwithstanding, as of now, if corrected_data == true, then lastPublishedStamp_ == filteredPosition.header.stamp anyway. However, I'm perfectly happy to move this up to line 1992.

@ayrton04
Copy link
Collaborator Author

Shouldn't this be targeted only onto noetic and foxy? I don't think this issue affects melodic

Yes, but we don't have a noetic-devel. Are you cool if we make one now? I'll take care of it.

Will roll your suggestion into the PR tomorrow. Thanks!

@SteveMacenski
Copy link
Collaborator

Yeah sure

@ayrton04 ayrton04 changed the base branch from melodic-devel to noetic-devel September 23, 2020 16:42
@ayrton04 ayrton04 closed this Oct 2, 2020
@ayrton04 ayrton04 reopened this Oct 2, 2020
@ayrton04
Copy link
Collaborator Author

ayrton04 commented Oct 2, 2020

@reobaird, were you able to try this out?

@ayrton04 ayrton04 merged commit 660793f into noetic-devel Oct 7, 2020
@ayrton04 ayrton04 deleted the 574-repeat-publication branch October 7, 2020 09:31
servos pushed a commit to clearpathrobotics/robot_localization that referenced this pull request Feb 16, 2021
servos pushed a commit to clearpathrobotics/robot_localization that referenced this pull request Feb 16, 2021
servos added a commit to clearpathrobotics/robot_localization that referenced this pull request Feb 17, 2021
Co-authored-by: James <jservos@clearpath.ai>
ayrton04 added a commit that referenced this pull request Mar 22, 2021
* navsat_transform diagram to address #550 (#570)

* add diagram for navsat_transform

Signed-off-by: Mabel Zhang <mabel@openrobotics.org>

* add diagram to tutorial

Signed-off-by: Mabel Zhang <mabel@openrobotics.org>

* Fix frame id of imu in differential mode, closes #482

* Added local Cartesian option to navsat_transform

* Fix navsat_transform issue with starting on uneven terrain

* Fix typo in navsat_transform_node.rst (#588)

"prodives" -> "provides"

* Fix sign error in dFY_dP in transfer function jacobian

* Making repeated state publication optional (#595)

* PR feedback

* Fixing build issues

* Fixing stamp issues

* Linting and uncrustifying

Co-authored-by: Mabel Zhang <mabel.m.zhang@gmail.com>
Co-authored-by: Jeffrey Kane Johnson <jeff@mapless.ai>
Timple pushed a commit to nobleo/robot_localization that referenced this pull request Apr 13, 2021
* navsat_transform diagram to address cra-ros-pkg#550 (cra-ros-pkg#570)

* add diagram for navsat_transform

Signed-off-by: Mabel Zhang <mabel@openrobotics.org>

* add diagram to tutorial

Signed-off-by: Mabel Zhang <mabel@openrobotics.org>

* Fix frame id of imu in differential mode, closes cra-ros-pkg#482

* Added local Cartesian option to navsat_transform

* Fix navsat_transform issue with starting on uneven terrain

* Fix typo in navsat_transform_node.rst (cra-ros-pkg#588)

"prodives" -> "provides"

* Fix sign error in dFY_dP in transfer function jacobian

* Making repeated state publication optional (cra-ros-pkg#595)

* PR feedback

* Fixing build issues

* Fixing stamp issues

* Linting and uncrustifying

Co-authored-by: Mabel Zhang <mabel.m.zhang@gmail.com>
Co-authored-by: Jeffrey Kane Johnson <jeff@mapless.ai>
mqcmd196 added a commit to mqcmd196/robot_localization that referenced this pull request Nov 2, 2023
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.

None yet

2 participants