Robobot software building blocks

From Rsewiki
Revision as of 16:21, 29 December 2023 by Jca (Talk | contribs)

Jump to: navigation, search

Back to Robobot.

Back to Robobot software description

C++ code

The Raubase software is built in modules with mostly only one function, structured from the 'NASREM' architecture.

Robobot level 3.png

Figure. The NASREM model is shown on the top right. This figure is for level 3 and primarily shows the behaviour and vision-related blocks.

File names

Each module has a header-file with the definition (e.g. bplan.h) of a class and a file with implementation (e.g. bplan.cpp).

The first letter in the filename is related to the NASREM model as:

  • sxxxxx.h/.cpp are sensor retrival classes.
  • mxxxxx.h/.cpp are modelling and feature extraction classes.
  • cxxxxx.h/.cpp are control classes.
  • bxxxxx.h/.cpp are behaviour classes.
  • uxxxxx.h/.cpp are utility functions.

C++ class structure

All classes have the same base structure. As an example (of a relatively simple class), the behaviour example called 'bplan1' is shown below; first the class definition in bplan1.h (all comments removed):

1   #pragma once
2   using namespace std;
3   class BPlan1
4   {
5   public:
6     ~BPlan1();
7     void setup();
8     void run();
9     void terminate(); 
10  private:
11    void toLog(const char * message);
12    int logCnt = 0;
13    bool toConsole = true;
14    FILE * logfile = nullptr;
15    bool setupDone = false;
16  };
17  extern BPlan1 plan1;

Line 1 is just to ensure that this definition is read once only.

Line 2 is to simplify some notations

Line 3 Is the start of the class definition, the class names start with Capital letters, following the normal convention for type definitions.

Line 6 Is the destructor that will ensure log files are properly closed.

Line 7-9 define the general functions to start (setup), run and terminate the class. Setup reads the configuration file (robot.ini), and prepares logfiles and other initialization tasks.

Line 11 defines a function to make it easier to save data to the logfile, in this case, the log is text messages. The function adds a timestamp for each call so that the timing of the message can be compared with other logfiles.

Line 13-15 are other private variables.

Line 17 creates a reference to an instance of this class (the instance is created in the implementation file bplan1.cpp).

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox