-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeeznut.py
88 lines (65 loc) · 2.24 KB
/
deeznut.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
import asyncio
import logging
import random
import argparse
from viam.robot.client import RobotClient
from viam.rpc.dial import Credentials, DialOptions
from viam.components.gantry import Gantry
async def connect():
creds = Credentials(
type='robot-location-secret',
payload='yzl1w4e70v5c3pl44nuv9on4r7s6vaug56x3qnm32eqbqd5i')
opts = RobotClient.Options(
refresh_interval=0,
dial_options=DialOptions(credentials=creds)
)
return await RobotClient.at_address('mbp-main.8fc0qlpm4c.viam.cloud', opts)
def getValue(minVal: float, maxVal: float) -> float:
return float(minVal + (maxVal - minVal) * random.random())
def mm2inch(l):
return l*0.0393701
async def draw_line(axidraw: Gantry, x1, y1, x2, y2):
pos = await axidraw.get_position()
#lift the pen
await axidraw.move_to_position([pos[0], pos[1], 1], [])
# go to initial point
await axidraw.move_to_position([x1, y1, 1], [])
#put down the pen
await axidraw.move_to_position([x1, y1, 0], [])
#draw the line
await axidraw.move_to_position([x2, y2, 0], [])
#lift the pen
await axidraw.move_to_position([x2, y2, 1], [])
async def main():
robot = await connect()
logger = logging.getLogger("axidraw")
axidraw = Gantry.from_robot(robot, "axidraw")
# axis = await axidraw.get_lengths()
# start = await axidraw.get_position()
# minX, maxX, minY, maxY, z = 0, 4, 0, 7, 0
# # make sure its at the origin
# await axidraw.move_to_position([0, 0, 0], [])
# while True:
# nextX = getValue(minX, maxX)
# nextY = getValue(minY, maxY)
# print(f"move to {nextX} - {nextY}")
# _ = await axidraw.move_to_position([nextX, nextY, z], [])
# # Don't forget to close the robot when you're done!
n = 30 ##number of lines
X1 = []
Y1 = []
X2 = []
Y2 = []
maxX = 175 #in mm
maxY = 120 # in mm
quantum = maxY/n
for i in range(n):
X1.append(quantum*i)
Y1.append(0)
X2.append(0)
Y2.append(quantum*(n-i))
for i in range(n):
await draw_line(axidraw, mm2inch(X1[i]), mm2inch(Y1[i]), mm2inch(X2[i]), mm2inch(Y2[i]))
await robot.close()
if __name__ == "__main__":
asyncio.run(main())