a

Dependencies:   mbed mbed-rtos

Committer:
alexpirciu
Date:
Thu Mar 28 07:44:42 2019 +0000
Revision:
1:ceee5a608e7c
assa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alexpirciu 1:ceee5a608e7c 1
alexpirciu 1:ceee5a608e7c 2
alexpirciu 1:ceee5a608e7c 3 /**
alexpirciu 1:ceee5a608e7c 4 * @brief Construct a new CConverterPolynom<NOrd>::CConverterPolynom object
alexpirciu 1:ceee5a608e7c 5 *
alexpirciu 1:ceee5a608e7c 6 * @param f_coeff The list of the coeffience.
alexpirciu 1:ceee5a608e7c 7 */
alexpirciu 1:ceee5a608e7c 8 template<uint8_t NOrd>
alexpirciu 1:ceee5a608e7c 9 CConverterPolynom<NOrd>::CConverterPolynom(std::array<float,NOrd+1> f_coeff)
alexpirciu 1:ceee5a608e7c 10 :m_coeff(f_coeff)
alexpirciu 1:ceee5a608e7c 11 {
alexpirciu 1:ceee5a608e7c 12 }
alexpirciu 1:ceee5a608e7c 13
alexpirciu 1:ceee5a608e7c 14
alexpirciu 1:ceee5a608e7c 15 /**
alexpirciu 1:ceee5a608e7c 16 * @brief Convert the input value.
alexpirciu 1:ceee5a608e7c 17 *
alexpirciu 1:ceee5a608e7c 18 */
alexpirciu 1:ceee5a608e7c 19 template<uint8_t NOrd>
alexpirciu 1:ceee5a608e7c 20 float CConverterPolynom<NOrd>::operator()(float f_v){
alexpirciu 1:ceee5a608e7c 21 float l_res = m_coeff[NOrd];
alexpirciu 1:ceee5a608e7c 22 for (uint8_t i = 0;i<NOrd;++i){
alexpirciu 1:ceee5a608e7c 23 l_res += std::pow(f_v, NOrd-i)*m_coeff[i];
alexpirciu 1:ceee5a608e7c 24 }
alexpirciu 1:ceee5a608e7c 25 return l_res;
alexpirciu 1:ceee5a608e7c 26 }
alexpirciu 1:ceee5a608e7c 27
alexpirciu 1:ceee5a608e7c 28
alexpirciu 1:ceee5a608e7c 29 /**
alexpirciu 1:ceee5a608e7c 30 * @brief Construct a new CConverterSpline<NrBreak, NOrd>::CConverterSpline object
alexpirciu 1:ceee5a608e7c 31 *
alexpirciu 1:ceee5a608e7c 32 * @tparam NrBreak
alexpirciu 1:ceee5a608e7c 33 * @tparam NOrd
alexpirciu 1:ceee5a608e7c 34 * @param f_breaks The list of the break points.
alexpirciu 1:ceee5a608e7c 35 * @param f_splines The list of the polynomial function.
alexpirciu 1:ceee5a608e7c 36 */
alexpirciu 1:ceee5a608e7c 37 template <uint8_t NrBreak, uint8_t NOrd>
alexpirciu 1:ceee5a608e7c 38 CConverterSpline<NrBreak, NOrd>::CConverterSpline(CConverterSpline<NrBreak, NOrd>::CBreakContainerType f_breaks,CConverterSpline<NrBreak, NOrd>::CSplineContainerType f_splines)
alexpirciu 1:ceee5a608e7c 39 :m_breaks(f_breaks)
alexpirciu 1:ceee5a608e7c 40 ,m_splines(f_splines)
alexpirciu 1:ceee5a608e7c 41 {
alexpirciu 1:ceee5a608e7c 42 }
alexpirciu 1:ceee5a608e7c 43
alexpirciu 1:ceee5a608e7c 44 /**
alexpirciu 1:ceee5a608e7c 45 * @brief Convert the input value.
alexpirciu 1:ceee5a608e7c 46 *
alexpirciu 1:ceee5a608e7c 47 */
alexpirciu 1:ceee5a608e7c 48 template <uint8_t NrBreak, uint8_t NOrd>
alexpirciu 1:ceee5a608e7c 49 float CConverterSpline<NrBreak, NOrd>::operator()(float f_value){
alexpirciu 1:ceee5a608e7c 50 typename CConverterSpline<NrBreak, NOrd>::CBreakContainerType::iterator it_breaks0=NULL,it_breaks1=NULL;
alexpirciu 1:ceee5a608e7c 51 typename CConverterSpline<NrBreak, NOrd>::CSplineContainerType::iterator it_spline = m_splines.begin();
alexpirciu 1:ceee5a608e7c 52 for (it_breaks1 = m_breaks.begin();it_breaks1 != m_breaks.end();){
alexpirciu 1:ceee5a608e7c 53 if((it_breaks0==NULL || (it_breaks0!=NULL && (*it_breaks0)<f_value)) && f_value<=(*it_breaks1)){
alexpirciu 1:ceee5a608e7c 54 break;
alexpirciu 1:ceee5a608e7c 55 }
alexpirciu 1:ceee5a608e7c 56 it_breaks0 = it_breaks1;
alexpirciu 1:ceee5a608e7c 57 ++it_breaks1;
alexpirciu 1:ceee5a608e7c 58 ++it_spline;
alexpirciu 1:ceee5a608e7c 59 }
alexpirciu 1:ceee5a608e7c 60 return this->splineValue(*it_spline, f_value);
alexpirciu 1:ceee5a608e7c 61 }
alexpirciu 1:ceee5a608e7c 62
alexpirciu 1:ceee5a608e7c 63 /**
alexpirciu 1:ceee5a608e7c 64 * @brief Convert the given value, by using the given polynom.
alexpirciu 1:ceee5a608e7c 65 *
alexpirciu 1:ceee5a608e7c 66 * @param f_coeff The coeffiences of the polynom
alexpirciu 1:ceee5a608e7c 67 * @param f_value The input value.
alexpirciu 1:ceee5a608e7c 68 */
alexpirciu 1:ceee5a608e7c 69 template <uint8_t NrBreak, uint8_t NOrd>
alexpirciu 1:ceee5a608e7c 70 float CConverterSpline<NrBreak, NOrd>::splineValue( CCoeffContainerType f_coeff,float f_value){
alexpirciu 1:ceee5a608e7c 71 float l_res = f_coeff[NOrd];
alexpirciu 1:ceee5a608e7c 72 for (uint8_t i = 0;i<NOrd;++i)
alexpirciu 1:ceee5a608e7c 73 {
alexpirciu 1:ceee5a608e7c 74 l_res+=std::pow(f_value,NOrd-i)*f_coeff[i];
alexpirciu 1:ceee5a608e7c 75 }
alexpirciu 1:ceee5a608e7c 76 return l_res;
alexpirciu 1:ceee5a608e7c 77 }