-
Notifications
You must be signed in to change notification settings - Fork 0
/
maintenance.py
120 lines (78 loc) · 2.47 KB
/
maintenance.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# -*- coding: utf-8 -*-
import sys #basic
import os
import time #time taking
import serial #connection to arduino
import serial.tools.list_ports #port identification
#----- UTILITY METHODS -----#
#prints error message and quits the program
def error(message):
sys.stderr.write("error(): " + message + "\n")
sys.exit(1)
#----- MAIN -----#
def main():
print("maintenance.py started...")
print("Available ports")
ports = list(serial.tools.list_ports.comports())
for p in ports:
print p
#if "Arduino" in p:
# print "This is an Arduino!"
print("Connecting to Arduino...")
try:
serial_connection = serial.Serial('/dev/ttyACM0' , 115200) # open serial port
time.sleep(1.0)
print("Communication established")
except Exception as e:
error(str(e))
#set pin P4 to low (dunno why)
serial_connection.write("M42 P4 S0\n")
time.sleep(1.0)
#home all axis
serial_connection.write("G28\n")
time.sleep(1.0)
#resetting all axis to zero
serial_connection.write("G92\n")
time.sleep(1.0)
#Linear Mode and applying values to XYZ axis | F - feedrate | S checks for endstop
serial_connection.write("G1 X65 Y28 Z501 F3000 S1\n")
time.sleep(1.0)
#wait for current moves to finish
serial_connection.write("M400\n")
time.sleep(1.0)
waiting = 10.0
time_1 = float(round(time.time()))
run = True
while(run):
data = serial_connection.readline()
if data:
print(str(data))
time_2 = float(round(time.time()))
time_left = time_2 - time_1
user_input = ""
if time_left > waiting:
user_input = raw_input("Some input please: ")
# Now do something with the above
serial_connection.write(str(user_input))
#input validation
if user_input == "quit":
run = False
print("Quitting main loop...")
time.sleep(0.1)
f = open("gcodescripts/9degree.gcode")
for line in f:
print(line)
serial_connection.write(str(line))
data = serial_connection.readline()
if data:
print(str(data))
f.close()
time.sleep(5.0)
try:
serial_connection.close() # close port
time.sleep(1.0)
print("Communication terminated")
except Exception as e:
error(str(e))
if __name__ == '__main__':
main()