hal/python control scheme help
26 Aug 2017 19:51 #98048
by blazini36
Replied by blazini36 on topic hal/python control scheme help
I'm having a pretty tough time putting this together in hal. I've been bouncing back and forth with the docs and so far I have a custom.hal file that probably doesn't make any sense.
Any chance you could help me out with an example?
my hal file
Any chance you could help me out with an example?
my hal file
# Generated by PNCconf at Sun Jul 16 19:11:56 2017
# If you make changes to this file, they will be
# overwritten when you run PNCconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt hostmot2
loadrt hm2_eth board_ip="10.10.10.10" config="firmware=hm2/7i76/7i76e.BIT num_encoders=1 num_pwmgens=0 num_stepgens=5 sserial_port_0=00xxxx"
setp hm2_7i76e.0.watchdog.timeout_ns 5000000
loadrt pid names=pid.x,pid.y,pid.z,pid.s
loadrt abs names=abs.spindle
loadrt lowpass names=lowpass.spindle
loadrt scale names=scale.spindle
addf hm2_7i76e.0.read servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf pid.x.do-pid-calcs servo-thread
addf pid.y.do-pid-calcs servo-thread
addf scale.spindle servo-thread
addf abs.spindle servo-thread
addf lowpass.spindle servo-thread
addf hm2_7i76e.0.write servo-thread
setp hm2_7i76e.0.dpll.01.timer-us -50
setp hm2_7i76e.0.stepgen.timer-number 1
# external output signals
# --- CAM0_TRIGGER_OUT ---
net cam0_trigger_OUT hm2_7i76e.0.7i76.0.0.output-00
# --- CAM0_FLASH_TRIGGER_OUT ---
net cam0_flash_trigger_OUT hm2_7i76e.0.7i76.0.0.output-01
# --- CAM1_TRIGGER_OUT ---
net cam1_trigger_OUT hm2_7i76e.0.7i76.0.0.output-04
# --- CAM1_FLASH_TRIGGER_OUT ---
net cam1_flash_trigger_OUT hm2_7i76e.0.7i76.0.0.output-05
# --- FLASH_INTENSITY_AOUT ---
# net Flash_intensity_AOUT-enable => hm2_7i76e.0.7i76.0.0..spinena
# net Flash_intensity_AOUT-output => hm2_7i76e.0.7i76.0.0..spinout
# net Flash_intensity_AOUT-direction => hm2_7i76e.0.7i76.0.0..spindir
# external input signals
# --- MIN-X ---
net min-x <= hm2_7i76e.0.7i76.0.0.input-00
# --- MAX-X ---
net max-x <= hm2_7i76e.0.7i76.0.0.input-01
# --- HOME-X ---
net home-x <= hm2_7i76e.0.7i76.0.0.input-02
# --- MIN-Y ---
net min-y <= hm2_7i76e.0.7i76.0.0.input-08
# --- MAX-Y ---
net max-y <= hm2_7i76e.0.7i76.0.0.input-09
# --- HOME-Y ---
net home-y <= hm2_7i76e.0.7i76.0.0.input-10
# --- DIN-01 ---
net Park-Cams <= hm2_7i76e.0.7i76.0.0.input-16
# --- DIN-01 ---
net cue-sense <= hm2_7i76e.0.7i76.0.0.input-17
#*******************
# AXIS X
#*******************
setp pid.x.Pgain [AXIS_0]P
setp pid.x.Igain [AXIS_0]I
setp pid.x.Dgain [AXIS_0]D
setp pid.x.bias [AXIS_0]BIAS
setp pid.x.FF0 [AXIS_0]FF0
setp pid.x.FF1 [AXIS_0]FF1
setp pid.x.FF2 [AXIS_0]FF2
setp pid.x.deadband [AXIS_0]DEADBAND
setp pid.x.maxoutput [AXIS_0]MAX_OUTPUT
setp pid.x.error-previous-target true
setp pid.x.maxerror .0005
net x-index-enable <=> pid.x.index-enable
net x-enable => pid.x.enable
net x-pos-cmd => pid.x.command
net x-vel-cmd => pid.x.command-deriv
net x-pos-fb => pid.x.feedback
net x-output => pid.x.output
# Step Gen signals/setup
setp hm2_7i76e.0.stepgen.00.dirsetup [AXIS_0]DIRSETUP
setp hm2_7i76e.0.stepgen.00.dirhold [AXIS_0]DIRHOLD
setp hm2_7i76e.0.stepgen.00.steplen [AXIS_0]STEPLEN
setp hm2_7i76e.0.stepgen.00.stepspace [AXIS_0]STEPSPACE
setp hm2_7i76e.0.stepgen.00.position-scale [AXIS_0]STEP_SCALE
setp hm2_7i76e.0.stepgen.00.step_type 0
setp hm2_7i76e.0.stepgen.00.control-type 1
setp hm2_7i76e.0.stepgen.00.maxaccel [AXIS_0]STEPGEN_MAXACCEL
setp hm2_7i76e.0.stepgen.00.maxvel [AXIS_0]STEPGEN_MAXVEL
# ---closedloop stepper signals---
net x-pos-cmd <= axis.0.motor-pos-cmd
net x-vel-cmd <= axis.0.joint-vel-cmd
net x-output <= hm2_7i76e.0.stepgen.00.velocity-cmd
net x-pos-fb <= hm2_7i76e.0.stepgen.00.position-fb
net x-pos-fb => axis.0.motor-pos-fb
net x-enable <= axis.0.amp-enable-out
net x-enable => hm2_7i76e.0.stepgen.00.enable
# ---setup home / limit switch signals---
net home-x => axis.0.home-sw-in
net min-x => axis.0.neg-lim-sw-in
net max-x => axis.0.pos-lim-sw-in
#*******************
# AXIS Y
#*******************
setp pid.y.Pgain [AXIS_1]P
setp pid.y.Igain [AXIS_1]I
setp pid.y.Dgain [AXIS_1]D
setp pid.y.bias [AXIS_1]BIAS
setp pid.y.FF0 [AXIS_1]FF0
setp pid.y.FF1 [AXIS_1]FF1
setp pid.y.FF2 [AXIS_1]FF2
setp pid.y.deadband [AXIS_1]DEADBAND
setp pid.y.maxoutput [AXIS_1]MAX_OUTPUT
setp pid.y.error-previous-target true
setp pid.y.maxerror .0005
net y-index-enable <=> pid.y.index-enable
net y-enable => pid.y.enable
net y-pos-cmd => pid.y.command
net y-vel-cmd => pid.y.command-deriv
net y-pos-fb => pid.y.feedback
net y-output => pid.y.output
# Step Gen signals/setup
setp hm2_7i76e.0.stepgen.01.dirsetup [AXIS_1]DIRSETUP
setp hm2_7i76e.0.stepgen.01.dirhold [AXIS_1]DIRHOLD
setp hm2_7i76e.0.stepgen.01.steplen [AXIS_1]STEPLEN
setp hm2_7i76e.0.stepgen.01.stepspace [AXIS_1]STEPSPACE
setp hm2_7i76e.0.stepgen.01.position-scale [AXIS_1]STEP_SCALE
setp hm2_7i76e.0.stepgen.01.step_type 0
setp hm2_7i76e.0.stepgen.01.control-type 1
setp hm2_7i76e.0.stepgen.01.maxaccel [AXIS_1]STEPGEN_MAXACCEL
setp hm2_7i76e.0.stepgen.01.maxvel [AXIS_1]STEPGEN_MAXVEL
# ---closedloop stepper signals---
net y-pos-cmd <= axis.1.motor-pos-cmd
net y-vel-cmd <= axis.1.joint-vel-cmd
net y-output <= hm2_7i76e.0.stepgen.01.velocity-cmd
net y-pos-fb <= hm2_7i76e.0.stepgen.01.position-fb
net y-pos-fb => axis.1.motor-pos-fb
net y-enable <= axis.1.amp-enable-out
net y-enable => hm2_7i76e.0.stepgen.01.enable
# ---setup home / limit switch signals---
net home-y => axis.1.home-sw-in
net min-y => axis.1.neg-lim-sw-in
net max-y => axis.1.pos-lim-sw-in
#*******************
# SPINDLE S
#*******************
setp pid.s.Pgain [SPINDLE_9]P
setp pid.s.Igain [SPINDLE_9]I
setp pid.s.Dgain [SPINDLE_9]D
setp pid.s.bias [SPINDLE_9]BIAS
setp pid.s.FF0 [SPINDLE_9]FF0
setp pid.s.FF1 [SPINDLE_9]FF1
setp pid.s.FF2 [SPINDLE_9]FF2
setp pid.s.deadband [SPINDLE_9]DEADBAND
setp pid.s.maxoutput [SPINDLE_9]MAX_OUTPUT
setp pid.s.error-previous-target true
net spindle-index-enable <=> pid.s.index-enable
net spindle-enable => pid.s.enable
net spindle-vel-cmd-rpm => pid.s.command
net spindle-vel-fb-rpm => pid.s.feedback
net spindle-output <= pid.s.output
# ---Encoder feedback signals/setup---
setp hm2_7i76e.0.encoder.00.counter-mode 0
setp hm2_7i76e.0.encoder.00.filter 1
setp hm2_7i76e.0.encoder.00.index-invert 0
setp hm2_7i76e.0.encoder.00.index-mask 0
setp hm2_7i76e.0.encoder.00.index-mask-invert 0
setp hm2_7i76e.0.encoder.00.scale [SPINDLE_9]ENCODER_SCALE
net spindle-revs <= hm2_7i76e.0.encoder.00.position
net spindle-vel-fb-rps <= hm2_7i76e.0.encoder.00.velocity
net spindle-index-enable <=> hm2_7i76e.0.encoder.00.index-enable
# ---setup spindle control signals---
net spindle-vel-cmd-rps <= motion.spindle-speed-out-rps
net spindle-vel-cmd-rps-abs <= motion.spindle-speed-out-rps-abs
net spindle-vel-cmd-rpm <= motion.spindle-speed-out
net spindle-vel-cmd-rpm-abs <= motion.spindle-speed-out-abs
net spindle-enable <= motion.spindle-on
net spindle-cw <= motion.spindle-forward
net spindle-ccw <= motion.spindle-reverse
net spindle-brake <= motion.spindle-brake
net spindle-revs => motion.spindle-revs
net spindle-at-speed => motion.spindle-at-speed
net spindle-vel-fb-rps => motion.spindle-speed-in
net spindle-index-enable <=> motion.spindle-index-enable
# ---Setup spindle at speed signals---
sets spindle-at-speed true
# Use ACTUAL spindle velocity from spindle encoder
# spindle-velocity bounces around so we filter it with lowpass
# spindle-velocity is signed so we use absolute component to remove sign
# ACTUAL velocity is in RPS not RPM so we scale it.
setp scale.spindle.gain 60
setp lowpass.spindle.gain 1.000000
net spindle-vel-fb-rps => scale.spindle.in
net spindle-fb-rpm scale.spindle.out => abs.spindle.in
net spindle-fb-rpm-abs abs.spindle.out => lowpass.spindle.in
net spindle-fb-rpm-abs-filtered lowpass.spindle.out
#******************************
# connect miscellaneous signals
#******************************
# ---HALUI signals---
net joint-select-a halui.joint.0.select
net x-is-homed halui.joint.0.is-homed
net jog-x-pos halui.jog.0.plus
net jog-x-neg halui.jog.0.minus
net jog-x-analog halui.jog.0.analog
net jog-selected-pos halui.jog.selected.plus
net jog-selected-neg halui.jog.selected.minus
net spindle-manual-cw halui.spindle.forward
net spindle-manual-ccw halui.spindle.reverse
net spindle-manual-stop halui.spindle.stop
net machine-is-on halui.machine.is-on
net jog-speed halui.jog-speed
# ---coolant signals---
net coolant-mist <= iocontrol.0.coolant-mist
net coolant-flood <= iocontrol.0.coolant-flood
# ---probe signal---
net probe-in => motion.probe-input
# ---motion control signals---
net in-position <= motion.in-position
net machine-is-enabled <= motion.motion-enabled
# ---digital in / out signals---
# ---estop signals---
net estop-out <= iocontrol.0.user-enable-out
net estop-out => iocontrol.0.emc-enable-in
# ---toolchange signals for custom tool changer---
net tool-number <= iocontrol.0.tool-prep-number
net tool-change-request <= iocontrol.0.tool-change
net tool-change-confirmed => iocontrol.0.tool-changed
net tool-prepare-request <= iocontrol.0.tool-prepare
net tool-prepare-confirmed => iocontrol.0.tool-prepared
Please Log in or Create an account to join the conversation.
30 Aug 2017 00:19 #98171
by blazini36
Replied by blazini36 on topic hal/python control scheme help
I'm working on this and I could have sworn that in halshow the hm2_7i76e.0.encoder.00.input-index pin would go true as the sensor on it went high. If I setp index-enable true the sensor going high changes the enable pin to false so I know it's being seen by the board. I should just be able to put the updown function on a field input right? we're probably talking 50hz max. Any Idea of the max GPIO speed? I'm sure it's above 50hz
Please Log in or Create an account to join the conversation.
30 Aug 2017 03:41 - 30 Aug 2017 03:41 #98175
by PCW
Replied by PCW on topic hal/python control scheme help
Both the hm2_7i76e.0.encoder.00.input-index pin and the field I/O are sampled at the servo thread rate so normally every
1 millisecond. So as long as the input high and low times are greater than 1 ms you should be fine
You may not see them reliably using the watch or halmeter functions since with default settings,
the GUI is only updated about 10 times per second, but you can check them with halscope.
1 millisecond. So as long as the input high and low times are greater than 1 ms you should be fine
You may not see them reliably using the watch or halmeter functions since with default settings,
the GUI is only updated about 10 times per second, but you can check them with halscope.
Last edit: 30 Aug 2017 03:41 by PCW.
Please Log in or Create an account to join the conversation.
30 Aug 2017 04:12 #98178
by blazini36
Replied by blazini36 on topic hal/python control scheme help
I'm was triggering the sensor slowly by hand, I never changed to voltage divider so the pin may not have been going completely low, but it did trigger index-enable false. the GPIO input
I'm writing a new hal file for this and I'm using updown as you suggested for the sensor I'm using for the index and it works.
My issue is I'm not sure what to do with the comparator you mentioned, I can't figure out how that works.
right now im trying to run encoder counts into another updown which might work but I'm afraid I'm using too much software to do this.
I'm writing a new hal file for this and I'm using updown as you suggested for the sensor I'm using for the index and it works.
My issue is I'm not sure what to do with the comparator you mentioned, I can't figure out how that works.
right now im trying to run encoder counts into another updown which might work but I'm afraid I'm using too much software to do this.
Please Log in or Create an account to join the conversation.
30 Aug 2017 06:40 #98182
by blazini36
Replied by blazini36 on topic hal/python control scheme help
I figured out the use of comparator and actually managed to write a hal file. This works exactly as intended.
Would you say this is an efficient way to do this?
loadrt updown names=updown.contrast
loadrt conv_s32_bit names=conv_s32_bit.contrast
loadrt offset names=offset.encoder
loadrt comp names=comp.trigger
addf updown.encoder servo-thread
addf updown.contrast servo-thread
addf conv_s32_bit.contrast servo-thread
addf comp.trigger servo-thread
####trigger encoder index enable on value of setp updown.contrast.max######
net contrast_count updown.contrast.countup <= hm2_7i76e.0.7i76.0.0.input-17
net contrast_limit_reached conv_s32_bit.contrast.in <= updown.contrast.count
net contrast_reset_encdr hm2_7i76e.0.encoder.00.reset <= conv_s32_bit.contrast.out
#####count encoder and trigger camera on comp.trigger.in0#####
net trigger_position comp.trigger.in1 <= hm2_7i76e.0.encoder.00.position
net cam0_trigger_OUT <= comp.trigger.out
setp hm2_7i76e.0.encoder.00.counter-mode 1
setp hm2_7i76e.0.encoder.00.scale [WEB_1]ENCODER_SCALE
setp updown.contrast.wrap true
setp updown.contrast.max 2
#####comparator input for trigger offset########
setp comp.trigger.in0 25
Would you say this is an efficient way to do this?
loadrt updown names=updown.contrast
loadrt conv_s32_bit names=conv_s32_bit.contrast
loadrt offset names=offset.encoder
loadrt comp names=comp.trigger
addf updown.encoder servo-thread
addf updown.contrast servo-thread
addf conv_s32_bit.contrast servo-thread
addf comp.trigger servo-thread
####trigger encoder index enable on value of setp updown.contrast.max######
net contrast_count updown.contrast.countup <= hm2_7i76e.0.7i76.0.0.input-17
net contrast_limit_reached conv_s32_bit.contrast.in <= updown.contrast.count
net contrast_reset_encdr hm2_7i76e.0.encoder.00.reset <= conv_s32_bit.contrast.out
#####count encoder and trigger camera on comp.trigger.in0#####
net trigger_position comp.trigger.in1 <= hm2_7i76e.0.encoder.00.position
net cam0_trigger_OUT <= comp.trigger.out
setp hm2_7i76e.0.encoder.00.counter-mode 1
setp hm2_7i76e.0.encoder.00.scale [WEB_1]ENCODER_SCALE
setp updown.contrast.wrap true
setp updown.contrast.max 2
#####comparator input for trigger offset########
setp comp.trigger.in0 25
Please Log in or Create an account to join the conversation.
Time to create page: 0.072 seconds