Showing Video Stream on the tablet of the robot Pepper

376 Views Asked by At

I am new to programming the robot Pepper and I wanna make a program, where Pepper shows on his tablet what he records from his camera (in the best case a live image). I try several things and at the moment it is not possible for me to show anything on the tablet screen.

I am using Pepper from Aldebaran/Softbankrobotic and the corresponding Choregraphe possibilities for block coding. I didn't find any box to show the camera image on the tablet screen in CHoregraphe. Because of this I used the Python script box and based on the documentation/api I wrote a code, which should record one image and then show this on the screen. The Code runs on the robot and also the screensaver on the tablet is removed, but only a black screen appears. Attached you will find the code. Did you know, where I done an error or do you have another idea to solve my problem? Thanks in advance.

import qi
import os
import time

# Connect to Pepper's session
session = qi.Session()
session.connect("tcp://<PEPPER_IP_ADDRESS>:9559")

# Get the services
tablet_service = session.service("ALTabletService")
photo_capture_service = session.service("ALPhotoCapture")

# Take a picture with the front camera
photo_capture_service.setResolution(2)  # 640x480 resolution
photo_capture_service.setCameraID(0)   # front camera
photo_capture_service.takePictures(1, "/home/nao/recordings/cameras/", "image")

# Wait for the picture to be saved
time.sleep(2)

# Display the picture on the tablet
image_path = "/home/nao/recordings/cameras/image.jpg"
image_data = open(image_path, "rb").read()
tablet_service.showImage(image_data)
time.sleep(2)

# Disconnect from Pepper's session
session.close()
1

There are 1 best solutions below

2
Ales Horak On

ALTabletService::showImage expects url of the image to display, not image_data. The best way is to store the image in the html folder of your application installed in the robot and access the image via the internal IP http://198.18.0.1/apps/your_app_name/image.jpg. The image also may need to be resized/clipped to 1280x800 px for the tablet. You may also check the image from a standard web browser via http://robot_ip/apps/your_app_name/image.jpg

There are several ways, how to find out the project directory path within the installed application on the robot:

  • if the code is inside a self-contained Python script (outside Choregraphe project, e.g. a service), you may use the info from the Python __file__ special variable:

     import os
     strPath = os.path.dirname(__file__)`
    
  • if the code is within a Choregraphe behavior, you may use behaviorAbsolutePath():

     def __init__(self):
         GeneratedClass.__init__(self)
         self.logger.info(self.behaviorAbsolutePath())
    
  • you may also stick to fixed paths - after an application package (with e.g. myapp as the Application ID) is installed to the Pepper, all the application files are stored in the directory of /home/nao/.local/share/PackageManager/apps/myapp/.

The html subdirectory (i.e. /home/nao/.local/share/PackageManager/apps/myapp/html/ within an installed application) is then accessible for standard browser access via http://robot_ip/apps/myapp (where robot_ip should be replaced with the real public IP of the robot).