You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
3.1 KiB
C++

/*
* RelativeSignal.cpp
*
* Author: Aleksey Gerasimenko
* gerasimenko.aleksey.n@gmail.com
*/
#include "SYSCTRL/SignalRelative.h"
namespace SYSCTRL
{
//CONSTRUCTOR
SignalRelative::SignalRelative():
BaseComponent(),
m_amplitude(FP_ZERO),
m_relative(FP_ZERO),
m_limit_relative_high(FP_ZERO),
m_limit_relative_low(FP_ZERO),
m_minimal_amplitude_level(FP_ZERO),
m_ampl_filter(),
_execute(&SYSCTRL::SignalRelative::_execute_undef)
{}//CONSTRUCTOR
//
void SignalRelative::setup(const SignalRelativeSetup& setup)
{
static bool status = true;
if(m_mode == SYSCTRL::SignalRelative::UNDEFINED)
{
m_time_sample = setup.time_sample;
m_ampl_filter.setup(m_time_sample);
status &= m_time_sample > FP_ZERO ? true : false;
status &= m_ampl_filter.compare(FLTSYSLIB::AMPL::CONFIGURATE);
if(status)
{
m_mode = SYSCTRL::SignalRelative::CONFIGURATE;
//
}//if
//
}//if
//
}//
//
void SignalRelative::configure(const SignalRelativeConfiguration& config)
{
static bool status = true;
if(m_mode == SYSCTRL::SignalRelative::CONFIGURATE)
{
m_limit_relative_high = config.limit_relative_high;
m_limit_relative_low = config.limit_relative_low;
m_minimal_amplitude_level = config.minimal_amplitude_level;
m_ampl_filter.configure(config.amplitude_filter);
status &= m_limit_relative_high > m_limit_relative_low ? true : false;
status &= m_minimal_amplitude_level > FP_ZERO ? true : false;
status &= m_ampl_filter.compare(FLTSYSLIB::AMPL::OPERATIONAL);
if(status)
{
m_mode = SYSCTRL::SignalRelative::OPERATIONAL;
_execute = &SYSCTRL::SignalRelative::_execute_operational;
//
}//if
//
}//if
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SignalRelative::reset()
{
m_amplitude = FP_ZERO;
m_relative = FP_ZERO;
m_ampl_filter.reset();
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SignalRelative::get_outputs(float& amplitude, float& relative)
{
amplitude = m_amplitude;
relative = m_relative;
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SignalRelative::execute(float reference)
{
(this->*_execute)(reference);
//
}//
//
#pragma CODE_SECTION("ramfuncs");
void SignalRelative::_execute_undef(float reference)
{}//
//
#pragma CODE_SECTION("ramfuncs");
void SignalRelative::_execute_operational(float reference)
{
static float _relative = FP_ZERO;
m_amplitude = m_ampl_filter.execute(reference);
if(m_amplitude > m_minimal_amplitude_level)
{
//
_relative = reference / m_amplitude;
//
if(_relative > m_limit_relative_high)
{
_relative = m_limit_relative_high;
//
}//if
//
if(_relative < m_limit_relative_low)
{
_relative = m_limit_relative_low;
//
}//if
//
}
else
{
_relative = FP_ZERO;
//
}// if else
//
m_relative = _relative;
//
}//
//
} /* namespace SYSCTRL */