H-bridge Tuning - Servo loop

More
31 Jan 2021 02:58 - 31 Jan 2021 22:48 #197198 by lrak
I found parts of this in various places. Thought it might help to have it all in one thread. The order things are done matters - I think I have all of this correct - let me know what I might have wrong.


H-bridge Tuning - Servo loop

What is PID?

PID loops are used in all sorts of systems, from temperature control, to advanced pressure regulators.

P - is Proportional feedback - it takes the error times a constant and adds it to the drive output. It is similar to the corrections one makes with the gas pedal of a car - if we are going a bit too slow, we don't floor it, we just press a proportional bit harder depending on the magnitude of the error. The original proportional only controllers go back to Huygens pendulums and latter Watts flying balls. The math behind all this was first explored by non other than James Clerk Maxwell in 1868. PID appeared about 1922.

I - is Integral feedback - it takes the average error over time times a constant - and adds it to the drive output ( improves fine accuracy)

D - Is Derivative feedback - it takes the change in error times a constant and adds it to the drive output ( reduces errors when the load suddenly changes)

Understanding Feedforward

While P(proportional) feed-back works - if you turn it up very high, it will oscillate - same with D - same with I. So what would be good is if we can give a drive value that is close to what is needed and use PID for fine corrections of error. So for any change in motion - d/dt - we want a value to send that should give something close to the correct response - that is called feedforward.

This brings us to OUTPUT_SCALE which should be set to the speed obtained by giving full output to the drive. Thus a motion request scaled to OUTPUT_SCALE should get us close to the correct output. If OUTPUT_SCALE is correct, FF1 should equal 1. This adds to the output value a pretty good guess to what it should be - and the PID section looks at any errors and sends correcting additions or subtractions to the output.

Tuning Procedure

This assumes you already know how to use the calibrate command - and HALscope.


Set DEADBAND to 1 machine resolution step * 0.6

Start with P, I and D FF0 and FF2 at zero

Set jog speed to 50 mm/min - know where your PHYSICAL ESTOP switch is and be sure it works - be ready to press it.

FF1=1 and increase P slowly so things can move - verify direction, limits, and homing.

Set P to low value - about 1/4 any possible oscillation.

Set OUTPUT_SCALE to encoder.N.velocity when pwmgen is pedal-to-the-metal. We are finding the maximum speed the table can move! This means changing things in ini so you can move things at dangerous speeds - work smart - this is dangerous - if you don't know exactly what you are doing - don't )

---- If you are OK with the danger - you will need to comment out temporarily for the axis under tuning FERROR, MAX_VELOCITY. In the [DISPLAY] section set MAX_LINEAR_VELOCITY to something insane. (I could not change this via the calibration window - had to edit the ini file and restart)

MAX_ACCELERATION - plot the velocity feedback in Halscope and max out acceleration. The slope of that will be the physical max - you will want to set to something like 90% of this (Perhaps a bunch less? No reason to hotrod..)(MAX_ACCELERATION has to be correct for tuning to work - if you ask a PID loop to accelerate things faster than possible - the numbers saturate and clip).

Getting FF1 correct and accurate is key - other things won't work if it is wrong. It will be correct if you measure - no guessing.

Be sure jog speed is quite low - start with 50mm/min

Set up the HALscope to look at f-error, motor-pos-command, and pos-relative for the axis you are working on.

Start up the Calibrate window.

Increase P slowly until you get a slight overshoot - something that looks like a damping factor of 0.4-0.7 - increase jog speed.

Double the jog speed and repeat the step above. - keep doubling until you get to something like 1000mm/min

FF1 - Start with a very low number - 0.01 Increase slowly - Tune to eliminate start and stop over/under shoots (about 0.005% of P).

Set FF2 so that the actual position does not lead or lag the commanded position during acceleration

Increase I until you start to see oscillations in FERROR


en.wikipedia.org/wiki/Damping_ratio#/med...r_Damping_Ratios.svg
Last edit: 31 Jan 2021 22:48 by lrak. Reason: Dislexia
The following user(s) said Thank You: tommylight, Aciera

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

Time to create page: 0.064 seconds
Powered by Kunena Forum