pythonflaskroboticspepperpreemption

How to stop Pepper robot from preempting its tablet?


I'm trying to create a program, a part of which will transmit real-time video in frames (or in other words images) from my PC's webcam to Pepper's tablet using naoqi Python SDK. On the robot's side there will be a program using ALTabletService's showWebview function to display the image as a html webpage. But after this process is started it carries on only for a few seconds and then the screen returns to its home page. I'm guessing the robot preempts my program. But this does not happen with playVideo function. Is there any way to over come this?

PC's side:

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

Pepper's side:

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

Solution

  • This is because Pepper's Autonomous Life is built around activities, and anytime an activity loses focus, Pepper resets everything - language, posture, LEDs and, yes, the tablet.

    So ideally your code should be inside an application (i.e. a behavior flagged as "interactive"), and as long as it has the focus, the tablet won't get reset.

    (edit) to create an application that is a standalone Python script, one easy way is using robot jumpstarter, a python script that will generate an app from a template (with all the boilerplate etc.), see here for instructions.