close loop whith step motor and encoder
31 Jan 2013 03:38 #29334
by maytzuc
close loop whith step motor and encoder was created by maytzuc
Hello, I read in several places that one of the advantages of linuxcnc is its ability to generate a closed loop between the stepper motor and encoder. Two weeks I've been looking for ways to generate this but can not find how. The only thing I could do is control the motor and reading of the encoder, but I can not find how to close the loop. I've tried using PID, not knowing if I got what it takes and the fedback PID positicion equals the engine, repeating that I'm not sure if I'm doing well. I managed to make my code attempt with a little bit of information on the web and carefully reading each book, I hope someone can help me please, and sorry for my English writing.
# Generated by stepconf at Fri Jan 25 09:34:03 2013
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt probe_parport
loadrt hal_parport cfg="0x378 out "
loadrt encoder num_chan=1
loadrt pid num_chan=1
loadrt stepgen step_type=0,0,0
addf parport.0.read base-thread
addf encoder.update-counters base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread
addf encoder.capture-position servo-thread
addf stepgen.capture-position servo-thread
addf pid.0.do-pid-calcs servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
setp encoder.0.position-scale 2500.00
addf stepgen.update-freq servo-thread
net spindle-cmd <= motion.spindle-speed-out
net Xpos-fb => pid.0.feedback
net xoutput <= pid.0.output
net enc0A encoder.0.phase-A <= parport.0.pin-10-in
net enc0B encoder.0.phase-B <= parport.0.pin-12-in
net Xpos-fb <= encoder.0.position
net estop-out => parport.0.pin-01-out
net xstep => parport.0.pin-08-out
net xdir => parport.0.pin-14-out
net xenable => parport.0.pin-17-out
setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 1
setp stepgen.0.dirhold 40000
setp stepgen.0.dirsetup 40000
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
net xpos-cmd axis.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => axis.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable axis.0.amp-enable-out => stepgen.0.enable
#set PID output limit to /- 1.00
setp pid.0.maxoutput [AXIS_0]MAX_VELOCITY
# establecemos los parametros los cuales vendran del archivo ini
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
#deadband should be just over 1 count
setp pid.0.deadband [AXIS_0]DEADBAND
#posotion comand signal
#net xpos-cmd axis.0.motor-pos-cmd =>pid.0.command
net xpos-fb axis.0.motor-pos-fb => pid.0.command
#axis enable signals
net xenable axis.0.amp-enable-out => pid.0.enable
net estop-out <= iocontrol.0.user-enable-out
net estop-out => iocontrol.0.emc-enable-in
loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
# Generated by stepconf at Fri Jan 25 09:34:03 2013
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt probe_parport
loadrt hal_parport cfg="0x378 out "
loadrt encoder num_chan=1
loadrt pid num_chan=1
loadrt stepgen step_type=0,0,0
addf parport.0.read base-thread
addf encoder.update-counters base-thread
addf stepgen.make-pulses base-thread
addf parport.0.write base-thread
addf encoder.capture-position servo-thread
addf stepgen.capture-position servo-thread
addf pid.0.do-pid-calcs servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
setp encoder.0.position-scale 2500.00
addf stepgen.update-freq servo-thread
net spindle-cmd <= motion.spindle-speed-out
net Xpos-fb => pid.0.feedback
net xoutput <= pid.0.output
net enc0A encoder.0.phase-A <= parport.0.pin-10-in
net enc0B encoder.0.phase-B <= parport.0.pin-12-in
net Xpos-fb <= encoder.0.position
net estop-out => parport.0.pin-01-out
net xstep => parport.0.pin-08-out
net xdir => parport.0.pin-14-out
net xenable => parport.0.pin-17-out
setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 1
setp stepgen.0.dirhold 40000
setp stepgen.0.dirsetup 40000
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
net xpos-cmd axis.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => axis.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable axis.0.amp-enable-out => stepgen.0.enable
#set PID output limit to /- 1.00
setp pid.0.maxoutput [AXIS_0]MAX_VELOCITY
# establecemos los parametros los cuales vendran del archivo ini
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
#deadband should be just over 1 count
setp pid.0.deadband [AXIS_0]DEADBAND
#posotion comand signal
#net xpos-cmd axis.0.motor-pos-cmd =>pid.0.command
net xpos-fb axis.0.motor-pos-fb => pid.0.command
#axis enable signals
net xenable axis.0.amp-enable-out => pid.0.enable
net estop-out <= iocontrol.0.user-enable-out
net estop-out => iocontrol.0.emc-enable-in
loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
Please Log in or Create an account to join the conversation.
31 Jan 2013 08:26 - 31 Jan 2013 08:27 #29346
by BigJohnT
Replied by BigJohnT on topic close loop whith step motor and encoder
Your English seems fine to me. To quote code use the code tags please.
Stepconf is designed for simple configurations only. Trying to use encoder feedback with a stepper is not an easy thing to do and is not normally done.
A couple of things I know are:
the encoder resolution must be > 2 times the step rate
the stepgen must be used in velocity mode.
Search the wiki for more information, there have been a couple of claims of success but like I said it is not really practical. I think Andy put it the best a day or two ago here on the forum... imagine you lose a steps because you have gone too fast and the stepgen makes faster step pulses you just get deeper into the hole...
John
Stepconf is designed for simple configurations only. Trying to use encoder feedback with a stepper is not an easy thing to do and is not normally done.
A couple of things I know are:
the encoder resolution must be > 2 times the step rate
the stepgen must be used in velocity mode.
Search the wiki for more information, there have been a couple of claims of success but like I said it is not really practical. I think Andy put it the best a day or two ago here on the forum... imagine you lose a steps because you have gone too fast and the stepgen makes faster step pulses you just get deeper into the hole...
John
Last edit: 31 Jan 2013 08:27 by BigJohnT.
Please Log in or Create an account to join the conversation.
Time to create page: 0.103 seconds