Closing the servo loop with HAL mesa 7i76

More
06 Jan 2020 18:42 #154164 by Clive S
I am experimenting with closing the loop in HAL

I am using a 7i76 with AC servo using step/dir in position mode. To drive the X axis

I have got the servo to move with jog. and MDI I have connected the encoder output from the drive to the mesa 7i76 TB3 encoder and can see with hal show the encoder pins count etc. counting up and down when rotating the motor shaft by hand.

But the DRO does not update. Q. what pins etc do I need to connect in HAL to achieve this?

#### DEAN servo test
loadrt trivkins
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt hostmot2
loadrt hm2_pci config=" num_encoders=1 num_pwmgens=0 num_stepgens=3 sserial_port_0=00xxxx"
setp hm2_5i25.0.watchdog.timeout_ns 5000000
loadrt pid names=pid.x,pid.s

addf hm2_5i25.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.s.do-pid-calcs servo-thread
addf hm2_5i25.0.write servo-thread

#*******************
# 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 .01

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_5i25.0.stepgen.00.dirsetup [AXIS_0]DIRSETUP
setp hm2_5i25.0.stepgen.00.dirhold [AXIS_0]DIRHOLD
setp hm2_5i25.0.stepgen.00.steplen [AXIS_0]STEPLEN
setp hm2_5i25.0.stepgen.00.stepspace [AXIS_0]STEPSPACE
setp hm2_5i25.0.stepgen.00.position-scale [AXIS_0]STEP_SCALE
setp hm2_5i25.0.stepgen.00.step_type 0
setp hm2_5i25.0.stepgen.00.control-type 1
setp hm2_5i25.0.stepgen.00.maxaccel [AXIS_0]STEPGEN_MAXACCEL
setp hm2_5i25.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_5i25.0.stepgen.00.velocity-cmd
net x-pos-fb <= hm2_5i25.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_5i25.0.stepgen.00.enable

# ---setup home / limit switch signals---

net x-home-sw => axis.0.home-sw-in
net x-neg-limit => axis.0.neg-lim-sw-in
net x-pos-limit => axis.0.pos-lim-sw-in


#******************************

# ---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
net MDI-mode halui.mode.is-mdi


# ---motion control signals---

net in-position <= motion.in-position
net machine-is-enabled <= motion.motion-enabled

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

More
06 Jan 2020 19:10 - 06 Jan 2020 19:11 #154166 by PCW
You would have to change this

net x-pos-fb <= hm2_5i25.0.stepgen.00.position-fb
to
net x-pos-fb <= hm2_5i25.0.encoder.00.position

and in addition make sure the encoder scale and stepgen scale
are commensurate. (expect runaways if these are not right)

in addition you would have to lower the P term to say 10 to start
or you will get massive oscillations because of the much slower
mechanical response of the drive vs the instantaneous response of the
stepgen velocity command.
Last edit: 06 Jan 2020 19:11 by PCW.
The following user(s) said Thank You: Clive S

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

More
06 Jan 2020 19:24 #154167 by Clive S
Thanks for the rapid response Peter.

I have seen you say that many times re the encoder scale and P term. I have P set at 10

I will test it out in the morning.

Does the above close the loop completely. I will be buying a 7i76e + 7i85 to fit to the real machine.

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

More
06 Jan 2020 20:19 - 06 Jan 2020 20:20 #154169 by Clive S

I will test it out in the morning.

Does the above close the loop completely. I will be buying a 7i76e + 7i85 to fit to the real machine.


I could not wait :woohoo:
Adding this change to net x-pos-fb <= hm2_5i25.0.encoder.00.position works as expected.

Just need to sort out the following error as my scales are way out. If I rotate the shaft about 3 revs the DRO shows about 15000mm
Last edit: 06 Jan 2020 20:20 by Clive S. Reason: added text

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

More
07 Jan 2020 17:18 #154223 by Clive S
I have a following error immediately on jog. Where do I look for this please

I notice that I did not have the encoder section in the hal file. before as one turn on the motor was showing about 10Mtr on the dro . adding the encoder section added the ENCODER_SCALE which I have set to 2000 in the ini file.

loadrt trivkins
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt hostmot2
loadrt hm2_pci config=" num_encoders=1 num_pwmgens=0 num_stepgens=3 sserial_port_0=00xxxx"
setp hm2_5i25.0.watchdog.timeout_ns 5000000
loadrt pid names=pid.x,pid.s

addf hm2_5i25.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.s.do-pid-calcs servo-thread
addf hm2_5i25.0.write servo-thread

#*******************
# 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 .01

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_5i25.0.stepgen.00.dirsetup [AXIS_0]DIRSETUP
setp hm2_5i25.0.stepgen.00.dirhold [AXIS_0]DIRHOLD
setp hm2_5i25.0.stepgen.00.steplen [AXIS_0]STEPLEN
setp hm2_5i25.0.stepgen.00.stepspace [AXIS_0]STEPSPACE
setp hm2_5i25.0.stepgen.00.position-scale [AXIS_0]STEP_SCALE
setp hm2_5i25.0.stepgen.00.step_type 0
setp hm2_5i25.0.stepgen.00.control-type 1
setp hm2_5i25.0.stepgen.00.maxaccel [AXIS_0]STEPGEN_MAXACCEL
setp hm2_5i25.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_5i25.0.stepgen.00.velocity-cmd
net x-pos-fb <= hm2_5i25.0.encoder.00.position
net x-pos-fb => axis.0.motor-pos-fb
net x-enable <= axis.0.amp-enable-out
net x-enable => hm2_5i25.0.stepgen.00.enable

# ---Encoder feedback signals/setup---

setp hm2_5i25.0.encoder.00.counter-mode 0
setp hm2_5i25.0.encoder.00.filter 1
setp hm2_5i25.0.encoder.00.index-invert 0
setp hm2_5i25.0.encoder.00.index-mask 0
setp hm2_5i25.0.encoder.00.index-mask-invert 0
setp hm2_5i25.0.encoder.00.scale [AXIS_0]ENCODER_SCALE

############################
Ini file

[EMC]

[DISPLAY]
DISPLAY = axis
POSITION_OFFSET = RELATIVE

POSITION_FEEDBACK = ACTUAL
DEFAULT_LINEAR_VELOCITY = 6.000000
MAX_LINEAR_VELOCITY = 25.000000
MIN_LINEAR_VELOCITY = 0.500000


[HOSTMOT2]
# **** This is for info only ****
# DRIVER0=hm2_pci
# BOARD0=5i25


[TRAJ]
AXES = 3
COORDINATES = X
LINEAR_UNITS = mm
ANGULAR_UNITS = degree
CYCLE_TIME = 0.010
DEFAULT_VELOCITY = 10
MAX_LINEAR_VELOCITY = 25.00
NO_FORCE_HOMING = 1

[EMCIO]
EMCIO = io
CYCLE_TIME = 0.100
TOOL_TABLE = tool.tbl

#********************
# Axis X
#********************
[AXIS_0]
TYPE = LINEAR
HOME = 0.0
FERROR = 10.0
MIN_FERROR = 1.0
MAX_VELOCITY = 25.0
MAX_ACCELERATION = 500

STEPGEN_MAXVEL = 31.25
STEPGEN_MAXACCEL = 600
P = 1.0
I = 0.01
D = 0.0
FF0 = 0.0
FF1 = 0.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_OUTPUT = 0.0

ENCODER_SCALE = 2000.0

# these are in nanoseconds
DIRSETUP = 1000
DIRHOLD = 1000
STEPLEN = 1000
STEPSPACE = 1000
STEP_SCALE = 200

MIN_LIMIT = -0.01
MAX_LIMIT = 400.0
HOME_OFFSET = 0.0

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

More
07 Jan 2020 17:28 #154225 by PCW
Are the scales correct (200 steps per mm and 2000 counts per mm?)

Is the encoder direction the same as the step/dir commanded direction?

You will need a FF1 of 1.0
The following user(s) said Thank You: Clive S

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

More
07 Jan 2020 18:10 #154228 by Clive S

Are the scales correct (200 steps per mm and 2000 counts per mm?)

Is the encoder direction the same as the step/dir commanded direction?

You will need a FF1 of 1.0

I have put FF1 to 1

Not sure about the (200 steps per mm and 2000 counts per mm?) these were just guesses the servo is only on the bench.
Thinking about that perhaps the encoder count should be 2500 !!

I have tried -200 and 2000 then tried 200 and -2000 no difference .

Jogging with right arrow the DRO goes -ve and turning the motor clockwise looking up the shaft by hand the DRO goes -ve

As always thanks for your time.

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

More
07 Jan 2020 18:40 #154232 by PCW
You need to get both scales correct before starting

If you go back to open loop, is the step scaling correct?

You can verify the encoder scaling by running open loop
and moving say 100 mm and seeing if the encoder position pin
changes by 100 mm

(open loop tuning is P=1000, FF1 = 1)

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

More
07 Jan 2020 18:57 #154234 by Clive S

You can verify the encoder scaling by running open loop
and moving say 100 mm and seeing if the encoder position pin
changes by 100 mm


The motor is on the bench free standing. Do you mean 100mm with MDI ie X100 and then check the encoder position pin ?

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

More
07 Jan 2020 19:43 #154242 by PCW
Yes
You should also be able to check the scale by commanding one turn worth of motion (say 5mm for 5mm pitch ballscrew) and verifying that the motor makes 1 turn. If this works, command 10 or 100 turns worth of motion and verify the the motor shaft ends up in the same place...
The following user(s) said Thank You: Clive S

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

Time to create page: 0.181 seconds
Powered by Kunena Forum