I am also interested in knowing this. As of now, I am giving my initial pose to cartographer via rviz similar to what we do in amcl and I have used the following strategy to localize:
1.Need to writer a subscriber in node.cc that would subscribe to /initialpose from rviz.
2.Whenever we receive an /initialpose we need to first finish the current Trajectory and then run final optimization.
3.Then a new trajectory needs to be started from the pose given by /initialpose and need to make sure it is with respect to map frame.
4.Push this pose all the way back to LocalTrajectoryBuilder class where the PoseEstimate is defined and change the value from identity to this pose.
5.Then pass the current pose estimate from localtrajectorybuilder to the sparse_pose_graph and then constraint_builder and finally to fast correlative scan matcher (MatchFullSubmap)
6.And instead of starting to scan match from the origin(or centre) of the submap, scan match from the current best pose estimate.(only when robot is in or near that submap)
As of now the cartographer tries to find a scan match in all trajectories from submap 0 to the last submap. For a large map with say 100 submaps and if we start somewhere near 100th submap it might take a long time for the robot to localize. So I am continuously calculating the distance between the pose of the robot(after you give an initial pose which also might have some error) and the origin of the submap in global frame(map frame) and finding the nearest submap in all trajectories and I scan match against that submap first, if we can connect trajectories then good enough else it will again try to scan match against all the submaps in all trajectories again as before.
I have tested with their bag file and it does localize faster as far as i can see(visually in rviz) with the same configuration. But still haven't done proper testing.
Some Issues:
I am finding it difficult to delete a trajectory, since it is not correct. As of now I have used the following strategy to delete the submaps:
1.I have added another instance of trimmer that would trim sparse pose graph(with the submaps to keep as 0)
2.Then when i finish trajectory set the state of all the submaps in that trajectory as finished.
3.Then call the new trimmer instead of the other pre-existing one only when initial pose is added.(In RunOptimzation).
This was just an initial quick fix that I used, definitely not the efficient way, would love know about better methods to do this.
But I am getting errors whenever I give an initial pose. It is quite difficult to track down where all the submaps ids and trajectories ids go. Is there any efficient way to say just delete the trajectory and all the submaps in it if we know it is wrong, ezpecially during localization were we dont care building a map.
Some improvements:
I think its better to sort the submap_ids in each trajectory based on the pose of the robot(especially when the are embedded with intial pose as in this case). In that case we can start to scan match against the nearest submap and then move sequentially away from that.(working on this now)