3

I need to send a user text input to the robot through the integrated tablet, and catch it somehow, for further processing in Choregraphe.

After reading the Aldebaran documentation about ALTabletService API, I found few methods which might be a solution to all this. The methods are ALTabletService::showInputTextDialog and ALTabletService::onInputText, but somehow I can't get them to work: they return absolutely nothing when I input some text through the tablet.

I need access to the string created when the user inputs a piece of text. Any advice how to do it?

Opat
  • 31
  • 3

3 Answers3

2

i realized this without ALTabletService methods showInputTextDialog or onInputText

My Approach: I made an html page with an input field and a button to send the input. On button press I use the forceInput method from ALDialog doc via QiMessaging Javascript library. doc

I can't test it right now but this should help as a inspiration

function forceInput(input) {
    QiSession(function(session) {
        session.service('ALDialog').then(function(ALDialog) {
            ALDialog.forceInput(input);
        });
    }
}

Now you can send the input to the topic. This could be sth like "imput_from_tablet blablabla". And in the Dialog you catch

u:(imput_from_tablet _*) $1

Where $1 should be blablabla.

Hope that helps best regards

TVK
  • 1,042
  • 7
  • 21
1

You can create a webpage for the tablet and package it in your application - see the documentation here; then on that webpage you can create a text input field (be careful that the bottom half of the screen will be hidden by the keyboard when the field is selected), and then use the javascript SDK to (for example) raise an ALMemory event with the inputted text value, that you can then get from Choregraphe.

Emile
  • 2,946
  • 2
  • 19
  • 22
  • I know that you can create a webpage and to use HTML/JavaScript to create a dialog and get the input value. What I can't understand is the purpose of `ALTabletService::showInputTextDialog` if we haven't a method to get the value of the input text. Do you have any idea if this can be done? – dim Aug 29 '18 at 15:35
  • I just saw that it can be done with [`qi::Signal ALTabletService::onInputText`](http://doc.aldebaran.com/2-4/naoqi/core/altabletservice-api.html#ALTabletService::onInputText__qi::Signal:i.ss:) but I have not tried it yet – dim Aug 29 '18 at 15:45
1

I had exactly the same problem and I found this ALTabletService::onInputText method in the signal list. You can find examples how to use signals on the same page. Based on these examples I created the following script that can get a value from the input field:

import qi
import sys

def main(app):
    try:
        session = app.session
        tabletService = session.service("ALTabletService")
        tabletService.showInputTextDialog("Example dialog", "OK", "Cancel")
        signal_id = 0

        def callback(button_id, input_text):
            if button_id == 1:
                print "'OK' button is pressed."
                print "Input text: " + input_text
            if button_id == 0:
                print "'Cancel' button is pressed"

            tabletService.onInputText.disconnect(signal_id)
            app.stop()

        # attach the callback function to onJSEvent signal
        signal_id = tabletService.onInputText.connect(callback)
        print "Signal ID: {}".format(signal_id)

        app.run()
    except Exception, e:
        print "Error was: ", e


if __name__ == "__main__":
    ip = "10.0.10.254" # the IP of the robot
    port = 9559

    try:
        connection_url = "tcp://{}:{}".format(ip, port)
        app = qi.Application(url=connection_url)
        app.start()
    except RuntimeError:
        print("Can't connect to Naoqi.")
        sys.exit(1)
    main(app)
dim
  • 992
  • 11
  • 26