Nao Webserver


The NPWS is a webserver special created for executing your python scripts
on the Nao. You can create on the server side a menu with buttons and
input fields. A button can execute your Python script and with the input fields
you can send extra information that you can use inside your script.
A button can also target another menu and in this way you can create
multiple submenu's.

Manual




 

Client Side (screenshot login)

 

http://developer.aldebaran-robotics.com/media/uploads/Triest/screenshot-login.png

http://developer.aldebaran-robotics.com/media/uploads/Triest/screenshot-say.png

 


Server Side (screenshot server application with user configuration)


http://developer.aldebaran-robotics.com/media/uploads/Triest/screenshot-sever.png

 

Client Side (screenshot client menu development)


http://developer.aldebaran-robotics.com/media/uploads/Triest/screenshot-menu.png

 


Nao meets Delphi.

 

To communicate with the Nao the program is using the Aldebaran Python SDK and the Python4Delphi components. The webserver is programmed in Delphi Pascal using the Datasnap technology and it is also using HTML and JavaScript to handle the web interface with the user.


The server is based on
DataSnap. You can compare this to creating webservices with the CGI (exe) or ISAPI (dll) technique. The main difference is that you don't need a separate webserver (like Apache, IIS, ..) to run the services. The webserver executable will contain both the webserver and the services. What remains the same is that the developer can create "Servermethods" in the base system (Delphi in this case) and these methods can be called from the web. In the base system the developer can use all the advanced functionality included in the system. (calculations, database, file handling, ..)

 

Technical Overview

 

Nao Personal Webserver

 

Client Side (webbrowser html, java script)


http://developer.aldebaran-robotics.com/media/uploads/Triest/Logo-Web.png

<input type="button" id="btnSayMessage" value="Say Message" onclick="javascript:oNaoServerMethods.onSay();" />';

 

# The user sees a webpage with a text edit (the message) and a submit button.

# The user fills in a message and clicks in the webbrowser on the button.

# The button executes a javascript function "onSay".



http://developer.aldebaran-robotics.com/media/uploads/Triest/Logo-Javascript.png

var oNaoServerMethods = {

 

    onSay: function () {

 

                var s = NaoServerMethods().Say(this.getAnswers());

                if (s.result.length > 0) {

                        $('#resultdisplay').html(s.result);

                }

        }

 

# In a Javasript library the "onSay" function is called. This function is getting the

# edit text message from the browser (getAnswers) and executes the servermethod "Say"

 

 

Server Side (webserver delphi pascal)


http://developer.aldebaran-robotics.com/media/uploads/Triest/Logo-DataSnap.png

function TNaoServerMethods.Say(aJSONValue: TJSONObject): string;

var JSONParseObject: TJSONParseObject;

    NaoDelphiPython: TNaoDelphiPython;

 

    aMessage: String;

    Session: TDSSession;

 

    NaoIP, NaoPort : String;

Begin

  Session := TDSSessionManager.GetThreadSession;

  if Session<>NIL then

  Begin

    NaoIP:=Session.GetData('naoip');

    NaoPort:=Session.GetData('naoport');

       

    JSONParseObject:=TJSONParseObject.Create(aJSONValue);

    Try

      aMessage:=JSONParseObject.GetValueByIndex(0);

      NaoDelphiPython:=TNaoDelphiPython.Create;

      Try

        NaoDelphiPython.Say(aMessage,NaoIP,NaoPort);

      Finally

        NaoDelphiPython.Free;

      End;

    Finally

      Result:='Nao says "'+aMessage+'"';

      JSONParseObject.Free;

    End;

  End;

End;

 

# On the server the severmethod "Say" is called.

# It receives the edit text parameter via aJSONValue.

# Via the session the server asks for the user NoaIP and NaoPort.

# These session values were set by the login page of the server.

# The servermethod creates a TNaoDelphiPython object and executes the Say function.

# The result is a small html message passed back to the user webbrowser.

 

Server Side (webserver pascal, python)


http://developer.aldebaran-robotics.com/media/uploads/Triest/Logo-Delphi.pnghttp://developer.aldebaran-robotics.com/media/uploads/Triest/Logo-Python4Delphi.pnghttp://developer.aldebaran-robotics.com/media/uploads/Triest/Logo-PythonSDK.png

procedure TNaoDelphiPython.Say(aMessage, aNaoIP, aNaoPort: String);

Var PythonStrings : TStringList;

Begin

  PythonStrings:=TStringList.Create;

  Try

    PythonStrings.Add('from naoqi import ALProxy');

    PythonStrings.Add('tts = ALProxy("ALTextToSpeech", "'+aNaoIP+'", '+aNaoPort+')');

    PythonStrings.Add('tts.say("'+aMessage+'")');

 

    FPythonEngine.ExecStrings(PythonStrings);

  Finally

    PythonStrings.Free;

  End;

End;

 

# In the TNaoDelphiPython object the final "Say" function is declared.

# It creates the proper Python script and executes it to Python.

 

 

Nao is a great developers platform. With Choregraphe programming software and the extensive API its't easy and a lot of fun to develop new Nao behaviors.

Nao Triest