Understanding LookAt ¶
In this tutorial, we will make Pepper lower his head as if looking at the ground just in front of him.
To do this, we will:
Before stepping in this tutorial, you should be familiar with the action notion. For further details, see: Running Actions on Pepper.
Let’s start a new project
- Start a new project, let’s call it LookAtPepper.
- Robotify it and make sure it implements the QiSDK & the Robot Life Cycle.
For further details, see: Creating a robot application.
Building the target frame¶
We will create the target
Frame, 1 meter in front of Pepper.
To retrieve this
Frame, we will first need to get the robot frame.
Put the following code in the
Now we can get the robot frame:
Next, we create a 1 meter forward translation corresponding to the transform between the robot frame and the target frame:
We will now create the target frame.
Mapping service provides a method to create a
FreeFrame represents a location free to be placed anywhere, that does not
move when other frames move.
The global position of a
FreeFrame can be updated by applying a
Transform to a base
Frame. The timestamp is left to 0, to update
targetFrame relatively to the last known location of robotFrame.
We now have the target frame. We will use it to build the
Looking at the target frame¶
You can make Pepper look at a
Frame by using the LookAt interface.
lookat field in your
We will create it with a
LookAtBuilder in the
Next, we will set the
LookAtMovementPolicy to use:
LookAtMovementPolicy parameter is set to
HEAD_ONLY so that Pepper
only moves his head when looking at the specified
Do not forget to remove this listener on LookAt in the
Future<Void> in the
It will be used to keep a reference on the action execution.
We will now run the LookAt action asynchronously:
We will finally chain the
lookAtFuture with a lambda:
Cancelling the action¶
The LookAt action needs to be cancelled to stop its execution.
The way to cancel this action is to call the
requestCancellation method on
Future representing the action execution:
We will use a
Button to cancel the action.
In the activity_main.xml layout file, add the following
<Button android:id="@+id/cancel_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Cancel action"/>
Set the button onClick listener in the onCreate method.
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 “Stare somewhere”.
If you click on the cancel button:
You are now able to make Pepper look at something!