Skip to content

Commit

Permalink
Merge pull request #129 from nasa/lag_comp_updates
Browse files Browse the repository at this point in the history
Updated lag compensation to address issue #128
  • Loading branch information
dandexter authored Oct 23, 2023
2 parents 4f79f84 + 8ee5ba5 commit f89a513
Show file tree
Hide file tree
Showing 31 changed files with 757 additions and 329 deletions.
38 changes: 27 additions & 11 deletions include/TrickHLA/LagCompensation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ NASA, Johnson Space Center\n
@rev_entry{Dan Dexter, L3 Titan Group, DSES, June 2006, --, DSES Initial Lag Compensation.}
@rev_entry{Dan Dexter, NASA ER7, TrickHLA, March 2019, --, Version 2 origin.}
@rev_entry{Edwin Z. Crues, NASA ER7, TrickHLA, March 2019, --, Version 3 rewrite.}
@rev_entry{Dan Dexter, NASA ER6, TrickHLA, October 2023, --, Added lag-comp bypass functions.}
@revs_end
*/
Expand Down Expand Up @@ -77,7 +78,32 @@ class LagCompensation
return;
}

public:
//-----------------------------------------------------------------
// These are virtual functions and must be defined by a full class.
//-----------------------------------------------------------------

/*! @brief Send side lag compensation callback. */
virtual void send_lag_compensation();

/*! @brief When lag compensation is disabled, this function is called to
* bypass the send side lag compensation and your implementation must copy
* the sim-data to the lag-comp data to effect the bypass. */
virtual void bypass_send_lag_compensation() = 0;

/*! @brief Receive side lag compensation callback. */
virtual void receive_lag_compensation();

/*! @brief When lag compensation is disabled, this function is called to
* bypass the receive side lag compensation and your implementation must
* copy the lag-comp data to the sim-data to effect the bypass. You must
* make sure to check the lag-comp data was received before copying to
* the sim-data otherwise you will be copying stale data. */
virtual void bypass_receive_lag_compensation() = 0;

//-----------------------------------------------------------------
// Helper functions.
//-----------------------------------------------------------------

/*! @brief Get the Attribute by FOM name.
* @return Attribute for the given name.
* @param attr_FOM_name Attribute FOM name. */
Expand Down Expand Up @@ -109,16 +135,6 @@ class LagCompensation
* @param obj Associated object for this class. */
virtual void initialize_callback( Object *obj );

//-----------------------------------------------------------------
// These are virtual functions and must be defined by a full class.
//-----------------------------------------------------------------

/*! @brief Send side lag compensation callback. */
virtual void send_lag_compensation();

/*! @brief Receive side lag compensation callback. */
virtual void receive_lag_compensation();

protected:
Object *object; ///< @trick_io{**} Object associated with this lag-comp class.

Expand Down
32 changes: 18 additions & 14 deletions include/TrickHLA/Packing.hh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ class Packing
/*! @brief Destructor for the TrickHLA Packing class. */
virtual ~Packing();

//-----------------------------------------------------------------
// These are virtual functions and must be defined by a full class.
//-----------------------------------------------------------------

/*! @brief Pack the data before being sent. */
virtual void pack() = 0;

/*! @brief Unpack the received data. */
virtual void unpack() = 0;

//-----------------------------------------------------------------
// Helper functions.
//-----------------------------------------------------------------

/*! @brief Initialize the callback object to the supplied Object pointer.
* @param obj Associated object for this class. */
virtual void initialize_callback( Object *obj );

/*! @brief Get the Attribute by FOM name.
* @return Attribute for the given name.
* @param attr_FOM_name Attribute FOM name. */
Expand All @@ -89,20 +107,6 @@ class Packing
* @return Returns the current CTE time. */
double get_cte_time();

/*! @brief Initialize the callback object to the supplied Object pointer.
* @param obj Associated object for this class. */
virtual void initialize_callback( Object *obj );

//-----------------------------------------------------------------
// These are virtual functions and must be defined by a full class.
//-----------------------------------------------------------------

/*! @brief Pack the data before being sent. */
virtual void pack() = 0;

/*! @brief Unpack the received data. The default */
virtual void unpack() = 0;

protected:
Object *object; ///< @trick_io{**} Object associated with this packing class.

Expand Down
3 changes: 1 addition & 2 deletions models/simconfig/src/SimpleSimConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ NASA, Johnson Space Center\n
@tldh
@trick_link_dependency{../source/TrickHLA/DebugHandler.cpp}
@trick_link_dependency{../source/TrickHLA/Int64BaseTime.cpp}
@trick_link_dependency{../source/TrickHLA/Int64Interval.cpp}
@trick_link_dependency{../source/TrickHLA/Object.cpp}
@trick_link_dependency{../source/TrickHLA/Types.cpp}
@trick_link_dependency{simconfig/src/SimpleSimConfig.cpp}
Expand All @@ -48,7 +47,7 @@ NASA, Johnson Space Center\n
// TrickHLA include files.
#include "TrickHLA/DebugHandler.hh"
#include "TrickHLA/Int64BaseTime.hh"
#include "TrickHLA/Int64Interval.hh"
#include "TrickHLA/KnownFederate.hh"
#include "TrickHLA/Object.hh"
#include "TrickHLA/Types.hh"

Expand Down
12 changes: 1 addition & 11 deletions models/sine/include/SineData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,7 @@ class SineData

/*! @brief Set the name of the sine wave object.
* @param new_name The name of the sine wave object. */
void set_name( char const *new_name )
{
if ( new_name != this->name ) {
if ( this->name != NULL ) {
if ( trick_MM->delete_var( static_cast< void * >( this->name ) ) ) {
send_hs( stderr, "TrickHLAModel::SineData::set_name():%d ERROR deleting Trick Memory for 'this->name'\n", __LINE__ );
}
}
this->name = ( new_name != NULL ) ? trick_MM->mm_strdup( new_name ) : NULL;
}
}
void set_name( char const *new_name );

//
// Public utility functions.
Expand Down
33 changes: 22 additions & 11 deletions models/sine/include/SineLagCompensation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,38 @@ NASA, Johnson Space Center\n
@trick_link_dependency{../source/TrickHLA/Attribute.cpp}
@trick_link_dependency{../source/TrickHLA/LagCompensation.cpp}
@trick_link_dependency{../source/TrickHLA/Object.cpp}
@trick_link_dependency{../source/TrickHLA/Types.cpp}
@trick_link_dependency{sine/src/SineData.cpp}
@trick_link_dependency{sine/src/SineLagCompensation.cpp}
@revs_title
@revs_begin
@rev_entry{Dan Dexter, NASA ER7, TrickHLA, June 2006, --, Version 2 origin.}
@rev_entry{Edwin Z. Crues, NASA ER7, TrickHLA, March 2020, --, Version 3 rewrite.}
@rev_entry{Dan Dexter, NASA ER6, TrickHLA, October 2023, --, Added lag-comp bypass functions.}
@revs_end
*/

#ifndef TRICKHLA_MODLE_SINE_LAG_COMPENSATION_HH
#define TRICKHLA_MODLE_SINE_LAG_COMPENSATION_HH

// Forward declarations.
namespace TrickHLA
{
class Object;
}
// System include files.
#include <string>

// TrickHLA include files.
#include "TrickHLA/Attribute.hh"
#include "TrickHLA/LagCompensation.hh"
#include "TrickHLA/Object.hh"
#include "TrickHLA/Types.hh"

// Model include files.
#include "SineData.hh"

namespace TrickHLAModel
{

class SineLagCompensation : public TrickHLA::LagCompensation
class SineLagCompensation : public SineData, public TrickHLA::LagCompensation
{
// Let the Trick input processor access protected and private data.
// InputProcessor is really just a marker class (does not really
Expand All @@ -74,9 +75,8 @@ class SineLagCompensation : public TrickHLA::LagCompensation
virtual ~SineLagCompensation();

/*! @brief Initialize the LagCompensation object.
* @param sim_data The sine wave data object.
* @param lag_comp_data The sine wave lag compensation data. */
void initialize( SineData *sim_data, SineData *lag_comp_data );
* @param sim_data The sine wave data object. */
void initialize( SineData *sim_data );

//
// From the TrickHLALag::Compensation class.
Expand All @@ -89,13 +89,22 @@ class SineLagCompensation : public TrickHLA::LagCompensation
* head by dt to predict the value at the next data cycle. */
virtual void send_lag_compensation();

/*! @brief When lag compensation is disabled, this function is called to
* bypass the send side lag compensation and your implementation must copy
* the sim-data to the lag-comp data to effect the bypass. */
virtual void bypass_send_lag_compensation();

/*! @brief Receive side lag-compensation where we propagate the sine wave
* state ahead by dt to predict the value at the next data cycle. */
virtual void receive_lag_compensation();

/*! @brief When lag compensation is disabled, this function is called to
* bypass the receive side lag compensation and your implementation must
* copy the lag-comp data to the sim-data to effect the bypass. */
virtual void bypass_receive_lag_compensation();

private:
SineData *sim_data; ///< @trick_units{--} Simulation data.
SineData *lag_comp_data; ///< @trick_units{--} Lag compensation data.
SineData *sim_data; ///< @trick_units{--} Simulation data.

TrickHLA::Attribute *time_attr; ///< @trick_io{**} Reference to the "Time" TrickHLA::Attribute.
TrickHLA::Attribute *value_attr; ///< @trick_io{**} Reference to the "Value" TrickHLA::Attribute.
Expand All @@ -106,6 +115,8 @@ class SineLagCompensation : public TrickHLA::LagCompensation
TrickHLA::Attribute *tol_attr; ///< @trick_io{**} Reference to the "Tolerance" TrickHLA::Attribute.
TrickHLA::Attribute *name_attr; ///< @trick_io{**} Reference to the "Name" TrickHLA::Attribute.

std::string lag_comp_type_str; ///< @trick_units{--} Type of lag compensation as a string.

private:
// Do not allow the copy constructor or assignment operator.
/*! @brief Copy constructor for SineLagCompensation class.
Expand Down
7 changes: 1 addition & 6 deletions models/sine/include/SineObjectDeleted.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ NASA, Johnson Space Center\n
#ifndef TRICKHLA_MODLE_SINE_OBJECT_DELETED_HH
#define TRICKHLA_MODLE_SINE_OBJECT_DELETED_HH

// Forward declarations.
namespace TrickHLA
{
class Object;
}

// Trick include files.
#include "TrickHLA/Object.hh"
#include "TrickHLA/ObjectDeleted.hh"

namespace TrickHLAModel
Expand Down
7 changes: 1 addition & 6 deletions models/sine/include/SineOwnershipHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ NASA, Johnson Space Center\n
#ifndef TRICKHLA_MODEL_SINE_OWNERSHIP_HANDLER_HH
#define TRICKHLA_MODEL_SINE_OWNERSHIP_HANDLER_HH

// Forward declarations.
namespace TrickHLA
{
class Object;
}

// TrickHLA include files.
#include "TrickHLA/Object.hh"
#include "TrickHLA/OwnershipHandler.hh"

namespace TrickHLAModel
Expand Down
9 changes: 2 additions & 7 deletions models/sine/include/SinePacking.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@ NASA, Johnson Space Center\n
#ifndef TRICKHLA_MODEL_SINE_PACKING_HH
#define TRICKHLA_MODEL_SINE_PACKING_HH

// Forward declarations.
namespace TrickHLA
{
class Object;
}

// TrickHLA include files.
#include "TrickHLA/Attribute.hh"
#include "TrickHLA/Object.hh"
#include "TrickHLA/Packing.hh"

// Model include files.
Expand All @@ -52,7 +47,7 @@ class Object;
namespace TrickHLAModel
{

class SinePacking : public TrickHLA::Packing
class SinePacking : public SineData, public TrickHLA::Packing
{
// Let the Trick input processor access protected and private data.
// InputProcessor is really just a marker class (does not really
Expand Down
52 changes: 49 additions & 3 deletions models/sine/src/SineData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ SineData::SineData()
tol( 0.001 ),
name( NULL )
{
// We don't want a NULL name by default (Trick Memory Manager allocated).
this->set_name( "" );

// Compute the value.
this->compute_value( time );

Expand All @@ -77,6 +80,9 @@ SineData::SineData(
tol( 0.001 ),
name( NULL )
{
// We don't want a NULL name by default (Trick Memory Manager allocated).
this->set_name( "" );

// Compute the value.
this->compute_value( time );

Expand All @@ -98,14 +104,54 @@ SineData::~SineData()
}
}

/*!
* @brief Set the name of the sine wave object.
* @param new_name The name of the sine wave object.
*/
void SineData::set_name( char const *new_name )
{
if ( new_name != this->name ) {
if ( this->name != NULL ) {
if ( trick_MM->delete_var( static_cast< void * >( this->name ) ) ) {
send_hs( stderr, "TrickHLAModel::SineData::set_name():%d ERROR deleting Trick Memory for 'this->name'\n", __LINE__ );
exit( -1 );
}
}
if ( new_name != NULL ) {
this->name = trick_MM->mm_strdup( new_name );
if ( this->name == NULL ) {
send_hs( stderr, "TrickHLAModel::SineData::set_name():%d ERROR cannot allocate Trick Memory for 'this->name'\n", __LINE__ );
exit( -1 );
}
} else {
this->name = NULL;
}
}

// We don't want a NULL name by default (Trick Memory Manager allocated).
if ( this->name == NULL ) {
this->name = trick_MM->mm_strdup( "" );
if ( this->name == NULL ) {
send_hs( stderr, "TrickHLAModel::SineData::set_name():%d ERROR cannot allocate Trick Memory for 'this->name'\n", __LINE__ );
exit( -1 );
}
}
}

/*!
* @job_class{scheduled}
*/
void SineData::copy_data(
SineData const *orig ) // IN: -- Orginal source data to copy.
SineData const *orig ) // IN: -- Original source data to copy from.
{
// Use the default assignment operator to copy.
*this = *orig;
this->set_name( orig->get_name() );
this->set_time( orig->get_time() );
this->set_value( orig->get_value() );
this->set_derivative( orig->get_derivative() );
this->set_phase( orig->get_phase() );
this->set_frequency( orig->get_frequency() );
this->set_amplitude( orig->get_amplitude() );
this->set_tolerance( orig->get_tolerance() );
}

/*!
Expand Down
5 changes: 4 additions & 1 deletion models/sine/src/SineInteractionHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NASA, Johnson Space Center\n
@tldh
@trick_link_dependency{../source/TrickHLA/DebugHandler.cpp}
@trick_link_dependency{../source/TrickHLA/Int64BaseTime.cpp}
@trick_link_dependency{../source/TrickHLA/InteractionHandler.cpp}
@trick_link_dependency{../source/TrickHLA/Types.cpp}
@trick_link_dependency{sine/src/SineInteractionHandler.cpp}
Expand Down Expand Up @@ -49,6 +50,7 @@ NASA, Johnson Space Center\n
// TrickHLA include files.
#include "TrickHLA/DebugHandler.hh"
#include "TrickHLA/Int64BaseTime.hh"
#include "TrickHLA/InteractionHandler.hh"
#include "TrickHLA/StandardsSupport.hh"
#include "TrickHLA/StringUtilities.hh"
#include "TrickHLA/Types.hh"
Expand All @@ -64,7 +66,8 @@ using namespace TrickHLAModel;
* @job_class{initialization}
*/
SineInteractionHandler::SineInteractionHandler()
: name( NULL ),
: TrickHLA::InteractionHandler(),
name( NULL ),
message( NULL ),
time( 0.0 ),
year( 2007 ),
Expand Down
Loading

0 comments on commit f89a513

Please sign in to comment.