-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCNC_Gcode.py
executable file
·78 lines (66 loc) · 2.22 KB
/
CNC_Gcode.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
from __future__ import print_function
import csv
import sys
import os
import time
from datetime import datetime
import ctypes
import tng
# -*- coding: utf-8 -*-
timesList = []
X = []
Y = []
Z = []
Speed = []
Acc = []
suffix = "CNC_Position_Eli_Y"
now = datetime.now()
timeBegin = time.time()
dateAndTime = now.strftime("%Y-%m-%d_%H-%M-%S_")
def listener():
#time.sleep(5)
tng.API.StartFnW("/home/pi/Desktop/Haptic_Bench/Gcode/Gcode_X_Sp.txt")
timeBegin = time.time()
with open("/home/pi/Desktop/Haptic_Bench/Measure/" + dateAndTime + suffix + ".txt" , "w") as file:
file.write("Time(s),X,Y,Z,Speed,\n")
period = 0.5
measurementNumber = 0.0
while True:
try:
timesList.append(time.time()-timeBegin)
x = tng.API.InfoWorkPosition(0)
time.sleep(1./100)
print(x)
y = tng.API.InfoWorkPosition(1)
print(y)
time.sleep(1./100)
z = tng.API.InfoWorkPosition(2)
print(z)
time.sleep(1./100)
v = tng.API.InfoSpeed()
time.sleep(1./100)
a = tng.API.InfoAcceleration()
time.sleep(1./100)
X.append(x)
Y.append(y)
Z.append(z)
Speed.append(v)
Acc.append(a)
if(time.time()-timeBegin > measurementNumber*period):
measurementNumber += 1
file.write(str(timesList[-1]) + "," + str(X[-1])+ ","+ str(Y[-1])+ ","+ str(Z[-1]) + ","+ str(Speed[-1])+"\n")
except KeyboardInterrupt:
print("Exiting program")
tng.API.ExitForce()
file.close()
exit()
#===============================================================================
# MAIN METHOD
#===============================================================================
if __name__ == '__main__':
print("[Initialising CNC Gcode...]\n")
time.sleep(1)
tng.Run()
#tng.API.Hide() # this line closes the CNCPlanet
listener()