Pepper android 应用从未在真正的胡椒上启动 onRobotFocusGained() 函数

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

我在 Pepper 机器人上使用一些简单的 Kotlin 代码时遇到问题。我遵循了 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) 的“入门”教程,效果很好。但是这个程序对于任何完全的初学者来说都太重了。 我的目标是为我的同事实现一个最小的示例,以开始在 Pepper 上编程。

那么,pepper 如何启动函数“onRobotFocusGained”(https://qisdk.softbankrobotics.com/sdk/doc/pepper-sdk/ch2_principles/focus_lifecycle.html#focus-lifecycle)?

这是我的简短程序,如果我启动该程序,胡椒会说一次“你好,人类”,但胡椒不会说。

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()
    }
}

你的代码在我看来没有任何错误,但作为一种调试方法,你可以尝试复制粘贴官方教程文件以确保你的机器人没有错误。如果正式版有效;仔细观察差异

https://github.com/aldebaran/qisdk-tutorials/blob/master/app/src/main/java/com/softbankrobotics/qisdktutorials/ui/tutorials/gettingstarted/HelloHumanTutorialActivity.kt

RobotService 应用程序存在一个已知问题,有时无法使 Android 应用程序与机器人通信。确保通过命令中心将其更新到最新版本。