-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFactory.whl
184 lines (166 loc) · 7.85 KB
/
Factory.whl
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
; Wheel, copyright (c) 2020 - present by Arno van der Vegt
; Distributed under an MIT
#include "lib/modules/standard.whl"
#include "lib/modules/math.whl"
#include "lib/modules/components/component.whl"
#include "lib/modules/components/form.whl"
#include "lib/modules/components/tabs.whl"
#include "lib/modules/components/selectButton.whl"
#include "lib/modules/components/button.whl"
#include "lib/modules/components/label.whl"
#include "lib/modules/components/title.whl"
#include "lib/modules/components/image.whl"
#include "lib/modules/components/interval.whl"
#include "robot/Robots.whl"
#include "factoryData.whl"
#include "Conveyor.whl"
#include "inventory/Order.whl"
#include "inventory/Inventory.whl"
#include "car/Cars.whl"
object Factory
number needsReset[5] ; Which robot needs to be reset?
Robots robots
Conveyor conveyor
Inventory inventory
Order order
Cars cars
end
proc Factory.setFormDisabled(number disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_MOTOR_A1, disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_MOTOR_A2, disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_MOTOR_B1, disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_MOTOR_B2, disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_MOTOR_C1, disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_MOTOR_C2, disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_MOTOR_D1, disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_MOTOR_D2, disabled)
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_RESET, disabled)
components.selectButton.setDisabled(mainWindow, FACTORY_FORM_SELECT_ROBOT, disabled)
end
proc Factory.setSequenceDisabled()
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT1_PICKUP1, needsReset[0])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT1_PICKUP2, needsReset[0])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT1_LOAD, needsReset[0])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT2_PICKUP1, needsReset[1])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT2_PICKUP2, needsReset[1])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT3_PICKUP_DROP1, needsReset[2])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT3_PICKUP1, needsReset[2])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT3_DROP1, needsReset[2])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT3_PICKUP_DROP2, needsReset[2])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT3_PICKUP2, needsReset[2])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT3_DROP2, needsReset[2])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT3_LOAD, needsReset[2])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT4_PICKUP_DROP1, needsReset[3])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT4_PICKUP1, needsReset[3])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT4_DROP1, needsReset[3])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT4_PICKUP_DROP2, needsReset[3])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT4_PICKUP2, needsReset[3])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT4_DROP2, needsReset[3])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_ROBOT4_LOAD, needsReset[3])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_STORAGE1, needsReset[4])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_STORAGE2, needsReset[4])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_STORAGE3, needsReset[4])
components.button.setDisabled(mainWindow, FACTORY_FORM_BUTTON_STORAGE4, needsReset[4])
end
proc Factory.updateCommand()
select command
case CMD_SELECT_ROBOT:
robots.setActiveRobot(commandIndex)
number motorBHidden = FALSE
number motorCHidden = FALSE
number motorDHidden = FALSE
if commandIndex == 0
motorDHidden = TRUE
components.image.setSrc(mainWindow, FACTORY_FORM_IMAGE1, "images/robot1.svg")
elseif commandIndex == 4
motorBHidden = TRUE
motorCHidden = TRUE
components.image.setSrc(mainWindow, FACTORY_FORM_IMAGE1, "images/robot5.svg")
else
components.image.setSrc(mainWindow, FACTORY_FORM_IMAGE1, "images/robot2.svg")
end
components.label.setHidden(mainWindow, FACTORY_FORM_LABEL_MOTOR2, motorBHidden)
components.label.setHidden(mainWindow, FACTORY_FORM_LABEL_MOTOR3, motorCHidden)
components.button.setHidden(mainWindow, FACTORY_FORM_BUTTON_MOTOR_B1, motorBHidden)
components.button.setHidden(mainWindow, FACTORY_FORM_BUTTON_MOTOR_B2, motorBHidden)
components.button.setHidden(mainWindow, FACTORY_FORM_BUTTON_MOTOR_C1, motorCHidden)
components.button.setHidden(mainWindow, FACTORY_FORM_BUTTON_MOTOR_C2, motorCHidden)
components.button.setHidden(mainWindow, FACTORY_FORM_BUTTON_MOTOR_D1, motorDHidden)
components.button.setHidden(mainWindow, FACTORY_FORM_BUTTON_MOTOR_D2, motorDHidden)
case CMD_REV:
robots.rev(commandIndex)
case CMD_FWD:
robots.fwd(commandIndex)
case CMD_STOP:
robots.stop(commandIndex)
case CMD_STOP_ALL:
robots.stopAll()
case CMD_RESET:
setFormDisabled(TRUE)
number active = components.selectButton.getActive(mainWindow, FACTORY_FORM_SELECT_ROBOT)
needsReset [active] = FALSE
robots.reset()
case CMD_CONVEYOR_BAR_DOWN:
conveyor.barDown()
case CMD_CONVEYOR_BAR_UP:
conveyor.barUp()
case CMD_CONVEYOR_FROM_1_TO_2:
conveyor.move1to2()
case CMD_CONVEYOR_FROM_2_TO_3:
conveyor.move2to3()
case CMD_CONVEYOR_FROM_3_TO_4:
conveyor.move3to4()
case CMD_START_SEQUENCE0:
robots.startSequence(0, commandIndex)
case CMD_START_SEQUENCE1:
robots.startSequence(1, commandIndex)
case CMD_START_SEQUENCE2:
robots.startSequence(2, commandIndex)
case CMD_START_SEQUENCE3:
robots.startSequence(3, commandIndex)
case CMD_START_SEQUENCE4:
robots.startSequence(4, commandIndex)
case CMD_ORDER_ADD_ITEM:
order.addItem()
case CMD_ORDER_CLEAR:
order.clear()
case CMD_ORDER_RUN:
cars.order(@order)
end
command = CMD_NONE
setFormDisabled(FALSE)
setSequenceDisabled()
end
proc Factory.interval()
number labels[3] = [FACTORY_FORM_LABEL_MOTOR1, FACTORY_FORM_LABEL_MOTOR2, FACTORY_FORM_LABEL_MOTOR3]
number i
with robots.activeRobot.robotConfig
for i = 0 to 2
with motors[i]
components.label.setValueNumber(mainWindow, labels[i], motorLayerRead(layer, port))
end
end
end
end
proc Factory.update()
robots.update()
cars.update()
if command != CMD_NONE
updateCommand()
end
end
proc Factory.init()
command = CMD_NONE
needsReset = [TRUE, TRUE, TRUE, TRUE, TRUE]
mainWindow = components.form.show("factoryForm.wfrm")
setSequenceDisabled()
robots.init()
inventory.reset()
conveyor.init()
cars.init()
cars.setRobots(@robots)
cars.setConveyor(@conveyor)
order.init()
order.setInventory(@inventory)
end
Factory factory