Repository navigation
Expand file tree
/
Copy pathlock_test.py
More file actions
144 lines (127 loc) · 3.75 KB
/
Copy pathlock_test.py
File metadata and controls
144 lines (127 loc) · 3.75 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from LockClass import LockClass
import logging
logging.VERBOSE = 5
logging.addLevelName(logging.VERBOSE, "VERBOSE")
logging.basicConfig(
filename='lock_test.log', encoding='utf-8', level=logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
lock = LockClass()
dial_step = 2
limit = 100.0/dial_step
dial_combo = [1.5, 0, 0]
destination = 0
current_position = lock.D / 10
A = 0
B = 1
C = 2
def move_cw(target, turns=0):
global current_position
logger.debug(f" moving_cw {target}, {turns}: {current_position}")
if current_position >= target:
destination = target
else:
destination = target - 100
if turns > 0:
destination = destination - (turns * 100)
lock.move(destination)
destination = target
current_position = target
return
def move_ccw(target, turns=0):
global current_position
logger.debug(f" moving_cw {target}, {turns}: {current_position}")
if current_position <= target:
destination = target
else:
destination = target + 100
if turns > 0:
destination = destination + (turns * 100)
lock.move(destination)
destination = target
current_position = target
def increment_target(index: int, step: float = 2) -> float:
rollover = 0
dial_combo[index] += step
if (dial_combo[index] >= 100):
dial_combo[index] -= 100
rollover = 1
return rollover
def decrement_target(index: int, step: float = 2) -> float:
rollover = 0
dial_combo[index] -= step
if (dial_combo[index] < 0):
dial_combo[index] += 100
rollover = 1
return rollover
def dial_dwell() -> bool:
# // Check the handle at this point
# destination.i = handle_pull;
# prepare_line_to_destination();
# planner.synchronize();
if (
dial_combo[A] == lock.A and
dial_combo[B] == lock.B and
dial_combo[C] == lock.C
):
logger.info(f"PASS: Target={dial_combo[A]:2},{dial_combo[B]:2},"
f"{dial_combo[C]:2} Actual={lock.A:2},{lock.B:2},"
f"{lock.C:2},{lock.D:2}")
else:
logger.info(f"FAIL: Target={dial_combo[A]:2},{dial_combo[B]:2},"
f"{dial_combo[C]:2} Actual={lock.A:2},{lock.B:2},"
f"{lock.C:2},{lock.D:2}")
# GcodeSuite::dwell(pull_dwell_time);
# bool locked = !endstops.state();
locked = True
if (
dial_combo[A] >= 100-dial_step and
dial_combo[B] < dial_step and
dial_combo[C] >= 100-dial_step
):
locked = False
# if (locked):
# destination.i = 0;
# prepare_line_to_destination();
# planner.synchronize();
return locked
b_cnt = 1
c_cnt = 1
dial_combo[B] = dial_combo[A]
dial_combo[C] = dial_combo[A]
move_ccw(dial_combo[A], 3)
move_cw(dial_combo[B], 2)
move_ccw(dial_combo[C], 1)
move_cw(0)
locked = dial_dwell()
locked = True
while (locked):
if (c_cnt < limit):
# //Need to try more of the third digit
extra = increment_target(C, dial_step)
c_cnt += 1
move_ccw(dial_combo[C], extra)
move_cw(0)
locked = dial_dwell()
elif (b_cnt < limit):
# //Need to decrement the second digit
decrement_target(B, dial_step)
b_cnt += 1
# sync_plan_position()
c_cnt = 1
move_cw(dial_combo[B], 1)
move_ccw(dial_combo[C], 1)
move_cw(0)
locked = dial_dwell()
else:
# //Need to increment the first digit
increment_target(A, dial_step)
b_cnt = 1
c_cnt = 1
dial_combo[B] = dial_combo[A]
dial_combo[C] = dial_combo[A]
move_ccw(dial_combo[A], 3)
move_cw(dial_combo[B], 2)
move_ccw(dial_combo[C], 1)
move_cw(0)
locked = dial_dwell()