Logo
Telescience Resource Kit
TReK C++  5.4.0 ART
trek::MathCalibrator Class Reference

This class calibrates a value using a mathematical equation. More...

#include <math_calibrator.h>

Inherits trek::Calibrator.

Public Member Functions

int32_t LoadFile (const char *filename)
 Loads the MathCalibrator definition from the specified file. More...
 
int32_t SaveFile (const char *filename)
 Saves the MathCalibrator definition to the specified file. More...
 
Constructors, Destructor, and Other Basic Methods
 MathCalibrator ()
 Default constructor of the class.
 
 MathCalibrator (MathCalibrator &input)
 Copy constructor of the class.
 
virtual ~MathCalibrator ()
 Class destructor. More...
 
virtual CalibratorClone ()
 Creates and returns an extact copy of the object.
 
void operator= (MathCalibrator &right_side)
 Provides the equal operator.
 
virtual void Init ()
 Initializes the object.
 
Calibration Methods
void AddConstant (double input_value)
 Adds a constant value for the calibration. More...
 
void AddThisValue ()
 Adds the value for this parameter to the calibration. More...
 
int32_t AddAnotherParameterValue (const char *name, uint32_t instance=1, bool calibrated=true)
 Adds the value for another parameter to the calibration. More...
 
void AddOperator (enum math_cal_op_type input)
 Adds a mathematical operator to the calibration. More...
 
int32_t SetPacket (Packet *input)
 
int32_t Calibrate (double input_value, double &output_value)
 Performs the calibration on the input value. More...
 
bool IsValid ()
 Validates the math calibrator. If it is invalid GetValidationError can be used to see the validation errors.. More...
 
const char * GetValidationError ()
 Return a string for any errors discovered by IsValid.
 
uint32_t GetNumberOfItems ()
 Returns the number of in calibration. More...
 
int32_t GetItem (uint32_t item_num, math_cal_item &item)
 Gets the specified item for the calibrator. More...
 
- Public Member Functions inherited from trek::Calibrator
virtual int32_t Calibrate (double input_value, double &output_value)=0
 Virtual method for derived classes to calibrate an input value. More...
 
 Calibrator ()
 Default constructor of the class.
 
 Calibrator (Calibrator &input)
 Copy constructor of the class.
 
virtual ~Calibrator ()
 Class destructor. More...
 
void operator= (Calibrator &right_side)
 Provides the equal operator.
 
- Public Member Functions inherited from trek::NamedItem
void SetName (const char *input_ptr)
 Sets the name of the item. More...
 
void SetAlias (const char *input)
 Sets the alias of the item. More...
 
void SetShortDescription (const char *input_ptr)
 Sets the short description of the item. More...
 
void SetLongDescription (const char *input_ptr)
 Sets the long description of the item. More...
 
void SetUserDescription (const char *input_ptr)
 Sets the user description of the item. More...
 
void SetOwner (const char *input_ptr)
 Sets the owner of the item. More...
 
void SetPath (const char *input_ptr)
 Sets the path for the item. More...
 
const char * GetName ()
 Returns the name of the item.
 
const char * GetAlias ()
 Returns the alias of the item.
 
const char * GetShortDescription ()
 Returns the short description of the item.
 
const char * GetLongDescription ()
 Returns the long description of the item.
 
const char * GetUserDescription ()
 Returns the user description of the item.
 
const char * GetOwner ()
 Returns the owner of the item.
 
const char * GetPath ()
 Returns the path for the item.
 
int32_t AddAttribute (const char *name, const char *value)
 Adds an attribute to the item. More...
 
void GetAttributeList (StringArray &attr_array)
 Gets a list of the attribute names. More...
 
int32_t GetAttribute (const char *name, char *value, uint32_t &value_len)
 Get the value of the specified attribute. More...
 
 NamedItem ()
 Default constructor of the class.
 
 NamedItem (NamedItem &input)
 Copy constructor of the class.
 
virtual ~NamedItem ()
 Class destructor. More...
 
void operator= (NamedItem &right_side)
 Provides the equal operator.
 
bool operator== (NamedItem &right_side)
 Provides the == operator.
 

Detailed Description

This class calibrates a value using a mathematical equation.

The math calibrator uses reverse Polish notation and is limited to the following operators: +, -, *, /, ^, and ln. The math calibrator can use the value of this parameter, the converted or calbirated value of another parameter in the same packet, and constants.

Constructor & Destructor Documentation

◆ ~MathCalibrator()

trek::MathCalibrator::~MathCalibrator ( )
virtual

Class destructor.

Removes all resources created with this instance of the class.

Member Function Documentation

◆ AddAnotherParameterValue()

int32_t trek::MathCalibrator::AddAnotherParameterValue ( const char *  name,
uint32_t  instance = 1,
bool  calibrated = true 
)

Adds the value for another parameter to the calibration.

Parameters
[in]nameThe name of the other parameter.
[in]instanceThe sample number to use (first sample is 1).
[in]calibratorIndicates to use the calibrated value of parameter if set to true.
Returns
SUCCESS
TREK_DATA_INVALID_INSTANCE

Example:

int32_t ret_value;
//
// Calibration function is y = (10 + x) * z
//
// where
// y is the calibrated value
// x is the value of the parameter being calibrated
// z is the value of a different parameter needed for the calculation
//
mc.AddConstant( 10 );
mc.AddOperator( MCOP_ADD );
ret_value = mc.AddAnotherParmaeterValue( "param2", 1, false );
mc.AddOperator( MCOP_MUL );
This class calibrates a value using a mathematical equation.
Definition: math_calibrator.h:50
void AddOperator(enum math_cal_op_type input)
Adds a mathematical operator to the calibration.
Definition: math_calibrator.cpp:275
void AddConstant(double input_value)
Adds a constant value for the calibration.
Definition: math_calibrator.cpp:154
void AddThisValue()
Adds the value for this parameter to the calibration.
Definition: math_calibrator.cpp:190

◆ AddConstant()

void trek::MathCalibrator::AddConstant ( double  input_value)

Adds a constant value for the calibration.

Parameters
[in]input_valueThe value to add.

Example:

int32_t ret_value;
//
// Calibration function is y = (10 + x) * z
//
// where
// y is the calibrated value
// x is the value of the parameter being calibrated
// z is the value of a different parameter needed for the calculation
//
mc.AddConstant( 10 );
mc.AddOperator( MCOP_ADD );
ret_value = mc.AddAnotherParmaeterValue( "param2", 1, false );
mc.AddOperator( MCOP_MUL );

◆ AddOperator()

void trek::MathCalibrator::AddOperator ( enum math_cal_op_type  input)

Adds a mathematical operator to the calibration.

Parameters
[in]input- The math operator to add.

Example:

int32_t ret_value;
//
// Calibration function is y = (10 + x) * z
//
// where
// y is the calibrated value
// x is the value of the parameter being calibrated
// z is the value of a different parameter needed for the calculation
//
mc.AddConstant( 10 );
mc.AddOperator( MCOP_ADD );
ret_value = mc.AddAnotherParmaeterValue( "param2", 1, false );
mc.AddOperator( MCOP_MUL );

◆ AddThisValue()

void trek::MathCalibrator::AddThisValue ( )

Adds the value for this parameter to the calibration.

Example:

int32_t ret_value;
//
// Calibration function is y = (10 + x) * z
//
// where
// y is the calibrated value
// x is the value of the parameter being calibrated
// z is the value of a different parameter needed for the calculation
//
mc.AddConstant( 10 );
mc.AddOperator( MCOP_ADD );
ret_value = mc.AddAnotherParmaeterValue( "param2", 1, false );
mc.AddOperator( MCOP_MUL );

◆ Calibrate()

int32_t trek::MathCalibrator::Calibrate ( double  input_value,
double &  output_value 
)
virtual

Performs the calibration on the input value.

Parameters
[in]input_valueValue to calibrate.
[out]output_valueCalibrated value.
Returns
SUCCESS

Example:

// Create equation for y = 3.1x^2 - 5;
mc.AddConstant( 3.1 )
mc.AddConstant( 2 )
mc.AddOperator( MCOP_POW );
mc.AddOperator( MCOP_MUL );
mc.AddConstant( 5 );
mc.AddOperator( MCOP_SUB );
double value;
if( mc.Calibrate( 3.14, value ) )
; // process error
else
printf("calibratied value is %lf\n", value);
int32_t Calibrate(double input_value, double &output_value)
Performs the calibration on the input value.
Definition: math_calibrator.cpp:421

Implements trek::Calibrator.

◆ GetItem()

int32_t trek::MathCalibrator::GetItem ( uint32_t  item_num,
math_cal_item &  item 
)

Gets the specified item for the calibrator.

Returns
SUCCESS
TREK_DATA_DOES_NOT_EXIST

Example:

int32_t ret_value;
math_cal_item item;
//
// Calibration function is y = (10 + x) * z
//
// where
// y is the calibrated value
// x is the value of the parameter being calibrated
// z is the value of a different parameter needed for the calculation
//
mc.AddConstant( 10 );
mc.AddOperator( MCOP_ADD );
ret_value = mc.AddAnotherParmaeterValue( "param2", 1, false );
mc.AddOperator( MCOP_MUL );
// get the first item
ret_value = mc.GetItem( 0, item );
int32_t GetItem(uint32_t item_num, math_cal_item &item)
Gets the specified item for the calibrator.
Definition: math_calibrator.cpp:353

◆ GetNumberOfItems()

uint32_t trek::MathCalibrator::GetNumberOfItems ( )

Returns the number of in calibration.

Returns
number of items in calibration equation.

Example:

int32_t ret_value;
//
// Calibration function is y = (10 + x) * z
//
// where
// y is the calibrated value
// x is the value of the parameter being calibrated
// z is the value of a different parameter needed for the calculation
//
mc.AddConstant( 10 );
mc.AddOperator( MCOP_ADD );
ret_value = mc.AddAnotherParmaeterValue( "param2", 1, false );
mc.AddOperator( MCOP_MUL );
printf( "The equation has %u items.\n", mc.GetNumberOfItems() );
uint32_t GetNumberOfItems()
Returns the number of in calibration.
Definition: math_calibrator.cpp:315

◆ IsValid()

bool trek::MathCalibrator::IsValid ( )

Validates the math calibrator. If it is invalid GetValidationError can be used to see the validation errors..

Returns
true If calibrator is valid.
false If calibrator is invalid.

Example:

// Create equation for y = 3.1x^2 - 5;
mc.AddConstant( 3.1 )
mc.AddConstant( 2 )
mc.AddOperator( MCOP_POW );
mc.AddOperator( MCOP_MUL );
mc.AddConstant( 5 );
mc.AddOperator( MCOP_SUB );
if( !mc.IsValid() )
printf( "%s", mc.GetValidationError() );
bool IsValid()
Validates the math calibrator. If it is invalid GetValidationError can be used to see the validation ...
Definition: math_calibrator.cpp:576
const char * GetValidationError()
Return a string for any errors discovered by IsValid.
Definition: math_calibrator.cpp:728

◆ LoadFile()

int32_t trek::MathCalibrator::LoadFile ( const char *  filename)

Loads the MathCalibrator definition from the specified file.

Reads an XML format for the MathCalibrator. It can be written in with SaveFile.

Parameters
[in]filenameThe file to load the parameter object from.
Returns
SUCCESS
TREK_DATA_NULL_PTR
Other return codes

Example:

ret_value = pc.LoadFile( "my_file.xml" );
int32_t LoadFile(const char *filename)
Loads the MathCalibrator definition from the specified file.
Definition: math_calibrator.cpp:797

◆ SaveFile()

int32_t trek::MathCalibrator::SaveFile ( const char *  filename)

Saves the MathCalibrator definition to the specified file.

Writes an XML format for the MathCalibrator. It can be read in with LoadFile.

Parameters
[in]filenameThe file to save the parameter object to.
Returns
SUCCESS
TREK_DATA_NULL_PTR
Other return codes

Example:

ret_value = pc.SaveFile( "my_file.xml" );
int32_t SaveFile(const char *filename)
Saves the MathCalibrator definition to the specified file.
Definition: math_calibrator.cpp:832