<commit_before><commit_msg>PID v2<commit_after>#ifndef __PID_v2__
#define __PID_v2__

namespace algorithm
{
    #define PIDMODE 1
    #define PIMODE  2
    #define PDMODE  3
    #define PMODE   4

    template< typename Type, class Process >
    struct PID
    {
    private:
        float factor[3];
        Type pre_i;
        Type pre_d;
        Type setpoint;
        Type output;
        Process f;

    public:
        PID(float Kp, float Ki, float Kd) : factor{Kp,Ki,Kd}, pre_i(), pre_d(), output() { }

        Type p(const Type& err)
        {
            return factor[0] * err;
        }

        Type i(const Type& err)
        {
            pre_i += err;
            return factor[1] * pre_i;
        }

        Type d(const Type& err)
        {
            return factor[2] * (err - pre_d);
        }

        Type calculate(const Type& in, int mode)
        {
            Type err = setpoint - in;
            switch (mode)
            {
                case PIDMODE:
                    output = f.process(p(err) + i(err) + d(err));
                    break;
                case PIMODE:
                    output = f.process(p(err) + i(err));
                    break;
                case PDMODE:
                    output = f.process(p(err) + d(err));
                    break;
                case PMODE:
                    output = f.process(p(err));
                    break;
            }
            return output;
        }
    };
}

#endif
{'fraction_non_alphanumeric': 0.09918478260869565, 'fraction_numerical': 0.007472826086956522, 'mean_word_length': 1.1409883720930232, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2183371', 'n_tokens_mistral': 460, 'n_tokens_neox': 434, 'n_words': 113}