This web-page gives information, links and resources to use and learn to program in C++ for the research purposes of LOCEN.
LOCEN uses C++ to perform its simulations of brain and behaviour and also research involving robot control. The reason of this is that C++ code is incredible fast at execution time. The reason why our simulations need fast execution is that they usually involve many loops with single variable or small vector operations, executed for millions and millions of times. LOCEN simulations have these features as they usually simulate the cyclic interactions between the organism/robot and its environment ("embodied systems") and also simulate the learning processes of these systems happening during these repeated interactions. Moreover, we often simulate in detail the body and the environment of the organism/robot, e.g. with realistic 3D physical simulators (such as ODE, Bullet, Newton). These type of simulations are computationally extremely heavy (require hours or even one whole day), so fast execution is essential for us.
A second reason for using C++ is that when dealing with robots, and also with electronic hardware of other type (sometimes used by the group, e.g. the Arduino board), C++ (and C, included in it) allow us to program at low-level, i.e. very close to the hardware. Much middleware to interface electronics devices is indeed written in C.
LOCEN also uses MATLAB and Python as programming languages to prototype some of its models. The reason of this is that it is very easy and fast to program with MATLAB and Python. On the other side, MATLAB is a interpreted language, and Python is interpreted for a virtual machine (or so), so they are rather slow at execution time. Moreover, Python is a bit used for robots, Matlab even less: C++ is definitely still the main language for robotics. For this reason LOCEN uses C++ to have fast simulation programs and to interface robots, in particular the iCub robot of the group.
C++ is founded on C. The main difference between the two languages are that:
- C is for procedural programming, whereas C++ is for object oriented programming (using classes and objects: see here)
- C++ contains brings innovations also at the level of the specific instructions, most notably: for the inferfaces (in particular, to print in the consol and to download/upload information in files), for memory allocation (which was very complicated in C), and for the minor/no use of "pointers" (variables that store the machine physical address of other variables rather than a specific contente such as a letter or a number: although not used much in C++, do learn the concept of pointer and its minimal use as it is a very fundamental concept for programming). These innovations allow the "use of C++ as an enhanced form of C" (there are some tutorials explicitly dedicated to this), which is the way people now program in C.
The type of use we make of C++ in LOCEN is as follows:
- We definitely use C++ possibilities as an advanded form C programming. so we do not use anymore the old C syntax when the C++ more handy one is available
- Some of us use the basic concepts of object oriented programming in their programs: mainly we use classes and objects in their simpler forms, e.g. without inheritance, virtual classes, and operators overloading. In particular, since the code done for research simulations is very often changed (as it is impossible to anticipate at the beginning of a research where it will go in the future), we tend to avoid to overstructure our programs with too many classes/objects/hierarchies dependencies. We rather use classes and objects for coding low-level parts of the program that we are sure will be reused many times in teh future, so it makes sense to incapsulate them in a clean form. Alongside this, we often use functions to encapsulate pieces of code at a higher level, so not to have a ligther progarm structure that is easier to modify (functions are typical of C, not only of C++, as they are a form of less strict encapsulation of code involving operations but not variables: see here here)
- Knowing the formalism of classes and objects, and also a bit beyond them (in particular inheritance and virtual classes), is however important to understand the code written for robots so as to be able to inferface with them. So, when you realise that you need this type of knowledge for what you are doing (e.g, if dealing with an API of a robot) go a bit in depth on it.
Learning to program in C++
A very good YouTube video tutorial on C++ is this one:
Another YouTube video tutorial on C++ is available from here:
A good web site giving many resources that might help you to learn to program in the main computer programming languages:
Another good tutorial is available from here:
A very good reference web-site, where one can quickly find what is needed, e.g. that has been forgotten after having gone through a previous systematic study of C++, is the following one (by the way: this web-site is also very useful for those who already know the general principles of programming - see here - and need to know the particular sintax of C++):
A web-page and papers where Stroustrup, one of the inventors of C and C++, gives useful indications on C++ and its modern versions, which are very different from the initial ones to which many programmers are used to (note: the book very formal, not easy, probably not good for beginners):
LOCEN uses QT to implement the Widgets (i.e. the graphical interfaces of programs, based on windows, buttons, sliders, graphs, etc.) of C++ programs. You can download the free libraries of QT, and much documentation about them, from here:
You can find very good tutorials on QT here:
Linear algebra: Armadillo and IT++
LOCEN uses the libraries Armadillo to implement linear algebra code in C++ programs. You can download the free libraries of Armadillo, and documentation about them, from here:
Another good library that LOCEN used to use for the same purposes is IT++. You can download the free libraries of IT++, and documentation about them, from here: