-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator.py
52 lines (39 loc) · 1.21 KB
/
simulator.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation
from gcodelib import line_reader
if len(sys.argv) != 2:
print "please specify gcode file you want to plot as commandline argument. E.g.:\n python postprocess.py model.gcode"
exit(1)
f = open(sys.argv[1])
gcode = f.readlines()
f.close()
## 3D
def update_line(state):
xdata.append(state["X"])
ydata.append(state["Y"])
zdata.append(state["Z"])
#line.set_data(np.asarray([xdata, ydata, zdata]))
line.set_data(xdata, ydata)
line.set_3d_properties(zdata)
fig = plt.figure()
ax = p3.Axes3D(fig)
xdata, ydata, zdata = [0,0], [0,0], [0,0]
line = ax.plot(xdata, ydata, zdata,"-")[0]
ax.set_xlim3d([90.0, 130.0])
ax.set_xlabel('X')
ax.set_ylim3d([90.0, 130.0])
ax.set_ylabel('Y')
ax.set_zlim3d([0.0, 4.0])
ax.set_zlabel('Z')
ani = animation.FuncAnimation(fig, update_line, line_reader(gcode), blit=False, interval=1, repeat=True)
plt.show()
## 2D
fig, ax = plt.subplots()
xdata, ydata = [], []
line, = ax.plot(xdata, ydata)
ax.set_ylim(0, 200)
ax.set_xlim(0, 200)
ani = animation.FuncAnimation(fig, update_line, line_reader(gcode), blit=False, interval=10, repeat=True)
plt.show()