Metadata-Version: 2.4
Name: py-feedback-controller
Version: 0.1.2
Summary: A Python package implementing feedback controllers in C++.
Home-page: https://github.com/Patrik-J/PyFC
Author: Patrik Jelic
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-python
Dynamic: summary

# py-feedback-controller

This library implements various feedback controllers in C++ to use in Python. As of latest, the implemented feedback controllers are:
* ordinary PID controller
* auto-optimizing PID controller

## Installation

To install the package, you can either build directly of this repo or use pip:

```bash 
    pip install py-feedback-controller
```

## Usage

While the test folder of this repo has a small test script, a similar example will be shown.

```Python
    from pyfc.pid import AutoOptimizingPID

    from matplotlib.animation import FuncAnimation
    from matplotlib import pyplot as plt
    import numpy as np

    setpoint = 1.0

    pid = AutoOptimizingPID(setpoint=setpoint, lr=1.0)
    pid.init()

    z = [0.0]
    t = [0.0]
    dt = 1e-3

    fig, ax = plt.subplots()  
    line = ax.plot(t, z)[0]
            
    def func(frame):
        global setpoint
        if (frame % 500) == 0:
            if setpoint == 1.0:
                setpoint = 2.0
            elif setpoint == 2.0:
                setpoint = 1.0
                    
        pid.setSetpoint(setpoint)        
        
        pid_out = pid.requestLoop(z[frame-1])
        
        z.append(z[frame-1] + dt * pid_out)
        t.append(t[frame-1] + dt)

        line.set_xdata(t)
        line.set_ydata(z)
        ax.set_ylim(-0.1, 1.2*np.max(z))
        ax.set_xlim(0, 1.2*np.max(t))
        
    anim = FuncAnimation(fig, func, frames=10000, interval=1)
    plt.grid()
    plt.show()
```
