Difference between revisions of "API2"

From RobotinoWiki
(add lighttpd link)
(Windows)
 
(27 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
==Introduction==
 
==Introduction==
{|cellspacing="20" cellpadding="10"
+
{|class="wikitable" cellpadding="20" vertical-align="top"
|- style="vertical-align:top"
+
|-
 
|[[Image:Robotino_api2_icon_64.png]]
 
|[[Image:Robotino_api2_icon_64.png]]
|The new API2 for Robotino is currently in its final stages of development and it is supposed to replace the current [[OpenRobotinoAPI]] on Robotino.
+
|A C/C++ library to access Robotino's sensors and actors from your own program.
! style="text-align:left; width:20em; background-color:#dddddd"|
+
|}
=== Package links ===
+
 
[[downloads#API2_beta|API2 binary packages]]
+
==Download and install==
 +
Check [[Robotino_OS|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
 +
* [http://packages.openrobotino.org/windows/robotino-api2/msvc-12 Visual Studio 2013]
 +
* [http://packages.openrobotino.org/windows/robotino-api2/msvc-140 Visual Studio 2015]
 +
* [http://packages.openrobotino.org/windows/robotino-api2/msvc-141 Visual Studio 2017]
 +
* [http://packages.openrobotino.org/windows/robotino-api2/msvc-142 Visual Studio 2019]
  
[[downloads#CF_card_images|API2 ready to use CF card image]]
+
==Build examples==
|}
+
The API2 package comes with examples showing how to use the C/C++ interface.
 +
 
 +
===Linux===
 +
<pre>
 +
mkdir examples
 +
cd examples
 +
cp -R /opt/robotino/examples/cpp/circle/ circle
 +
cd circle
 +
mkdir build
 +
cd build
 +
cmake ..
 +
make
 +
</pre>
 +
 
 +
===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
 +
 
 +
==Quick links==
 +
* [https://doc.openrobotino.org/download/RobotinoAPI2/rec_robotino_api2/ Documentation]
 +
 
 +
==C++ example==
 +
<pre>
 +
#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;
 +
}
 +
</pre>
 +
 
 +
==C example==
 +
<pre>
 +
#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();
  
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 completely based on Qt and does not have any other dependencies.
+
  if( argc > 1 )
 +
  {
 +
    Com_setAddress( com, argv[1] );
 +
  }
 +
  else
 +
  {
 +
    Com_setAddress( com, "172.26.1.1" );
 +
  }
  
=== New features ===
+
  if( FALSE == Com_connect( com ) )
The major new features introduced in the API2 are:
+
  {
* Kinect sensor now supported
+
    printf( "Error on connect" );
* Support for up to 4 cameras.
+
    exit(1);
* Support for up to 4 laser rangefinders.
+
  }
* Support for camera controls like brightness, contrast, auto white balance (Note: The supported controls depend on the camera used).
+
  else
* Integrated web server for controlling Robotino by a web browser or your smartphone.
+
  {
* Easier build process due to minimal dependencies on external libraries.
+
    char addressBuffer[256];
* Uses TCP port 12080 for communication only. This minimizes problems with firewalls.
+
    Com_address( com, addressBuffer, 256 );
 +
    printf( "Connected to %s\n", addressBuffer );
 +
  }
  
== Getting started ==
+
  while( Com_isConnected( com ) && FALSE == Bumper_value( bumper ) )
* [[API2_quickstart|Quickstart guide to use API2]]
+
  {
* [[Cpp2|How to build API2 examples]]
+
    printf("Value of bumper is %d\n",Bumper_value( bumper ) )
* [[API2_install_daemons|How to install API2 daemons on Robotino]]
+
    msleep( 50 );
* [[API2_source_build|Building API2 from sources]]
+
  }
* [[Cpp2|C++ programming with API2]]
 
* [[Java|Java programming with API2]]
 
* [[dotnet|.Net programming with API2]]
 
  
== Robotino API2 Overview ==
+
  Bumper_destroy( bumper );
 +
  Com_destroy( com );
  
<imagemap>Image:Api2_overview_600.jpg|
+
  return 0;
rect 1 106 80 152 [[smartsoft|]]
+
}
rect 1 166 80 212 [[dotnet|]]
+
</pre>
rect 2 226 80 272 [[java|]]
 
rect 0 285 81 334 [[matlab|]]
 
rect 1 347 81 393 [[labview|]]
 
rect 1 405 80 453 [[ROS|]]
 
rect 1 465 80 513 [[MRDS|]]
 
rect 111 46 163 509 [[Cpp|]]
 
rect 210 586 284 640 [[fcgid|]]
 
rect 316 46 358 852 [[rpcd|]]
 
rect 391 46 464 101 [[controld3|]]
 
rect 390 121 464 175 [[lcdd2|]]
 
rect 391 196 464 251 [[camd2|]]
 
rect 391 330 464 386 [[ftdid|]]
 
rect 391 495 464 551 [[laserd2|]]
 
rect 391 600 464 654 [[robotinoxtd|]]
 
rect 391 720 464 775 [[grapplerd|]]
 
rect 391 794 464 851 [[kinectd|]]
 
rect 494 46 554 123 [[I/O_boards|]]
 
rect 496 136 568 187 [[display|]]
 
rect 495 197 557 272 [[camera|]]
 
rect 495 284 570 358 [[gyro|]]
 
rect 495 375 566 467 [[northstar|]]
 
rect 495 479 558 579 [[scanner|]]
 
rect 494 600 588 666 [[cbha|]]
 
rect 494 675 565 786 [[grappler|]]
 
rect 494 801 589 859 [[kinect|]]
 
rect 45 569 165 659 [[lighttpd|]]
 
</imagemap>
 

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;
}