Difference between revisions of "API2"
From RobotinoWiki
(→Getting started) |
|||
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. |
− | + | |} | |
− | |||
− | |||
− | + | ==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> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | </ |
Revision as of 11:38, 18 March 2019
Introduction
A C/C++ library to access Robotino's sensors and actors from your own program. |
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; }