Creating a new application outside Choregraphe using the qi Framework

Step one: choose your langage

You can do this using either C++ or Python.

C++

If you choose to do this in C++, please follow the C++ SDK Installation first.

Python

If you choose to do this in Python, please follow the Python SDK Install Guide

Step two: write the service

See the appropriate documentation in the libqi documentation

  • C++: create a new service

Your layout will look like this

worktree
|__ myservice
    |__ qiproject.xml
    |__ CMakeLists.txt
    |__ main.cpp
    |__ myservice.cpp
    |__ myservice.hpp
<!-- in qiproject.xml -->
<project version="3">
  <qibuild name="myservice" />
</project>
# In CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(myservice)
find_package(qibuild)

qi_create_bin(myservice main.cpp myservice.cpp myservice.hpp)
qi_use_lib(myservice QIMESSAGING QITYPE)
// in myservice.hpp

#include <string>
#include <qitype/anyobject.hpp>
#include <qitype/objecttypebuilder.hpp>

class MyService {
  public:
    MyService();

    std::string echo(const std::string& message);
    void doSomething();
};

QI_REGISTER_OBJECT(MyService, echo, doSomething);

// in myservice.cpp

#include "myservice.hpp"

MyService::MyService()
{
}

std::string MyService::echo(const std::string& message)
{
  return message;
}

void MyService::doSomething()
{
}

// in main.cpp

#include "myservice.hpp"
#include <qi/application.hpp>
#include <qitype/anyobject.hpp>
#include <qimessaging/url.hpp>
#include <qimessaging/session.hpp>

int main(int argc, char *argv[])
{
  qi::Url url("localhost", "tcp", 9559);

  qi::Application app(argc, argv);
  qi::Session session;
  session.connect(url);

  qi::Object<MyService> myService(new MyService());

  session.registerService("MyService", myService);
  app.run();
}
  • Python: create a new service

Your layout will look like this:

worktree
  |__ myservice
    |__ qiproject.xml
    |__ myservice.py
    |__ setup.py
<!-- in qiproject.xml -->
<project version="3">
  <qipython name="myservice" />
</project>
# in myservice.py

import sys
import qi

class MyService:

    def echo(self, message):
        return message

    def do_something(self):
        pass

def main():
    app = qi.Application()
    app.start()
    session = app.session
    myService = MyService()
    session.registerService("myservice", myService)
    app.run()

if __name__ == "__main__":
    main()
# in setup.py

from setuptools import setup, find_packages

setup(name="myservice",
      version="0.1",
      scripts=["myservice.py"]
)

Step three (C++ only): configure and build the project

At this stage you should have installed the cross-toolchain and configure qibuild to use it. If not, please go back to the C++ SDK Installation section.

Basically it boils down to:

qitoolchain create atom /path/to/ctc/toolchain.xml

Then configure and build the project with

cd myservice
qibuild configure -c atom
qibuild make -c atom

Step four: generate a package for the Aldebaran store

In both cases you will end up with an executable able to start your new service.

Then create the following files in order to generate a package

<!-- in manifest.xml -->

<package uuid="myservice" version="0.1.0">
  <services>
    <!-- if written in Python -->
    <service name="myservice" autorun="true" execStart="./python bin/myservice.py" />
    <executableFiles>
      <file path="python" />
    </executableFiles>

    <!-- if written in C++ -->
    <service name="myservice" autorun="true" execStart="bin/myservice" />
    <executableFiles>
      <file path="bin/myservice" />
    </executableFiles>
  </services>

</package>
<!-- in myservice.pml -->

<Package name="myservice" format_version="4">
  <Manifest src="manifest.xml" />
  <!-- optional resources : -->
  <!--
  <Resources>
    <File src="path/to/some/data" />
  </Resources>
  -->

  <!-- if written in Python -->
  <qipython name="myservice" />

  <!-- if written in C++ -->
  <qibuild name="myservice" />

</Package>

Then you can generate the package using:

# If using python:
qipy bootstrap -c atom

qipkg make-package myservice.pml -c atom

This will generate a file named myservice-0.1.0.pkg in the current working directory.

Step 5: deploy the package to the robot

First, uninstall previous version of the package, by connecting to the robot and running:

qicli call PackageManager.uninstall myservice

Then, make sure you have installed the Python SDK, and run

qipkg deploy-package myservice-0.1.0.pkg --url nao@nao.local

If everything works fine, you can then submit your package to the Aldebaran store.