<commit_before><commit_msg>Added controllers.py to epc, currently only has PID control<commit_after>
##
# Classic PID controller with maximum integral thresholding to
# prevent windup.
class PIDController(object):
    def __init__(self, k_p, k_i, k_d, i_max, rate, name=None):
        self.k_p = k_p
        self.k_i = k_i
        self.k_d = k_d
        self.i_max = i_max
        self.rate = rate
        self.err_last = 0
        self.integral = 0
        if name is not None:
            self.err_pub = rospy.Publisher("/pid_controller/" + name + "_error", Float64)
            self.out_pub = rospy.Publisher("/pid_controller/" + name + "_output", Float64)

    ##
    # Updates the controller state and returns the current output.
    def update_state(self, err):
        self.integral += err / self.rate
        self.integral = np.clip(self.integral, -self.i_max, self.i_max)
        y = (self.k_p * err + 
             self.k_d * (err - self.err_last) * self.rate +
             self.k_i * self.integral)
        self.err_last = err
        self.err_pub.publish(err)
        self.out_pub.publish(y)
        return y

    def reset_controller(self):
        self.err_last = 0
        self.integral = 0
{'fraction_non_alphanumeric': 0.10613598673300166, 'fraction_numerical': 0.006633499170812604, 'mean_word_length': 2.1763157894736844, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3407724', 'n_tokens_mistral': 411, 'n_tokens_neox': 390, 'n_words': 98}