robotinocom API documentation
This API is depreceted. Please use the rec::robotino::com API instead.
The application programming interface (API) for Robotino(r) from Festo Didactic permits full access to Robotino's sensors and actors. Communication between the control program and Robotino is handled via TCP and UDP and is therefor fully network transparent. It does not matter whether the control program runs direcly on Robotino or on a remote system.
The API is available in binary form for Windows and Linux and source code via svn.
Install the API either from binary or from source. On a german Windows the default install path is C:\Programme\REC GmbH\OpenRobotinoAPI\1. On Linux the API is installed in /usr/local/OpenRobotinoAPI/1. In the following this path is refered to as "install". Please replace "Programme" with your systems program folder name.
To build your own program you need to
- include install/include in your compilers include search path
- use #include "robotinocom/robotinocom.h" in your program to use RobotinoCom
- include install/lib/win32 or install/lib/linux to your linkers library search path
- link against robotinocom.lib on win32 and librobotinocom.so on linux systems
If you are familiry with cmake you might prefer using install/tools/FindOpenRobotino1.cmake.
In the following you will find a simple example on how to drive Robotino in x direction with 100mm/s for 10 seconds.
You need to include at least "robotinocom/robotinocom.h". "xutils.h" defines mlseep and <iostream> is needed for printing status information.
include "robotinocom/robotinocom.h"
include "xutils.h"
include <iostream>
You might install a couple of callback functions. This is optional but helps you to see what is going on.
void errorCb( void* data, int error )
{
std::cout << std::endl << "Error " << RobotinoCom::errorString( error ) << std::endl;
}
void connectedCb( void* data )
{
std::cout << std::endl << "Connected" << std::endl;
}
void connectionClosedCb( void* data )
{
std::cout << std::endl << "Connection closed." << std::endl;
}
Within the main program the following steps are neccessary to drive Robotino:
- Initialise RobotinoCom
- Install callback handlers (optional)
- Setup the network connection
- Continuously send set point values to Robotino
- Close the connection
Robotino's ip address is defined. If not given as the first command line argument we use 172.26.1.1 which is Robotino's default address. If you are running this program on Robotino you might use localhost as address to be independent from any changes to Robotino's network settings.
int main(int argc, char **argv)
{
std::string hostname = "172.26.1.1";
if( argc > 1 )
{
hostname = argv[1];
}
RobotinoCom com;
unsigned int startTime;
if( false == com.init() )
{
return 1;
}
com.setErrorCallback( &errorCb, NULL );
com.setConnectedCallback( &connectedCb, NULL );
com.setConnectionClosedCallback( &connectionClosedCb, NULL );
The connection to Robotino is established by connectToHost. This function is non blocking so we check the status of the connection as long as we are in the ConnectingState. This state is left by either the connection is successfully established or by an error.
std::cout << "Connecting to host " << hostname;
com.connectToHost( hostname );
while( com.state() == ConnectingState )
{
std::cout << ".";
msleep( 200 );
}
std::cout << std::endl;
if( com.error() != NoError )
{
goto CLEANUP;
}
Now we are ready to send set point values for Robotino's motors. This is done by setVelocity. The data is send by a call to update. This function not only sends all set point values to Robotino but also receives the status of Robotino's sensors.
startTime = com.msecsElapsed();
com.stopAsyncCommunication();
while( false == com.bumper() )
{
unsigned int msecsElapsed = com.msecsElapsed() - startTime;
if( msecsElapsed < 10000 )
{
//drive forward with 100mm/s
com.setVelocity( 100, //vx=100 mm/s
0, //vy=0 mm/s
0 //omega=0 deg/s
);
}
else
{
break;
}
//sending the set values to Robotino and receiving the sensor readings
if( com.update() == false )
{
break;
}
}
After 10s or if update failed the connection is closed and the program exits.
CLEANUP:
com.close();
return 0;
}