Ease tablet interaction — EnforceTabletReachability


In this tutorial, we will use EnforceTabletReachability in order to make Pepper reduce his movements, and therefore ease user interaction on the tablet.


Before stepping in this tutorial, you should:

Let’s start a new project

  • Start a new project, let’s call it TabletReachabilityPepper.
  • Robotify it and make sure it implements the QiSDK & the Robot Life Cycle.

For further details, see: Creating a robot application.

Creating an EnforceTabletReachability action

In this section, we will see how to create an EnforceTabletReachability action.

Start by storing the following field in your MainActivity:

/// Store qiContext
private QiContext qiContext;

// Store the action.
private EnforceTabletReachability enforceTabletReachability;

Then, put the following code in the onRobotFocusGained method:

public void onRobotFocusGained(final QiContext qiContext) {
    // Store qiContext
    this.qiContext = qiContext;

    // Build EnforceTabletReachability action.
    enforceTabletReachability = EnforceTabletReachabilityBuilder.with(qiContext).build();


In order to observe the effect of EnforceTabletReachability, we will make Pepper talk when his tablet reaches the wanted position. To do so, add the following code in the same onRobotFocusGained method:

// On position reached listener
enforceTabletReachability.addOnPositionReachedListener(() -> {
    Log.i(TAG, "The tablet now is in position.");

    // Say action
    String textToSay = "My movements are now limited. Cancel the action to see the difference.";
    Say say = SayBuilder.with(qiContext)


Also, place this code in the onRobotFocusLost method:

public void onRobotFocusLost() {
    // Remove the QiContext.
    this.qiContext = null;

    // Remove all the listeners

Running the action

In this section, we will see how to run the EnforceTabletReachability action.

Start by storing this following field in your MainActivity:

// Store the action's future.
private Future<Void> enforceTabletReachabilityFuture;

Then, create a startEnforceTabletReachability() method in your MainActivity.

private void startEnforceTabletReachability() {
    // Run the action asynchronously
    enforceTabletReachabilityFuture = enforceTabletReachability.async().run();

    // Handle the action's end
    enforceTabletReachabilityFuture.thenConsume(future -> {
        // Log the eventual errors
        if (future.hasError()) {
            Log.e(TAG, "The EnforceTabletReachability action finished with error.", future.getError());
        } else {
            Log.i(TAG, "The EnforceTabletReachability action has finished.");

        // Say text when the action is cancelled
        String text = "My movements are back to normal. Run the action again to see the difference.";

        Say s = SayBuilder.with(qiContext)


Calling this method will run the EnforceTabletReachability action asynchronously. We also added some code to make Pepper talk when the action is done. This will allow us to observe the difference in Pepper’s movements when the action is running or not.

Stopping the action

Add this simple stopEnforceTabletReachability to your MainActivity:

private void stopEnforceTabletReachability() {

Calling this method will stop the EnforceTabletReachability action that is running.

Testing EnforceTabletReachability

Let’s test our code using a button:


The following code is just a quick way to test the functionality, this is not what you would do in a real application.

In the activity_main.xml layout file, add the following Button:

    android:text="Enforce tablet reachability"/>

In the onCreate method, add the following code:

// Run the EnforceTabletReachability when button clicked.
Button enforceTabletReachabilityButton = (Button) findViewById(R.id.tablet_reachability_button);
enforceTabletReachabilityButton.setOnClickListener(v -> {
    if (enforceTabletReachability == null) {
        Log.e(TAG, "EnforceTabletReachability has not been built yet");
    } else if (enforceTabletReachabilityFuture == null || enforceTabletReachabilityFuture.isDone()) {
        // The EnforceTabletReachability action is not running
    } else {
        // The EnforceTabletReachability is running

Clicking on the button will either start or stop the EnforceTabletReachability action, accordingly to its running state.

Let’s try it

github_icon The sources for this tutorial are available on GitHub.

Step Action

Install and run the application.

For further details, see: Running an application.

Choose “Enforce tablet reachability”.

Notice that Pepper moves his arms and torso while talking.

Click on the button and the robot will reduce his movements, easing tablet interaction.

Click again on the button and the robot will go back to his previous state.


You are now able to ease tablet interaction on Pepper!