TReK C++  5.3.3
Telemetry/Command API
trek::PolynomialCalibrator Class Reference

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

#include <polynomial_calibrator.h>

Inherits trek::Calibrator.

Public Member Functions

int32_t LoadFile (const char *filename)
 Loads the PolynomialCalibrator definition from the specified file. More...
 
int32_t SaveFile (const char *filename)
 Saves the PolynomialCalibrator definition to the specified file. More...
 
Constructors, Destructor, and Other Basic Methods
 PolynomialCalibrator ()
 Default constructor of the class.
 
 PolynomialCalibrator (PolynomialCalibrator &input)
 Copy constructor of the class.
 
virtual ~PolynomialCalibrator ()
 Class destructor. More...
 
virtual CalibratorClone ()
 Creates and returns an extact copy of the object.
 
void operator= (PolynomialCalibrator &right_side)
 Provides the equal operator.
 
virtual void Init ()
 Initializes the object.
 
Calibration Methods
int32_t SetOrder (uint16_t input_value, bool keep_coefficients=false)
 Sets the order for the polynomial calibrator. More...
 
int32_t SetCoefficient (uint16_t power, double input_value)
 Sets the coefficient value for the specified term. More...
 
uint16_t GetOrder ()
 Returns the current order of the calibrator.
 
int32_t GetCoefficient (uint16_t power, double &value)
 Gets the coefficient value for the specified term. More...
 
int32_t Calibrate (double input_value, double &output_value)
 Performs the calibration on the input value. 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...
 
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.
 
 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 polynomial equation.

The order of the equation is not limited by this class, but restrictions may be placed by projects.

Constructor & Destructor Documentation

◆ ~PolynomialCalibrator()

trek::PolynomialCalibrator::~PolynomialCalibrator ( )
virtual

Class destructor.

Removes all resources created with this instance of the class.

Member Function Documentation

◆ Calibrate()

int32_t trek::PolynomialCalibrator::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:

pc.SetOrder( 2 );
// Set coeffiecients for y = 3.1x^2 - 5;
pc.SetCoefficient( 2, 3.1 );
pc.SetCoefficient( 0, -5 );
double value;
if( pc.Calibrate( 3.14, value ) )
; // process error
else
printf("calibratied value is %lf\n", value);
This class calibrates a value using a polynomial equation.
Definition: polynomial_calibrator.h:17
int32_t Calibrate(double input_value, double &output_value)
Performs the calibration on the input value.
Definition: polynomial_calibrator.cpp:273
int32_t SetCoefficient(uint16_t power, double input_value)
Sets the coefficient value for the specified term.
Definition: polynomial_calibrator.cpp:211
int32_t SetOrder(uint16_t input_value, bool keep_coefficients=false)
Sets the order for the polynomial calibrator.
Definition: polynomial_calibrator.cpp:121

Implements trek::Calibrator.

◆ GetCoefficient()

int32_t trek::PolynomialCalibrator::GetCoefficient ( uint16_t  power,
double &  value 
)

Gets the coefficient value for the specified term.

Parameters
[in]powerSpecifies the power of the term.
[in]valueThe value for the coefficient
Returns
SUCCESS
TREK_DATA_INVALID_VALUE

Example:

pc.SetOrder( 2 );
double value;
if( pc.GetCoefficient( 0, value ) )
; // process error
else
printf("value is %lf\n", value);
int32_t GetCoefficient(uint16_t power, double &value)
Gets the coefficient value for the specified term.
Definition: polynomial_calibrator.cpp:240

◆ LoadFile()

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

Loads the PolynomialCalibrator definition from the specified file.

Reads an XML format for the PolynomialCalibrator. 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 PolynomialCalibrator definition from the specified file.
Definition: polynomial_calibrator.cpp:301

◆ SaveFile()

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

Saves the PolynomialCalibrator definition to the specified file.

Writes an XML format for the PolynomialCalibrator. 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 PolynomialCalibrator definition to the specified file.
Definition: polynomial_calibrator.cpp:336

◆ SetCoefficient()

int32_t trek::PolynomialCalibrator::SetCoefficient ( uint16_t  power,
double  input_value 
)

Sets the coefficient value for the specified term.

Parameters
[in]powerSpecifies the power of the term.
[in]input_valueThe new value for the coefficient
Returns
SUCCESS
TREK_DATA_INVALID_VALUE

Example:

pc.SetOrder( 2 );
// Set coeffiecients for y = 3.1x^2 - 5;
pc.SetCoefficient( 2, 3.1 );
pc.SetCoefficient( 0, -5 );

◆ SetOrder()

int32_t trek::PolynomialCalibrator::SetOrder ( uint16_t  input_value,
bool  keep_coefficients = false 
)

Sets the order for the polynomial calibrator.

If the order is higher than the previous value, memory is destroyed and then recreated.

Parameters
[in]input_valueThe new order number.
[in]keep_coefficientsIf true, current coefficients are kept. Otherwise all coefficients are set to 0.
Returns
SUCCESS
TREK_DATA_INVALID_VALUE

Example:

ret_value = pc.SetOrder( 10 ); // keep_coefficients defaults to false
if( ret_value )
; // process error