python - 如何阻止 Pepper 机器人抢占其平板电脑?

标签 python flask robotics pepper preemption

我正在尝试创建一个程序,其中一部分将使用 naoqi Python SDK 将实时视频帧(或换句话说图像)从我的 PC 网络摄像头传输到 Pepper 的平板电脑。在机器人方面,会有一个程序使用 ALTabletService 的 showWebview 函数将图像显示为 html 网页。但此过程启动后,仅持续几秒钟,然后屏幕返回主页。我猜机器人抢占了我的程序。但使用 playVideo 函数不会发生这种情况。有什么办法可以克服这个问题吗?

PC端:

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

def gen(camera):
    # Set our pipelines state to Playing.
    video_pipeline.set_state(Gst.State.PLAYING)
    audio_pipeline.set_state(Gst.State.PLAYING)
    while True:
        frame = camera.get_frame()
        yield (b'--frame\r\n'
            b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n') #sending frames to the webpage

@app.route('/video_feed')
def video_feed():
    try:
        return Response(stream_with_context(gen(VideoCamera())), mimetype='multipart/x-mixed-replace; boundary=frame')
    except Exception:
        return None

if __name__ == '__main__':
#   app.run(host='0.0.0.0', port = http, debug=True, threaded=True)
    http_server = WSGIServer(('0.0.0.0', http), app) #creating a server with open ip
    http_server.serve_forever()

胡椒面:

tabletService = session.service('ALTabletService')
tabletService.loadUrl('http://' + user_ip + ':' + str(user_http_port) + '/')
tabletService.showWebview()

最佳答案

这是因为 Pepper 的自主生活是围绕 activities 构建的,只要事件失去焦点,Pepper 就会重置所有内容 - 语言、姿势、LED 以及平板电脑。

因此,理想情况下,您的代码应该位于应用程序内部(即标记为“交互式”的行为),并且只要它具有焦点,平板电脑就不会重置。

(编辑)要创建一个独立的Python脚本应用程序,一种简单的方法是使用robot Jumpstarter,这是一个Python脚本,它将从模板(包含所有样板文件等)生成应用程序,请参阅here获取说明。

关于python - 如何阻止 Pepper 机器人抢占其平板电脑?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50696587/

相关文章:

Nginx错误: (13: Permission denied) while connecting to upstream

python - 在项目目录下的终端上输入 "flask run"后发生了什么?

python - 使用 python 合并两个电子表格 - 新工作表中的列源在源文件之间交替

python - 如何按时间戳向后过滤数据

python - 函数作为返回值,Python

python - 机器人机器学习模型的正确方法

python - np.random.normal 中的样本总和应该为零吗?

python - Tox 总是需要 30 秒才能运行

python - Flask 显示 TypeError : send_from_directory() missing 1 required positional argument: 'path'

algorithm - 考虑代理质量的转向行为