Difference between revisions of "API2"

From RobotinoWiki
(Building API2 from source)
(Windows)
 
(64 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The new API2 is currently under development. The main new features are
+
==Introduction==
* Support for up to 4 cameras
+
{|class="wikitable" cellpadding="20" vertical-align="top"
* Support for camera controls like brightness, contrast, auto white balance ... The supported controls depend on the camera used
+
|-
* Integrated web server for controlling Robotino by a web browser or your smartphone
+
|[[Image:Robotino_api2_icon_64.png]]
* Easy build process due to minimal dependencies to external libraries
+
|A C/C++ library to access Robotino's sensors and actors from your own program.
 +
|}
  
The new API2 is based on a RPC like infrastructure. The [http://servicerobotics.eu/weitere-projekte/rec-rpc-library/ REC-RPC] library is a interprocess communication middleware similar to ROS. It is based on Qt and does not have any other dependencies.
+
==Download and install==
 +
Check [[Robotino_OS|Robotino OS]] to find the link to the API2 library.
  
===API2 packages for Robotino===
+
===Windows===
In order to use the API2 you need to replace packages on Robotino. The easiest way is to give Robotino Internet access. The file '''/etc/apt/sources.list''' should look like this.
+
On Windows (Visual Studio) you need to install the binary package that fits your compiler. Currently we support two compilers. Please open a command prompt and use ''set'' to see your Visual Studio or Visual Studio Tools version.
<pre>
 
deb http://doc.openrobotino.org/download/packages/i386 ./
 
deb http://old-releases.ubuntu.com/ubuntu/ jaunty main restricted
 
deb-src http://old-releases.ubuntu.com/ubuntu/ jaunty main restricted
 
</pre>
 
  
<pre>
+
API2 for
echo "deb http://doc.openrobotino.org/download/packages/i386 ./" > /etc/apt/sources.list
+
* [http://packages.openrobotino.org/windows/robotino-api2/msvc-12 Visual Studio 2013]
echo "deb http://old-releases.ubuntu.com/ubuntu/ jaunty main restricted" >> /etc/apt/sources.list
+
* [http://packages.openrobotino.org/windows/robotino-api2/msvc-140 Visual Studio 2015]
echo "deb-src http://old-releases.ubuntu.com/ubuntu/ jaunty main restricted" >> /etc/apt/sources.list
+
* [http://packages.openrobotino.org/windows/robotino-api2/msvc-141 Visual Studio 2017]
</pre>
+
* [http://packages.openrobotino.org/windows/robotino-api2/msvc-142 Visual Studio 2019]
  
After setting up the sources.list
+
==Build examples==
<pre>
+
The API2 package comes with examples showing how to use the C/C++ interface.
apt-get update
 
apt-get install rec-rpc-qt4.5.0 robotino-common robotino-daemons robotino-api robotino-examples
 
</pre>
 
  
Questions during the installation process
+
===Linux===
 
<pre>
 
<pre>
Install these packages without verification [y/N]? y
+
mkdir examples
Do you want to install symlinks? -> Yes
+
cd examples
</pre>
+
cp -R /opt/robotino/examples/cpp/circle/ circle
This will remove the API1 daemons and install the API2 counterparts. Reboot the system when installation is finished.
+
cd circle
 
+
mkdir build
Alternatively you can download the packages to your computer. Replace * by the latest version.
+
cd build
<pre>
+
cmake ..
wget http://doc.openrobotino.org/download/packages/i386/rec-rpc-qt4.5.0_*_i386.deb
+
make
wget http://doc.openrobotino.org/download/packages/i386/robotino-common_*_i386.deb
 
wget http://doc.openrobotino.org/download/packages/i386/robotino_daemons_*_i386.deb
 
wget http://doc.openrobotino.org/download/packages/i386/robotino-api_*_i386.deb
 
wget http://doc.openrobotino.org/download/packages/i386/robotino-examples_*_i386.deb
 
</pre>
 
 
 
Then copy the files to Robotino using scp or ftp. On Robotino do
 
<pre>
 
dpkg -i rec-rpc-qt4.5.0_*_i386.deb
 
dpkg -i robotino-common_*_i386.deb
 
dpkg -i --auto-reconfigure robotino-daemons_*_i386.deb
 
dpkg -i robotino-api_*_i386.deb
 
dpkg -i robotino-examples_*_i386.deb
 
 
</pre>
 
</pre>
  
===API2 for Windows===
+
===Windows===
 +
* Download and install [https://cmake.org/ cmake].
 +
* Copy c:\program files\rec gmb\api2\examples to a user writable directory.
 +
* Run cmake-gui
 +
* Choose source and destiantion directory
 +
* Configure and Generate
 +
* Open the generated Visual Studio Solution
  
===API2 for Linux===
+
==Quick links==
Setup your '''/etc/apt/sources.list'''. On i386 system
+
* [https://doc.openrobotino.org/download/RobotinoAPI2/rec_robotino_api2/ Documentation]
<pre>
 
deb http://doc.openrobotino.org/download/packages/i386 ./
 
<pre>
 
  
On amd64 systems
+
==C++ example==
<pre>
 
deb http://doc.openrobotino.org/download/packages/amd64 ./
 
 
<pre>
 
<pre>
 +
#include <iostream>
 +
#include "rec/robotino/api2/all.h"
  
Install the packages
+
rec::robotino::api2::Com com;
* robotino-api
+
rec::robotino::api2::Bumper bumper;
* robotino-examples
 
* libqt4-dev
 
<pre>
 
apt-get install robotino-api robotino-examples libqt4-dev
 
</pre>
 
  
Pre build binaries are in ''/usr/local/robotino/examples/bin''
+
int main( int argc, char **argv )
 +
{
 +
  std::string hostname = "172.26.1.1";
 +
  if( argc > 1 )
 +
  {
 +
    hostname = argv[1];
 +
  }
  
Build the circle example see section below.
+
  com.setAddress( hostname.c_str() );
 +
  com.connectToServer( true );
 +
 
 +
  while(com.isConnected() && false == bumper.value())
 +
  {
 +
    std::cout << "Bumper is " << (bumper.value()?"":"not") << " pressed" << std::endl;
 +
    com.processEvents();
 +
    rec::robotino::api2::msleep( 100 );
 +
  }
  
===Building API2 from source===
+
  com.disconnectFromServer();
Get the source via SVN:
 
<pre>
 
svn co http://svn.openrobotino.org/api/trunk source/api
 
</pre>
 
Configure the build environment with cmake, build and install:
 
<pre>
 
mkdir build/api
 
cd build/api
 
ccmake ../../source/api
 
make install
 
</pre>
 
  
On Windows:
+
  rec::robotino::api2::shutdown();
In case you used a 32bit compiler set the environment variable '''ROBOTINOAPI32_DIR''' to the installation directory. When you compiled the library with a 64bit compiler set the environment variable '''ROBOTINOAPI64_DIR''' The environment variable is used by the other packages to find the FindRobotinoApi.cmake scripts.
 
Example: On my system I got
 
<pre>ROBOTINOAPI32_DIR=E:\build\robotino_api_win32_vc100\install</pre>
 
  
On Linux:
+
  return 0;
<pre>
+
}
make ALL_CREATE_INSTALLER
 
sudo dpkg -i robotino-api-*.deb
 
 
</pre>
 
</pre>
  
===Building the API2 examples on Robotino===
+
==C example==
 
<pre>
 
<pre>
mkdir -p build/circle
+
#include <stdio.h>
cd build/circle
+
#include <stdlib.h>
ccmake /usr/local/robotino/examples/src/c++/circle/
+
#include <string.h>
configure(c) 2x, generate(g)
 
make
 
target/example_circle 127.0.0.1
 
</pre>
 
  
Right now you can run the example as root only. If you change permissions manually
+
#ifdef WIN32
<pre>
+
#include <windows.h>
chmod 777 /tmp/*
+
#else
</pre>
+
#include <unistd.h> //usleep
you can run the example as user robotino.
+
#endif
  
===Build Robotino tools and daemons===
+
#include "rec/robotino/api2/c/Com.h"
  
Windows:
+
void msleep( unsigned int ms )
* Get the latest Qt libraries from [http://qt.nokia.com/downloads Digia]
+
{
* Alternatively build Qt from source
+
#ifdef WIN32
 +
  SleepEx( ms, FALSE );
 +
#else
 +
  usleep( ms * 1000 );
 +
#endif
 +
}
  
Linux:
+
ComId com;
* Install libqt4-dev
+
BumperId bumper;
  
====Build REC-RPC====
+
int main( int argc, char **argv )
Get the source via SVN:
+
{
<pre>
+
  com = Com_construct();
svn co http://svn.servicerobotics.eu/rec_rpc/trunk source/rec_rpc
 
</pre>
 
Configure the build environment with cmake, build and install:
 
<pre>
 
mkdir build/rec_rpc
 
cd build/rec_rpc
 
ccmake ../../source/rec_rpc
 
make install
 
</pre>
 
  
On Windows:
+
  if( argc > 1 )
In case you used a 32bit compiler set the environment variable '''RECRPC32_DIR''' to the installation directory. When you compiled the library with a 64bit compiler set the environment variable '''RECRPC64_DIR''' The environment variable is used by the other packages to find the FindRecRpc.cmake scripts. Example: On my system I got
+
  {
<pre>RECRPC32_DIR=E:\build\rec-rpc_win32_vc100\install</pre>
+
    Com_setAddress( com, argv[1] );
 +
  }
 +
  else
 +
  {
 +
    Com_setAddress( com, "172.26.1.1" );
 +
  }
  
On Linux:
+
  if( FALSE == Com_connect( com ) )
<pre>
+
  {
make ALL_CREATE_INSTALLER
+
    printf( "Error on connect" );
sudo dpkg -i rec-rpc-*.deb
+
    exit(1);
</pre>
+
  }
 +
  else
 +
  {
 +
    char addressBuffer[256];
 +
    Com_address( com, addressBuffer, 256 );
 +
    printf( "Connected to %s\n", addressBuffer );
 +
  }
  
====Build Robotino Common====
+
  while( Com_isConnected( com ) && FALSE == Bumper_value( bumper ) )
Get the source via SVN:
+
  {
<pre>
+
    printf("Value of bumper is %d\n",Bumper_value( bumper ) )
svn co http://svn.openrobotino.org/common/trunk source/common
+
    msleep( 50 );
</pre>
+
  }
Configure the build environment with cmake, build and install:
 
<pre>
 
mkdir build/common
 
cd build/common
 
ccmake ../../source/common
 
make install
 
</pre>
 
 
 
On Windows:
 
In case you used a 32bit compiler set the environment variable '''ROBOTINOCOMMON32_DIR''' to the installation directory. When you compiled the library with a 64bit compiler set the environment variable '''ROBOTINOCOMMON64_DIR''' The environment variable is used by the other packages to find the FindRobotinoCommon.cmake scripts.
 
Example: On my system I got
 
<pre>ROBOTINOCOMMON32_DIR=E:\build\robotino_common_win32_vc100\install</pre>
 
  
On Linux:
+
  Bumper_destroy( bumper );
<pre>
+
  Com_destroy( com );
make ALL_CREATE_INSTALLER
 
sudo dpkg -i robotino-common-*.deb
 
</pre>
 
  
====Build Robotino Daemons====
+
  return 0;
Get the source via SVN:
+
}
<pre>
 
svn co http://svn.openrobotino.org/daemons/trunk source/daemons
 
</pre>
 
Configure the build environment with cmake, build and install:
 
<pre>
 
mkdir build/daemons
 
cd build/daemons
 
ccmake ../../source/daemons
 
make install
 
 
</pre>
 
</pre>

Latest revision as of 08:24, 10 May 2019

Introduction

Robotino api2 icon 64.png A C/C++ library to access Robotino's sensors and actors from your own program.

Download and install

Check Robotino OS to find the link to the API2 library.

Windows

On Windows (Visual Studio) you need to install the binary package that fits your compiler. Currently we support two compilers. Please open a command prompt and use set to see your Visual Studio or Visual Studio Tools version.

API2 for

Build examples

The API2 package comes with examples showing how to use the C/C++ interface.

Linux

mkdir examples
cd examples
cp -R /opt/robotino/examples/cpp/circle/ circle
cd circle
mkdir build
cd build
cmake ..
make

Windows

  • Download and install cmake.
  • Copy c:\program files\rec gmb\api2\examples to a user writable directory.
  • Run cmake-gui
  • Choose source and destiantion directory
  • Configure and Generate
  • Open the generated Visual Studio Solution

Quick links

C++ example

#include <iostream>
#include "rec/robotino/api2/all.h"

rec::robotino::api2::Com com;
rec::robotino::api2::Bumper bumper;

int main( int argc, char **argv )
{
  std::string hostname = "172.26.1.1";
  if( argc > 1 )
  {
    hostname = argv[1];
  }

  com.setAddress( hostname.c_str() );
  com.connectToServer( true );
  
  while(com.isConnected() && false == bumper.value())
  {
    std::cout << "Bumper is " << (bumper.value()?"":"not") << " pressed" << std::endl;
    com.processEvents();
    rec::robotino::api2::msleep( 100 );
  }

  com.disconnectFromServer();

  rec::robotino::api2::shutdown();

  return 0;
}

C example

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h> //usleep
#endif

#include "rec/robotino/api2/c/Com.h"

void msleep( unsigned int ms )
{
#ifdef WIN32
  SleepEx( ms, FALSE );
#else
  usleep( ms * 1000 );
#endif
}

ComId com;
BumperId bumper;

int main( int argc, char **argv )
{
  com = Com_construct();

  if( argc > 1 )
  {
    Com_setAddress( com, argv[1] );
  }
  else
  {
    Com_setAddress( com, "172.26.1.1" );
  }

  if( FALSE == Com_connect( com ) )
  {
    printf( "Error on connect" );
    exit(1);
  }
  else
  {
    char addressBuffer[256];
    Com_address( com, addressBuffer, 256 );
    printf( "Connected to %s\n", addressBuffer );
  }

  while( Com_isConnected( com ) && FALSE == Bumper_value( bumper ) )
  {
    printf("Value of bumper is %d\n",Bumper_value( bumper ) )
    msleep( 50 );
  }

  Bumper_destroy( bumper );
  Com_destroy( com );

  return 0;
}