rendered paste body# components
loadrt pid num_chan=4
#
# 0x378,0x778 is the on-board parallel port (cable has radioshack logo)
# 0xdc48,0xdc50 is the parallel port on the pci card (cable has no logo)
#
loadrt hostmot2 debug_idrom=1 debug_module_descriptors=1 debug_pin_descriptors=1 debug_modules=1
loadrt probe_parport
loadusr -w /home/seb/emc2/bfload/bin/bfload 7i43=/home/seb/emc2/hm2/src/hal/drivers/mesa7i43-firmware/hostmot2/svst4_4s.bit
#loadusr -w /home/seb/emc2/bfload/bin/bfload 7i43=/home/seb/emc2/hm2/src/hal/drivers/mesa-hostmot2/firmware/7i43/SVST4_4B.BIT
#loadusr -w /home/seb/emc2/bfload/bin/bfload 7i43=/home/seb/emc2/hm2/src/hal/drivers/mesa-hostmot2/firmware/7i43/SV8B.BIT
loadrt hm2_7i43 ioaddr=0x0378 config="num_encoders=3 num_pwmgens=3 num_stepgens=1"
loadusr -w /home/seb/emc2/bfload/bin/bfload 5i20=/home/seb/emc2/hm2/src/hal/drivers/mesa-hostmot2/firmware/5i20/SVST8_4.BIT
loadrt hm2_5i20
#
# set up the watchdogs
#
setp hm2_7i43.0.watchdog.timeout_ns 10000000
setp hm2_5i20.0.watchdog.timeout_ns 10000000
#
# set up the encoders, encoder position becomes pid's feedback
#
setp hm2_7i43.0.encoder.00.scale -1024
setp hm2_7i43.0.encoder.01.scale -2048
setp hm2_7i43.0.encoder.02.scale -2048
net motor-00-position hm2_7i43.0.encoder.00.position => pid.0.feedback
net motor-01-position hm2_7i43.0.encoder.01.position => pid.1.feedback
#
# let the pid outputs drive the pwm generators
#
setp hm2_7i43.0.pwmgen.00.scale .0002442002
setp hm2_7i43.0.pwmgen.01.scale .0002442002
setp hm2_7i43.0.pwmgen.02.scale .0002442002
net pid-00-command pid.0.output => hm2_7i43.0.pwmgen.00.value
net pid-01-command pid.1.output => hm2_7i43.0.pwmgen.01.value
#
# PID config
#
# Tuning on the workbench:
# without a load
# servo thread at 1 ms
# encoder.scale = -1024
# pwmgen.scale = .0002442002 (goes from -1.0 to +1.0
#
#
# Old:
#
# I get oscillation at Pgain = Kc = 14.5, no oscillation at 14.
# Oscillation period is Pc = 0.029 s.
#
# So by Ziegler-Nichols, I should have P=0.6Kc, I=Pc/2, D=Pc/8
#
# This gives me 5 or 6 zero-crossing overshoots on the error signal,
# and it settles with an error up to 0.027 revolutions.
#
# In the steady state, the motor is squeaky because the PWM duty cycle
# never goes to zero. If i turn up the pid.deadband, the stable error gets
# worse.
#
# By twisting the shaft slowly, I can get a stable error of up to 0.067.
#
setp pid.0.Pgain 2.0
setp pid.0.Igain 0.0
setp pid.0.Dgain 0.0
setp pid.0.FF0 0
setp pid.0.FF1 0
setp pid.0.FF2 0
setp pid.0.bias 0
setp pid.0.deadband 0.0005
setp pid.0.maxoutput 0
setp pid.1.Pgain 2.0
setp pid.1.Igain 0.0
setp pid.1.Dgain 0.0
setp pid.1.FF0 0
setp pid.1.FF1 0
setp pid.1.FF2 0
setp pid.1.bias 0
setp pid.1.deadband 0.0005
setp pid.1.maxoutput 0
#
# stepgen
#
setp hm2_7i43.0.stepgen.00.dirsetup 0.0000002
setp hm2_7i43.0.stepgen.00.dirhold 0.0000002
setp hm2_7i43.0.stepgen.00.steplen 0.000040
setp hm2_7i43.0.stepgen.00.stepspace 0.000040
setp hm2_7i43.0.stepgen.00.position-scale 1600
#
# stepper 0 and servos 0 and 1 clone servo 2's position
#
net follow-the-leader hm2_7i43.0.encoder.02.position => pid.0.command pid.1.command hm2_7i43.0.stepgen.00.position-cmd
#
# enable
#
newsig Enable bit
sets Enable FALSE
net Enable => pid.0.enable pid.1.enable hm2_7i43.0.pwmgen.00.enable hm2_7i43.0.pwmgen.01.enable
#
# realtime threads & functions
#
loadrt threads name1=epp fp1=1 period1=1000000 name2=pci fp2=1 period2=1000000
addf hm2_7i43.0.pet_watchdog epp
addf hm2_7i43.0.read epp
addf pid.0.do-pid-calcs epp
addf pid.1.do-pid-calcs epp
addf hm2_7i43.0.write epp
addf hm2_5i20.0.pet_watchdog pci
addf hm2_5i20.0.read pci
addf hm2_5i20.0.write pci
#
# set up some halmeters
#
#loadusr halmeter -s pin hm2_7i43.0.watchdog.has_bit
#loadusr halmeter -s param hm2_7i43.0.io_error
#loadusr halmeter -s pin hm2_7i43.0.encoder.01.position
#
# ok, all set up
#
start
sets Enable 1