Robobot level 3 details

From Rsewiki

Back to Robobot_B

Back to Robobot architecture

Mission control

The example mission is intended to illustrate how mission (elements) could be programmed.

Divide and conqer

Do not make the whole DTU Robocup track in one function; divide the task into smaller parts to make it easy to test, modify, reorder and skip.

Simple plan

An example mission is available in the file bplan1.h and bplan1.cpp

Header file

The header file bplan1.h is:

#pragma once
using namespace std;
class BPlan1
{
public:
 ~BPlan1();
 void setup();
 void run();
 void terminate();
private:
 void toLog(const char * message);
 int logCnt = 0;
 bool toConsole = true;
 FILE * logfile = nullptr;
 bool setupDone = false;
};
extern BPlan1 plan1;

Explained line by line

Pragma and namespace

#pragma once
using namespace std;

The first line ensures that the file is used once only. Other files may include other header files that in turn also includes this file, the #pragma once ensures the definitions are used once only.

The namespace is used to avoid writing 'std::' for all standard functions, e.g. the type 'std::string' can be specified as just 'string'.

Class

class BPlan1
{
public:
  ...
private:
  ...
};
extern BPlan1 plan1;

This is the declaration of the class. That is, what is needed to use the class. The content or definition of the functions are found in the 'bplan1.cpp' file.

The name of the class has to be unique. Here the naming convention is that the start

The last line makes an instance of the class called 'plan1'. That is the name that is to be used when this plan has to be activated.

=