-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathsim_spindle_encoder.hal
More file actions
54 lines (40 loc) · 1.88 KB
/
sim_spindle_encoder.hal
File metadata and controls
54 lines (40 loc) · 1.88 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
# simulated spindle encoder (for spindle-synced moves)
loadrt sim_spindle names=sim_spindle
setp sim_spindle.scale 0.01666667
loadrt limit2 names=limit_speed
loadrt lowpass names=spindle_mass
loadrt near names=near_speed
loadrt quant names=sim_spindle_encoder,spindle_vel_est
# Bound spindle acceleration to something reasonable
setp limit_speed.maxv 5000.0 # rpm/second
# encoder reset control
# hook up motion controller's sync output
net spindle-index-enable motion.spindle-index-enable <=> sim_spindle.index-enable
# Set resolution of spindle encoder in counts / revolution (Note: this value is 4 * LPR or PPR)
setp sim_spindle_encoder.resolution 64.0
# Simulated spindle encoder
net spindle-pos-raw sim_spindle.position-fb => sim_spindle_encoder.in
# report our revolution count to the motion controller
net spindle-pos sim_spindle_encoder.out => motion.spindle-revs
# simulate spindle mass
setp spindle_mass.gain .005
# Limit spindle speed by our maximum value
net spindle-speed-cmd motion.spindle-speed-out => limit_speed.in
# Simulate spindle mass with a low-pass filter on the velocity command
net spindle-speed-limited limit_speed.out => spindle_mass.in
# Feed the simulated spindle speed into the sim spindle to generate a position signal
net spindle-rpm-filtered spindle_mass.out => sim_spindle.velocity-cmd near_speed.in2 spindle_vel_est.in
# Approximate velocity quantization assuming 360 RPM, 30kHz base thread, 100 PPR encoder
setp spindle_vel_est.resolution 8.0
net spindle-rpm-est spindle_vel_est.out => motion.spindle-speed-in
# at-speed detection
setp near_speed.scale 1.1
setp near_speed.difference 10
net spindle-speed-cmd => near_speed.in1
net spindle-at-speed near_speed.out motion.spindle-at-speed
addf limit_speed servo-thread
addf spindle_mass servo-thread
addf near_speed servo-thread
addf sim_spindle servo-thread
addf sim_spindle_encoder servo-thread
addf spindle_vel_est servo-thread