More physics
This commit is contained in:
parent
0805b54e31
commit
b43c0b64c3
3 changed files with 25293 additions and 10 deletions
12
shell.nix
Normal file
12
shell.nix
Normal file
|
@ -0,0 +1,12 @@
|
|||
let
|
||||
pkgs = import <nixpkgs> {};
|
||||
in
|
||||
pkgs.mkShell {
|
||||
packages = [
|
||||
(pkgs.python3.withPackages (ps : [
|
||||
ps.numpy
|
||||
ps.pyaudio
|
||||
ps.matplotlib
|
||||
ps.scipy]))
|
||||
];
|
||||
}
|
30
simulator.py
30
simulator.py
|
@ -3,12 +3,12 @@ import os
|
|||
import time
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from colour import Color
|
||||
#from color import Color
|
||||
|
||||
|
||||
c1 = Color("#7d1dd3")
|
||||
c2 = Color("#ffe500")
|
||||
colors = list(c1.range_to(c2, 42))
|
||||
#c1 = Color("#7d1dd3")
|
||||
#c2 = Color("#ffe500")
|
||||
#colors = list(c1.range_to(c2, 42))
|
||||
|
||||
|
||||
def infinite_colors():
|
||||
|
@ -116,7 +116,6 @@ class Douche:
|
|||
self.line, = ax.plot(self.xs, self.ys)
|
||||
|
||||
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)
|
||||
|
@ -128,11 +127,16 @@ class NaiveSimulator(Simulator, Douche):
|
|||
steps = [0, 0, 0]
|
||||
|
||||
time_step = 0
|
||||
last_update = 0.
|
||||
last_update = np.nan
|
||||
|
||||
J = np.array([1., 1., 1.]) # Moment of inertia vector times 1/R
|
||||
# We have on each axis
|
||||
# Jw' = Gamma(motor) - f0*w
|
||||
# which can be expressed as
|
||||
# Jv' = (R*Gamma)(motor) - f0*v
|
||||
|
||||
J = np.array([1., 1., 1.]) # Moment of inertia vector
|
||||
f = np.array([0., 0., 0.]) # viscous friction coefficient
|
||||
G = np.array([1., 1., 1.]) # Motor gain : Gamma = G * delta_w
|
||||
G = np.array([1., 1., 1.]) # Motor gain : Gamma*R = G * delta_v
|
||||
# FIXME: this is not very realistic, this looks like a model of
|
||||
# an asynchronous motor, not a stepper.
|
||||
|
||||
|
@ -148,11 +152,17 @@ class NaiveSimulator(Simulator, Douche):
|
|||
def simulate(self):
|
||||
lt = time.time()
|
||||
self.time_step = lt - self.last_update
|
||||
if(self.time_step == np.nan):
|
||||
return
|
||||
self.last_update = lt
|
||||
gamma = self.G*(self.command_spd - self.speed)
|
||||
|
||||
self.speed += 1./self.J * (gamma - self.f*self.speed ) * self.time_step
|
||||
|
||||
self.pos += self.speed * self.time_step
|
||||
self.speed += 1./self.J * (gamma - self.f*self.speed) * self.time_step
|
||||
print("timestep ", self.time_step)
|
||||
print("gamma ", gamma)
|
||||
print("speed ", self.speed)
|
||||
print("position ", self.pos)
|
||||
|
||||
self.steps = np.ceil(self.pos * np.array([self.X_STEPS_PER_MM,
|
||||
self.Y_STEPS_PER_MM,
|
||||
|
|
Loading…
Add table
Reference in a new issue