Skip to content
Auke Wiggers edited this page Jun 11, 2013 · 2 revisions

This is a short tutorial on how to create a new Cognition module in the NaoTH project.
Note: the best way to create a new module is to cope an existing one and to clean out everything you don't need.

Step 1: Create .h/.cpp files

Open the directory NaoTHSoccer/Source/Core/Cognition/Modules and choose the cathegory for your new module, e.g., Experiment. Create a new directory with the name of your new module, e.g., NaoTHSoccer/Source/Core/Cognition/Modules/Experiment/MyModule. Within this new directory create two new files MyModule.hand MyModule.cpp with the following content:

MyModule.h
/**
* @file MyModule.h
*/

#ifndef _MyModule_H
#define _MyModule_H

#include <ModuleFramework/Module.h>
#include <Representations/Infrastructure/FrameInfo.h>

BEGIN_DECLARE_MODULE(MyModule)
 REQUIRE(FrameInfo)
END_DECLARE_MODULE(MyModule)

class MyModule: public MyModuleBase
{
public:
 MyModule();
 ~MyModule();

 virtual void execute();
};

#endif  /* _MyModule_H */
MyModule.cpp
/**
* @file MyModule.cpp
*/

#include "MyModule.h"

MyModule::MyModule()
{
  // initialize some stuff here
}

MyModule::~MyModule()
{
  // clean some stuff here
}

void MyModule::execute()
{
  // do some stuff here
}

Step 2: Register your Module

Open the file NaoTHSoccer/Source/Core/Cognition/Cognition.cpp. Include the header of your module, e.g.,

#include "Modules/Experiment/MyModule/MyModule.h"

Register your module by adding the following line in the init method

REGISTER_MODULE(MyModule);

Note: the order of the registration defines the order of the execution of the modules. Make sure your module is executed in the correct order.

Also, don't forget to enable your module in the config (modulename=true in modules.cfg).

Step 3: Regenerate the Project

Close your IDE and regenerate the project files as described in Generate Project Files.

Clone this wiki locally