/ docs / src / config / integrator-concepts.txt
integrator-concepts.txt
  1  [[cha:integrator-concepts]]
  2  
  3  = Integrator Concepts
  4  
  5  == File Locations
  6  
  7  LinuxCNC looks for the configuration and G code files in a specific place. The
  8  location depends on how you run LinuxCNC.
  9  
 10  === Installed
 11  
 12  If your running LinuxCNC from the LiveCD or you installed via a deb and use the
 13  configuration picker 'LinuxCNC' from the menu LinuxCNC looks in the following
 14  directories:
 15  
 16  * The LinuxCNC directory is located at '/home/user-name/linuxcnc'.
 17  * The Configuration directories are located at '/home/user-name/linuxcnc/configs'.
 18  **  Configuration files are located at '/home/user-name/linuxcnc/configs/name-of-config'.
 19  * G code files are located at /home/user-name/linuxcnc/nc_files'.
 20  
 21  For example for a configuration called Mill and a user name Fred the directory
 22  and file structure would look like this.
 23  
 24  * '/home/fred/linuxcnc'
 25  * '/home/fred/linuxcnc/nc_files'
 26  * '/home/fred/linuxcnc/configs/mill'
 27  ** '/home/fred/linuxcnc/configs/mill/mill.ini'
 28  ** '/home/fred/linuxcnc/configs/mill/mill.hal'
 29  ** '/home/fred/linuxcnc/configs/mill/mill.var'
 30  ** '/home/fred/linuxcnc/configs/mill/tool.tbl'
 31  
 32  === Command Line
 33  
 34  If you run LinuxCNC from the command line and specify the name and location of
 35  the INI file the file locations can be in a different place. To view the
 36  options for running LinuxCNC from the command line run 'linuxcnc -h'.
 37  
 38  [NOTE]
 39  Optional locations for some files can be configured in the INI file. See the
 40  <<sec:display-section,DISPLAY>> section and the <<sec:rs274ngc-section,RS274NGC>>
 41  section.
 42  
 43  
 44  == Files
 45  
 46  Each configuration directory requires at least the following files:
 47  
 48  * An INI file .ini
 49  * A HAL file .hal or HALTCL file .tcl specified in the 
 50    <<sec:hal-section,HAL>> section of the INI file.
 51  
 52  [NOTE]Other files may be required for some GUI's.
 53  
 54  Optionally you can also have:
 55  
 56  * A Variables file .var
 57  ** If you omit a .var file in a directory but include
 58     [<<sec:rs274ngc-section,RS274NGC>>] PARAMETER_FILE=somefilename.var, the file
 59     will be created for you when LinuxCNC starts.
 60  ** If you omit a .var file  and  omit the item [RS274NGC] PARAMETER_FILE, a var
 61     file named rs274ngc.var will be created when LinuxCNC starts. There may be
 62     some confusing messages if [RS274NGC]PARAMETER_FILE is omitted.
 63  * A Tool Table file .tbl if [<<sec:emcmot-section,EMCMOT>>]TOOL_TABLE has been
 64    specified in the INI file. Some configurations do not need a tool table.
 65  
 66  == Stepper Systems
 67  
 68  === Base Period
 69  
 70  BASE_PERIOD is the 'heartbeat' of your LinuxCNC computer.footnote:[This 
 71  section refers to using *stepgen*, LinuxCNC's built-in 
 72  step generator. Some hardware devices have their own step 
 73  generator and do not use LinuxCNC's built-in one. In that case, refer to 
 74  your hardware manual.] Every period, the 
 75  software step generator decides if it is time for another step pulse. 
 76  A shorter period will allow you to generate more pulses per second,
 77  within limits. But if you go too short, your computer will spend so
 78  much time generating step pulses that everything else will slow to a
 79  crawl, or maybe even lock up. Latency and stepper drive requirements
 80  affect the shortest period you can use.
 81  
 82  Worst case latencies might only happen a few times a minute, and the
 83  odds of bad latency happening just as the motor is changing direction
 84  are low. So you can get very rare errors that ruin a part every once in
 85  a while and are impossible to troubleshoot.
 86  
 87  The simplest way to avoid this problem is to choose a BASE_PERIOD that
 88  is the sum of the longest timing requirement of your drive, and the
 89  worst case latency of your computer. This is not always the best choice. 
 90  For example, if you are running a drive with a 20 us  direction signal hold time 
 91  requirement, and your latency test said you have a maximum latency of
 92  11 us , then if you set the BASE_PERIOD to 20+11 = 31 us  you get a 
 93  not-so-nice 32,258 steps per second in one mode and 16,129 steps per 
 94  second in another mode. 
 95  
 96  The problem is with the 20 us  hold time requirement. That plus the 11 us 
 97  latency is what forces us to use a slow 31 us  period. But the LinuxCNC
 98  software step generator has some parameters that let you increase the
 99  various times from one period to several. For example, if 'steplen' footnote:[steplen 
100  refers to a parameter that adjusts the performance of LinuxCNC's built-in step generator, 
101  'stepgen', which is a HAL component. This parameter adjusts the length of the 
102  step pulse itself. Keep reading, all will be explained eventually.] is
103  changed from 1 to 2, then there will be two periods between the
104  beginning and end of the step pulse. Likewise, if 'dirhold' footnote:[dirhold 
105  refers to a parameter that adjusts the length of the direction hold time.] is 
106  changed from 1 to 3, there will be at least three periods between the step
107  pulse and a change of the direction pin.
108  
109  If we can use 'dirhold' to meet the 20 us  hold time requirement, then the
110  next longest time is the 4.5 us  high time. Add the 11 us  latency to the
111  4.5 us  high time, and you get a minimum period of 15.5 us . When you try
112  15.5 us , you find that the computer is sluggish, so you settle on 16 us .
113  If we leave 'dirhold' at 1 (the default), then the minimum time between
114  step and direction is the 16 us  period minus the 11 us  latency = 5 us ,
115  which is not enough. We need another 15 us . Since the period is 16 us , we
116  need one more period. So we change 'dirhold' from 1 to 2. Now the minimum
117  time from the end of the step pulse to the changing direction pin is
118  5+16=21 us , and we don't have to worry about the drive stepping the
119  wrong direction because of latency.
120  
121  For more information on stepgen see the <<sec:stepgen,stepgen section>>. 
122  
123  === Step Timing
124  
125  Step Timing and Step Space on some drives are different. In this case
126  the Step point becomes important. If the drive steps on the falling
127  edge then the output pin should be inverted.
128  
129  == Servo Systems
130  
131  === Basic Operation
132  
133  Servo systems are capable of greater speed and accuracy than equivalent 
134  stepper systems, but are more costly and complex. 
135  Unlike stepper systems, servo systems require some type of position 
136  feedback device, and must be adjusted or 'tuned', as they don't quite 
137  work right out of the box as a stepper system might. These differences 
138  exist because servos are a 'closed loop' system, 
139  unlike stepper motors which are generally run 'open loop'. What does 
140  'closed loop' mean? Let's look at a simplified diagram of how a servomotor 
141  system is connected. 
142  
143  .Servo Loop
144  image::images/servo-feedback.png[alt="simplified diagram of how a servomotor system is connected"]
145  
146  This diagram shows that the input signal (and the feedback signal) drive 
147  the summing amplifier, the summing amplifier drives the power amplifier, 
148  the power amplifier drives the motor, the motor drives the load 
149  (and the feedback device), and the feedback device (and the input signal) 
150  drive the motor.  This looks very much like a circle (a closed loop) where 
151  A controls B, B controls C, C controls D, and D controls A. 
152  
153  If you have not worked with servo systems before, this will no doubt seem a 
154  very strange idea at first, especially as compared to more normal electronic 
155  circuits, where the inputs proceed smoothly to the outputs, and never go 
156  back.footnote:[If it helps, the closest equivalent to this in the digital 
157  world are 'state machines', 'sequential machines' and so forth, where what 
158  the outputs are doing 'now' depends on what the inputs (and the outputs) 
159  were doing 'before'. If it doesn't help, then nevermind.] If 'everything' 
160  controls 'everything else', how can that ever work, who's in 
161  charge? The answer is that LinuxCNC 'can' control this system, 
162  but it has to do it by choosing one of several control methods. 
163  The control method that LinuxCNC uses, one of the simplest and best, 
164  is called PID. 
165  
166  PID stands for Proportional, Integral, and Derivative. The Proportional
167  value determines the reaction to the current error, the Integral value
168  determines the reaction based on the sum of recent errors, and the
169  Derivative value determines the reaction based on the rate at which the
170  error has been changing. They are three common mathematical techniques
171  that are applied to the task of getting a working process to follow a
172  set point. In the case of LinuxCNC the process we want to control is actual
173  axis position and the set point is the commanded axis position.
174  
175  .PID Loop
176  image::images/pid-feedback.png[alt="PID Loop, PID stands for Proportional, Integral, and Derivative"]
177  
178  By 'tuning' the three constants in the PID controller algorithm, the
179  controller can provide control action designed for specific process
180  requirements. The response of the controller can be described in terms
181  of the responsiveness of the controller to an error, the degree to
182  which the controller overshoots the set point and the degree of system
183  oscillation.
184  
185  === Proportional term
186  
187  The proportional term (sometimes called gain) makes a change to the 
188  output that is proportional to the current error value. A high 
189  proportional gain results in a large change in the output for a given 
190  change in the error. If the proportional gain is too high, the system 
191  can become unstable. In contrast, a small gain results in a small 
192  output response to a large input error. If the proportional gain is too 
193  low, the control action may be too small when responding to system 
194  disturbances. 
195  
196  In the absence of disturbances, pure proportional control will not 
197  settle at its target value, but will retain a steady state error that 
198  is a function of the proportional gain and the process gain. Despite 
199  the steady-state offset, both tuning theory and industrial practice 
200  indicate that it is the proportional term that should contribute the 
201  bulk of the output change. 
202  
203  === Integral term
204  
205  The contribution from the integral term (sometimes called reset) is 
206  proportional to both the magnitude of the error and the duration of the
207  error. Summing the instantaneous error over time (integrating the
208  error) gives the accumulated offset that should have been corrected
209  previously. The accumulated error is then multiplied by the integral
210  gain and added to the controller output.
211  
212  The integral term (when added to the proportional term) accelerates
213  the movement of the process towards set point and eliminates the
214  residual steady-state error that occurs with a proportional only
215  controller. However, since the integral term is responding to
216  accumulated errors from the past, it can cause the present value to
217  overshoot the set point value (cross over the set point and then create
218  a deviation in the other direction).
219  
220  === Derivative term
221  
222  The rate of change of the process error is calculated by determining
223  the slope of the error over time (i.e. its first derivative with
224  respect to time) and multiplying this rate of change by the derivative
225  gain.
226  
227  The derivative term slows the rate of change of the controller output
228  and this effect is most noticeable close to the controller set point.
229  Hence, derivative control is used to reduce the magnitude of the
230  overshoot produced by the integral component and improve the combined
231  controller-process stability.
232  
233  === Loop tuning
234  
235  If the PID controller parameters (the gains of the proportional,
236  integral and derivative terms) are chosen incorrectly, the controlled
237  process input can be unstable, i.e. its output diverges, with or
238  without oscillation, and is limited only by saturation or mechanical
239  breakage. Tuning a control loop is the adjustment of its control
240  parameters (gain/proportional band, integral gain/reset, derivative
241  gain/rate) to the optimum values for the desired control response.
242  
243  === Manual tuning
244  
245  A simple tuning method is to first set the I and D values to zero.
246  Increase the P until the output of the loop oscillates, then the P
247  should be set to be approximately half of that value for a 'quarter
248  amplitude decay' type response. Then increase I until any offset is
249  correct in sufficient time for the process. However, too much I will
250  cause instability. Finally, increase D, if required, until the loop is
251  acceptably quick to reach its reference after a load disturbance.
252  However, too much D will cause excessive response and overshoot. A fast
253  PID loop tuning usually overshoots slightly to reach the set point more
254  quickly; however, some systems cannot accept overshoot, in which case
255  an 'over-damped' closed-loop system is required, which will require a P
256  setting significantly less than half that of the P setting causing
257  oscillation.
258  
259  == RTAI
260  
261  The Real Time Application Interface (RTAI) is used to provide the best
262  Real Time (RT) performance. The RTAI patched kernel lets you write
263  applications with strict timing constraints. RTAI gives you the ability
264  to have things like software step generation which require precise
265  timing.
266  
267  === ACPI
268  
269  The Advanced Configuration and Power Interface (ACPI) has a lot of
270  different functions, most of which interfere with RT performance (for
271  example: power management, CPU power down, CPU frequency scaling, etc).
272  The LinuxCNC kernel (and probably all RTAI-patched kernels) has ACPI
273  disabled. ACPI also takes care of powering down the system after a
274  shutdown has been started, and that's why you might need to push the power
275  button to completely turn off your computer. The RTAI group has been 
276  improving this in recent releases, so your LinuxCNC system may shut off by 
277  itself after all. 
278