Difference between revisions of "API2"

From RobotinoWiki
(Getting started)
(Find the correct version)
(8 intermediate revisions by the same user 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|API2 binary packages]]
 
  
[[downloads#CF_card_images|API2 ready to use CF card image]]
+
==Find the correct version==
|}
+
===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.
 +
* msvc-12: Visual Studio 2013 with VisualStudioVersion=12.0 [https://doc.openrobotino.org/download/RobotinoAPI2/msvc-12/ download]
 +
* msvc-141: Visual Studio 2017 with VCToolsVersion=14.16.27023 [https://doc.openrobotino.org/download/RobotinoAPI2/msvc-141/ download]
 +
API2 for msvc-12 is available for 32bit and 64bit while the msvc-141 library is 64bit only.
 +
 
 +
===Linux===
 +
Get the latest Debian package from [http://packages.openrobotino.org/xenial/pool/main/r/robotino-api2/ here].
 +
 
 +
==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" );
 +
  }
  
Documentation can be found [http://doc.openrobotino.org/download/RobotinoAPI2/rec_robotino_api2/index.html here].
+
  if( FALSE == Com_connect( com ) )
=== New features ===
+
  {
The major new features introduced in the API2 are:
+
    printf( "Error on connect" );
* Kinect sensor now supported
+
    exit(1);
* Support for up to 4 cameras.
+
  }
* Support for up to 4 laser rangefinders.
+
  else
* Support for camera controls like brightness, contrast, auto white balance (Note: The supported controls depend on the camera used).
+
  {
* Integrated web server for controlling Robotino by a web browser or your smartphone.
+
    char addressBuffer[256];
* Easier build process due to minimal dependencies on external libraries.
+
    Com_address( com, addressBuffer, 256 );
* Uses TCP port 12080 for communication only. This minimizes problems with firewalls.
+
    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 ) )
* [[Install_daemons_v3|How to install API2 daemons on Robotino]]
+
    msleep( 50 );
* [[Cpp2|C++ programming with API2]]
+
  }
  
== Robotino API2 Overview ==
+
  Bumper_destroy( bumper );
 +
  Com_destroy( com );
  
<imagemap>Image:Api2_overview_600.png|
+
  return 0;
rect 0 96 103 144 [[smartsoft|]]
+
}
rect 25 158 103 204 [[dotnet|]]
+
</pre>
rect 25 215 103 263 [[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 185 689 297 743 [[fleetcomd|]]
 
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 [[Robotino_Web_Interface|]]
 
</imagemap>
 

Revision as of 12:49, 18 March 2019

Introduction

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

Find the correct version

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.

  • msvc-12: Visual Studio 2013 with VisualStudioVersion=12.0 download
  • msvc-141: Visual Studio 2017 with VCToolsVersion=14.16.27023 download

API2 for msvc-12 is available for 32bit and 64bit while the msvc-141 library is 64bit only.

Linux

Get the latest Debian package from here.

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