-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisturbance.py
More file actions
70 lines (53 loc) · 2.12 KB
/
Disturbance.py
File metadata and controls
70 lines (53 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import abc
import numpy as np
class Disturbance(object):
"""Base class for arbitrary disturbance"""
def __init__(self):
self.idx_lookup = {'p': 0, 'e': 1, "lambda": 2, 'f': 3, 'b': 4}
@abc.abstractmethod
def eval(self, t):
""":return ndarray (with 5 elements) describing the disturbance at t for p, e, d, f and b"""
return
class DisturbanceStep(Disturbance):
"""Heaviside step"""
def __init__(self, t_start, z0, zf, point_of_application):
super().__init__()
self.t_start = t_start
self.z0 = z0
self.zf = zf
self.point_of_application = point_of_application
def eval(self, t):
ret = np.zeros(5)
ret[self.idx_lookup[self.point_of_application]] = self.z0 + self.zf * np.heaviside(t - self.t_start, 0.5)
return ret
class DisturbanceSinus(Disturbance):
"""Heaviside step"""
def __init__(self, t_start, z_offset, z_amplitude, z_frequency, point_of_application):
super().__init__()
self.t_start = t_start
self.z_offset = z_offset
self.z_amplitude = z_amplitude
self.z_frequency = z_frequency
self.point_of_application = point_of_application
def eval(self, t):
ret = np.zeros(5)
ret[self.idx_lookup[self.point_of_application]] = (np.heaviside(t - self.t_start, 0.5) * (self.z_offset +
self.z_amplitude * np.sin(2*np.pi*self.z_frequency * t)))
return ret
class DisturbanceRect(Disturbance):
"""Impulse with specific length and height"""
def __init__(self, t_start, t_length, zf, point_of_application):
super().__init__()
self.t_start = t_start
self.t_length = t_length
self.zf = zf
self.point_of_application = point_of_application
def eval(self, t):
ret = np.zeros(5)
ret[self.idx_lookup[self.point_of_application]] = self.zf if self.t_start <= t < self.t_start + self.t_length else 0
return ret
class NoDisturbance(Disturbance):
def __init__(self):
super().__init__()
def eval(self, t):
return np.zeros(5)