Skip to content

Commit 22a5af1

Browse files
committed
update readme; add example usage
1 parent 231d8dd commit 22a5af1

File tree

8 files changed

+45
-11
lines changed

8 files changed

+45
-11
lines changed

README.md

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PythonVRFT Library - Version 0.0.5
1+
# PythonVRFT Library - Version 0.0.6
22
VRFT Adaptive Control Library written in Python. Aim of this library is to provide an implementation of the VRFT (Virtual Reference Feedback Tuning) algorithm.
33

44
You can find the package also at the following [link](https://pypi.org/project/pythonvrft/)
@@ -22,10 +22,44 @@ Other dependencies:
2222
- Install from source: git clone this repo and from the root folder execute the command ```pip install .```
2323

2424
## Usage/Examples
25-
You can import the library by typing ```import vrft``` in your code.
25+
You can import the library by typing ```python import vrft``` in your code.
26+
2627
To learn how to use the library, check the examples located in the examples/ folder. At the moment there are examples available.
2728
Check example3 to see usage of instrumental variables.
2829

30+
In general the code has the following structure
31+
```python
32+
from vrft import ExtendedTF # Discrete transfer function (inherits from the scipy.signal.dlti class)
33+
from vrft import iddata # object used to store input/output data
34+
from vrft import compute_vrft # VRFT algorithm
35+
36+
# Parameters
37+
dt = 0.1 # sampling time
38+
39+
# Define a reference model
40+
ref_model = ExtendedTF([0.6], [1, -0.4], dt=t_step) # 0.6/ (z-0.4)
41+
42+
# Define pre-filter
43+
pre_filter = (1 - ref_model) * ref_model
44+
45+
# Define control base (PI control)
46+
control = [ExtendedTF([1], [1, -1], dt=t_step), # 1/(z-1)
47+
ExtendedTF([1, 0], [1, -1], dt=t_step)] # z/(z-1)
48+
49+
# Generate input/output data from a system
50+
u = .... # Generate input
51+
y = .... # measured output
52+
53+
# Create an iddata object
54+
y0 = ... # initial conditions of the system (the length depends on the order of the reference model)
55+
data = iddata(y, u, dt, y0)
56+
57+
# Compute VRFT
58+
# theta is the vector of parameters that parametrizes the control base
59+
# C is the final controller (computed as control.dot(theta))
60+
theta, _, _, C = compute_vrft(data, ref_model, control, pre_filter)
61+
```
62+
2963
## Tests
3064
To execute tests run the following command
3165
```sh

examples/example1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# along with PythonVRFT. If not, see <http://www.gnu.org/licenses/>.
1212
#
1313
# Code author: [Alessio Russo - alessior@kth.se]
14-
# Last update: 06th January 2020, by alessior@kth.se
14+
# Last update: 08th January 2020, by alessior@kth.se
1515
#
1616

1717
import numpy as np
@@ -75,7 +75,7 @@
7575
ys = np.array(ys).flatten()
7676
yc = np.array(yc).flatten()
7777
fig, ax = plt.subplots(4, sharex=True, figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')
78-
ax[0].plot(t, yr,label='Ref System')
78+
ax[0].plot(t, yr,label='Reference System')
7979
ax[0].plot(t, yc, label='CL System')
8080
ax[0].set_title('Systems response')
8181
ax[0].grid(True)

examples/example2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def generateNoise(t):
8484
ys = np.array(ys).flatten()
8585
yc = np.array(yc).flatten()
8686
fig, ax = plt.subplots(4, sharex=True, figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')
87-
ax[0].plot(t, yr,label='Ref System')
87+
ax[0].plot(t, yr,label='Reference System')
8888
ax[0].plot(t, yc, label='CL System')
8989
ax[0].set_title('Systems response')
9090
ax[0].grid(True)

examples/example3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
t_start = 0
3131
t_end = 10
3232
dt = 1e-2
33-
t = np.array([i * dt for i in range(int(t_end/dt ))])
33+
t = np.array([i * dt for i in range(int(t_end/dt))])
3434

3535
#Experiment
3636
num = [0.5]
@@ -88,7 +88,7 @@ def generate_data(sys, u, t):
8888
yc_iv = yc_iv.flatten()
8989

9090
fig, ax = plt.subplots(4, sharex=True, figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')
91-
ax[0].plot(t, yr,label='Ref System')
91+
ax[0].plot(t, yr,label='Reference System')
9292
ax[0].plot(t, yc_iv, label='CL System - IV')
9393
ax[0].plot(t, yc_noiv, label='CL System - No IV')
9494
ax[0].set_title('CL Systems response')

examples/notebook_example_1.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
"ys = np.array(ys).flatten()\n",
189189
"yc = np.array(yc).flatten()\n",
190190
"fig, ax = plt.subplots(4, sharex=True, figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')\n",
191-
"ax[0].plot(t, yr,label='Ref System')\n",
191+
"ax[0].plot(t, yr,label='Reference System')\n",
192192
"ax[0].plot(t, yc, label='CL System')\n",
193193
"ax[0].set_title('Systems response')\n",
194194
"ax[0].grid(True)\n",

examples/notebook_example_2.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
"ys = np.array(ys).flatten()\n",
198198
"yc = np.array(yc).flatten()\n",
199199
"fig, ax = plt.subplots(4, sharex=True, figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')\n",
200-
"ax[0].plot(t, yr,label='Ref System')\n",
200+
"ax[0].plot(t, yr,label='Reference System')\n",
201201
"ax[0].plot(t, yc, label='CL System')\n",
202202
"ax[0].set_title('Systems response')\n",
203203
"ax[0].grid(True)\n",

examples/notebook_example_3.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
"yc_iv = yc_iv.flatten()\n",
213213
"\n",
214214
"fig, ax = plt.subplots(4, sharex=True, figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')\n",
215-
"ax[0].plot(t, yr,label='Ref System')\n",
215+
"ax[0].plot(t, yr,label='Reference System')\n",
216216
"ax[0].plot(t, yc_iv, label='CL System - IV')\n",
217217
"ax[0].plot(t, yc_noiv, label='CL System - No IV')\n",
218218
"ax[0].set_title('CL Systems response')\n",

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
setup(name = 'pythonvrft',
9-
version = '0.0.5',
9+
version = '0.0.6',
1010
description = 'VRFT Python Library',
1111
long_description = long_description,
1212
long_description_content_type = 'text/markdown',

0 commit comments

Comments
 (0)