MCA2 Calculator Tutorial Chapter 1

From Mca2
Jump to navigationJump to search


This tutorial is for mca2 beginners. It shows the basic idea and functionality of the modular ar- chitecture of mca2. Within this tutorial you will learn the basic idea how mca2 works. Afterwards you will learn how to create a project, a part, groups and modules. To do so, we will implement a simple pocket calculator with the basic calculation types add, subtract, multiply and divide. We will create a module for each calculation type to show how modules work together and how they can be connected with each other and with the group that surrounds them. At the end we will create a graphic user interface (gui) for the program and examine the running program with mcabrowser.

The tutorial assumes that you have downloaded and compiled a version of mca2. While this tutorial and the associated source code was written on Linux (Ubuntu Lucid) it should also work on Windows. Furthermore is assumed that you are familiar with basics in

  • C++ programming
  • Object orientation and class inheritance
  • Linux (or correspondent) command line operations.

How MCA2 Works

As MCA2 stands for Modular Controller Architecture v2, the core idea is to create modules and combine their functionality to do whatever you want your program to do. Advantages of the modular design are for example that you can divide the main functionality of your program into smaller parts which’s complexity and responsibility range are much less. This makes implementing a lot easier. It is also possible to exchange different modules later (if neccesary) which simplifies optimization and maintanance. And, of course, you can create different abstaction layers within your software to handle the complexity of commands of the underlying hardware. Abstraction may also make it possible to run your program on different hardware systems as you can exchange hardware abstraction layers – if your modular design supports this. It may be advantageous to keep the modular design in mind when creating programs with mca2.


Every module consists of four interfaces to communicate with other modules in it’s environment. Those interfaces are called ControllerInput, ControllerOutput, SensorInput and SensorOutput. The module’s functionality is organized as shown in figure 1. Information (or commands) are given to the module on the ControllerInput on top right. This information is available for the module and can be obtained and manipulated if neccesary in the Control() function whereafter the data can be written to the ControllerOutput on bottom right of the module to communicate with another module below. So the Control() side of a module handles top-down communication. On the other hand the Sense() side of a module handles bottup-up communication: Information from modules below (or the underlying hardware) are given to the SensorInput on the bottom left side of a module, where the Sense() function is able to read and manipulate it and then pass it to the SensorOutput on the top left of the module for other modules above.

Calc tut module.gif

Figure 1: Structure of a module (source:


To combine different modules mca2 offers a structure called group. A group is capable of holding as many modules as you want and organize the way those modules are connected with each other. It has – exactly like a module – a ControllerInput, ControllerOutput, SensorInput and a SensorOutput. The higher a module is placed within a group, the greater is it’s abstaction level. The further down you go, the more specific a module should be – as explained above. From the outside a group looks and works exactly like a module which makes it possible to combine groups with each other and put them together again in another group (on higher abstraction level). Communication between the different modules is established by so called communication edges (or short: edges). An edge is a unidirectional, multidimensional “wire” from an module’s output to a different module’s input on Control() or on Sense() side (see fig. 2). Edges that connect ControllerOutputs with ControllerInputs are called “down” edges as data from the one module’s ControllerOutput is passed down to the other module’s ControllerInput. Those edges connecting the SensorOutputs with SensorInputs are called “up” edges respectively. As edges are multidimensional you can pass as many variables as you want along an edge.

Calc tut group.jpg

Figure 2: Combine modules within a group and connect them via communication edges (source:


A part is the highest structure in mca2 that executes a main() method you know from C/C++ programming and is responsible for starting your mca2-program. All of the groups and modules you will add to your project are indirectly “started” here. There is only one part per mca2 program 2 and a part creates only one group (which can hold as many groups and modules as you want it to). To communicate between different parts, mca2 has the ability of using a LAN as it opens TCP- sockets on a port of your choice (default is port 1500). As our tutorial is for beginners, we don’t make use of this functionality and so there is no need to go further into detail here. If you need more information on mca2 go ahead reading on the mca2 homepage1 and have a look into the mca2 wiki2 .

< Back === Forward >