Takahiro Tanaka / Mbed 2 deprecated mbed_effector

Dependencies:   C12832 mbed

Clipper.h

Committer:
vaifreak
Date:
2015-09-04
Revision:
2:25adc1277b3e
Parent:
1:bfbfd6fede05
Child:
3:1666e2d5bd46

File content as of revision 2:25adc1277b3e:

//=============================================================================
//  @author vaifreak
//  @brief  clipper sub unit ( for Drive )
//=============================================================================
#pragma once

//---------------------------------------------
// Clipper, Base class.
//---------------------------------------------
class ClipperBase
{
public:
    virtual float Process( float samp ) = 0;
};

//---------------------------------------------
// Simple clipper.
//---------------------------------------------
class SimpleClipper : public ClipperBase
{
private:
    float clip;

public:
    SimpleClipper( float c = 0.5f )
    {
        clip = c;
    }
    virtual float Process( float samp )
    {
        if( samp > clip ) {
            return clip;
        } else {
            return samp;
        }
    }
};

//---------------------------------------------
// Simple clipper.
//---------------------------------------------
class SoftClipper : public ClipperBase
{
private:
    float clip;
    float comp_k;

public:
    SoftClipper( float c = 0.5f, float k = 0.01f )
    {
        clip = c;
        comp_k = k;
    }
  
    virtual float Process( float samp )
    {
        if( samp > clip ) {
            return clip + (samp-clip)*comp_k;
        } else {
            return samp;
        }
    }
};