Skip to content

adding a filter to derivative term #44

@CamDavidsonPilon

Description

@CamDavidsonPilon

👋 what are your thoughts on allowing users to add a hook into the class to add a filter infront of the derivative term. I've read in a few places that adding a filter infront of the derivative term is a good idea (i.e. instead of passing the raw input_ to d_input, we pass in some filtered version).

High level:

def my_filter(input_, previous_input_):
   # compute things    
   return some_float

pid = PID(...)
pid.add_derivative_hook(my_filter)

low level:

   
   def _compute_derivative(self, input, last_input):
       return input - (last_input if (last_input is not None) else input)

   def add_derivative_hook(self, callable):
       self._compute_derivative = callable

   def __call__(...):
        ...
        # Compute error terms
        error = self.setpoint - input_
        d_input = self._compute_derivative(input, self._last_input)
       ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions