-
Notifications
You must be signed in to change notification settings - Fork 2
/
RP2040_and_ender.py
129 lines (94 loc) · 3.08 KB
/
RP2040_and_ender.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
121
122
123
124
125
126
127
128
129
import time
import sys
import serial
from serial_device import *
import fullcontrol as fc
import create_gcode as cg
z_range = 0.1 # fader val conversion -z_range to z_range (if custom mapping is on)
total_z = 0
gcode_line = 0 # Starts gcode at line 0
zval = 0
i = 0
gcode = []
gcode_path = "C:\\Users\\malbe\\OneDrive - TU Eindhoven\\1 Online Bureaublad\\GitHub\\nonplanar\\created gcode\\Oval.gcode"
def custom_mapping(value): #Maps from 0, 120 to -z_range to z_range
return (value / 60 - 1) * z_range
print_ports()
MP2040 = get_ports_with_vid(9114)
print("MP2040 device = ", MP2040)
print("connecting to the RP2040")
rp2040 = SerialDevice()
rp2040.open(MP2040[-1],baud=9600)
ENDER3 = get_ports_with_vid(6790)
print("MP2040 device = ", ENDER3)
p = Printer()
print("connecting to the Ender")
p.open(ENDER3[-1], baud=115200)
p.send_gcode("G28")
print('Homing..')
p.wait_for_ok()
time.sleep(1.0)
while True:
s = p.readline()
if s == None:
print("init done")
break
else:
print(s)
start_position = ('{}\n'.format(input('Type starting position here: '))) #Write start position to the fader
rp2040.write(start_position)
time.sleep(1.0)
with open(gcode_path, 'r') as file:
for line in file:
gcode_line = line.strip()
if gcode_line: # This condition checks if the line is not empty (it seems to stall serial communication)
gcode.append(gcode_line)
# Only sends fader data to printer
# while 1:
# l = rp2040.readline_bytes()
# if l != None:
# print('raw sensor value = ', l)
# fader_val = (float(f"{l}"))*z_range
# print('zval conversion = ', fader_val)
# code = ('G0 F1000 Z{}'.format(fader_val)) # Moves Z-axis
# p.send_gcode(code)
# p.wait_for_ok
while 1: #Sends z coordinates seperate from gcode: not so smooth
faderval = rp2040.readline_bytes()
if faderval != None:
print(faderval)
zval = (float(f"{faderval}"))*z_range
print('zval = ', zval)
p.send_gcode('G0 F1000 Z{}'.format(zval)) # Travel to z height
p.send_gcode(gcode[i])
p.wait_for_ok()
faderval = rp2040.readline_bytes()
i = i +1
# while 1: #Appends z directly to coordinates
# faderval = rp2040.readline_bytes()
# print(faderval)
# if faderval != None:
# print(faderval)
# zval = (float(f"{faderval}"))*z_range
# print('zval = ', zval)
# adjusted_gcode = cg.adjust_z_height(gcode[i],zval)
# p.send_gcode(adjusted_gcode)
# p.wait_for_ok()
# i=i+1
# if faderdiff < margin : adjust z_height
# Incremental zheight adjustment?
# Apply sine wave on contours of shoe?
# Send z back to the fader
# while 1:
# l = rp2040.readline_bytes()
# p.send_gcode(gcode[i])
# print(gcode[i])
# if l != None:
# print(l)
# fader_val = (float(f"{l}"))*z_range
# print('faderval = ', fader_val)
# code = ('G0 F1000 Z{}'.format(fader_val)) # Moves Z-axis
# print('Total_z (absolute position) = ', fader_val)
# p.send_gcode(code)
# p.wait_for_ok()
# i = i + 1