-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmn_cnc.hal
executable file
·360 lines (296 loc) · 12.5 KB
/
mn_cnc.hal
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#mn_cnc.hal
#copied fromm Xylotex.hal and then modified for the mn_cnc machine.
# the machine uses a Xylotex BarebonesCNC cape and a Sound Logic BoB.
# The cape buffers pins 1-17 on the DB25 port and routes them to
# 17 BBB header pins.
#
# The machine hardware is not wired to the BoB exactly as the BoB
# labels imply. In particular the limit switches for all axes are
# wired in paralles to act as additional Estops.
# the cape also uses one pin (811) to enable the buffers.
#
# The cape has been modified to swap pins 810 and 914. The BBB PWM
# HW can drive pin 914, but not 810. We sue 914 to drive a puls stream
# onto DB25 pin1 for spingle speed contol.
#
########################################
# Launch the setup script to make sure hardware setup looks good
loadusr -w ./setup.sh
#initialize pin modes and values by running config-pin with an input file
loadusr -w config-pin -f ./mn_cnc.bbio
# ###################################
# Core EMC/HAL Loads
# ###################################
# kinematics
loadrt trivkins
# trajectory planner
loadrt tp
# motion controller, get name and thread periods from ini file
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES tp=tp kins=trivkins
# load low-level drivers (not the PRU pins) 811 is barebonesCNC enable.
loadrt hal_bb_gpio output_pins=811,810,807,914,915, input_pins=911,913,923,941,809
#mn_cnc PRU stepgen pins are 812 thru 819
#mn_cnc uses two PRU PWMs (charge pump and VFD speed)
loadrt [PRUCONF](DRIVER) prucode=$(HAL_RTMOD_DIR)/[PRUCONF](PRUBIN) [PRUCONF](CONFIG)
loadrt pid count=4
loadrt limit1 count=2
#mn_cnc spindle speed control stuff
#load the two components and wait for them to set up
loadusr -Wn spindle pyvcp -c spindle spindle.xml
loadusr -Wn bbpwmgen bbpwmgen.py
#hook the components to each other and to others.
#no net is needed fo pin 914. The component sets the hardware up directly.
setp bbpwmgen.bbbpin 914
net gear spindle.gear.high =>bbpwmgen.gear-hi
net pulleyA spindle.pulley.A =>bbpwmgen.pulley-A
net pulleyB spindle.pulley.B =>bbpwmgen.pulley-B
net pulleyC spindle.pulley.C =>bbpwmgen.pulley-C
net pulleyD spindle.pulley.D =>bbpwmgen.pulley-D
net spindle-dir motion.spindle-forward => bbpwmgen.direction
net srpm motion.spindle-speed-out-abs spindle.speed bbpwmgen.speed
# ################################################
# THREADS
# ################################################
addf hpg.capture-position servo-thread
addf bb_gpio.read servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
# Not doing PID for temperature sensor for PWM output
addf pid.0.do-pid-calcs servo-thread
addf pid.1.do-pid-calcs servo-thread
addf pid.2.do-pid-calcs servo-thread
addf pid.3.do-pid-calcs servo-thread
addf limit1.0 servo-thread
addf limit1.1 servo-thread
addf hpg.update servo-thread
addf bb_gpio.write servo-thread
net vfd_direction bbpwmgen.vfd-direction => bb_gpio.p8.out-07
# ######################################################
# Configs for X, Y, Z, and A axes
# ######################################################
# ################
# X [0] Axis
# ################
# axis enable chain
newsig emcmot.00.enable bit
sets emcmot.00.enable FALSE
net emcmot.00.enable <= axis.0.amp-enable-out
net emcmot.00.enable => hpg.stepgen.00.enable pid.0.enable
# position command and feedback
net emcmot.00.pos-cmd axis.0.motor-pos-cmd => pid.0.command
net emcmot.00.vel-cmd axis.0.joint-vel-cmd => pid.0.command-deriv
net motor.00.pos-fb <= hpg.stepgen.00.position-fb axis.0.motor-pos-fb pid.0.feedback
net motor.00.command pid.0.output hpg.stepgen.00.velocity-cmd
setp pid.0.error-previous-target true
setp pid.0.maxerror .001
# timing parameters
setp hpg.stepgen.00.dirsetup [AXIS_0]DIRSETUP
setp hpg.stepgen.00.dirhold [AXIS_0]DIRHOLD
setp hpg.stepgen.00.steplen [AXIS_0]STEPLEN
setp hpg.stepgen.00.stepspace [AXIS_0]STEPSPACE
setp hpg.stepgen.00.position-scale [AXIS_0]SCALE
setp hpg.stepgen.00.maxvel [AXIS_0]STEPGEN_MAX_VEL
setp hpg.stepgen.00.maxaccel [AXIS_0]STEPGEN_MAX_ACC
setp hpg.stepgen.00.control-type 1
setp hpg.stepgen.00.stepinvert [AXIS_0]STEP_INVERT
#setp hpg.stepgen.00.step_type 0
#modified for mn_cnc:
setp hpg.stepgen.00.steppin 819
setp hpg.stepgen.00.dirpin 815
# set PID loop gains from inifile
setp pid.0.Pgain [AXIS_0]P
setp pid.0.Igain [AXIS_0]I
setp pid.0.Dgain [AXIS_0]D
setp pid.0.bias [AXIS_0]BIAS
setp pid.0.FF0 [AXIS_0]FF0
setp pid.0.FF1 [AXIS_0]FF1
setp pid.0.FF2 [AXIS_0]FF2
setp pid.0.deadband [AXIS_0]DEADBAND
setp pid.0.maxoutput [AXIS_0]MAX_OUTPUT
# Add X home switch input on DB25-11
#modified for mn_cnc. by coincidence still DB25-11, but pin is 913
#net home-x bb_gpio.p9.in-13 => axis.0.home-sw-in
#however, the Machine does not use limit switches, so comment them out
#net both-home-x <= bb_gpio.p9.in-13
#net both-home-x => axis.0.home-sw-in
#net both-home-x => axis.0.neg-lim-sw-in
#net both-home-x => axis.0.pos-lim-sw-in
#setp bb_gpio.p9.in-13.invert 1
# ################
# Y [1] Axis
# ################
# axis enable chain
newsig emcmot.01.enable bit
sets emcmot.01.enable FALSE
net emcmot.01.enable <= axis.1.amp-enable-out
net emcmot.01.enable => hpg.stepgen.01.enable pid.1.enable
# position command and feedback
net emcmot.01.pos-cmd axis.1.motor-pos-cmd => pid.1.command
net emcmot.01.vel-cmd axis.1.joint-vel-cmd => pid.1.command-deriv
net motor.01.pos-fb <= hpg.stepgen.01.position-fb axis.1.motor-pos-fb pid.1.feedback
net motor.01.command pid.1.output hpg.stepgen.01.velocity-cmd
setp pid.1.error-previous-target true
setp pid.1.maxerror .001
# timing parameters
setp hpg.stepgen.01.dirsetup [AXIS_1]DIRSETUP
setp hpg.stepgen.01.dirhold [AXIS_1]DIRHOLD
setp hpg.stepgen.01.steplen [AXIS_1]STEPLEN
setp hpg.stepgen.01.stepspace [AXIS_1]STEPSPACE
setp hpg.stepgen.01.position-scale [AXIS_1]SCALE
setp hpg.stepgen.01.maxvel [AXIS_1]STEPGEN_MAX_VEL
setp hpg.stepgen.01.maxaccel [AXIS_1]STEPGEN_MAX_ACC
setp hpg.stepgen.01.control-type 1
setp hpg.stepgen.01.stepinvert [AXIS_1]STEP_INVERT
#setp hpg.stepgen.01.step_type 0
#modified for mn_cnc
setp hpg.stepgen.01.steppin 818
setp hpg.stepgen.01.dirpin 814
# set PID loop gains from inifile
setp pid.1.Pgain [AXIS_1]P
setp pid.1.Igain [AXIS_1]I
setp pid.1.Dgain [AXIS_1]D
setp pid.1.bias [AXIS_1]BIAS
setp pid.1.FF0 [AXIS_1]FF0
setp pid.1.FF1 [AXIS_1]FF1
setp pid.1.FF2 [AXIS_1]FF2
setp pid.1.deadband [AXIS_1]DEADBAND
setp pid.1.maxoutput [AXIS_1]MAX_OUTPUT
# Add Y home switch input on DB25-12
#modified for mn_cnc. still on DB25-12, but pin is 923
#net home-y bb_gpio.p9.in-23 => axis.1.home-sw-in
# However, not actually wired for our machine
#net both-home-y <= bb_gpio.p9.in-23
#net both-home-y => axis.1.home-sw-in
#net both-home-y => axis.1.neg-lim-sw-in
#net both-home-y => axis.1.pos-lim-sw-in
#setp bb_gpio.p9.in-23.invert 1
# ################
# Z [2] Axis
# ################
# axis enable chain
newsig emcmot.02.enable bit
sets emcmot.02.enable FALSE
net emcmot.02.enable <= axis.2.amp-enable-out
net emcmot.02.enable => hpg.stepgen.02.enable pid.2.enable
# position command and feedback
net emcmot.02.pos-cmd axis.2.motor-pos-cmd => pid.2.command
net emcmot.02.vel-cmd axis.2.joint-vel-cmd => pid.2.command-deriv
net motor.02.pos-fb <= hpg.stepgen.02.position-fb axis.2.motor-pos-fb pid.2.feedback
net motor.02.command pid.2.output hpg.stepgen.02.velocity-cmd
setp pid.2.error-previous-target true
setp pid.2.maxerror .001
# timing parameters
setp hpg.stepgen.02.dirsetup [AXIS_2]DIRSETUP
setp hpg.stepgen.02.dirhold [AXIS_2]DIRHOLD
setp hpg.stepgen.02.steplen [AXIS_2]STEPLEN
setp hpg.stepgen.02.stepspace [AXIS_2]STEPSPACE
setp hpg.stepgen.02.position-scale [AXIS_2]SCALE
setp hpg.stepgen.02.maxvel [AXIS_2]STEPGEN_MAX_VEL
setp hpg.stepgen.02.maxaccel [AXIS_2]STEPGEN_MAX_ACC
setp hpg.stepgen.02.control-type 1
setp hpg.stepgen.02.stepinvert [AXIS_2]STEP_INVERT
#setp hpg.stepgen.02.step_type 0
#modified for mn_cnc
setp hpg.stepgen.02.steppin 817
setp hpg.stepgen.02.dirpin 813
# set PID loop gains from inifile
setp pid.2.Pgain [AXIS_2]P
setp pid.2.Igain [AXIS_2]I
setp pid.2.Dgain [AXIS_2]D
setp pid.2.bias [AXIS_2]BIAS
setp pid.2.FF0 [AXIS_2]FF0
setp pid.2.FF1 [AXIS_2]FF1
setp pid.2.FF2 [AXIS_2]FF2
setp pid.2.deadband [AXIS_2]DEADBAND
setp pid.2.maxoutput [AXIS_2]MAX_OUTPUT
# Add Z home switch input on DB25-13
#modified for mn_cnc. still on DB25-13, but pin is 941
#net home-z bb_gpio.p8.in-18 => axis.2.home-sw-in
#However, not wired for our machine
#net both-home-z <= bb_gpio.p9.in-41
#net both-home-z => axis.2.home-sw-in
#net both-home-z => axis.2.neg-lim-sw-in
#net both-home-z => axis.2.pos-lim-sw-in
#setp bb_gpio.p9.in-41.invert 1
# ################
# A [3] Axis
# ################
# axis enable chain
newsig emcmot.03.enable bit
sets emcmot.03.enable FALSE
net emcmot.03.enable <= axis.3.amp-enable-out
net emcmot.03.enable => hpg.stepgen.03.enable pid.3.enable
# position command and feedback
net emcmot.03.pos-cmd axis.3.motor-pos-cmd => pid.3.command
net emcmot.03.vel-cmd axis.3.joint-vel-cmd => pid.3.command-deriv
net motor.03.pos-fb <= hpg.stepgen.03.position-fb axis.3.motor-pos-fb pid.3.feedback
net motor.03.command pid.3.output hpg.stepgen.03.velocity-cmd
setp pid.3.error-previous-target true
setp pid.3.maxerror .001
# timing parameters
setp hpg.stepgen.03.dirsetup [AXIS_3]DIRSETUP
setp hpg.stepgen.03.dirhold [AXIS_3]DIRHOLD
setp hpg.stepgen.03.steplen [AXIS_3]STEPLEN
setp hpg.stepgen.03.stepspace [AXIS_3]STEPSPACE
setp hpg.stepgen.03.position-scale [AXIS_3]SCALE
setp hpg.stepgen.03.maxvel [AXIS_3]STEPGEN_MAX_VEL
setp hpg.stepgen.03.maxaccel [AXIS_3]STEPGEN_MAX_ACC
setp hpg.stepgen.03.control-type 1
setp hpg.stepgen.03.stepinvert [AXIS_3]STEP_INVERT
#setp hpg.stepgen.03.step_type 0
#modified for mn_cnc
setp hpg.stepgen.03.steppin 816
setp hpg.stepgen.03.dirpin 812
# set PID loop gains from inifile
setp pid.3.Pgain [AXIS_3]P
setp pid.3.Igain [AXIS_3]I
setp pid.3.Dgain [AXIS_3]D
setp pid.3.bias [AXIS_3]BIAS
setp pid.3.FF0 [AXIS_3]FF0
setp pid.3.FF1 [AXIS_3]FF1
setp pid.3.FF2 [AXIS_3]FF2
setp pid.3.deadband [AXIS_3]DEADBAND
setp pid.3.maxoutput [AXIS_3]MAX_OUTPUT
# Add A home switch input
# modifiec for mn_cnc (not yet implemented, DB25-15, pin 809)
#net home-a bb_gpio.p8.in-09 => axis.3.home-sw-in
# ##################################################
# Standard I/O - EStop, Enables, Limit Switches, Etc
# ##################################################
# create signals for tool loading loopback
net tool-prep-loop iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
net tool-change-loop iocontrol.0.tool-change => iocontrol.0.tool-changed
#modified for mn_cnc. I am not sure about this. We know we need to activate
#811, but we don't know exactly when.
# Axis enable and IO control enable signals
# All external Inputs and Outputs on external boards
# should have pullups/downs since when the interface board is
# not enabled, it will look dosconnected for all signals
# it is also used to enable the LVC541 driver/receiver on the interface board
#net machine-on bb_gpio.p8.out-11 => halui.machine.is-on
#setp bb_gpio.p8.out-11.invert 1
#probe input on DB25-15
#net probe motion.probe-input <= bb_gpio.p8.in-18
#setp bb_gpio.p8.in-18.invert 1
# this currently goes to an LED on the interface board
# it is simply a duplicate of the enable signal on DB25-1 right now
#setp bb_gpio.p8.out-26.invert 1
# this input signal must be active LOW to allow the system to energize.
# this should be fed through an NC STOP type switch from DB25-1 to DB25-10
#net estop-in <= halui.machine.is-on
net estop-in => bb_gpio.p8.in-09
net estop-in => iocontrol.0.emc-enable-in
setp bb_gpio.p8.in-09.invert 1
# This output is on DB25-14 and is currently tied to spindle control (M3/M5)
#net Output1 bb_gpio.p8.out-13 => motion.spindle-on
#setp bb_gpio.p8.out-13.invert 1
#net Output1 bb_gpio.p8.out-13 => halui.spindle.is-on
#net Output1 bb_gpio.p8.out-13 => motion.spindle-on
#setp bb_gpio.p8.out-13.invert 1
#modified for mn_cnc. coolant on DB25-16, pin 914
# This output is on DB25-17 (M8/M9)
#net Output3 bb_gpio.p9.out-14 => halui.flood.is-on
#setp bb_gpio.p9.out-14.invert 1
#added for mn_cnc charge pump on DB25-17, pin 915
#net chargepump charge_pump.0.out => bb_gpio.p9.out-15
setp bb_gpio.p9.out-15 1