Make physics actually run
There is still a weird jump at t=0 though
This commit is contained in:
parent
59636d22cd
commit
263565c98f
1 changed files with 11 additions and 6 deletions
17
simulator.py
17
simulator.py
|
@ -60,6 +60,7 @@ class Simulator:
|
||||||
with socket.SocketIO(self.s, 'r') as buffer:
|
with socket.SocketIO(self.s, 'r') as buffer:
|
||||||
try:
|
try:
|
||||||
time.sleep(1e-5)
|
time.sleep(1e-5)
|
||||||
|
self.simulate()
|
||||||
req = buffer.readline()
|
req = buffer.readline()
|
||||||
self.s.setblocking(True)
|
self.s.setblocking(True)
|
||||||
match req:
|
match req:
|
||||||
|
@ -77,6 +78,9 @@ class Simulator:
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def simulate(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def realize(self):
|
def realize(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -100,13 +104,14 @@ class Douche:
|
||||||
self.xs = []
|
self.xs = []
|
||||||
self.ys = []
|
self.ys = []
|
||||||
self.line, = self.ax.plot(self.xs, self.ys)#, color=self.cm)
|
self.line, = self.ax.plot(self.xs, self.ys)#, color=self.cm)
|
||||||
plt.show()
|
|
||||||
|
|
||||||
def add_point(self, x, y):
|
def add_point(self, x, y):
|
||||||
|
print(x, y)
|
||||||
self.xs.append(x)
|
self.xs.append(x)
|
||||||
self.ys.append(y)
|
self.ys.append(y)
|
||||||
self.line.set_data(self.xs, self.ys)
|
self.line.set_data(self.xs, self.ys)
|
||||||
plt.draw()
|
plt.draw()
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
class NaiveSimulator(Simulator, Douche):
|
class NaiveSimulator(Simulator, Douche):
|
||||||
|
@ -115,9 +120,9 @@ class NaiveSimulator(Simulator, Douche):
|
||||||
time_step = 0
|
time_step = 0
|
||||||
last_update = 0.
|
last_update = 0.
|
||||||
|
|
||||||
J = [1., 1., 1.] # Moment of inertia vector times 1/R
|
J = np.array([1., 1., 1.]) # Moment of inertia vector times 1/R
|
||||||
f = [0., 0., 0.] # viscous friction coefficient
|
f = np.array([0., 0., 0.]) # viscous friction coefficient
|
||||||
G = [1., 1., 1.] # Motor gain : Gamma = G * delta_w
|
G = np.array([1., 1., 1.]) # Motor gain : Gamma = G * delta_w
|
||||||
# FIXME: this is not very realistic, this looks like a model of
|
# FIXME: this is not very realistic, this looks like a model of
|
||||||
# an asynchronous motor, not a stepper.
|
# an asynchronous motor, not a stepper.
|
||||||
|
|
||||||
|
@ -134,9 +139,9 @@ class NaiveSimulator(Simulator, Douche):
|
||||||
lt = time.time()
|
lt = time.time()
|
||||||
self.time_step = lt - self.last_update
|
self.time_step = lt - self.last_update
|
||||||
self.last_update = lt
|
self.last_update = lt
|
||||||
gamma = G*(command_spd - spd)
|
gamma = self.G*(self.command_spd - self.speed)
|
||||||
|
|
||||||
self.speed += 1./J * (G - f*self.speed ) * self.time_step
|
self.speed += 1./self.J * (self.G - self.f*self.speed ) * self.time_step
|
||||||
self.pos += self.speed * self.time_step
|
self.pos += self.speed * self.time_step
|
||||||
|
|
||||||
self.steps = np.ceil(self.pos * np.array([self.X_STEPS_PER_MM,
|
self.steps = np.ceil(self.pos * np.array([self.X_STEPS_PER_MM,
|
||||||
|
|
Loading…
Reference in a new issue