#LyX 1.3 created this file. For more info see http://www.lyx.org/ \lyxformat 221 \textclass book \begin_preamble \usepackage[plainpages=false,pdfpagelabels,colorlinks=true,linkcolor=blue]{hyperref} \end_preamble \language english \inputencoding default \fontscheme bookman \graphics default \float_placement !htbp \paperfontsize default \spacing single \papersize letterpaper \paperpackage a4 \use_geometry 1 \use_amsmath 0 \use_natbib 0 \use_numerical_citations 0 \paperorientation portrait \leftmargin 1in \topmargin 1in \rightmargin 0.8in \bottommargin 0.8in \secnumdepth 1 \tocdepth 5 \paragraph_separation skip \defskip smallskip \quotes_language english \quotes_times 2 \papercolumns 1 \papersides 1 \paperpagestyle default \layout Chapter \begin_inset LatexCommand \label{cha:Internal-Components} \end_inset Internal Components \layout Standard Most components have unix-style manual pages. To view manual pages for real-time components, type \begin_inset Quotes eld \end_inset man 9 \emph on componentname \emph default \begin_inset Quotes erd \end_inset at the terminal prompt. \layout Standard This document focuses on more complicated components which have figures which are hard to reproduce in the manual page format. \layout Section \begin_inset LatexCommand \label{sec:Stepgen} \end_inset Stepgen \begin_inset LatexCommand \index{stepgen} \end_inset \layout Standard This component provides software based generation of step pulses in response to position or velocity commands. In position mode, it has a built in pre-tuned position loop, so PID tuning is not required. In velocity mode, it drives a motor at the commanded speed, while obeying velocity and acceleration limits. It is a realtime component only, and depending on CPU speed, etc, is capable of maximum step rates of 10kHz to perhaps 50kHz. Figure \begin_inset LatexCommand \ref{fig:Stepgen-Block-Diag} \end_inset shows three block diagrams, each is a single step pulse generator. The first diagram is for step type '0', (step and direction). The second is for step type '1' (up/down, or pseudo-PWM), and the third is for step types 2 through 14 (various stepping patterns). The first two diagrams show position mode control, and the third one shows velocity mode. Control mode and step type are set independently, and any combination can be selected. \layout Standard \begin_inset Float figure wide false collapsed false \layout Standard \align center \begin_inset Graphics filename stepgen-block-diag.eps width 7.5in height 8.5in keepAspectRatio clip \end_inset \layout Caption \begin_inset LatexCommand \label{fig:Stepgen-Block-Diag} \end_inset Step Pulse Generator Block Diagram (position mode) \end_inset \layout Standard \begin_inset Float figure wide false collapsed false \layout Standard \align center \begin_inset Graphics filename freqgen-block-diag.eps width 7.5in height 8.5in keepAspectRatio clip \end_inset \layout Caption \begin_inset LatexCommand \label{fig:Freqgen-Block-Diag} \end_inset Step Pulse Generator Block Diagram (velocity mode) \end_inset \layout Subsection Installing \layout LyX-Code emc2$ \series bold halcmd loadrt stepgen step_type= [ctrl_type=] \layout Standard \family typewriter \family default is a series of comma separated decimal integers. Each number causes a single step pulse generator to be loaded, the value of the number determines the stepping type. \family typewriter \family default is a comma separated series of \begin_inset Quotes eld \end_inset \family typewriter \series bold p \family default \series default \begin_inset Quotes erd \end_inset or \begin_inset Quotes eld \end_inset \family typewriter \series bold v \family default \series default \begin_inset Quotes erd \end_inset characters, to specify position or velocity mode. \family typewriter \series bold ctrl_type \family default \series default is optional, if ommitted, all of the step generators will be position mode. For example: \layout LyX-Code emc2# \series bold halcmd loadrt stepgen.o step_type=0,0,2 ctrl_type=p,p,v \layout Standard will install three step generators. The first two use step type '0' (step and direction) and run in position mode. The last one uses step type '2' (quadrature) and runs in velocity mode. The default value for \family typewriter \family default is \family typewriter \begin_inset Quotes eld \end_inset 0,0,0 \begin_inset Quotes erd \end_inset \family default which will install three type '0' (step/dir) generators. The maximum number of step generators is 8 (as defined by MAX_CHAN in stepgen.c). Each generator is independent, but all are updated by the same function(s) at the same time. In the following descriptions, \family typewriter \family default is the number of a specific generator. The first generator is number 0. \layout Subsection Removing \layout LyX-Code emc2$ \series bold halcmd unloadrt stepgen \layout Subsection Pins \layout Standard Each step pulse generator will have only some of these pins, depending on the step type and control type selected. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..position-cmd \family default -- Desired motor position, in position units (position mode only). \layout Itemize \family typewriter \noun on (float) \noun default stepgen..velocity-cmd \family default -- Desired motor velocity, in position units per second (velocity mode only). \layout Itemize \family typewriter \noun on (s32) \noun default stepgen..counts \family default -- Feedback position in counts, updated by \family typewriter capture_position() \family default . \layout Itemize \family typewriter \noun on (float) \noun default stepgen..position-fb \family default -- Feedback position in position units, updated by \family typewriter capture_position() \family default . \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..step \family default -- Step pulse output (step type 0 only). \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..dir \family default -- Direction output (step type 0 only). \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..up \family default -- UP pseudo-PWM output (step type 1 only). \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..down \family default -- DOWN pseudo-PWM output (step type 1 only). \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..phase-A \family default -- Phase A output (step types 2-14 only). \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..phase-B \family default -- Phase B output (step types 2-14 only). \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..phase-C \family default -- Phase C output (step types 3-14 only). \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..phase-D \family default -- Phase D output (step types 5-14 only). \layout Itemize \family typewriter \noun on (bit) \noun default stepgen..phase-E \family default -- Phase E output (step types 11-14 only). \layout Subsection Parameters \layout Itemize \family typewriter \noun on (float) \noun default stepgen..position-scale \family default -- Steps per position unit. This parameter is used for both output and feedback. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..maxvel \family default -- Maximum velocity, in position units per second. If 0.0, has no effect. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..maxaccel \family default -- Maximum accel/decel rate, in positions units per second squared. If 0.0, has no effect. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..frequency \family default -- The current step rate, in steps per second. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..steplen \family default -- Length of a step pulse (step type 0 and 1) or minimum time in a given state (step types 2-14), in nano-seconds. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..stepspace \family default -- Minimum spacing between two step pulses (step types 0 and 1 only), in nano-seconds. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..dirsetup \family default -- Minimum time from a direction change to the beginning of the next step pulse (step type 0 only), in nanoseconds. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..dirhold \family default -- Minmum time from the end of a step pulse to a direction change (step type 0 only), in nanoseconds. \layout Itemize \family typewriter \noun on (float) \noun default stepgen..dirdelay \family default -- Minmum time any step to a step in the opposite direction (step types 1-14 only), in nano-seconds. \layout Itemize \family typewriter \noun on (s32) \noun default stepgen..rawcounts \family default -- The raw feedback count, updated by \family typewriter make_pulses() \family default . \layout Standard In position mode, the values of maxvel and maxaccel are used by the internal position loop to avoid generating step pulse trains that the motor cannot follow. When set to values that are appropriate for the motor, even a large instantaneo us change in commanded position will result in a smooth trapezoidal move to the new location. The algorithm works by measuring both position error and velocity error, and calculating an acceleration that attempts to reduce both to zero at the same time. For more details, including the contents of the \begin_inset Quotes eld \end_inset control equation \begin_inset Quotes erd \end_inset box, consult the code. \layout Standard In velocity mode, maxvel is a simple limit that is applied to the commanded velocity, and maxaccel is used to ramp the actual frequency if the commanded velocity changes abruptly. As in position mode, proper values for these parameters ensure that the motor can follow the generated pulse train. \layout Subsection \begin_inset LatexCommand \label{sub:Stepgen-Step-Types} \end_inset Step Types \layout Standard The step generator supports 15 different \begin_inset Quotes eld \end_inset step types \begin_inset Quotes erd \end_inset . Step type 0 is the most familiar, standard step and direction. When configured for step type 0, there are four extra parameters that determine the exact timing of the step and direction signals. See figure \begin_inset LatexCommand \ref{fig:StepDir-timing} \end_inset for the meaning of these parameters. The parameters are in nanoseconds, but will be rounded up to an integer multiple of the thread period for the threaed that calls \family typewriter make_pulses() \family default . For example, if \family typewriter make_pulses() \family default is called every 16uS, and steplen is 20000, then the step pulses will be 2 x 16 = 32uS long. The default value for all four of the parameters is 1nS, but the automatic rounding takes effect the first time the code runs. Since one step requires \family typewriter steplen \family default nS high and \family typewriter stepspace \family default nS low, the maximum frequency is 1,000,000,000 divided by \family typewriter (steplen+stepspace) \family default . If \family typewriter maxfreq \family default is set higher than that limit, it will be lowered automatically. If maxfreq is zero, it will remain zero, but the output frequency will still be limited. \layout Standard \begin_inset Float figure wide false collapsed false \layout Standard \align center \begin_inset Graphics filename stepgen-type0.eps width 7in height 4in keepAspectRatio \end_inset \layout Caption \begin_inset LatexCommand \label{fig:StepDir-timing} \end_inset Step and Direction Timing \end_inset \layout Standard Step type 1 has two outputs, up and down. Pulses appear on one or the other, depending on the direction of travel. Each pulse is \family typewriter steplen \family default nS long, and the pulses are separated by at least \family typewriter stepspace \family default nS. The maximum frequency is the same as for step type 0. If \family typewriter maxfreq \family default is set higher than the limit it will be lowered. If \family typewriter maxfreq \family default is zero, it will remain zero but the output frequency will still be limited. \layout Standard Step types 2 through 14 are state based, and have from two to five outputs. On each step, a state counter is incremented or decremented. Figures \begin_inset LatexCommand \ref{fig:Quad-Three-Phase} \end_inset , \begin_inset LatexCommand \ref{fig:Four-Phase} \end_inset , and \begin_inset LatexCommand \ref{fig:Five-Phase} \end_inset show the output patterns as a function of the state counter. The maximum frequency is 1,000,000,000 divided by \family typewriter steplen \family default , and as in the other modes, \family typewriter maxfreq \family default will be lowered if it is above the limit. \layout Standard \begin_inset Float figure wide false collapsed false \layout Standard \align center \begin_inset Graphics filename stepgen-type2-4.eps width 7.5in height 8.5in keepAspectRatio rotateAngle 90 \end_inset \layout Caption Three-Phase step types \begin_inset LatexCommand \label{fig:Quad-Three-Phase} \end_inset \end_inset \layout Standard \begin_inset Float figure wide false collapsed false \layout Standard \align center \begin_inset Graphics filename stepgen-type5-10.eps width 7.5in height 8.5in keepAspectRatio rotateAngle 90 \end_inset \layout Caption \begin_inset LatexCommand \label{fig:Four-Phase} \end_inset Four-Phase Step Types \end_inset \layout Standard \begin_inset Float figure wide false collapsed false \layout Standard \align center \begin_inset Graphics filename stepgen-type11-14.eps width 7.5in height 8.5in keepAspectRatio \end_inset \layout Caption \begin_inset LatexCommand \label{fig:Five-Phase} \end_inset Five-Phase Step Types \end_inset \layout Subsection Functions \layout Standard The component exports three functions. Each function acts on all of the step pulse generators - running different generators in different threads is not supported. \layout Itemize \family typewriter \noun on (funct) \noun default stepgen.make-pulses \family default -- High speed function to generate and count pulses (no floating point). \layout Itemize \family typewriter \noun on (funct) \noun default stepgen.update-freq \family default -- Low speed function does position to velocity conversion, scaling and limiting. \layout Itemize \family typewriter \noun on (funct) \noun default stepgen.capture-position \family default -- Low speed function for feedback, updates latches and scales position. \layout Standard The high speed function \family typewriter stepgen.make-pulses \family default should be run in a very fast thread, from 10 to 50uS depending on the capabilit ies of the computer. That thread's period determines the maximum step frequency, since \family typewriter steplen \family default , \family typewriter stepspace \family default , \family typewriter dirsetup \family default , \family typewriter dirhold \family default , and \family typewriter dirdelay \family default are all rounded up to a integer multiple of the thread periond in nanoseconds. The other two functions can be called at a much lower rate. \layout Standard \begin_inset ERT status Collapsed \layout Standard \backslash clearpage \end_inset \layout Section \begin_inset LatexCommand \label{sec:PWMgen} \end_inset PWMgen \begin_inset LatexCommand \index{pwmgen} \end_inset \layout Standard This component provides software based generation of PWM (Pulse Width Modulation ) and PDM (Pulse Density Modulation) waveforms. It is a realtime component only, and depending on CPU speed, etc, is capable of PWM frequencies from a few hundred Hertz at pretty good resolution, to perhaps 10KHz with limited resolution. \layout Subsection Installing \layout LyX-Code emc2$ \series bold halcmd loadrt pwmgen output_type= \layout Standard \family typewriter \family default is a series of comma separated decimal integers. Each number causes a single PWM generator to be loaded, the value of the number determines the output type. For example: \layout LyX-Code emc2$ \series bold halcmd loadrt pwmgen step_type=0,1,2 \layout Standard will install three PWM generators. The first one will use output type '0' (PWM only), the next uses output type 1 (PWM and direction) and the last one uses output type 2 (UP and DOWN). There is no default value, if \family typewriter \family default is not specified, no PWM generators will be installed. The maximum number of frequency generators is 8 (as defined by MAX_CHAN in pwmgen.c). Each generator is independent, but all are updated by the same function(s) at the same time. In the following descriptions, \family typewriter \family default is the number of a specific generator. The first generator is number 0. \layout Subsection Removing \layout LyX-Code emc2$ \series bold halcmd unloadrt pwmgen \layout Subsection Pins \layout Standard Each PWM generator will have the following pins: \layout Itemize \family typewriter \noun on (float) \noun default pwmgen..value \family default -- Command value, in arbitrary units. Will be scaled by the \family typewriter scale \family default parameter (see below). \layout Itemize \family typewriter \noun on (bit) \noun default pwmgen..enable \family default -- Enables or disables the PWM generator outputs. \layout Standard Each PWM generator will also have some of these pins, depending on the output type selected: \layout Itemize \family typewriter \noun on (bit) \noun default pwmgen..pwm \family default -- PWM (or PDM) output, (output types 0 and 1 only). \layout Itemize \family typewriter \noun on (bit) \noun default pwmgen..dir \family default -- Direction output (output type 1 only). \layout Itemize \family typewriter \noun on (bit) \noun default pwmgen..up \family default -- PWM/PDM output for positive input value (output type 2 only). \layout Itemize \family typewriter \noun on (bit) \noun default pwmgen..down \family default -- PWM/PDM output for negative input value (output type 2 only). \layout Subsection Parameters \layout Itemize \family typewriter \noun on (float) \noun default pwmgen..scale \family default -- Scaling factor to convert \family typewriter value \family default from arbitrary units to duty cycle. \layout Itemize \family typewriter \noun on (float) \noun default pwmgen..pwm-freq \family default -- Desired PWM frequency, in Hz. If 0.0, generates PDM instead of PWM. If set higher than internal limits, next call of \family typewriter update_freq() \family default will set it to the internal limit. If non-zero, and \family typewriter dither \family default is false, next call of \family typewriter update_freq() \family default will set it to the nearest integer multiple of the \family typewriter make_pulses() \family default function period. \layout Itemize \family typewriter \noun on (bit) \noun default pwmgen..dither-pwm \family default -- If true, enables dithering to achieve average PWM frequencies or duty cycles that are unobtainable with pure PWM. If false, both the PWM frequency and the duty cycle will be rounded to values that can be achieved exactly. \layout Itemize \family typewriter \noun on (float) \noun default pwmgen..min-dc \family default -- Minimum duty cycle, between 0.0 and 1.0 (duty cycle will go to zero when disabled, regardless of this setting). \layout Itemize \family typewriter \noun on (float) \noun default pwmgen..max-dc \family default -- Maximum duty cycle, between 0.0 and 1.0. \layout Itemize \family typewriter \noun on (float) \noun default pwmgen..curr-dc \family default -- Current duty cycle - after all limiting and rounding (read only). \layout Subsection Output Types \layout Standard The PWM generator supports three different \begin_inset Quotes eld \end_inset output types \begin_inset Quotes erd \end_inset . Type 0 has a single output pin. Only positive commands are accepted, negative values are treated as zero (and will be affected by \family typewriter min-dc \family default if it is non-zero). Type 1 has two output pins, one for the PWM/PDM signal and one to indicate direction. The duty cycle on the PWM pin is based on the absolute value of the command, so negative values are acceptable. The direction pin is false for positive commands, and true for negative commands. Finally, type 2 also has two outputs, called up and down. For positive commands, the PWM signal appears on the up output, and the down output remains false. For negative commands, the PWM signal appears on the down output, and the up output remains false. Output type 2 is suitable for driving most H-bridges. \layout Subsection Functions \layout Standard The component exports two functions. Each function acts on all of the PWM generators - running different generators in different threads is not supported. \layout Itemize \family typewriter \noun on (funct) \noun default pwmgen.make-pulses \family default -- High speed function to generate PWM waveforms (no floating point). \layout Itemize \family typewriter \noun on (funct) \noun default pwmgen.update \family default -- Low speed function to scale and limit value and handle other paremeters. \layout Standard The high speed function \family typewriter pwmgen.make-pulses \family default should be run in a very fast thread, from 10 to 50uS depending on the capabilit ies of the computer. That thread's period determines the maximum PWM carrier frequency, as well as the resolution of the PWM or PDM signals. The other function can be called at a much lower rate. \layout Standard \begin_inset ERT status Collapsed \layout Standard \backslash clearpage \end_inset \layout Section \begin_inset LatexCommand \label{sec:Encoder} \end_inset Encoder \begin_inset LatexCommand \index{encoder} \end_inset \layout Standard This component provides software based counting of signals from quadrature encoders. It is a realtime component only, and depending on CPU speed, etc, is capable of maximum count rates of 10kHz to perhaps 50kHz. Figure \begin_inset LatexCommand \ref{fig:Encoder-Block-Diag} \end_inset is a block diagram of one channel of encoder counter. \layout Standard \begin_inset Float figure wide false collapsed false \layout Standard \align center \begin_inset Graphics filename encoder-block-diag.eps width 7in height 6in keepAspectRatio \end_inset \layout Caption \begin_inset LatexCommand \label{fig:Encoder-Block-Diag} \end_inset Encoder Counter Block Diagram \end_inset \layout Subsection Installing \layout LyX-Code emc2$ \series bold halcmd loadrt encoder [num_chan=] \layout Standard \family typewriter \family default is the number of encoder counters that you want to install. If \family typewriter numchan \family default is not specified, three counters will be installed. The maximum number of counters is 8 (as defined by MAX_CHAN in encoder.c). Each counter is independent, but all are updated by the same function(s) at the same time. In the following descriptions, \family typewriter \family default is the number of a specific counter. The first counter is number 0. \layout Subsection Removing \layout LyX-Code emc2$ \series bold halcmd unloadrt encoder \layout Subsection Pins \layout Itemize \family typewriter \noun on (bit) \noun default encoder..phase-A \family default -- Phase A of the quadrature encoder signal. \layout Itemize \family typewriter \noun on (bit) \noun default encoder..phase-B \family default -- Phase B of the quadrature encoder signal. \layout Itemize \family typewriter \noun on (bit) \noun default encoder..phase-Z \family default -- Phase Z (index pulse) of the quadrature encoder signal. \layout Itemize \family typewriter \noun on (bit) \noun default encoder..reset \family default -- See canonical encoder interface, section \begin_inset LatexCommand \ref{sec:CanonEncoder} \end_inset . \layout Itemize \family typewriter \noun on (bit) \noun default encoder..velocity \family default -- Estimated speed of the quadrature signal. \layout Itemize \family typewriter \noun on (bit) \noun default encoder..index-enable \family default -- See canonical encoder interface. \layout Itemize \family typewriter \noun on (s32) \noun default encoder..count \family default -- See canonical encoder interface. \layout Itemize \family typewriter \noun on (float) \noun default encoder..position \family default -- See canonical encoder interface. \layout Subsection Parameters \layout Itemize \family typewriter \noun on (s32) \noun default encoder..raw-count \family default -- The raw count value, updated by \family typewriter update-counters() \family default . \layout Itemize \family typewriter ( \noun on bit \noun default ) encoder..x4-mode \family default -- Sets encoder to 4x or 1x mode. The 1x mode is usefull for some jogwheels. \layout Itemize \family typewriter \noun on (float) \noun default encoder..position-scale \family default -- See canonical encoder interface, section \begin_inset LatexCommand \ref{sec:CanonEncoder} \end_inset . \layout Subsection Functions \layout Standard The component exports two functions. Each function acts on all of the encoder counters - running different counters in different threads is not supported. \layout Itemize \family typewriter \noun on (funct) \noun default encoder.update-counters \family default -- High speed function to count pulses (no floating point). \layout Itemize \family typewriter \noun on (funct) \noun default encoder.capture-position \family default -- Low speed function to update latches and scale position. \layout Standard \begin_inset ERT status Collapsed \layout Standard \backslash clearpage \end_inset \layout Section \begin_inset LatexCommand \label{sec:PID} \end_inset PID \begin_inset LatexCommand \index{pid} \end_inset \layout Standard This component provides Proportional/Integeral/Derivative control loops. It is a realtime component only. For simplicity, this discussion assumes that we are talking about position loops, however this component can be used to implement other feedback loops such as speed, torch height, temperature, etc. Figure \begin_inset LatexCommand \ref{fig:PID-block-diag} \end_inset is a block diagram of a single PID loop. \layout Standard \begin_inset Float figure wide false collapsed false \layout Standard \align center \begin_inset Graphics filename pid-block-diag.eps width 8in height 10in keepAspectRatio rotateAngle 90 rotateOrigin center \end_inset \layout Caption \begin_inset LatexCommand \label{fig:PID-block-diag} \end_inset PID Loop Block Diagram \end_inset \layout Subsection Installing \layout LyX-Code emc2$ \series bold halcmd loadrt pid [num_chan=] [debug=1] \layout Standard \family typewriter \family default is the number of PID loops that you want to install. If \family typewriter numchan \family default is not specified, one loop will be installed. The maximum number of loops is 16 (as defined by MAX_CHAN in pid.c). Each loop is completely independent. In the following descriptions, \family typewriter \family default is the loop number of a specific loop. The first loop is number 0. \layout Standard If \family typewriter debug=1 \family default is specified, the component will export a few extra parameters that may be useful during debugging and tuning. By default, the extra parameters are not exported, to save shared memory space and avoid cluttering the parameter list. \layout Subsection Removing \layout LyX-Code emc2$ \series bold halcmd unloadrt pid \layout Subsection Pins \layout Standard The three most important pins are \layout Itemize \family typewriter \noun on (float) \noun default pid..command \family default -- The desired position, as commanded by another system component. \layout Itemize \family typewriter \noun on (float) \noun default pid..feedback \family default -- The present position, as measured by a feedback device such as an encoder. \layout Itemize \family typewriter \noun on (float) \noun default pid..output \family default -- A velocity command that attempts to move from the present position to the desired position. \layout Standard For a position loop, 'command' and 'feedback' are in position units. For a linear axis, this could be inches, mm, meters, or whatever is relevant. Likewise, for an angular axis, it could be degrees, radians, etc. The units of the 'output' pin represent the change needed to make the feedback match the command. As such, for a position loop 'Output' is a velocity, in inches/sec, mm/sec, degrees/sec, etc. Time units are always seconds, and the velocity units match the position units. If command and feedback are in meters, then output is in meters per second. \layout Standard Each loop has two other pins which are used to monitor or control the general operation of the component. \layout Itemize \family typewriter \noun on (float) \noun default pid..error \family default -- Equals \family typewriter .command \family default minus \family typewriter .feedback \family default . \layout Itemize \family typewriter \noun on (bit) \noun default pid..enable \family default -- A bit that enables the loop. If \family typewriter .enable \family default is false, all integrators are reset, and the output is forced to zero. If \family typewriter .enable \family default is true, the loop operates normally. \layout Subsection Parameters \layout Standard The PID gains, limits, and other 'tunable' features of the loop are implemented as parameters. \layout Itemize \family typewriter \noun on (float) \noun default pid..Pgain \family default -- Proportional gain \layout Itemize \family typewriter \noun on (float) \noun default pid..Igain \family default -- Integral gain \layout Itemize \family typewriter \noun on (float) \noun default pid..Dgain \family default -- Derivative gain \layout Itemize \family typewriter \noun on (float) \noun default pid..bias \family default -- Constant offset on output \layout Itemize \family typewriter \noun on (float) \noun default pid..FF0 \family default -- Zeroth order feedforward - output proportional to command (position). \layout Itemize \family typewriter \noun on (float) \noun default pid..FF1 \family default -- First order feedforward - output proportional to derivative of command (velocity). \layout Itemize \family typewriter \noun on (float) \noun default pid..FF2 \family default -- Second order feedforward - output proportional to 2nd derivative of command (acceleration) \begin_inset Foot collapsed true \layout Standard FF2 is not currently implemented, but it will be added. Consider this note a \begin_inset Quotes eld \end_inset FIXME \begin_inset Quotes erd \end_inset for the code \end_inset . \layout Itemize \family typewriter \noun on (float) \noun default pid..deadband \family default -- Amount of error that will be ignored \layout Itemize \family typewriter \noun on (float) \noun default pid..maxerror \family default -- Limit on error \layout Itemize \family typewriter \noun on (float) \noun default pid..maxerrorI \family default -- Limit on error integrator \layout Itemize \family typewriter \noun on (float) \noun default pid..maxerrorD \family default -- Limit on error derivative \layout Itemize \family typewriter \noun on (float) \noun default pid..maxcmdD \family default -- Limit on command derivative \layout Itemize \family typewriter \noun on (float) \noun default pid..maxcmdDD \family default -- Limit on command 2nd derivative \layout Itemize \family typewriter \noun on (float) \noun default pid..maxoutput \family default -- Limit on output value \layout Standard All of the \family typewriter max??? \family default limits are implemented such that if the parameter value is zero, there is no limit. \layout Standard If \family typewriter debug=1 \family default was specified when the component was installed, four additional parameters will be exported: \layout Itemize \family typewriter \noun on (float) \noun default pid..errorI \family default -- Integral of error. \layout Itemize \family typewriter \noun on (float) \noun default pid..errorD \family default -- Derivative of error. \layout Itemize \family typewriter \noun on (float) \noun default pid..commandD \family default -- Derivative of the command. \layout Itemize \family typewriter \noun on (float) \noun default pid..commandDD \family default -- 2nd derivative of the command. \layout Subsection Functions \layout Standard The component exports one function for each PID loop. This function performs all the calculations needed for the loop. Since each loop has its own function, individual loops can be included in different threads and execute at different rates. \layout Itemize \family typewriter \noun on (funct) \noun default pid..do_pid_calcs \family default -- Performs all calculations for a single PID loop. \layout Standard If you want to understand the exact algorithm used to compute the output of the PID loop, refer to figure \begin_inset LatexCommand \ref{fig:PID-block-diag} \end_inset , the comments at the beginning of \family typewriter emc2/src/hal/components/pid.c \family default , and of course to the code itself. The loop calculations are in the C function \family typewriter calc_pid() \family default . \layout Standard \begin_inset ERT status Collapsed \layout Standard \backslash clearpage \end_inset \layout Section \begin_inset LatexCommand \label{sec:Simulated-Encoder} \end_inset Simulated Encoder \begin_inset LatexCommand \index{sim-encoder} \end_inset \layout Standard The simulated encoder is exactly that. It produces quadrature pulses with an index pulse, at a speed controlled by a HAL pin. Mostly useful for testing. \layout Subsection Installing \layout LyX-Code emc2$ \series bold halcmd loadrt sim-encoder num_chan= \layout Standard \family typewriter \family default is the number of encoders that you want to simulate. If not specified, one encoder will be installed. The maximum number is 8 (as defined by MAX_CHAN in sim_encoder.c). \layout Subsection Removing \layout LyX-Code emc2$ \series bold halcmd unloadrt sim-encoder \layout Subsection Pins \layout Itemize \family typewriter \noun on (float) \noun default sim-encoder..speed \family default -- The speed command for the simulated shaft. \layout Itemize \family typewriter \noun on (bit) \noun default sim-encoder..phase-A \family default -- Quadrature output. \layout Itemize \family typewriter \noun on (bit) \noun default sim-encoder..phase-B \family default -- Quadrature output. \layout Itemize \family typewriter \noun on (bit) \noun default sim-encoder..phase-Z \family default -- Index pulse output. \layout Standard When \family typewriter .speed \family default is positive, \family typewriter .phase-A \family default leads \family typewriter .phase-B \family default . \layout Subsection Parameters \layout Itemize \shape smallcaps \noun on (u32) \family typewriter \shape default \noun default sim-encoder..ppr \family default -- Pulses Per Revolution. \layout Itemize \shape smallcaps \noun on (float) \family typewriter \shape default \noun default sim-encoder..scale \family default -- Scale Factor for \family typewriter \series bold speed \family default \series default . The default is 1.0, which means that \family typewriter \series bold speed \family default \series default is in revolutions per second. Change to 60 for RPM, to 360 for degrees per second, 6.283185 for radians per seconed, etc. \layout Standard Note that pulses per revolution is not the same as counts per revolution. A pulse is a complete quadrature cycle. Most encoder counters will count four times during one complete cycle. \layout Subsection Functions \layout Standard The component exports two functions. Each function affects all simulated encoders. \layout Itemize \family typewriter \noun on (funct) \noun default sim-encoder.make-pulses \family default -- High speed function to generate quadrature pulses (no floating point). \layout Itemize \family typewriter \noun on (funct) \noun default sim-encoder.update-speed \family default -- Low speed function to read \family typewriter \series bold speed \family default \series default , do scaling, and set up \family typewriter \series bold make-pulses \family default \series default . \layout Standard \begin_inset ERT status Collapsed \layout Standard \backslash clearpage \end_inset \layout Section \begin_inset LatexCommand \label{sec:Debounce} \end_inset Debounce \begin_inset LatexCommand \index{debounce} \end_inset \layout Standard Debounce is a realtime component that can filter the glitches created by mechanical switch contacts. It may also be useful in other applications where short pulses are to be rejected. \layout Subsection Installing \layout LyX-Code emc2$ \series bold halcmd loadrt debounce cfg= \begin_inset Quotes erd \end_inset \begin_inset Quotes erd \end_inset \layout Standard \family typewriter \family default is a series of space separated decimal integers. Each number installs a group of identical debounce filters, the number determines how many filters are in the group. For example: \layout LyX-Code emc2$ \series bold halcmd loadrt debounce cfg= \begin_inset Quotes erd \end_inset 1 4 2 \begin_inset Quotes erd \end_inset \layout Standard will install three groups of filters. Group 0 contains one filter, group 1 contains four, and group 2 contains two filters. The default value for \family typewriter \family default is \family typewriter \begin_inset Quotes eld \end_inset 1 \begin_inset Quotes erd \end_inset \family default which will install a single group containing a single filter. The maximum number of groups 8 (as defined by MAX_GROUPS in debounce.c). The maximum number of filters in a group is limited only by shared memory space. Each group is completely independent. All filters in a single group are identical, and they are all updated by the same function at the same time. In the following descriptions, \family typewriter \family default is the group number and \family typewriter \family default is the filter number within the group. The first filter is group 0, filter 0. \layout Subsection Removing \layout LyX-Code emc2$ \series bold halcmd unloadrt debounce \layout Subsection Pins \layout Standard Each individual filter has two pins. \layout Itemize \family typewriter \noun on (bit) \noun default debounce...in \family default -- Input of filter \family typewriter \family default in group \family typewriter \family default . \layout Itemize \family typewriter \noun on (bit) \noun default debounce...out \family default -- Output of filter \family typewriter \family default in group \family typewriter \family default . \layout Subsection Parameters \layout Standard Each group of filters has one parameter \begin_inset Foot collapsed true \layout Standard Each individual filter also has an internal state variable. There is a compile time switch that can export that variable as a parameter. This is intended for testing, and simply wastes shared memory under normal circumstances. \end_inset . \layout Itemize \family typewriter \noun on (s32) \noun default debounce..delay \family default -- Filter delay for all filters in group \family typewriter \family default . \layout Standard The filter delay is in units of thread periods. The minimum delay is zero. The output of a zero delay filter exactly follows its input - it doesn't filter anything. As \family typewriter delay \family default increases, longer and longer glitches are rejected. If \family typewriter delay \family default is 4, all glitches less than or equal to four thread periods will be rejected. \layout Subsection Functions \layout Standard Each group of filters has one function, which updates all the filters in that group \begin_inset Quotes eld \end_inset simultaneously \begin_inset Quotes erd \end_inset . Different groups of filters can be updated from different threads at different periods. \layout Itemize \family typewriter \noun on (funct) \noun default debounce. \family default -- Updates all filters in group \family typewriter \family default . \layout Section \begin_inset LatexCommand \label{sec:Siggen} \end_inset Siggen \begin_inset LatexCommand \index{siggen} \end_inset \layout Standard Siggen is a realtime component that generates square, triangle, and sine waves. It is primarily used for testing. \layout Subsection Installing \layout LyX-Code emc2$ \series bold halcmd loadrt siggen [num_chan=] \layout LyX-Code \layout Standard \family typewriter \family default is the number of signal generators that you want to install. If \family typewriter numchan \family default is not specified, one signal generator will be installed. The maximum number of generators is 16 (as defined by MAX_CHAN in siggen.c). Each generator is completely independent. In the following descriptions, \family typewriter \family default is the number of a specific signal generator (the numbers start at 0). \layout Subsection Removing \layout LyX-Code emc2$ \series bold halcmd unloadrt siggen \layout Subsection Pins \layout Standard Each generator has five output pins. \layout Itemize \family typewriter \noun on (float) \noun default siggen..sine \family default -- Sine wave output. \layout Itemize \family typewriter \noun on (float) \noun default siggen..cosine \family default -- Cosine output. \layout Itemize \family typewriter \noun on (float) \noun default siggen..sawtooth \family default -- Sawtooth output. \layout Itemize \family typewriter \noun on (float) \noun default siggen..triangle \family default -- Triangle wave output. \layout Itemize \family typewriter \noun on (float) \noun default siggen..square \family default -- Square wave output. \layout Standard All five outputs have the same frequency, amplitude, and offset. \layout Standard In addition to the output pins, there are three control pins: \layout Itemize \family typewriter \noun on (float) \noun default siggen..frequency \family default -- Sets the frequency in Hertz, default value is 1 Hz. \layout Itemize \family typewriter \noun on (float) \noun default siggen..amplitude \family default -- Sets the peak amplitude of the output waveforms, default is 1. \layout Itemize \family typewriter \noun on (float) \noun default siggen..offset \family default -- Sets DC offset of the output waveforms, default is 0. \layout Standard For example, if \family typewriter siggen.0.amplitude \family default is 1.0 and \family typewriter siggen.0.offset \family default is 0.0, the outputs will swing from -1.0 to +1.0. If \family typewriter siggen.0.amplitude \family default is 2.5 and \family typewriter siggen.0.offset \family default is 10.0, then the outputs will swing from 7.5 to 12.5. \layout Subsection Parameters \layout Standard None. \begin_inset Foot collapsed true \layout Standard Prior to version 2.1, frequency, amplitude, and offset were parameters. They were changed to pins to allow control by other components. \end_inset \layout Subsection Functions \layout Itemize \family typewriter \noun on (funct) \noun default siggen..update \family default -- Calculates new values for all five outputs. \the_end