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== | ||
− | {| | + | {|class="wikitable" cellpadding="20" vertical-align="top" |
− | + | |- | |
|[[Image:Robotino_api2_icon_64.png]] | |[[Image: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 [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(); | ||
− | + | 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; | |
− | + | } | |
− | + | </pre> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | </ |
Revision as of 12:49, 18 March 2019
Contents
Introduction
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; }