Setting initialpose for AMCL using difference between initial TFs
I'm working on bag files containing odometry and laser scan data. I have a launch file that runs simultaneously the bag, AMCL and a map node. The TF from odom to base_link is different in each bag.
When I run AMCL with initial pose not set (default values) it takes much time to estimate proper robot position on map and sometimes it doesn't even find it properly.
I'm trying to init AMCL using first odom -> base_link transform value in the bag file so that laser scan image matches the map with the highest probability. Calling /global_localization service helps but not well and it also takes too much time. Bags are only 30 sec.
Question: What is the best way to pass this transform values as initial positions in AMCL? Should I write a publisher that reads first tf in bag and then publish on /initialpose topic or is there any easier way to do it (params, services, bash files, extract data from bag to csv and then read it somehow, etc.)?
I suppose that relation between odom->base_link may be insufficient to achieve my goal but finding at least rotation between tfs would be helpful (to eliminate initial rotation between laser scan and map)