SoftBank Robotics documentation What's new in NAOqi 2.5?

ALTabletService API

NAOqi Core - Overview | API


Namespace : AL

Method list

Has the following methods:

class ALTabletService

Web view

Video Player

Image

Dialog

Wifi

System

Deprecated

Methods

Web view

void ALTabletService::cleanWebview()

Clean the web browser.

void ALTabletService::executeJS(const std::string& script)

Execute javascript on the web browser.

Parameters:
  • script – Script to execute

altabletservice_executejs.py

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use executeJS Method"""

import qi
import argparse
import sys
import time


def main(session):
    """
    This example uses the executeJS method.
    To Test ALTabletService, you need to run the script ON the robot.
    """
    # Get the service ALTabletService.
    tabletService = session.service("ALTabletService")

    try:
        # Display a local web page located in boot-config/html folder
        # The ip of the robot from the tablet is 198.18.0.1
        tabletService.showWebview("http://198.18.0.1/apps/boot-config/preloading_dialog.html")

        time.sleep(3)

        # Javascript script for displaying a prompt
        # ALTabletBinding is a javascript binding inject in the web page displayed on the tablet
        script = """
            var name = prompt("Please enter your name", "Harry Pepper");
            ALTabletBinding.raiseEvent(name)
        """

        # Don't forget to disconnect the signal at the end
        signalID = 0

        # function called when the signal onJSEvent is triggered
        # by the javascript function ALTabletBinding.raiseEvent(name)
        def callback(event):
            print "your name is:", event
            promise.setValue(True)

        promise = qi.Promise()

        # attach the callback function to onJSEvent signal
        signalID = tabletService.onJSEvent.connect(callback)

        # inject and execute the javascript in the current web page displayed
        tabletService.executeJS(script)

        try:
            promise.future().hasValue(30000)
        except RuntimeError:
            raise RuntimeError('Timeout: no signal triggered')

    except Exception, e:
        print "Error was:", e

    # Hide the web view
    tabletService.hideWebview()
    # disconnect the signal
    tabletService.onJSEvent.disconnect(signalID)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session)
float ALTabletService::getOnTouchScaleFactor()

Get the touch scale factor of current view displayed. Default is 1.0 for all views except for the browser view which is 1.34 .

Returns:the scale factor.
bool ALTabletService::hideWebview()

Hide the webview on the tablet, the idle screen appears instead.

Returns:True if successful, false otherwise.
bool ALTabletService::loadApplication(const std::string& name)

Start new application on tablet.

Parameters:
  • name – Name of application. It must have a index.html to load.
Returns:

True if successful, false if the application is not found or unreachable.

altabletservice_loadapplication.py

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use loadApplication Method"""

import qi
import argparse
import sys
import time


def main(session):
    """
    This example uses the loadApplication method.
    To Test ALTabletService, you need to run the script ON the robot.
    """
    # Get the service ALTabletService.

    try:
        tabletService = session.service("ALTabletService")

        # Display the index.html page of a behavior name j-tablet-browser
        # The index.html must be in a folder html in the behavior folder
        tabletService.loadApplication("j-tablet-browser")
        tabletService.showWebview()

        time.sleep(3)

        # Hide the web view
        tabletService.hideWebview()
    except Exception, e:
        print "Error was: ", e


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session)
bool ALTabletService::loadUrl(const std::string& url)

Load an URL in the browser of the tablet. Warning: you need to call ALTabletService::showWebview to display the browser.

Parameters:
  • url – Url of the page to display.
Returns:

True if successful, false if the URL is not found or unreachable.

void ALTabletService::reloadPage(bool bypassCache)

Reload the current displayed web page.

Parameters:
  • bypassCache – set to true in order to reload the current page by bypassing the local web cache.
void ALTabletService::setOnTouchWebviewScaleFactor(float scaleFactor)

Set the touch scale factor of the webview. Default is 1.34 so the touch viewport is 1707 × 1067. If set to 1, the touch view port will be 1280x800.

Parameters:
  • scaleFactor – scale factor to set.
bool ALTabletService::showWebview()

There are two overloads of this function:

Display the webview on the tablet.

Warning

Tablet screen density may vary without notice. This has an impact on browser display resolution.

Make sure your application remains compatible: create and use responsive content!

For further details, see: Browser display resolution troubleshooting.

Returns:True if successful, false otherwise.
bool ALTabletService::showWebview(const std::string& url)

Display the webview on the tablet and load the url.

Warning

Tablet screen density may vary without notice. This has an impact on browser display resolution.

Make sure your application remains compatible: create and use responsive content!

For further details, see: Browser display resolution troubleshooting.

Parameters:
  • url – Url of the page to display.
Returns:

True if succeed to load the url, false if the url is not found or unreachable.

altabletservice_showwebview.py

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use showWebview Method"""

import qi
import argparse
import sys
import time


def main(session):
    """
    This example uses the showWebview method.
    To Test ALTabletService, you need to run the script ON the robot.
    """
    # Get the service ALTabletService.

    try:
        tabletService = session.service("ALTabletService")

        # Ensure that the tablet wifi is enable
        tabletService.enableWifi()

        # Display a web page on the tablet
        tabletService.showWebview("http://www.google.com")

        time.sleep(3)

        # Display a local web page located in boot-config/html folder
        # The ip of the robot from the tablet is 198.18.0.1
        tabletService.showWebview("http://198.18.0.1/apps/boot-config/preloading_dialog.html")

        time.sleep(3)

        # Hide the web view
        tabletService.hideWebview()
    except Exception, e:
        print "Error was: ", e


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session)

Video Player

int ALTabletService::getVideoLength()

Get video length in milliseconds.

Returns:-1 on error.
int ALTabletService::getVideoPosition()

Get the time elapsed since the beginning of the video in milliseconds.

Returns:-1 if no video is played, a positive number otherwise.
bool ALTabletService::pauseVideo()

Pause the video playing but do not close the video player. Can be resumed by ALTabletService::resumeVideo.

Returns:True if video is playing, false otherwise.
bool ALTabletService::playVideo(const std::string& url)

Open a video player on tablet and play video from given url. Recommend format is mp4 container, video codec H.264, audio codec AAC For further details see: pepp pepper-tablet.

Can be stopped by ALTabletService::stopVideo.

Parameters:
  • url – URL of the video to play.
Returns:

True if video is playing, false otherwise.

altabletservice_playvideo.py

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use playVideo Method"""

import qi
import argparse
import sys
import time


def main(session):
    """
    This example uses the playVideo method.
    To Test ALTabletService, you need to run the script ON the robot.
    """
    # Get the service ALTabletService.

    try:
        tabletService = session.service("ALTabletService")

        # Ensure that the tablet wifi is enable
        tabletService.enableWifi()

        # Play a video from the web and display the player
        # If you want to play a local video, the ip of the robot from the tablet is 198.18.0.1
        # Put the video in the HTML folder of your behavior
        # "http://198.18.0.1/apps/my_behavior/my_video.mp4"
        tabletService.playVideo("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")

        time.sleep(3)

        # Display the time elapse / the total time of the video
        print tabletService.getVideoPosition(), " / ", tabletService.getVideoLength()

        # Pause the video
        tabletService.pauseVideo()

        time.sleep(3)

        # resume the video
        tabletService.resumeVideo()

        time.sleep(3)

        # stop the video and hide the player
        tabletService.stopVideo()
    except Exception, e:
        print "Error was: ", e


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session)
void ALTabletService::resumeVideo()

Resume the video paused by ALTabletService::pauseVideo.

Returns:True if video is playing, false otherwise.
bool ALTabletService::stopVideo()

Close the video player.

Returns:True if video player is open, false otherwise.

Image

void ALTabletService::hideImage()

Hide image currently displayed.

void ALTabletService::pauseGif()

Pause current gif displayed.

bool ALTabletService::preLoadImage(const std::string& url)

Pre-load an image. Use the same URL for showImage.

Parameters:
  • url – URL of the image to pre-load.
Returns:

True if pre-load succeed, false if it cannot ping the URL or if it is not a image.

void ALTabletService::resumeGif()

Resume current gif displayed.

Returns:True if gif is playing, false otherwise.
void ALTabletService::setBackgroundColor(const std::string& color)

Set image background color.

Parameters:
  • color – hexadecimal color code, from “#000000” to “#FFFFFF”.
bool ALTabletService::showImage(const std::string& url)

Show an image, using the cache. Download the image before displaying it, unless the picture is already in the cache, because it has been preloaded or already displayed.

Parameters:
  • url – url of the image to display.
Returns:

true if show succeed, false if it can’t ping the URL or if it’s not a image.

altabletservice_showimage.py

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use showImage Method"""

import qi
import argparse
import sys
import time


def main(session):
    """
    This example uses the showImage method.
    To Test ALTabletService, you need to run the script ON the robot.
    """
    # Get the service ALTabletService.

    try:
        tabletService = session.service("ALTabletService")

        # Display a local image located in img folder in the root of the web server
        # The ip of the robot from the tablet is 198.18.0.1
        tabletService.showImage("http://198.18.0.1/img/help_charger.png")

        time.sleep(3)

        # Hide the web view
        tabletService.hideImage()
    except Exception, e:
        print "Error was: ", e


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    session = qi.Session()
    try:
        session.connect("tcp://" + args.ip + ":" + str(args.port))
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(session)
bool ALTabletService::showImageNoCache(const std::string& url)

Show an image, without using the cache. Download the image before displaying it.

Parameters:
  • url – url of the image to display.
Returns:

true if show succeed, false if it can’t ping the URL or if it’s not a image.

Dialog

void ALTabletService::hideDialog()

Hide the dialog view.

void ALTabletService::showAlertView(const float& radius, const std::string& color, const int& delay)

Show an alert view.

Parameters:
  • radius – radius of the 3 displayed points
  • color – hexadecimal color code, from “#000000” to “#FFFFFF”.
  • delay – refresh time.
void ALTabletService::showInputDialog(const std::string& type, const std::string& title, const std::string& ok, const std::string& cancel)

There are two overloads of this function:

Show a native input text dialog.

Parameters:
  • type – Type among: “text”, “password”, “email”, “url”, “number”.
  • title – Title of the box (could be just a title or a question).
  • ok – text of the OK button.
  • cancel – text of the Cancel button.
void ALTabletService::showInputDialog(const std::string& type, const std::string& title, const std::string& ok, const std::string& cancel)

Show a native input text dialog.

Parameters:
  • type – Type among: “text”, “password”, “email”, “url”, “number”.
  • title – Title of the box (could be just a title or a question).
  • ok – text of the OK button.
  • cancel – text of the Cancel button.
  • value – pre-filled text of the input field.
  • limit – Limit of characters that can be input.
void ALTabletService::showInputTextDialog(const std::string& title, const std::string& ok, const std::string& cancel)

There are two overloads of this function:

Show a native input text dialog.

Parameters:
  • title – Title of the box (could be just a title or a question).
  • ok – text of the OK button.
  • cancel – text of the Cancel button.
void ALTabletService::showInputTextDialog(const std::string& title, const std::string& ok, const std::string& cancel, const std::string& value, const int& limit)

Show a native input text dialog with a pre-filled input.

Parameters:
  • title – Title of the box (could be just a title or a question).
  • ok – text of the OK button.
  • cancel – text of the Cancel button.
  • value – pre-filled text of the input field.
  • limit – Limit of characters that can be input.

Wifi

bool ALTabletService::configureWifi(const std::string& security, const std::string& ssid, const std::string& key)

Configure the WiFi.

Parameters:
  • security – among (wep, wpa, open)
  • ssid – network name
  • key – encryption key (for wep or wpa only).
Returns:

true if this configuration is valid

bool ALTabletService::connectWifi(const std::string& ssid)

Connect to a known wifi.

Parameters:
  • ssid – network name
Returns:

True if connection was established successfully, False otherwise.

void ALTabletService::disableWifi()

Disable the wifi.

bool ALTabletService::disconnectWifi()

Disconnect current connected wifi.

Returns:true if it succeed to disconnect, false otherwise
void ALTabletService::enableWifi()

Enable the wifi.

bool ALTabletService::forgetWifi(const std::string& ssid)

Forget a wifi network.

Parameters:
  • ssid – ssid of the network to forget.
Returns:

true if it find the network and succeed to forget it.

std::string ALTabletService::getWifiStatus()

Check WiFi status on the tablet.

Returns:IDLE, SCANNING, DISCONNECTED, or CONNECTED.

System

float ALTabletService::getBrightness()

Get the tablet brightness.

Returns:a float between 0 and 1.
std::vector<std::string> ALTabletService::getAvailableKeyboards()

Get the list of available keyboards installed on the tablet.

Returns:a list of keyboard IDs
std::string ALTabletService::getWifiMacAddress()

Get the wifi mac address

Returns:the wifi mac address
void ALTabletService::goToSleep()

Put the tablet in sleep mode (standby mode).

void ALTabletService::hide()

Hide view currently displayed (video, image, web, alert ...).

void ALTabletService::resetTablet()

Reset the tablet as if no one used it before, i.e. clean the stack of activities, the web browser content, and the web browser cache.

std::string ALTabletService::robotIp()
Returns:Current robot IP.
bool ALTabletService::setBrightness(float newBrightness)

Set tablet brightness.

Parameters:
  • newBrightness – New brightness value. Must be between 0 (exclusive) and 1.
Returns:

True if successful, false otherwise.

bool ALTabletService::setKeyboard(const std::string& keyboardID)

Set the tablet keyboard.

Parameters:
Returns:

True if the change succeed, false otherwise.

bool ALTabletService::setTabletLanguage(const std::string& locale)

Set the tablet language.

Parameters:
  • locale – locale, like ja_JP, en_US.
bool ALTabletService::setVolume(const int& volume)

Configure the media volume of the tablet.

Parameters:
  • volume – a positive integer between 0 and 15.
Returns:

true if it’s work false otherwise, if the volume isn’t in the proper range.

void ALTabletService::turnScreenOn(const bool& isOn)

Turn on/off the tablet screen.

Parameters:
  • isOn – true to turn on the screen, false to turn it off.
std::string ALTabletService::version()
Returns:the tablet browser version.
void ALTabletService::wakeUp()

Wake the tablet (from standby mode).

Deprecated

void ALTabletService::postEventToApplication()

Deprecated since version 2.0.2: Deprecated and removed. Do not use anymore.

Forward given signal to current web application.

std::string ALTabletService::getLastVideoErrorLog()

Deprecated since version 2.0.1: use ALTabletService/error() instead.

void ALTabletService::resetToDefaultValue()

Deprecated since version 2.3.1: use ALTabletService::resetTablet instead.

reset view to default values.

std::string ALTabletService::getCurrentLifeActivity()

Deprecated since version 2.4.0: use ALAutonomousLifeProxy::focusedActivity instead.

Get the name of the current life activity running. :return: the name of the current life activity running or “” if there isn’t.

Signals

Tactile screen

qi::Signal<float, float> ALTabletService::onTouchDown

Sent when someone touches the tablet screen. Does not work when a video or an image activity is running on the tablet.

  • float x: Abscissa of touched point.
  • float y: Ordinate of touched point.

altabletservice_ontouchdown.py

#! /usr/bin/env python
# -*- encoding: UTF-8 -*-

"""Example: Use onTouchDown Method"""

import qi
import argparse
import sys


def main(app):
    """
    This example uses the onTouchDown method.
    To Test ALTabletService, you need to run the script ON the robot.
    """
    # Get the service ALTabletService.

    try:
        session = app.session
        tabletService = session.service("ALTabletService")

        # Don't forget to disconnect the signal at the end
        signalID = 0

        # function called when the signal onTouchDown is triggered
        def callback(x, y):
            print "coordinate are x: ", x, " y: ", y
            if x > 640:
                # disconnect the signal
                tabletService.onTouchDown.disconnect(signalID)
                app.stop()

        # attach the callback function to onJSEvent signal
        signalID = tabletService.onTouchDown.connect(callback)
        app.run()
    except Exception, e:
        print "Error was: ", e


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--ip", type=str, default="127.0.0.1",
                        help="Robot IP address. On robot or Local Naoqi: use '127.0.0.1'.")
    parser.add_argument("--port", type=int, default=9559,
                        help="Naoqi port number")

    args = parser.parse_args()
    try:
        connection_url = "tcp://" + args.ip + ":" + str(args.port)
        app = qi.Application(["TabletModule", "--qi-url=" + connection_url])
        app.start()
    except RuntimeError:
        print ("Can't connect to Naoqi at ip \"" + args.ip + "\" on port " + str(args.port) +".\n"
               "Please check your script arguments. Run with -h option for help.")
        sys.exit(1)
    main(app)
qi::Signal<float, float, std::string> ALTabletService::onTouchDownRatio

Sent when someone touches the tablet screen.

  • float x: Abscissa ratio of touched point between 0 and 1.0 .
  • float y: Ordinate ratio of touched point between 0 and 1.0 .
  • std::string viewTouched: Name of the view touched among AlertActivity, BootActivity, GifActivity, ImageActivity, OpenGLActivity, BrowserActivity or VideoActivity .
qi::Signal<float, float> ALTabletService::onTouchMove

Sent when someone moves its finger on the tablet screen.

  • float x: Abscissa of touched point.
  • float y: Ordinate of touched point.
qi::Signal<float, float> ALTabletService::onTouchUp

Sent when someone removes its finger from the tablet screen.

  • float x: Abscissa of touched point.
  • float y: Ordinate of touched point.

Web view

qi::Signal<std::string> ALTabletService::onJSEvent

Sent by web applications. Get the event raised by Javascript method raiseEvent or closeWindow

Tip: in command line, use: qicli watch ALTabletService.onJSEvent.
  • std::string eventName: Name of the event.
qi::Signal<std::string> ALTabletService::onConsoleMessage

Sent by web applications. View JavaScript console message written by web applications loaded on tablet.

Tip: in command line, use: qicli watch ALTabletService.onConsoleMessage.
  • std::string message: Content of message.
qi::Signal<void> ALTabletService::onPageFinished

Sent when page upload is finished.

qi::Signal<void> ALTabletService::onPageStarted

Sent when page upload is started.

Video Player

qi::Signal<void> ALTabletService::videoFinished

Sent when video started by ALTabletService::playVideo is finished. Warn NAOqi modules that displayed video is finished.

qi::Signal<void> ALTabletService::videoStarted

Sent when video started by ALTabletService::playVideo is started. Warn NAOqi modules that displayed video is started.

Other

qi::Signal<void> ALTabletService::onImageLoaded

Sent when an image is pre-loaded.

qi::Signal<int, std::string> ALTabletService::onInputText
Sent when ALTabletService::showInputDialog
or ALTabletService::showInputTextDialog returns a text.
  • int validation: Button clicked by the user: 1 means ‘OK’, 0 means ‘Cancel’.
  • std::string input: input entered by user.
qi::Signal<int, std::string, std::string> ALTabletService::onLoadPageError

Sent when a web page failed to load.

  • int errorCode: the error id.
  • std::string description: A string describing the error.
  • std::string failingUrl: The url that failed to load.
qi::Signal<std::string> ALTabletService::onWifiStatusChange

Sent when the tablet WiFi status changes.

  • std::string status: WiFi status among IDLE, SCANNING, DISCONNECTED, CONNECTED

Deprecated

qi::Signal<float, float> ALTabletService::onTouch

Deprecated since version 2.0.2: use more specific events instead.

  • float x: Abscissa of touched point.
  • float y: Ordinate of touched point.

Events

Event: "ALTabletService/error"
callback(std::string eventName, std::string subscriberIdentifier)

Raised when an error occurs.

Event: "ALTabletService/message"
callback(std::string eventName, std::string subscriberIdentifier)

Raised when message occurs.

Event: "ALTabletService/onInputText"
callback(std::string eventName, std::string subscriberIdentifier)

Raised when text input occurs.