MRC/Tutorials/The EMC framework
So, we've got a C++ source file that we can compile, but it is still not very useful. We have to build software that runs on a robot and can perform a complex task. Starting from scratch would take a lot of time, but fortunately a lot is already provided! Actually it was already secretly sitting on your computer, being installed by the install script. This software that is provided is not something that is runnable on its own, but a set of functions and C++ classes that we can use in our own project. Such a set of reusable software parts is called a software library. Now, we have to include this installed library in the project.
Open the example.cpp file, and change it to the following:
#include <emc/io.h>
#include <unistd.h>
int main()
{
emc::IO io;
while( io.ok() )
{
sleep(1);
io.speak("test " );
}
return 0;
}
The include statement on top includes the emc framework in your source file, which means that all functions, classes, etc declared there can be used by your project. The *io* object is something we will use to build our application with. Don't worry about it now, we'll get back to that later.
Try to compile the project (make sure to 'be' in your project root, i.e.: ~/emc/my_project):
g++ -o bin/example src/example.cpp
Woah, errors! Note that the error states something about undefined reference. We included emc/engine.h so we should be fine right? No: often *.h-files only declare functions etc, but they do not define them, that is: they tell the compiler something with that name is out there, but they do not provide the actual implementation. We need to tell the compiler where the implementation, which is already compiled into binary form, is. This is called linking, and we need to specify it in the g++ command:
g++ -o bin/example src/example.cpp -lemc-framework
Here, the *-l* specifies that g++ should link the program to the library that is called *emc-framework*. For those who are wondering, the compiler does not grab emc-framework out of thin air. Take a look in the */usr/lib* directory: you will find *libemc-framework.so* sitting there, along with many other libraries. The extension so stands for shared object: it is a piece of software that can be shared across different applications. The *h-files*, which are called *header files* can be found in */usr/include* (e.g., look for */usr/include/emc/io.h*).
To run this example, you will first need to start a ROS master. We can do this by launching the simulator. Afterwards run the executable that was compiled.