-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdynamics.py
34 lines (31 loc) · 955 Bytes
/
dynamics.py
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
import jax.numpy as np
class SingleIntegrator(object):
def __init__(self, N) -> None: # N = the number of drones
self.dt = 1 # timestep
self.n = 2 # dimensionality of the states (x, y, z) would be 3
self.m = 2 # dimensionality of the controls (vx, vy, vz) would be 3
self.N = N
B = np.array([
[1.,0.],
[0.,1.],
])
def _f(x, u):
return x + self.dt*B@u
def f(x1, u1):
# assumes x1 a Nxn, u1 a Nxm dim
x2 = []
for i in range(self.N):
x2.append(_f(x1[i,:], u1[i,:]))
return np.stack(x2)
self._f = _f
self.f = f
def _f_test(x, u):
dt = 1
B = np.array([[1.,0.],
[0.,1.]],)
return x + dt*B@u
def f_test(x, u, N):
x2 = []
for i in range(N):
x2.append(_f_test(x[i,:], u[i,:]))
return np.stack(x2)