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.
To build your own program you need to
If you are familiar with cmake you might prefer using $(OPENROBOTINOAPI_DIR)/1/tools/FindOpenRobotino1.cmake.
include "rec/robotino/com/all.h" include "rec/core_lt/Timer.h" include <cmath> include <iostream>
using namespace rec::robotino::com;
class MyCom : public Com
{
public:
MyCom()
{
}
void errorEvent( Error error, const char* errorString )
{
std::cerr << "Error: " << errorString << std::endl;
}
void connectedEvent()
{
std::cout << "Connected." << std::endl;
}
void connectionClosedEvent()
{
std::cout << "Connection closed." << std::endl;
}
};
MyCom com; OmniDrive omniDrive;
Notice the class MyCom which has rec::robotino::com::Com as base class. MyCom overwrites the three virtual funtions to handle different events.
void init()
{
// Tell omniDrive which Robotino to drive
// It is possible to have multiple Com objects and multiple OmniDrive objects.
// By this you can drive multiple Robotinos from one program.
omniDrive.setComId( com.id() );
// Connect std::cout << "Connecting..." << std::endl; com.setAddress( "127.0.0.1" ); com.connect(); std::cout << std::endl << "Connected" << std::endl; }
void drive()
{
rec::core_lt::Timer timer;
timer.start();
const float speed = 200.0f; const float rotationSpeed = 36.0f;
while( com.isConnected() )
{
float rot = rotationSpeed * ( 2.0f * (float)M_PI / 360.0f ) * ( timer.msecsElapsed() / 1000.0f );
omniDrive.setVelocity( cos(rot) * speed, sin(rot) * speed, 5.0f );
com.waitForUpdate(); //wait until actor set values are transmitted and new sensor readings are available } }
void destroy()
{
com.disconnect();
}
int main()
{
try
{
init();
drive();
destroy();
}
catch( const std::exception& e )
{
std::cerr << "Error: " << errorString << std::endl;
}
std::cout << "Press any key to exit..." << std::endl; rec::core_lt::waitForKey(); }
1.5.5