Search code examples
ros

Is there a way I can force the robots to be already localized?


I want the robots to be already localized when I start the program. Is there any way for this, so that I do not have to move the robot manually and localize it?

I have two robots and in order to explore with the second robot, I have to localize it first which takes a lot of time. By the time I localize it, the other robot explores whole of the map.

Thanks


Solution

  • From the documentation of amcl, the localization node listens for the initial pose on the topic initialpose, with message type geometry_msgs/PoseWithCovarianceStamped. This specifies with which localization estimate amcl initially starts running with. As you see, besides the mean of the pose estimate you can also provide a full covariance matrix telling the uncertainty of the pose estimate.

    There is some default value that this initial pose is set to internally, but to resolve your issue, what you want to do is publish a message on the aforementioned topic, telling amcl to start with your specified initial pose.

    You might do this via the command line using rostopic pub, or through rviz: see e.g. documentation and this Q&A for more information.


    I just remembered that it is even possible to specify the initial pose estimate directly as startup parameters for amcl, see initial_pose_x and other similar parameters. This is appropriate for example if you can fix these parameters in your launch file before starting the node.