STEP/DIR output and encoder input. How to connect?

More
20 Aug 2010 11:52 #3832 by aike
Hi!
I use servo-drive with step/dir pulses. The motor of this drive has encoder. A B & Index pulses come to Mesa card.
I try to create feedback with PID to control mesa stepgen. Unfortunatly.
Here is the sample code of HAL. Plese check it and tell me the errors.
All finctions connected to thread and all loaded.
######### HAL example for X axis ##################
#PID
# set PID loop gains from inifile
setp pid.0.Pgain 1.0
setp pid.0.Igain 0.0
setp pid.0.Dgain 0.0
setp pid.0.bias 0.0
setp pid.0.FF0 1.0
setp pid.0.FF1 0.0
setp pid.0.FF2 0.0
setp pid.0.deadband 0.000015
setp pid.0.maxoutput 100.0

#set encoder scale
setp hm2_5i20.0.encoder.00.scale [AXIS_0]SCALE

#connect Mesa encoder to PID
net Xpos-fb hm2_5i20.0.encoder.00.position => pid.0.feedback
#push copy back to Axis GUI
net Xpos-fb => axis.0.motor-pos-fb

#translate command to pid
net Xpos-cmd <= axis.0.motor-pos-cmd
net Xpos-cmd => pid.0.command

#allow PID and stepgen work
net Xenable <= axis.0.amp-enable-out
net Xenable => pid.0.enable hm2_5i20.0.stepgen.00.enable

#pid output to stepgen command position
net Xoutput <= pid.0.output
net Xoutput => hm2_5i20.0.stepgen.00.position-cmd

#set stepgen
setp hm2_5i20.0.stepgen.00.dirsetup [AXIS_0]DIRSETUP
setp hm2_5i20.0.stepgen.00.dirhold [AXIS_0]DIRHOLD
setp hm2_5i20.0.stepgen.00.steplen [AXIS_0]STEPLEN
setp hm2_5i20.0.stepgen.00.stepspace [AXIS_0]STEPSPACE
setp hm2_5i20.0.stepgen.00.position-scale [AXIS_0]SCALE
setp hm2_5i20.0.stepgen.00.maxaccel 0
setp hm2_5i20.0.stepgen.00.maxvel 0
setp hm2_5i20.0.stepgen.00.step_type 0

Please Log in or Create an account to join the conversation.

More
20 Aug 2010 16:05 - 20 Aug 2010 16:08 #3833 by PCW
Not exactly sure what you are trying to accomplish here as the servo drive has its own position PID loop,
which keeps the motor position locked to the step count, and EMCs loop would mainly duplicate the drives PID loop.

Does the drive work ok in open loop mode? (setup like a step motor)?


If you still want to try using EMC to close the loop, I see at least 2 errors

1.
setp hm2_5i20.0.stepgen.00.step_type 0
this should be step type 1 (velocity mode)

2.
net Xoutput => hm2_5i20.0.stepgen.00.position-cmd
this should be hm2_5i20.0.stepgen.00.velocity-cmd
Last edit: 20 Aug 2010 16:08 by PCW. Reason: clarify

Please Log in or Create an account to join the conversation.

More
23 Aug 2010 13:07 #3852 by andypugh
aike wrote:

Hi!
I use servo-drive with step/dir pulses. The motor of this drive has encoder. A B & Index pulses come to Mesa card.
I try to create feedback with PID to control mesa stepgen.

I think that is probably the wrong way to do it.
It is probably better to let the step/direction drives handle the positioning, and only use the encode feedback to check for following errors and display.

ie, connect
XXX.motor-pos-cmd => YYYstepgen.position-cmd
YYY.encoder.position => XXX.motor-pos-fb.

If you really want the position loop to be inside EMC (And there are definitely reasons why you might) then you might get better results with a velocity-mode stepgen.

Please Log in or Create an account to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum