Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 37 additions & 102 deletions configs/sim/axis/lathe_multispindle/lathe.hal
Original file line number Diff line number Diff line change
@@ -1,109 +1,44 @@
# counting the spindle encoder in software
loadrt encoder names=encoder_0,encoder_1
# simulate the encoder
loadrt sim_encoder names=sim_encoder_0,sim_encoder_1
loadrt limit2 names=limit_speed

addf limit_speed servo-thread

#######################################################
# Beginning of threading related stuff
#######################################################

# spindle speed control
net spindle.0.cmd spindle.0.speed-out => sim_encoder_0.speed
net spindle.1.cmd spindle.1.speed-out => sim_encoder_1.speed

# simulate spindle mass
setp limit_speed.maxv 500.0 # rpm/second

# spindle encoder 0
# connect encoder signals to encoder counter
net spindle-phase-A sim_encoder_0.phase-A => encoder_0.phase-A
net spindle-phase-B sim_encoder_0.phase-B => encoder_0.phase-B
net spindle-phase-Z sim_encoder_0.phase-Z => encoder_0.phase-Z

# assume 120 ppr = 480 counts/rev for the spindle
setp sim_encoder_0.ppr 120
# iocontrol output is in rpm, but sim-encoder speed is rps
setp sim_encoder_0.scale 60
# scale encoder output to read in revolutions
# (that way thread pitches can be straightforward,
# a 20 tpi thread would multiply the encoder output
# by 1/20, etc)
setp encoder_0.position-scale 480

# encoder reset control
# hook up motion controller's sync output
net spindle-index-enable spindle.0.index-enable <=> encoder_0.index-enable

# report our revolution count to the motion controller
net spindle.0.pos encoder_0.position => spindle.0.revs

# spindle encoder 1
# connect encoder signals to encoder counter
net spindle-phase-A1 sim_encoder_1.phase-A => encoder_1.phase-A
net spindle-phase-B1 sim_encoder_1.phase-B => encoder_1.phase-B
net spindle-phase-Z1 sim_encoder_1.phase-Z => encoder_1.phase-Z

# assume 120 ppr = 480 counts/rev for the spindle
setp sim_encoder_1.ppr 120
# iocontrol output is in rpm, but sim-encoder speed is rps
setp sim_encoder_1.scale 60
# scale encoder output to read in revolutions
# (that way thread pitches can be straightforward,
# a 20 tpi thread would multiply the encoder output
# by 1/20, etc)
setp encoder_1.position-scale 480

# encoder reset control
# hook up motion controller's sync output
net spindle-index-enable spindle.1.index-enable <=> encoder_0.index-enable

# report our revolution count to the motion controller
net spindle.1.pos encoder_1.position => spindle.1.revs

# for spindle velocity estimate
loadrt lowpass names=lowpass_velocity.0,lowpass_velocity.1
loadrt scale names=scale_to_rpm.0,scale_to_rpm.1
net spindle-rps-raw.0 encoder_0.velocity lowpass_velocity.0.in
net spindle-rps-filtered.0 lowpass_velocity.0.out scale_to_rpm.0.in spindle.0.speed-in
net spindle-rpm-filtered.0 scale_to_rpm.0.out
setp scale_to_rpm.0.gain 60
setp lowpass_velocity.0.gain .07
addf lowpass_velocity.0 servo-thread
addf scale_to_rpm.0 servo-thread

net spindle-rps-raw.1 encoder_1.velocity lowpass_velocity.1.in
net spindle-rps-filtered.1 lowpass_velocity.1.out scale_to_rpm.1.in spindle.1.speed-in
net spindle-rpm-filtered.1 scale_to_rpm.1.out
setp scale_to_rpm.1.gain 60
setp lowpass_velocity.1.gain .07
addf lowpass_velocity.1 servo-thread
addf scale_to_rpm.1 servo-thread

# for at-speed detection
# simulated spindles with index pulse, for spindle-synced moves (G33, G76, G95)
loadrt sim_spindle names=sim_spindle.0,sim_spindle.1
loadrt lowpass names=spindle_mass.0,spindle_mass.1
loadrt scale names=rpm_rps.0,rpm_rps.1
loadrt near names=near_speed.0,near_speed.1
addf near_speed.0 servo-thread

# speed-out is in rpm, sim_spindle wants rps
setp sim_spindle.0.scale 0.01666667
setp sim_spindle.1.scale 0.01666667

# spindle 0
net spindle.0.cmd spindle.0.speed-out => sim_spindle.0.velocity-cmd spindle_mass.0.in near_speed.0.in1
net spindle-index-enable.0 spindle.0.index-enable <=> sim_spindle.0.index-enable
net spindle.0.pos sim_spindle.0.position-fb => spindle.0.revs
setp spindle_mass.0.gain .07
setp rpm_rps.0.gain .01666667
net spindle-rpm-filtered.0 spindle_mass.0.out => rpm_rps.0.in near_speed.0.in2
net spindle-rps-filtered.0 rpm_rps.0.out => spindle.0.speed-in
setp near_speed.0.scale 1.1
setp near_speed.0.difference 10
net spindle.0.cmd => near_speed.0.in1
net spindle-rpm-filtered.0 => near_speed.0.in2
net spindle-at-speed.0 near_speed.0.out spindle.0.at-speed
net spindle.0-fwd <= spindle.0.forward

addf near_speed.1 servo-thread
net spindle.0-fwd <= spindle.0.forward

# spindle 1
net spindle.1.cmd spindle.1.speed-out => sim_spindle.1.velocity-cmd spindle_mass.1.in near_speed.1.in1
net spindle-index-enable.1 spindle.1.index-enable <=> sim_spindle.1.index-enable
net spindle.1.pos sim_spindle.1.position-fb => spindle.1.revs
setp spindle_mass.1.gain .07
setp rpm_rps.1.gain .01666667
net spindle-rpm-filtered.1 spindle_mass.1.out => rpm_rps.1.in near_speed.1.in2
net spindle-rps-filtered.1 rpm_rps.1.out => spindle.1.speed-in
setp near_speed.1.scale 1.1
setp near_speed.1.difference 10
net spindle.1.cmd => near_speed.1.in1
net spindle-rpm-filtered.1 => near_speed.1.in2
net spindle-at-speed.1 near_speed.1.out spindle.1.at-speed

net spindle.1-fwd <= spindle.1.forward

addf encoder.capture-position servo-thread
addf sim-encoder.update-speed servo-thread

addf sim-encoder.make-pulses base-thread
addf encoder.update-counters base-thread

net spindle.1-fwd <= spindle.1.forward

addf spindle_mass.0 servo-thread
addf spindle_mass.1 servo-thread
addf rpm_rps.0 servo-thread
addf rpm_rps.1 servo-thread
addf near_speed.0 servo-thread
addf near_speed.1 servo-thread
addf sim_spindle.0 servo-thread
addf sim_spindle.1 servo-thread
71 changes: 21 additions & 50 deletions configs/sim/gmoccapy/lathe_configs/spindle_sim.hal
Original file line number Diff line number Diff line change
@@ -1,69 +1,40 @@
# counting the spindle encoder in software
loadrt encoder names=encoder_0
# simulate the encoder
loadrt sim_encoder names=sim_encoder_0
# simulated spindle with index pulse, for spindle-synced moves (G33, G76, G95)
loadrt sim_spindle names=sim_spindle
loadrt limit2 names=limit_speed
loadrt lowpass names=spindle_mass
loadrt scale names=rpm_rps
loadrt near names=near_speed

addf limit_speed servo-thread

#######################################################
# Beginning of threading related stuff
#######################################################

# spindle speed control
net spindle-speed-cmd spindle.0.speed-out => limit_speed.in
net spindle-speed-limited limit_speed.out => sim_encoder_0.speed

# simulate spindle mass
# spindle speed control, ramped to simulate the spindle mass
net spindle-speed-cmd spindle.0.speed-out => limit_speed.in near_speed.in1
net spindle-speed-limited limit_speed.out => sim_spindle.velocity-cmd spindle_mass.in
setp limit_speed.maxv 3000.0 # rpm/second

# spindle encoder
# connect encoder signals to encoder counter
net spindle-phase-A sim_encoder_0.phase-A => encoder_0.phase-A
net spindle-phase-B sim_encoder_0.phase-B => encoder_0.phase-B
net spindle-phase-Z sim_encoder_0.phase-Z => encoder_0.phase-Z

# assume 120 ppr = 480 counts/rev for the spindle
setp sim_encoder_0.ppr 12
# iocontrol output is in rpm, but sim-encoder speed is rps
setp sim_encoder_0.scale 60
# scale encoder output to read in revolutions
# (that way thread pitches can be straightforward,
# a 20 tpi thread would multiply the encoder output
# by 1/20, etc)
setp encoder_0.position-scale 48
# speed-out is in rpm, sim_spindle wants rps
setp sim_spindle.scale 0.01666667

# encoder reset control
# hook up motion controller's sync output
net spindle-index-enable spindle.0.index-enable <=> encoder_0.index-enable
net spindle-index-enable spindle.0.index-enable <=> sim_spindle.index-enable

# report our revolution count to the motion controller
net spindle-pos encoder_0.position => spindle.0.revs
net spindle-pos sim_spindle.position-fb => spindle.0.revs

# for spindle velocity estimate
loadrt lowpass names=lowpass_velocity
loadrt scale names=scale_to_rpm
net spindle-rps-raw encoder_0.velocity lowpass_velocity.in
net spindle-rps-filtered lowpass_velocity.out scale_to_rpm.in spindle.0.speed-in
net spindle-rpm-filtered scale_to_rpm.out
setp scale_to_rpm.gain 60
setp lowpass_velocity.gain .07
addf lowpass_velocity servo-thread
addf scale_to_rpm servo-thread
setp spindle_mass.gain .07
setp rpm_rps.gain .01666667
net spindle-rpm-filtered spindle_mass.out => rpm_rps.in near_speed.in2
net spindle-rps-filtered rpm_rps.out => spindle.0.speed-in

# for at-speed detection
loadrt near names=near_speed
addf near_speed servo-thread
setp near_speed.scale 1.1
setp near_speed.difference 10
net spindle-speed-cmd => near_speed.in1
net spindle-rpm-filtered => near_speed.in2
net spindle-at-speed near_speed.out spindle.0.at-speed

net spindle-fwd <= spindle.0.forward

addf encoder.capture-position servo-thread
addf sim-encoder.update-speed servo-thread

addf sim-encoder.make-pulses base-thread
addf encoder.update-counters base-thread
addf limit_speed servo-thread
addf spindle_mass servo-thread
addf rpm_rps servo-thread
addf near_speed servo-thread
addf sim_spindle servo-thread
69 changes: 0 additions & 69 deletions configs/sim/gmoccapy/non_trivial_kinematics/scara/spindle_sim.hal

This file was deleted.

71 changes: 21 additions & 50 deletions configs/sim/gmoccapy/spindle_sim.hal
Original file line number Diff line number Diff line change
@@ -1,69 +1,40 @@
# counting the spindle encoder in software
loadrt encoder names=encoder_0
# simulate the encoder
loadrt sim_encoder names=sim_encoder_0
# simulated spindle with index pulse, for spindle-synced moves (G33, G76, G95)
loadrt sim_spindle names=sim_spindle
loadrt limit2 names=limit_speed
loadrt lowpass names=spindle_mass
loadrt scale names=rpm_rps
loadrt near names=near_speed

addf limit_speed servo-thread

#######################################################
# Beginning of threading related stuff
#######################################################

# spindle speed control
net spindle-speed-cmd spindle.0.speed-out => limit_speed.in
net spindle-speed-limited limit_speed.out => sim_encoder_0.speed

# simulate spindle mass
# spindle speed control, ramped to simulate the spindle mass
net spindle-speed-cmd spindle.0.speed-out => limit_speed.in near_speed.in1
net spindle-speed-limited limit_speed.out => sim_spindle.velocity-cmd spindle_mass.in
setp limit_speed.maxv 3000.0 # rpm/second

# spindle encoder
# connect encoder signals to encoder counter
net spindle-phase-A sim_encoder_0.phase-A => encoder_0.phase-A
net spindle-phase-B sim_encoder_0.phase-B => encoder_0.phase-B
net spindle-phase-Z sim_encoder_0.phase-Z => encoder_0.phase-Z

# assume 120 ppr = 480 counts/rev for the spindle
setp sim_encoder_0.ppr 12
# iocontrol output is in rpm, but sim-encoder speed is rps
setp sim_encoder_0.scale 60
# scale encoder output to read in revolutions
# (that way thread pitches can be straightforward,
# a 20 tpi thread would multiply the encoder output
# by 1/20, etc)
setp encoder_0.position-scale 48
# speed-out is in rpm, sim_spindle wants rps
setp sim_spindle.scale 0.01666667

# encoder reset control
# hook up motion controller's sync output
net spindle-index-enable spindle.0.index-enable <=> encoder_0.index-enable
net spindle-index-enable spindle.0.index-enable <=> sim_spindle.index-enable

# report our revolution count to the motion controller
net spindle-pos encoder_0.position => spindle.0.revs
net spindle-pos sim_spindle.position-fb => spindle.0.revs

# for spindle velocity estimate
loadrt lowpass names=lowpass_velocity
loadrt scale names=scale_to_rpm
net spindle-rps-raw encoder_0.velocity lowpass_velocity.in
net spindle-rps-filtered lowpass_velocity.out scale_to_rpm.in spindle.0.speed-in
net spindle-rpm-filtered scale_to_rpm.out
setp scale_to_rpm.gain 60
setp lowpass_velocity.gain .07
addf lowpass_velocity servo-thread
addf scale_to_rpm servo-thread
setp spindle_mass.gain .07
setp rpm_rps.gain .01666667
net spindle-rpm-filtered spindle_mass.out => rpm_rps.in near_speed.in2
net spindle-rps-filtered rpm_rps.out => spindle.0.speed-in

# for at-speed detection
loadrt near names=near_speed
addf near_speed servo-thread
setp near_speed.scale 1.1
setp near_speed.difference 10
net spindle-speed-cmd => near_speed.in1
net spindle-rpm-filtered => near_speed.in2
net spindle-at-speed near_speed.out spindle.0.at-speed

net spindle-fwd <= spindle.0.forward

addf encoder.capture-position servo-thread
addf sim-encoder.update-speed servo-thread

addf sim-encoder.make-pulses base-thread
addf encoder.update-counters base-thread
addf limit_speed servo-thread
addf spindle_mass servo-thread
addf rpm_rps servo-thread
addf near_speed servo-thread
addf sim_spindle servo-thread
Loading