banner



how to build an android robot

Creating a robot application¶

1. Creating a project¶

To create a robot application, we first create a standard Android project, then we will convert it to a robot application.

Step Action

From Android Studio, choose: File > New > New Project.

../_images/project_wizard.png

Click the Next button.

../_images/project_wizard2.png

Configure your project:

  • Give a name to your application.
  • Choose the language you want to use, Kotlin or Java.
  • Make sure the Minimum Api level selected is API 23: Android 6.0 (Marshmallow).
Click the Finish button.

Choose File > Project Structure… > Module and make sure Source Compatibility and Target Compatibility are set to 1.8 (Java 8).

../_images/project_structure_java1.8.png

2. Creating a robot application¶

Now that you have created the Android project, let's convert it into a robot application:

Step Action

Once the project is created, choose File > New > Robot Application.

../_images/new_robot_app.png
Select the minimum Robot SDK version and the module to robotify. Then click OK.

Result

Your project is now a robot application!

As a result, you should see the following changes:

  • The robotsdk.xml file has been added to the assets/robot directory.

    It contains the minimum Robot SDK version for your project (the one you have selected).

  • New tools are available in Tools > Pepper SDK and also in the toolbar: emulator Emulator and connect Connect.

    Use emulator to start a new robot emulator and connect to connect to a real robot.

  • The QiSDK dependency has been added to your module's build.gradle file.

    It provides you all the functionalities to interact with Pepper.

  • A uses-feature tag has been added to your AndroidManifest.xml .

    It states that your application uses Pepper and will only be available for the robot tablet.

3. Getting ready to manage Pepper's screen layout¶

When using Android Layout Editor, to obtain an accurate display of your applications for Pepper, make sure to set the Device for Preview to Pepper 1.9 (1280 x 800, tvdpi) .

For further details, see: Layout Editor.

4. Implementing QiSDK Design & the Robot Life Cycle¶

We have configured a robot application, now it is time to let our code take the control of Pepper's body.

Code Sample¶

                                    class                  MainActivity                  :                  RobotActivity                  (),                  RobotLifecycleCallbacks                  {                  override                  fun                  onCreate                  (                  savedInstanceState                  :                  Bundle                  ?)                  {                  super                  .                  onCreate                  (                  savedInstanceState                  )                  // Register the RobotLifecycleCallbacks to this Activity.                  QiSDK                  .                  register                  (                  this                  ,                  this                  )                  }                  override                  fun                  onDestroy                  ()                  {                  // Unregister the RobotLifecycleCallbacks for this Activity.                  QiSDK                  .                  unregister                  (                  this                  ,                  this                  )                  super                  .                  onDestroy                  ()                  }                  override                  fun                  onRobotFocusGained                  (                  qiContext                  :                  QiContext                  )                  {                  // The robot focus is gained.                  }                  override                  fun                  onRobotFocusLost                  ()                  {                  // The robot focus is lost.                  }                  override                  fun                  onRobotFocusRefused                  (                  reason                  :                  String                  )                  {                  // The robot focus is refused.                  }                  }                
                                    public                  class                  MainActivity                  extends                  RobotActivity                  implements                  RobotLifecycleCallbacks                  {                  @Override                  protected                  void                  onCreate                  (                  Bundle                  savedInstanceState                  )                  {                  super                  .                  onCreate                  (                  savedInstanceState                  );                  // Register the RobotLifecycleCallbacks to this Activity.                  QiSDK                  .                  register                  (                  this                  ,                  this                  );                  }                  @Override                  protected                  void                  onDestroy                  ()                  {                  // Unregister the RobotLifecycleCallbacks for this Activity.                  QiSDK                  .                  unregister                  (                  this                  ,                  this                  );                  super                  .                  onDestroy                  ();                  }                  @Override                  public                  void                  onRobotFocusGained                  (                  QiContext                  qiContext                  )                  {                  // The robot focus is gained.                  }                  @Override                  public                  void                  onRobotFocusLost                  ()                  {                  // The robot focus is lost.                  }                  @Override                  public                  void                  onRobotFocusRefused                  (                  String                  reason                  )                  {                  // The robot focus is refused.                  }                  }                

Step by step¶

Step Action
Register the MainActivity to the QiSDK.

Unregister the MainActivity .

Tip: You could also use QiSDK.unregister(this) to unregister all the RobotLifecycleCallbacks for this Activity, just be careful not to inadvertently remove a callback that should stay registered.

Important

In this first example, we recommend to register and unregister in the onCreate and onDestroy methods. It is not the only option we have.

For further details, see: Mastering Focus & Robot lifecycle.

Make your MainActivity class extends RobotActivity .

Why? This activity, provided by The QiSDK Design library, brings visual feedbacks when a vocal communication is running.

For further details, see: Managing Conversation Feedbacks.

Make your MainActivity class implement the RobotLifecycleCallbacks interface.

Why? This interface allows the RobotLifecycleCallbacks to know when the Activity to which it has registered, gains or loses the robot focus.

For further details, see: Mastering Focus & Robot lifecycle.

Override the onRobotFocusGained , onRobotFocusLost and onRobotFocusRefused methods.

Why? The onRobotFocusGained method is called when the related Activity gains the robot focus. When the focus is gained, we can, for instance, run various actions on the robot.

When the onRobotFocusLost method is called, the related Activity lost the focus and actions cannot be run on Pepper.

Important

The onRobotFocusGained and onRobotFocusLost methods are executed on a background thread, so the UI thread will not be blocked when we will use the QiSDK synchronously.

Summary¶

  • Register and unregister the MainActivity to the QiSDK.
  • Make your MainActivity class extends RobotActivity .
  • Make your MainActivity class implement the RobotLifecycleCallbacks interface.
  • Override the onRobotFocusGained , onRobotFocusLost and onRobotFocusRefused methods.

Result¶

That's it! You have created your first robot application.

See now the next step: Running an application.

how to build an android robot

Source: https://qisdk.softbankrobotics.com/sdk/doc/pepper-sdk/ch1_gettingstarted/starting_project.html

Posted by: baileyteplongues1974.blogspot.com

0 Response to "how to build an android robot"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel