Detect humans with localization ¶
In this tutorial, we will use Pepper’s localization ability to enhance the detection and the tracking of humans.
Before stepping in this tutorial, you should be familiar with the robot focus and robot lifecycle notions.
For further details, see: Mastering Focus & Robot lifecycle.
Let’s start a new project
- Start a new project, let’s call it DetectHumansWithLocPepper.
- Robotify it and make sure it implements the QiSDK & the Robot Life Cycle.
For further details, see: Creating a robot application.
Mapping Pepper’s surroundings¶
First, we need to create a map of Pepper’s surroundings. To achieve this, we will use the LocalizeAndMap action.
startMapping method to your
Then call it in the
LocalizeAndMap field in your
Create it with a
LocalizeAndMapBuilder in the
The LocalizeAndMap interface has an
addOnStatusChangedListener method that allows
us to be notified when the localization status of the LocalizeAndMap action changes.
We will use it to know when Pepper has mapped his environment.
Add the following code in the
Do not forget to remove this listener on LocalizeAndMap in the
We can now run the
Future<Void> field in your
And run the
LocalizeAndMap action asynchronously in the
We will now retrieve the map of Pepper’s surroundings.
ExplorationMap field in your
addOnStatusChangedListener method, in the
LOCALIZED case, add the following code to get the map:
Now that we have the map, we don’t need the
LocalizeAndMap action to run anymore, so we can add the following
code to stop its execution, just after retrieving the map:
In the next step of this tutorial, we will need to know when the
LocalizeAndMap action actually stops, so add
the following code in the
To recap, here is what the whole
startMapping method should look like:
Localizing Pepper in a map¶
In order to enhance Pepper’s ability to detect and track humans, we need him to be localized in a map.
startLocalizing method to your
Then call it in when
localizationAndMapping is cancelled:
Localize field in your
startLocalizing implementation is very similar to the
In this implementation, we:
- Use a
LocalizeAndMapBuilderwith the stored
ExplorationMapto create the
- Use the
addOnStatusChangedListenerto know when the robot is localized in the map.
- Run the
- Log an error if the action execution fails.
Do not forget to remove the listener on Localize in the
Let’s try it¶
The sources for this tutorial are available on GitHub.
Install and run the application.
For further details, see: Running an application.
Choose “Detect humans with localization”.
Wait for pepper to map his environment.
Wait for Pepper to localize himself in the map.
When Pepper is localized in his environment, try to come from behind him and he will detect you.
You are now able to use localization to detect humans with Pepper!