Visual Localization

 


 The goal of this exercise is to program a robot similar to an autonomous vacuum cleaner to enable the autolocalization based on the positions of pasive visual markers.


The pasive visual markers in this case are AprilTags. They are similar to QR codes and are used in applications such as robotics, augmented reality, and camera calibration.


To obtain the current position of the robot from the image we must obtain all of the translation and rotation matices of the following formula:


1.World2Marker

To get this matrix we must know which tag we have in the image and its position. We obtain the global positions from the file "apriltags_poses.yaw", and we can get the id tag from the image using the "pyapriltags.Detector()".

2.Marker2Camera

To get this matrix we must solve the Perspective-n-Point problem. We will use the "solvePnP()" function from Opencv. In order to use it we need:
  • The four corners of the tag in the camera frame (obtained from "pyapriltags.Detector()").

  • The four corners of the tag in the local frame (size of the april tag / 2).



We can use the translation components from the output of the function, but to get the rotation matrix we need use the "Rodrigues()" function from Opencv. After adding padding to both matrices and multipliying them we get the matrix "RT_Camera2Marker". We can obtain the one we need by computing the inverse matrix.

We also have to take into account the reference axis from the april tags are not the same as in gazebo:



To align them with the ones used in the simulation we must perform a rotation of -90 degrees in the z axis and the x axis to the matrix.

3.Camera2Robot

The last matrix is the easiest one, since we can get the information from the position of the camera in the robot sdf file.


Once we have all the matrices we multiply them. To obtain the "x" and "y" coordinates we look at the translation part of our result matrix (positions 0,3 and 1,3). To get the "yaw" orientation we must first get the pitch and then use it as seen in the next formulas (in python code):

 


In the cases where there are multiple AprilTags detections we simply perform the average position of the two we obtained.
If there are no AprilTags detections we update the position by calculating the difference between the last position we got and the odometry obtained from the sensor.

We can see two test executions in the next videos:








Comments

Popular posts from this blog

Local Navigation with VFF

Autoparking

Global Navigation with GPP