Commit 5cb3efd5 authored by Lorenz Halt's avatar Lorenz Halt 🔀
Browse files

Commenting sandbox notebook

parent ed3470fa
%% Cell type:code id: tags:
``` python
import numpy as np
import ilc_lib
import os
from ilc_lib import cos_traj,e_traj
```
%% Cell type:code id: tags:
``` python
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
```
%% Cell type:code id: tags:
``` python
## Parameter Definitions ##
ws_path = "/home/ipa325/logs"
error_path = ws_path + "/logger_0.csv"
ff_path = ws_path + "/lin_ff_2.txt"
traj_path = ws_path + "/server/trajectory.txt"
out_path = ws_path + "/lin_ff_out.txt"
traj_type = "cos"
L = 2.0
cutoff_freq = 0.5
T = 8 #ms
```
%% Cell type:code id: tags:
``` python
## Test Reading of csv error-file ##
data_org, header = ilc_lib.read(error_path)
#remove first row with negative tick
#data = data[1:]
#plt.plot(data[:,0], data[:,1])
#plt.plot(data[:,0], data[:,2])
plt.plot(data_org[:,0], data_org[:,3], '.-')
```
%% Cell type:code id: tags:
``` python
## Test resampling error-file to T-th timesteps
data = ilc_lib.resample(data_org, T)
plt.plot(data[:,0], data[:,3], '-o')
plt.plot(data_org[:,0], data_org[:,3], 'x')
```
%% Cell type:code id: tags:
``` python
## Test setpoint-trajectory generation ##
trajectory = ilc_lib.traj_handle(data, "cos", decay_time=None)
#print(trajectory)
#plt.plot(trajectory[:,0], trajectory[:,1])
#plt.plot(trajectory[:,0], trajectory[:,2])
plt.plot(trajectory[:,0], trajectory[:,3], '-o')
```
%% Cell type:code id: tags:
``` python
plt.plot(data[:,0], data[:,3])
plt.plot(trajectory[:,0], trajectory[:,3])
## Test time series combination functions ##
plt.plot(data[:,0], data[:,3], label="error")
plt.plot(trajectory[:,0], trajectory[:,3], label="trajectory")
plt.legend()
plt.show()
## Test difference (error to desired trajectory) ##
data_diff = ilc_lib.combine_data(data, trajectory, "diff")
plt.plot(data_diff[:,0], data_diff[:,3], label='diff')
## Test addition (update ilc feedforward with last feedfoward) ##
data_sum = ilc_lib.combine_data(data, trajectory, "sum")
plt.plot(data_sum[:,0], data_sum[:,3], label='sum')
plt.legend()
```
%% Cell type:code id: tags:
``` python
## Test multiplication (ilc calculation) with factor and vector ##
test = data[:,0:2]
test[:,1] = np.arange(0, data[-1,0]+1, T) / (data[-1,0]+1) * L
test[:,1] = np.arange(0, data[-1,0]+1, T) / (data[-1,0]+1) * L # linear vanishing factor vector
#plt.plot(test[:,0], test[:,1])
#plt.show()
data_ff = ilc_lib.ilc_calculations(data_diff, L)
data_ff_vec = ilc_lib.ilc_calculations(data_diff[:,0:2], test)
plt.plot(data_diff[:,0], data_diff[:,1], label='diff')
plt.plot(data_ff[:,0], data_ff[:,1], label="np.mult(L)")
plt.plot(data_ff_vec[:,0], data_ff_vec[:,1], label="np.mult(vec)")
plt.legend()
```
%% Cell type:code id: tags:
``` python
## Test updateing ilc feedforward (sum) ##
old_ff = ilc_lib.ilc_calculations(data_diff, 5)
ilc_data = ilc_lib.combine_data(data_ff, data_ff, "sum")
ilc_data = ilc_lib.combine_data(data_ff, old_ff, "sum")
plt.plot(data_ff[:,0], data_ff[:,3], label="last_ff")
plt.plot(old_ff[:,0], old_ff[:,3], label="last_ff")
plt.plot(data_ff[:,0], data_ff[:,3], label="data_ff")
plt.plot(ilc_data[:,0], ilc_data[:,3], label="addition")
plt.legend()
```
%% Cell type:code id: tags:
``` python
def pad_data(a, b, val=0):
print a.shape[0]
print b.shape[0]
if a.shape[0] > b.shape[0]:
b = np.pad(b, [(0, a.shape[0]-b.shape[0]), (0, 0)], mode='constant', constant_values=val)
b[:,0] = a[:,0] # restore timestamp
elif b.shape[0] > a.shape[0]:
a = np.pad(a, [(0, b.shape[0]-a.shape[0]), (0, 0)], mode='constant', constant_values=val)
a[:,0] = b[:,0] # restore timestamp
return a, b
```
%% Cell type:code id: tags:
## Test updating including padding if file is too short ##
``` python
old_ff, _ = ilc_lib.read(ff_path)
try:
ilc_data = ilc_lib.combine_data(data_ff, old_ff, "sum")
except:
data_ff, old_ff = ilc_lib.pad_data(data_ff, old_ff)
ilc_data = ilc_lib.combine_data(data_ff, old_ff, "sum")
plt.plot(old_ff[:,0], old_ff[:,3], label="last_ff")
plt.plot(data_ff[:,0], data_ff[:,3], label="data_ff")
plt.plot(ilc_data[:,0], ilc_data[:,3], label="addition")
plt.legend()
```
%% Cell type:code id: tags:
``` python
## Test butterworth Q-Filter ##
plt.plot(ilc_data[:,0], ilc_data[:,3], label="ilc_data")
ilc_data_t = ilc_lib.butter_lowpass_filter(ilc_data, cutoff_freq, 1/(T*0.001), 5)
plt.plot(ilc_data_t[:,0], ilc_data_t[:,3], label="ilc_data_t")
plt.legend()
```
%% Cell type:code id: tags:
``` python
## Test writing of result csv ##
ilc_lib.write(out_path, ilc_data_t, header)
data_new, header = ilc_lib.read(out_path)
plt.plot(ilc_data_t[:,0], ilc_data_t[:,3], 'x')
plt.plot(data_new[:,0], data_new[:,3], '-')
```
%% Cell type:code id: tags:
``` python
## Test debug output storage ##
ilc_lib.external_data_store(ws_path + "/read_error", "read_error.csv", data, header)
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment