Search code examples
androidkotlinpepper

Pepper android app never started function onRobotFocusGained() on a real pepper


I have a problem with some simple kotlin code on a pepper robot. I followed the "get started" tutorial from softbanks (https://qisdk.softbankrobotics.com/sdk/doc/pepper-sdk/ch1_gettingstarted/hello_human_tutorial.html) and it works fine, except to start the function onRobotFocusGained. I have implemented some logs to see, that the program starts the functions "onCreate", "onStart" and "onResume" but never the "onRobotFocusGained". If I start the code from the tutorial on GitHub (https://github.com/aldebaran/qisdk-tutorials), it works fine. But this program is too heavy for any complete beginners. My goal is to implement a minimal example for my colleagues to start with programming on pepper.

So, how pepper starts the function "onRobotFocusGained" (https://qisdk.softbankrobotics.com/sdk/doc/pepper-sdk/ch2_principles/focus_lifecycle.html#focus-lifecycle)?

Here is my short program for pepper to say once "hello humans" if i start the program but pepper never says it.

package com.example.hello_pepper_2

import android.os.Bundle
import android.util.Log
import android.com.aldebaran.qi.sdk.QiContext
import android.com.aldebaran.qi.sdk.QiSDK
import android.com.aldebaran.qi.sdk.RobotLifecycleCallbacks
import android.com.aldebaran.qi.sdk.`object`.conversation.Say
import android.com.aldebaran.qi.sdk.builder.SayBuilder
import android.com.aldebaran.qi.sdk.design.activity.RobotActivity

class MainActivity : RobotActivity(), RobotLifecycleCallbacks {

    var robotContext: QiContext? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Register the RobotLifecycleCallbacks to this Activity.
        QiSDK.register(this, this)
        setContentView(R.layout.activity_main)

        Log.e("MSG", "onCreate")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onStart() {
        super.onStart()

        Log.e("MSG", "onStart")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onResume() {
        super.onResume()

        Log.e("MSG", "onResume")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onRestart() {
        super.onRestart()

        Log.e("MSG", "onRestart")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onPause() {
        super.onPause()

        Log.e("MSG", "onPause")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onStop() {
        super.onStop()

        Log.e("MSG", "onStop")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onDestroy() {
        // Unregister the RobotLifecycleCallbacks for this Activity.
        QiSDK.unregister(this, this)
        super.onDestroy()

        robotContext = null

        Log.e("MSG", "onDestroy")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onRobotFocusGained(qiContext: QiContext) {
        // The robot focus is gained.

        robotContext = qiContext

        saySomething("Hello Humans")

        Log.e("MSG", "onRobotFocusGained")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onRobotFocusLost() {
        // The robot focus is lost.

        Log.e("MSG", "onRobotFocusLost")
        Log.e("Context", "robot.Context.toString()")
    }

    override fun onRobotFocusRefused(reason: String) {
        // The robot focus is refused.

        Log.e("MSG", "onRobotFocusRefused")
        Log.e("Context", "robot.Context.toString()")
    }

    fun saySomething(phrase: String) {
        Log.e("MSG", "saySomething")
        Log.e("Context", "robot.Context.toString()")

        val say: Say = SayBuilder
            .with(robotContext)
            .withText(phrase)
            .build()

        say.run()
    }
}


Solution

  • There is a known issue about the RobotService app, that sometimes fails to make the Android apps communicate with the robot. Make sure to update it to the latest version via the Command Center.