Repository navigation
Expand file tree
/
Copy pathstacker.old.py
More file actions
70 lines (57 loc) · 1.75 KB
/
Copy pathstacker.old.py
File metadata and controls
70 lines (57 loc) · 1.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
import re
import os
import time
import signal
import sys
import drive
import flow
'''
Should do:
- Drive to start position without feeding
- Start feeder
- Build stockpile by file and measurement of amount
- log amount per color and position
- allow user to pause (e.g. because something needs fixing but user want to continue later)
'''
currentPos = 0
stop = False
def getProgram(file):
file = open(file, 'r')
program = []
for line in file:
matches = re.search('(.*)\t(.*)', line)
program.append((float(matches.group(1)), float(matches.group(2))))
return program
def stack(file):
global currentPos
global stop
drive.init()
drive.moveTo(0)
time.sleep(45)
program = getProgram(file)
programStep = 1
flow.init()
currentStepMaterial = 0
lastCheck = time.time()
minMoveToTimeDiff = 0
lastMoveTo = time.time() - minMoveToTimeDiff
while (not stop and programStep < len(program)):
now = time.time()
lastPos = program[programStep - 1][0]
nextPos = program[programStep][0]
targetStepMaterial = program[programStep][1]
currentFlow = flow.get(currentPos)
if (now > lastMoveTo + minMoveToTimeDiff):
currentPos = lastPos + (nextPos - lastPos) * (currentStepMaterial / targetStepMaterial)
drive.moveTo(currentPos)
lastMoveTo = now
print(str(currentStepMaterial) + ' of ' + str(targetStepMaterial) + ' mm3 @ ' + str(currentFlow) + ' mm3/s in step ' + str(programStep) + ', pos: ' + str(round(100 * currentPos)) + '%')
currentStepMaterial += round(currentFlow * (now - lastCheck))
lastCheck = now
if (currentStepMaterial > targetStepMaterial):
currentStepMaterial -= targetStepMaterial # add overflow material to next step
programStep += 1
print('step: ' + str(programStep))
flow.cleanup()
drive.moveTo(0)
print('done')