How to detect a targetยถ

๐Ÿ Goal of this tutorial

By the end of this tutorial, you will know how to use any of the sensorโ€™s mounted on your robot to detect a target and locate it in the map of the environment.

Pre-requisitesยถ

Warning

Some parts of this tutorial refer to robots equipeed with a specific sensor (Camera or LiDAR). If your robot does not have that sensor, you can skip the corresponding parts.

Detect a Laser Patternยถ

Warning

This section requires your robot to be equipped with a LiDAR sensor.

In this tutorial, we are going to detect and locate the unique pattern of the PAL Docking Station.

../_images/dock_pattern.svg

The easiest way to visualize the detection result is by using the RViz GUI. This requires that you first establish the communication with the robot as explained in Set up ROS 2 communication with the robot.

Then, in the same terminal that is connected to the robot, you can start RViz with the command:

rviz2 -d /opt/pal/$PAL_DISTRO/share/<ROBOT>_2dnav/config/rviz/navigation.rviz

Attention

Make sure to replace the <ROBOT> placeholder with the name of your robot (e.g. pmb2, omni_base, ari, etc.). If you are using a TIAGo-Family robot, use the base_type name (either, pmb2 or omni_base).

Otherwise, if you want to use the simulation, you can use the following command:

source /opt/pal/${PAL_DISTRO}/setup.bash
ros2 launch <robot>_gazebo <robot>_gazebo.launch.py navigation:=True advanced_navigation:=True world_name:=pal_office_w_docks

This starts the simulation in a virtual environment with several dockstations available.

../_images/pal_office_w_docks.svg

Once RViz is running and is connected to the robot or to the simulation, to visualize the detection result you can add the visualization of the /target_detector_server/detected_target in RViz.

Then, before triggering the target detection, you need to bring the robot close to the target that you want to detect.

../_images/staging_pose.svg

Finally, to trigger the target detection, you can use the following command:

ros2 action send_goal /detect_target pal_nav2_msgs/action/DetectTarget "ids: [0]
detector: 'laser_target_detector'
recurrent_detection: false"

This command will trigger the /detect_target to detect a new target with ID 0 (the PAL Docking Station) using the Laser Target Detector plugin.

Attention

The Laser target Detector only accepts one ID at the time!

Tip

For moving targets, you can set the recurrent_detection parameter to true to keep detecting the target and localizing it as it moves in the environment.

The position of the detected target is returned in the Result message of the action and is also published in the /target_detector_server/detected_target topic.

Detect an ArUCO Markerยถ

Warning

This section requires your robot to be equipped with a Camera sensor.

In this tutorial, we are going to detect and locate ArUCO markers in the environment.

../_images/aruco_pattern.svg

The easiest way to visualize the detection result is by using the RViz GUI. This requires that you first establish the communication with the robot as explained in Set up ROS 2 communication with the robot.

Then, in the same terminal that is connected to the robot, you can start RViz with the command:

rviz2 -d /opt/pal/$PAL_DISTRO/share/<ROBOT>_2dnav/config/rviz/navigation.rviz

Attention

Make sure to replace the <ROBOT> placeholder with the name of your robot (e.g. tiago, omni_base, tiago_pro, etc.).

If you are using the real robot, you first need to download and print an ArUCO marker from an online generator. Then, you can place the marker in the environment where the robot can detect it.

Attention

For an accurate detection of the marker, the suggested size is 25cm.

Tip

Write down the ID of the marker you generated as you will need it to detect the target.

Otherwise, if you want to use the simulation, you can use the following command:

source /opt/pal/${PAL_DISTRO}/setup.bash
ros2 launch <robot>_gazebo <robot>_gazebo.launch.py navigation:=True advanced_navigation:=True world_name:=pal_office_w_aruco

This starts the simulation in a virtual environment with several ArUCOs available.

../_images/pal_office_w_aruco.svg

Once RViz is running and is connected to the robot or to the simulation, to visualize the detection result you can add the visualization of the /target_detector_server/detected_target in RViz.

ros2 action send_goal /detect_target pal_nav2_msgs/action/DetectTarget "ids: [20]
detector: 'aruco_target_detector'
recurrent_detection: false"

This command will trigger the /detect_target to detect a new target with ID 20 using the Aruco Target Detector plugin.

Attention

The IDs must match the IDs of the ArUCO markers you want to detect. In the simulation, the ArUCO markers placed on the walls are ID 0 and ID 20. In order to detect more than one ArUCO marker you must write all the IDs of the markers you wish to detect separated by a comma.

ros2 action send_goal /detect_target pal_nav2_msgs/action/DetectTarget "ids: [20, 0]
detector: 'aruco_target_detector'
recurrent_detection: false"

This command will trigger the /detect_target to detect a new target with ID 20 and ID 0 using the Aruco Target Detector plugin.

Attention

If only some of the ArUCO markers you wish to detect are present in the image frame then the detection will be successful just for those. If you specify, for example, ids: [20, 0] and in the image there is also another ArUCO marker present, then this latter will not be considered. If you specify an empty vector ids: []` then you will be able to detect all ArUCO markers present in image, regardless of their id.

The position of the detected target is returned in the Result message of the action and is also published in the /target_detector_server/detected_target topic.

Tip

For moving targets, you can set the recurrent_detection parameter to true to keep detecting the target and localizing it as it moves in the environment.

Next stepsยถ