Skip to main content
 首页 » 编程设计

python之如何阻止 Pepper 机器人抢占它的平板电脑

2024年09月07日37三少

我正在尝试创建一个程序,其中一部分将使用 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获取说明。