diff --git a/simulator.py b/simulator.py index 31f154e..514d89c 100755 --- a/simulator.py +++ b/simulator.py @@ -60,6 +60,7 @@ class Simulator: with socket.SocketIO(self.s, 'r') as buffer: try: time.sleep(1e-5) + self.simulate() req = buffer.readline() self.s.setblocking(True) match req: @@ -77,6 +78,9 @@ class Simulator: except OSError: pass + def simulate(self): + pass + def realize(self): pass @@ -100,13 +104,14 @@ class Douche: self.xs = [] self.ys = [] self.line, = self.ax.plot(self.xs, self.ys)#, color=self.cm) - plt.show() def add_point(self, x, y): + print(x, y) self.xs.append(x) self.ys.append(y) self.line.set_data(self.xs, self.ys) plt.draw() + plt.show() class NaiveSimulator(Simulator, Douche): @@ -115,9 +120,9 @@ class NaiveSimulator(Simulator, Douche): time_step = 0 last_update = 0. - J = [1., 1., 1.] # Moment of inertia vector times 1/R - f = [0., 0., 0.] # viscous friction coefficient - G = [1., 1., 1.] # Motor gain : Gamma = G * delta_w + J = np.array([1., 1., 1.]) # Moment of inertia vector times 1/R + f = np.array([0., 0., 0.]) # viscous friction coefficient + G = np.array([1., 1., 1.]) # Motor gain : Gamma = G * delta_w # FIXME: this is not very realistic, this looks like a model of # an asynchronous motor, not a stepper. @@ -134,9 +139,9 @@ class NaiveSimulator(Simulator, Douche): lt = time.time() self.time_step = lt - self.last_update 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.steps = np.ceil(self.pos * np.array([self.X_STEPS_PER_MM,