Module: magneticFieldBase

General magnetic field base class used to calculate the magnetic field above a planet using multiple models. The MagneticField class is used to calculate the magnetic field vector above a body using multiple models. This base class is used to hold relevant planetary magnetic field properties to compute answers for a given set of spacecraft locations relative to a specified planet. Specific magnetic field models are implemented as classes that inherit from this base class. Planetary parameters, including position and input message, are settable by the user. In a given simulation, each planet of interest should have only one magnetic field model associated with it linked to the spacecraft in orbit about that body.


class MagneticFieldBase : public SysModel

Public Functions

MagneticFieldBase()

This method initializes some basic parameters for the module.

Return

void

~MagneticFieldBase()

Destructor.

Return

void

void SelfInit()

SelfInit for this method creates a seperate magnetic field message for each of the spacecraft that were added using AddSpacecraftToModel. Additional model outputs are also initialized per-spacecraft.

Return

void

void CrossInit()

This method is used to connect the input position message from the spacecraft. Additonal model-specific cross inits are also conducted.

Return

void

void Reset(uint64_t CurrentSimNanos)

This method is used to reset the module.

Return

void

void addSpacecraftToModel(std::string tmpScMsgName)

Adds the spacecraft message name to a vector of sc message names and automatically creates an output message name.

Return

void

Parameters
  • tmpScMsgName: A spacecraft state message name.

void UpdateState(uint64_t CurrentSimNanos)

Computes the current local magnetic field for each spacecraft and writes their respective messages.

Return

void

Parameters
  • CurrentSimNanos: The current simulation time in nanoseconds

Public Members

std::vector<std::string> scStateInMsgNames

Vector of the spacecraft position/velocity message names.

std::vector<std::string> envOutMsgNames

Vector of message names to be written out by the environment.

std::string planetPosInMsgName

Message name for the planet’s SPICE position message.

double envMinReach

[m] Minimum planet-relative position needed for the environment to work, default is off (neg. value)

double envMaxReach

[m] Maximum distance at which the environment will be calculated, default is off (neg. value)

double planetRadius

[m] Radius of the planet

BSKLogger bskLogger

BSK Logging

Protected Functions

void writeMessages(uint64_t CurrentClock)

This method is used to write the output magnetic field messages whose names are established in AddSpacecraftToModel.

Return

void

Parameters
  • CurrentClock: The current time used for time-stamping the message

bool readMessages()

This method is used to read the incoming command message and set the associated spacecraft positions for computing the atmosphere.

Return

void

void updateLocalMagField(double currentTime)

This method is used to update the local magnetic field based on each spacecraft’s position.

Return

void

void updateRelativePos(SpicePlanetStateSimMsg *planetState, SCPlusStatesSimMsg *scState)

This method is used to determine the spacecraft position vector relative to the planet.

Return

void

Parameters
  • planetState: A space planetstate message struct.

  • scState: A spacecraftPlusStates message struct.

void evaluateMagneticFieldModel(MagneticFieldSimMsg *msg, double currentTime) = 0
void customSelfInit()

Custom SelfInit() method. This allows a child class to add additional functionality to the SelfInit() method

Return

void

void customCrossInit()

Custom CrossInit() method. This allows a child class to add additional functionality to the CrossInit() method

Return

void

void customReset(uint64_t CurrentClock)

Custom Reset() method. This allows a child class to add additional functionality to the Reset() method

Return

void

void customWriteMessages(uint64_t CurrentClock)

Custom output message writing method. This allows a child class to add additional functionality.

Return

void

bool customReadMessages()

Custom output input reading method. This allows a child class to add additional functionality.

Return

void

void customSetEpochFromVariable()

Custom customSetEpochFromVariable() method. This allows a child class to specify how the module epoch information is set by a module variable.

Return

void

Protected Attributes

Eigen::Vector3d r_BP_N

[m] sc position vector relative to planet in inertial N frame components

Eigen::Vector3d r_BP_P

[m] sc position vector relative to planet in planet-fixed frame components

double orbitRadius

[m] sc orbit radius about planet

uint64_t OutputBufferCount

number of output buffers for messaging system

std::vector<MagneticFieldSimMsg> magFieldOutBuffer

Message buffer for magnetic field messages

std::vector<int64_t> envOutMsgIds

vector of module output message IDs

std::vector<int64_t> scStateInMsgIds

vector of spacecraft state message IDs

int64_t planetPosInMsgId

ID of the planet state message.

std::vector<SCPlusStatesSimMsg> scStates

vector of the spacecraft state messages

SpicePlanetStateSimMsg planetState

planet state message

struct tm epochDateTime

time/date structure containing the epoch information using a Gregorian calendar

int64_t epochInMsgId

ID of the epoch message.