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

Clean trimming of frozen trajectory data. #1767

Merged

Conversation

MichaelGrupp
Copy link
Contributor

@MichaelGrupp MichaelGrupp commented Oct 28, 2020

The deletion logic needs to take care of deleting all data that is
"exclusively" connected to the submaps that are to be removed. This is
achieved by looking at the data that is connected via constraints in
the graph.

Deleting a frozen trajectory (one without optimization constraints)
doesn't work that way and would leave dangling nodes in the graph.

This modifies the logic to use the node_ids field of the submap
instead of the constraints.

Signed-off-by: Michael Grupp [email protected]

@@ -323,6 +323,59 @@ TEST_F(PoseGraph3DTest, EvenSubmapTrimmer) {
}
}

TEST_F(PoseGraph3DTest, EvenSubmapTrimmerOnFrozenTrajectory) {
Copy link
Contributor Author

@MichaelGrupp MichaelGrupp Oct 28, 2020

Choose a reason for hiding this comment

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

Note: this test-case is based on the existing EvenSubmapTrimmer test case above, with the difference that no constraints are added and the graph is built like we do when loading frozen state. It would fail without this patch.

There's no equivalent test case in pose_graph_2d_test.cc yet, so I did it only for 3D. If we want to extend the 2D test cases, this would be a larger change for separate PRs IMO.

@MichaelGrupp
Copy link
Contributor Author

Related to the linked RFC PR and the associated PR in cartographer_ros.

if (parent_->IsTrajectoryFrozen(submap_id.trajectory_id)) {
// Remove node_ids that are associated with the frozen submap to be trimmed.
nodes_to_remove.insert(
parent_->data_.submap_data.at(submap_id).node_ids.begin(),
Copy link
Member

Choose a reason for hiding this comment

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

Do these node_ids always exist? Would it then make sense to get rid of the old style of handling deletion of nodes and replace it by your improved strategy completely? Something along these lines:

  1. Compute nodes_to_retain by going through all submaps and adding all node_ids for submaps not equal to the given submap_id to remove.
  2. Compute nodes_to_remove as all node_ids of submap_id not to be retained.
  3. Remove the constraints similar to before, but without the need to build up the nodes_to_remove as part of it. We could add a CHECK to validate that all retained constraints use nodes not in nodes_to_remove.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding your 3. point: There's already a loop that only keeps constraints for which nodes_to_remove.count(constraint.node_id) == 0 holds. With this in place we don't need to check afterwards, no?

The deletion logic needs to take care of deleting all data that is
"exclusively" connected to the submaps that are to be removed. This is
achieved by looking at the data that is connected via constraints in
the graph.

Deleting a frozen trajectory (one without optimization constraints)
doesn't work that way and would leave dangling nodes in the graph.

This adds an additional logic that uses the `node_ids` field of the
submap instead of the constraints if the trajectory is frozen.

Signed-off-by: Michael Grupp <[email protected]>
@MichaelGrupp MichaelGrupp force-pushed the upstream-delete-frozen-trajectories branch from 5afa6c9 to c1a4f0f Compare January 11, 2021 16:51
Signed-off-by: Michael Grupp <[email protected]>
@MichaelGrupp MichaelGrupp force-pushed the upstream-delete-frozen-trajectories branch from c1a4f0f to 5f328ad Compare January 11, 2021 16:57
Signed-off-by: Michael Grupp <[email protected]>
@MichaelGrupp MichaelGrupp force-pushed the upstream-delete-frozen-trajectories branch from a2fa7c3 to c5e6a85 Compare January 12, 2021 09:33
Copy link
Member

@wohe wohe left a comment

Choose a reason for hiding this comment

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

Looks good. Only one nit: Could we update the comment in map_builder.cc? Now setting the nodes contained in a submap is not only needed for 3D, but also 2D: https://github.com/cartographer-project/cartographer/blob/master/cartographer/mapping/map_builder.cc#L362

Maybe simply change it to:
// Information about which nodes belong to which submap is required even without constraints.

Signed-off-by: Michael Grupp <[email protected]>
@wohe wohe merged commit 802e9f1 into cartographer-project:master Jan 19, 2021
@cuicuihaohaoxuexi
Copy link

Hi there, I've tried this DeleteTrajectory service to try to remove a loaded frozen trajectory. It works well and the frozen trajectory is deleted. However, the code crashes after the frozen trajectory is deleted. The error is shown as below:

terminate called after throwing an instance of 'std::out_of_range'
what(): map::at

I find it happens in constraint_builder_2d.cc. The line of "(*callback)(result);" I used the latest master for cartographer which has all the updates above. Does anyone have any idea why it happens and how to resolve it? Thanks very much in advance.

@shamengjun
Copy link

@cuicuihaohaoxuexi I'm also confused with this problem, my error is the same as you!

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.

4 participants