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

This class calibrates a value using a series of line segments. More...

#include <spline_calibrator.h>

Inherits trek::Calibrator.

Public Member Functions

int32_t LoadFile (const char *filename)
 Loads the SplineCalibrator definition from the specified file. More...
 
int32_t SaveFile (const char *filename)
 Saves the SplineCalibrator definition to the specified file. More...
 
Constructors, Destructor, and Other Basic Methods
 SplineCalibrator ()
 Default constructor of the class.
 
 SplineCalibrator (SplineCalibrator &input)
 Copy constructor of the class.
 
virtual ~SplineCalibrator ()
 Class destructor. More...
 
void operator= (SplineCalibrator &right_side)
 Provides the equal operator.
 
virtual CalibratorClone ()
 Creates and returns an extact copy of the object.
 
virtual void Init ()
 Initializes the object.
 
Calibration Methods
int32_t AddPoint (double converted_value, double calibrated_value)
 Adds a point to the calibrator. More...
 
void ClearAllPoints ()
 Removes all points defining the line segments.
 
int32_t Calibrate (double input_value, double &output_value)
 Performs the calibration on the input value. More...
 
uint32_t GetNumberOfPoints ()
 Returns the number of points in the calibrator. More...
 
void GetPoints (double **conv_values, double **cal_values, uint32_t &num_values)
 Gets all of the points for the calibrator. More...
 
int32_t GetPoints (double *conv_values, double *cal_values)
 Gets all of the points 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...
 
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 series of line segments.

The number of line segments allowed is unbouded.

Constructor & Destructor Documentation

◆ ~SplineCalibrator()

trek::SplineCalibrator::~SplineCalibrator ( )
virtual

Class destructor.

Removes all resources created with this instance of the class.

Member Function Documentation

◆ AddPoint()

int32_t trek::SplineCalibrator::AddPoint ( double  converted_value,
double  calibrated_value 
)

Adds a point to the calibrator.

Line segments are calculated automatically by the class.

Parameters
[in]converted_valueConverted value.
[in]calibrated_valueCorresponding calibrated value.
Returns
SUCCESS
TREK_DATA_ALREADY_EXISTS

Example:

if( sc.AddPoint( 0, 10.0 ) )
{
// point not added. it probably already existed.
}
sc.AddPoint( 10, 100.0 );
sc.AddPoint( 100, 200.0 );
This class calibrates a value using a series of line segments.
Definition: spline_calibrator.h:16
int32_t AddPoint(double converted_value, double calibrated_value)
Adds a point to the calibrator.
Definition: spline_calibrator.cpp:109

◆ Calibrate()

int32_t trek::SplineCalibrator::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
TREK_DATA_CALIBRATION_ERROR

Example:

sc.AddPoint( 0, 10.0 );
sc.AddPoint( 10, 100.0 );
sc.AddPoint( 100, 200.0 );
double value;
if( sc.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: spline_calibrator.cpp:173

Implements trek::Calibrator.

◆ GetNumberOfPoints()

uint32_t trek::SplineCalibrator::GetNumberOfPoints ( )

Returns the number of points in the calibrator.

Returns
number of points Example:
if( sc.AddPoint( 0, 10.0 ) )
{
// point not added. it probably already existed.
}
sc.AddPoint( 10, 100.0 );
sc.AddPoint( 100, 200.0 );
// it better be 3
printf( "Number of points: %u\n", sc.GetNumberOfPoints );
uint32_t GetNumberOfPoints()
Returns the number of points in the calibrator.
Definition: spline_calibrator.cpp:218

◆ GetPoints() [1/2]

void trek::SplineCalibrator::GetPoints ( double **  conv_values,
double **  cal_values,
uint32_t &  num_values 
)

Gets all of the points for the calibrator.

Returns the number of points and the converted and calibrated value for each point. Memory is created by this function when the number of values returned is non-zero. It is the responsibility of the caller to delete the associated memory.

Parameters
[out]conv_valuesConverted value array. Valid if num_values > 0.
[out]cal_valuesCorresponding calibrated value. Valid if num_values > 0.
[out]num_valuesNumber of value pairs returned.

Example:

if( sc.AddPoint( 0, 10.0 ) )
{
// point not added. it probably already existed.
}
sc.AddPoint( 10, 100.0 );
sc.AddPoint( 100, 200.0 );
double *conv, *cal;
uint32_t num_points;
sc.GetPoints( &conv, &cal, num_points );
for( uint32_t ii = 0; ii < num_points; ii++ )
printf( "Point (%lf,%lf)\n", conv[ii], cal[ii] );
if( num_points )
{
delete conv;
delete cal;
}
void GetPoints(double **conv_values, double **cal_values, uint32_t &num_values)
Gets all of the points for the calibrator.
Definition: spline_calibrator.cpp:261

◆ GetPoints() [2/2]

int32_t trek::SplineCalibrator::GetPoints ( double *  conv_values,
double *  cal_values 
)

Gets all of the points for the calibrator.

Populates the user allocated arrays with the the points of the spline calibrator. The user of the function should call GetNumberOfPoints() to determine how much memory to allocate.

Parameters
[out]conv_valuesConverted value array.
[out]cal_valuesCorresponding calibrated value.
Returns
SUCCESS
TREK_DATA_NULL_PTR

Example:

if( sc.AddPoint( 0, 10.0 ) )
{
// point not added. it probably already existed.
}
sc.AddPoint( 10, 100.0 );
sc.AddPoint( 100, 200.0 );
uint32_t num_values = sc.GetNumberOfPoints();
double *conv_values = new double[num_values];
double *cal_values = new double[num_values];
sc.GetPoints(conv_values, cal_values);

◆ LoadFile()

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

Loads the SplineCalibrator definition from the specified file.

Reads an XML format for the SplineCalibrator. 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 = sc.LoadFile( "my_file.xml" );
int32_t LoadFile(const char *filename)
Loads the SplineCalibrator definition from the specified file.
Definition: spline_calibrator.cpp:343

◆ SaveFile()

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

Saves the SplineCalibrator definition to the specified file.

Writes an XML format for the SplineCalibrator. 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 = sc.SaveFile( "my_file.xml" );
int32_t SaveFile(const char *filename)
Saves the SplineCalibrator definition to the specified file.
Definition: spline_calibrator.cpp:378