Saturday 3 April 2021

PID tuning the X and Z axes

Setting up the tools:

I set up the "configuration" tool using the menu within LinuxCNC. This allows you to change the main PID parameters and test them on a live system. 

Also set up the Halscope tool (also available from the manu) to display the demand and follow error signals, so get an idea of how the changes were affecting the response. And turning round to observe the ballscrews rotating - nothing like a visual to get a feel for how good it actually is in the metal. 

First settings for the X axis that seemed almost workable:

 

Almost final values:


You can write the values back to your INI file (if you choose). Here's what I've got so far:

[JOINT_0]
TYPE = LINEAR
# HOME is the distance the axis moves - AFTER setting home position zero
# MAKE CERTAIN IT IS NEGATIVE ON X AXIS!!
# It can be within the soft limits but will error if it's not.
HOME = 0.000
FERROR = 10
MIN_FERROR = 1.00
MAX_VELOCITY = 50
MAX_ACCELERATION = 100.0
BACKLASH = 0.000
....

STEPGEN_MAXVEL = 125
STEPGEN_MAXACCEL = 750
P = 30
I = 0.2
D = 5
FF0 = 0
FF1 = 1
FF2 = 0
BIAS = 0
DEADBAND = 0.0025
MAX_OUTPUT = 0
....


[JOINT_1]
TYPE = LINEAR
HOME = 0.0
FERROR = 300.0
MIN_FERROR = 1.0
MAX_VELOCITY = 100
MAX_ACCELERATION = 200
# What are these scale things?
BACKLASH = 0.000
....
STEPGEN_MAXVEL = 125
STEPGEN_MAXACCEL = 200
P = 80
I = 5
D = 20
FF0 = 0
FF1 = 1
FF2 = 0
BIAS = 0
DEADBAND = 0.005
MAX_OUTPUT = 0

..for the record.

And this is what I see on the Z axis. Hardly a text book example of servo response:

I started off with the X axis which is a simpler assembly, turning up P from 1 until it started to oscillate around 50, then backed it off to 30 and dialled in some D, trying to speed up the response without significant overshoot. I couldn't improve much on D=5. Finally, some I term. I couldn't see much improvement beyond I=0.2.

With the Z axis, I ended up with P=80, I=0.5 and D=20.

Where did that get you, fatty?

The response is hardly a textbook example of a well tuned servo system. I get a fairly rapid initial move, followed typically by a slower creep up to the final position. Given that P and D are about as high as they can go sensibly, I'm not seeing any great opportunity to improve on that. Ideally I'd be getting there mostly due to the P and D terms, with the I providing a last, steady state adjustment.

There's a lot going on in reality, so this isn't quite a simple mass spring damper type situation. There are 3 factors making life less than straightforward:

  1. The mechanisms both have a degree of backlash and although I've taken care to minimise them, they are of the same order as the movements I am trying to optimise ie ~+/-10-20um. I have reasonably good quality Korean ground ballscrews but the lathe itself (Colchester Bantam) has seen better days and the saddle is being driven some way from its centre of mass and the likely line of action of the cutting forces. The Z axis is less ideal than the X, not surprisingly, due to the vee and flat ways and larger mass.
  2. The encoders have "5um" resolution, so realistically I can't expect to control position much better than somewhere in the region of +/- 5-10um surely.
  3. The Lichuan servo drives will be a pig to try to tune. The absolute first thing to do in a dual control loop system like this would surely be to get the servos as optimised as possible before playing with the external (LinuxCNC) loop. However, the tuning "software" is no more than a means of downloading and uploading the table of parameters from a PC to the drives and I don't seem to be alone in being unable to even load the "software" on a W10 machine. So I've started out with the standard tune, which I suspect is pretty ropey and must be limiting what I can do.
So I have 2 hysteretic elements (backlash and encoder resolution) and servo drives with questionable responses. I can feel a battle with the Lichuan servos coming on, otherwise I suspect I am close to what I can expect as a final result.

Grumble and jitter:
Given the 5um resolution of the encoders, what is the recommended deadband? I'm guessing somewhere between 2.5 and 5um but I can't figure out a convincing logical answer to that. Certainly, increasing the deadband towards the 5um (0.005) level seems to get rid of much of the grumbling / jittering that arises after some moves.

I seem to have inherited FF1=1, presumably from the original CNCconf setup. The other FF terms are zero. I did play with a couple of them and it didn't end well, with the joint drifting out of position, so I left them as they were. I don't have any high frequency bursts going on but until I reread the docs, I'm not clear if I'm missing anything here.

Still to be resolved:
Finally, how do the STEPGEN_MAXACCEL and STEPGEN_MAXVEL affect the PID behaviour? Presumably they will affect the slope of the rising edge of the demand step I'm using to observe the system response, which would in turn affect the effect of the D feedforward term for instance.

No comments:

Post a Comment

Final assembly and test of the spindle nose adaptor - RESULT!!

After the recent distraction caused by the 3D scanner, resurrecting the 3D printer and buggering about with the throttle bodies for my Honda...