-
Notifications
You must be signed in to change notification settings - Fork 2
/
interactive.py
69 lines (50 loc) · 1.26 KB
/
interactive.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
import time
import sys
import serial
from serial_device import *
import math
print_ports()
print("connecting to the einsy")
devices = get_ports_with_vid(10161)
print(devices)
p = Printer()
p.open(devices[-1], baud=250000)
time.sleep(1.0)
while True:
s = p.readline()
if s == None:
print("printer init done")
break
else:
print(s)
p.home()
p.wait_for_ok()
print("homing done")
min_height = 10
height = min_height
target_height = height
radius = 25
# Z30 seems the maximum
p.send_gcode("M203 X500.00 Y500.00 Z30.0")
p.wait_for_ok()
p.move(100, 100, height, speed=15000)
p.wait_for_ok()
print("connecting to the RP2040")
rp2040 = SerialDevice()
rp2040.open(get_ports_with_vid(9114)[-1])
i = 0
while 1:
i = (i + 1) % 72
x = 100 + radius * math.cos(math.radians(i * 5))
y = 100 + radius * math.sin(math.radians(i * 5))
if target_height > height:
height = min(target_height, height + 0.1)
if target_height < height:
height = max(target_height, height - 0.1)
p.move(x, y, height, speed=12000)
p.wait_for_ok()
# print(height, target_height)
new_height = rp2040.readline()
if new_height != None:
target_height = min_height + float(new_height) * 50
print(float(new_height) * 50)