Module Header File

Parent Class

Every Basilisk module is a sub-class of sys_model. This parent class provides common modules variables such as ModelTag and moduleID.

Module Class Name

The Basilisk module class name should be descriptive and unique. Its spelling has to be upper camel case and thus start with a capital letter.

Sample Code

Let us assume the module is to be called SomeModule. The input and output message type is SomeMsg. A basic C++ module header file would contain for example:

 1#ifndef SOME_MODULE_H
 2#define SOME_MODULE_H
 3
 4#include "architecture/_GeneralModuleFiles/sys_model.h"
 5#include "architecture/msgPayloadDefC/SomeMsgPayload.h"
 6#include "architecture/messaging/messaging.h"
 7#include "architecture/utilities/bskLogging.h"
 8
 9/*! @brief basic Basilisk C++ module class */
10class SomeModule: public SysModel {
11public:
12    SomeModule();
13    ~SomeModule();
14
15    void Reset(uint64_t CurrentSimNanos);
16    void UpdateState(uint64_t CurrentSimNanos);
17
18public:
19
20    double dummy;                           //!< [units] sample module variable declaration
21
22    Message<SomeMsgPayload> dataOutMsg;     //!< attitude navigation output msg
23    ReadFunctor<SomeMsgPayload> dataInMsg;  //!< translation navigation output msg
24
25    BSKLogger bskLogger;                    //!< -- BSK Logging
26
27private:
28    double internalVariable;                //!< [units] variable description
29
30};
31
32#endif

Some quick comments about what is included here:

  • The #ifndef statement is used to avoid this header file being imported multiple times during compiling.

  • All include statements should be made relative to basilisk/src

  • The sys_model.h file must be imported as the BSK modules are a subclass of sys_model.

  • All the message payload definition files need to be included. In the above example there is only one.

  • Include the Basilisk messaging.h file to have access to creating message objects

  • Include the bskLogging.h file to use the BSK logging functions.

Be sure to add descriptions to both the module and to the class variables used.

Required Module Methods

Each module should define the Reset() method that is called when initializing the BSK simulation, and the UpdateState() method which is called every time the task to which the module is added is updated.

Module Variables

The public class variables can contain any variables that you want to have access to from the python layer. For example, you might want to set a gain variable, the spacecraft area for solar radiation pressure evaluation, etc.

The output messages are defined through the Message<> template class as shown above. This creates a message object instance which is also able to write to its own message data copy.

The input message object is defined through the ReadFunctor<> template class.

Finally, the bskLogger variable is defined to allow for BSK message logging with variable verbosity. See scenarioBskLog for an example of how to set the logging verbosity.

Variables and methods that don’t need to be accessible from the python layer can be defined as private variables.

Vector of Input Messages

To define a vector of input messages, you can define:

public:
    std::vector<ReadFunctor<SomeMsgPayload>> moreInMsgs;    //!< variable description
private:
    std::vector<SomeMsgPayload> moreInMsgsBuffer;           //!< variable description

Note that the vector of input messages is defined as a public variable. In contrast, the vector of message definition structures (i.e. the message buffer variable) can be defined as a private variable as it is only used within the module and not accessed outside.

Vector of Output Messages

To define a vector of output messages, we define a vector of message pointer using:

public:
    std::vector<Message<SomeMsgPayload>*> moreOutMsgs;      //!< variable description