Robobot level 3 details

From Rsewiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "Back to Robobot_B Back to Robobot architecture == Mission control == The example mission is intended to illustrate how mission (elements) could be programmed. === ...")
 
(Simple plan)
 
Line 14: Line 14:
  
 
An example mission is available in the file bplan1.h and bplan1.cpp
 
An example mission is available in the file bplan1.h and bplan1.cpp
 +
 +
=== Header file ===
  
 
The header file bplan1.h is:
 
The header file bplan1.h is:
Line 37: Line 39:
 
Explained line by line
 
Explained line by line
  
=== Pragma and namespace ===
+
==== Pragma and namespace ====
  
 
  #pragma once
 
  #pragma once
Line 46: Line 48:
 
The namespace is used to avoid writing 'std::' for all standard functions, e.g. the type 'std::string' can be specified as just 'string'.
 
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 ====
  
 
  class BPlan1
 
  class BPlan1
Line 56: Line 58:
 
  };
 
  };
 
  extern BPlan1 plan1;
 
  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.
 +
 +
===

Latest revision as of 15:52, 17 November 2023

Back to Robobot_B

Back to Robobot architecture

Contents

[edit] Mission control

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

[edit] 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.

[edit] Simple plan

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

[edit] 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

[edit] 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'.

[edit] 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.

[edit] =

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox