-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdynamics.py
More file actions
31 lines (28 loc) · 803 Bytes
/
dynamics.py
File metadata and controls
31 lines (28 loc) · 803 Bytes
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
import theano as th
import theano.tensor as tt
class Dynamics(object):
def __init__(self, nx, nu, f, dt=None):
self.nx = nx
self.nu = nu
self.dt = dt
if dt is None:
self.f = f
else:
self.f = lambda x, u: x+dt*f(x, u)
def __call__(self, x, u):
return self.f(x, u)
class CarDynamics(Dynamics):
def __init__(self, dt=0.1, ub=[(-3., 3.), (-1., 1.)], friction=1.):
def f(x, u):
return tt.stacklists([
x[3]*tt.cos(x[2]),
x[3]*tt.sin(x[2]),
x[3]*u[0],
u[1]-x[3]*friction
])
Dynamics.__init__(self, 4, 2, f, dt)
if __name__ == '__main__':
dyn = CarDynamics(0.1)
x = tt.vector()
u = tt.vector()
dyn(x, u)