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

RSDK-3323 - addSensorReading refactor #102

Conversation

kim-mishra
Copy link
Collaborator

@kim-mishra kim-mishra commented May 26, 2023

Changes

Move parts of code in ProcessDataAndStartSavingMaps that are not file syste dependent into new method called AddSensorReading

Testing

  • Viewed cartographer map on main and then again on this branch and they looked the same.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label May 26, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 26, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 26, 2023
viam-cartographer/src/slam_service/slam_service.cc Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 26, 2023
@kim-mishra kim-mishra requested a review from kkufieta May 26, 2023 18:11
Copy link
Collaborator

@EshaMaharishi EshaMaharishi left a comment

Choose a reason for hiding this comment

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

Looking good! Noted the conclusions from our discussion

viam-cartographer/src/slam_service/slam_service.cc Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 26, 2023
Copy link
Collaborator

@EshaMaharishi EshaMaharishi left a comment

Choose a reason for hiding this comment

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

LGTM mod comment!

Comment on lines 260 to 261
cartographer::mapping::TrajectoryBuilderInterface *trajectory_builder;
int trajectory_id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

@kkufieta , do we need to access trajectory_builder and trajectory_id under map_builder_mutex?

If so @kim-mishra could we move this to just after L244, so that it's grouped with things that need to be accessed under map_builder_mutex?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, trajectory_builder should be protected by map_builder_mutex. It makes sense to do the same for trajectory_id even though it's probably not strictly necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we please move this to CPU bound initialization time (i.e. point 5)?

viam-cartographer/src/slam_service/slam_service.cc Outdated Show resolved Hide resolved
@@ -252,6 +256,9 @@ class SLAMServiceImpl final : public SLAMService::Service {
// started.
std::string latest_pointcloud_map;
// ---

cartographer::mapping::TrajectoryBuilderInterface *trajectory_builder;
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Why does this need to be global?
  2. Where is this pointer initialized?
  3. Is it possible for AddSensorReading to be called before ProcessDataAndStartSavingMaps is called & causes memory corruption due to this pointer pointing at invalid memory?
  4. When do we free the object this pointer points to?
  5. If we really need a pointer on an object, could we construct this at CPU-bound initialization time (that way we are guaranteed it will always be a valid pointer) & have this be a smart pointer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. I believe we put this definition here so that it could be accessed within AddSensorReading so that we did not have to pass it in and change the function signature
  2. I think it is initialized here within map_builder.SetTrajectoryBuilder()
  3. I think that would be a problem yes, we talked about moving it into the initialization function @kkufieta is working on as a separate PR
  4. I think that would happen in the terminate function this ticket refers to
  5. I am a little confused on what you mean here - would putting it in Kats init function be what you are talking aout?

Comment on lines 260 to 261
cartographer::mapping::TrajectoryBuilderInterface *trajectory_builder;
int trajectory_id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we please move this to CPU bound initialization time (i.e. point 5)?

@@ -741,6 +744,8 @@ void SLAMServiceImpl::ProcessDataAndStartSavingMaps(double data_start_time) {
if (!use_live_data) {
// We still want to optimize the map in localization mode, but we do not
// need to update the backup of the map
cartographer::transform::Rigid3d tmp_global_pose;
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Why did we need to move this inside the loop?
  2. Is there a risk of us leaking memory from creating new tmp_global_poses every iteration of the while loop without ever freeing the one from the previous loop?

Copy link
Collaborator Author

@kim-mishra kim-mishra May 30, 2023

Choose a reason for hiding this comment

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

  1. Because we wanted to keep the function signature simple and not have to pass this var into AddSensorReading we wanted to only initialize it if it were going to be used, although now I am getting a little confused why it is better for this to be in the loop. @kkufieta would you mind explaining this again
  2. Based on this doc I think we actually will need to delete this if we continue with this route thanks for pointing that out I don't think so, I think memory leaks only happen when you use dynamic memory (i.e. new or malloc)

Copy link
Contributor

Choose a reason for hiding this comment

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

This is happening outside the loop. This code is only executed in offline mode after we've processed all the data.

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 30, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 30, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 30, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 30, 2023
@kkufieta kkufieta requested review from kkufieta and removed request for kkufieta May 31, 2023 19:04
@kim-mishra kim-mishra requested review from kkufieta and removed request for kkufieta June 1, 2023 19:07
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jun 1, 2023
@kkufieta kkufieta removed their request for review June 6, 2023 17:34
@kkufieta kkufieta dismissed their stale review June 6, 2023 17:36

In order to remove myself as a reviewer, I have to dismiss my review.

@@ -647,10 +647,34 @@ void SLAMServiceImpl::SaveMapWithTimestamp() {
}
}

bool SLAMServiceImpl::AddSensorReading(
Copy link
Collaborator

Choose a reason for hiding this comment

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

NOTE: In the implementation which makes it into CartoFacade you will need to detect the first time AddSensorReading has been called & set the start time on the map builder to be the time that the first lidar reading was taken.

@nicksanford nicksanford closed this Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants