⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutorial.lyx

📁 CNC 的开放码,EMC2 V2.2.8版
💻 LYX
📖 第 1 页 / 共 4 页
字号:
 We can call them anything we want, for this example they will be \family typewriter X_vel\family default  and \family typewriter Y_vel\family default . The signal \family typewriter X_vel\family default  is intended to run from the cosine output of the signal generator to the velocity input of the first step pulse generator. The first step is to connect the signal to the signal generator output. To connect a signal to a pin we use the net command.\layout LyX-Codehalcmd:\series bold  net X_vel <= siggen.0.cosine\layout StandardTo see the effect of the \family typewriter net\family default  command, we show the signals again:\layout LyX-Codehalcmd:\series bold  show sig\series default \newline ignals:\newline Type      Value      Name\newline float   0.00000e+00  X_vel\newline                          <== siggen.0.cosine\layout StandardWhen a signal is connected to one or more pins, the show command lists the pins immediately following the signal name. The \begin_inset Quotes eld\end_inset arrow\begin_inset Quotes erd\end_inset  shows the direction of data flow - in this case, data flows from pin \family typewriter siggen.0.cosine\family default  to signal \family typewriter X_vel\family default . Now let's connect the \family typewriter X_vel\family default  to the velocity input of a step pulse generator:\layout LyX-Codehalcmd:\series bold  net X_vel => freqgen.0.velocity\layout StandardWe can also connect up the Y axis signal \family typewriter Y_vel\family default . It is intended to run from the sine output of the signal generator to the input of the second step pulse generator. The following command accomplishes in one line what two \family typewriter net\series bold  \family default \series default commands accomplished for \family typewriter X_vel\family default :\layout LyX-Codehalcmd:\series bold  net Y_vel siggen.0.sine => freqgen.1.velocity\layout StandardNow let's take a final look at the signals and the pins connected to them:\layout LyX-Codehalcmd:\series bold  show sig\series default \newline Signals:\newline Type      Value      Name\newline float   0.00000e+00  X_vel\newline                          <== siggen.0.cosine\newline                          ==> freqgen.0.velocity\newline float   0.00000e+00  Y_vel\newline                          <== siggen.0.sine\newline                          ==> freqgen.1.velocity\layout StandardThe \family typewriter show sig\family default  command makes it clear exactly how data flows through the HAL. For example, the\family typewriter  X_vel\family default  signal comes from pin \family typewriter siggen.0.cosine\family default , and goes to pin \family typewriter freqgen.0.velocity\family default .\layout SubsectionSetting up realtime execution - threads and functions\layout StandardThinking about data flowing through \begin_inset Quotes eld\end_inset wires\begin_inset Quotes erd\end_inset  makes pins and signals fairly easy to understand. Threads and functions are a little more difficult. Functions contain the computer instructions that actually get things done. Thread are the method used to make those instructions run when they are needed. First let's look at the functions available to us:\layout LyX-Codehalcmd:\series bold  show funct\newline \series default Exported Functions:\newline Owner CodeAddr   Arg    FP  Users  Name\newline  03   D89051C4 D88F10FC YES    0   siggen.0.update\newline  02   D8902868 D88F1054 YES    0   freqgen.capture_position\newline  02   D8902498 D88F1054 NO     0   freqgen.make_pulses\newline  02   D89026F0 D88F1054 YES    0   freqgen.update_freq\layout StandardIn general, you will have to refer to the documentation for each component to see what its functions do. In this case, the function \family typewriter siggen.0.update\family default  is used to update the outputs of the signal generator. Every time it is executed, it calculates the values of the sine, cosine, triangle, and square outputs. To make smooth signals, it needs to run at specific intervals. \layout StandardThe other three functions are related to the step pulse generators:\layout StandardThe first one, \family typewriter freqgen.capture_position\family default , is used for position feedback. It captures the value of an internal counter that counts the step pulses as they are generated. Assuming no missed steps, this counter indicates the position of the motor.\layout StandardThe main function for the step pulse generator is \family typewriter freqgen.make_pulses\family default . Every time \family typewriter make_pulses\family default  runs it decides if it is time to take a step, and if so sets the outputs accordingly. For smooth step pulses, it should run as frequently as possible. Because it needs to run so fast, \family typewriter make_pulses\family default  is highly optimized and performs only a few calculations. Unlike the others, it does not need floating point math. \layout StandardThe last function, \family typewriter freqgen.update_freq\family default , is responsible for doing scaling and some other calculations that need to be performed only when the frequency command changes.\layout StandardWhat this means for our example is that we want to run \family typewriter siggen.0.update\family default  at a moderate rate to calculate the sine and cosine values. Immediately after we run \family typewriter siggen.0.update\family default , we want to run \family typewriter freqgen.update_freq\family default  to load the new values into the step pulse generator. Finally we need to run \family typewriter freqgen.make_pulses\family default  as fast as possible for smooth pulses. Because we don't use position feedback, we don't need to run \family typewriter freqgen.capture_position\family default  at all.\layout StandardWe run functions by adding them to threads. Each thread runs at a specific rate. Let's see what threads we have available:\layout LyX-Codehalcmd:\series bold  show thread\series default \newline Realtime Threads:\newline    Period   FP   Name\newline     1005720 YES  slow    ( 0, 0 )\newline       50286 NO   fast    ( 0, 0 )\layout StandardThe two threads were created when we loaded \family typewriter threads\family default . The first one, \family typewriter slow\family default , runs every millisecond, and is capable of running floating point functions. We will use it for s\family typewriter iggen.0.update\family default  and \family typewriter freqgen.update_freq\family default . The second thread is \family typewriter fast\family default , which runs every 50 microseconds, and does not support floating point. We will use it for \family typewriter freqgen.make_pulses\family default . To connect the functions to the proper thread, we use the \family typewriter addf\family default  command. We specify the function first, followed by the thread:\layout LyX-Codehalcmd:\series bold  addf siggen.0.update slow\series default \newline halcmd:\series bold  addf freqgen.update_freq slow\series default \newline halcmd:\series bold  addf freqgen.make_pulses fast\layout StandardAfter we give these commands, we can run the \family typewriter show thread\family default  command again to see what happened:\layout LyX-Codehalcmd:\series bold  show thread\newline \series default Realtime Threads:\newline    Period   FP   Name    (Time, Max-Time)\newline     1005720 YES  slow    ( 0, 0 )\newline                   1 siggen.0.update\newline                   2 freqgen.update-freq\newline       50286 NO   fast    ( 0, 0 )\newline                   1 freqgen.make-pulses\layout StandardNow each thread is followed by the names of the functions, in the order in which the functions will run.\layout SubsectionSetting parameters\layout StandardWe are almost ready to start our HAL system. However we still need to adjust a few parameters. By default, the siggen component generates signals that swing from +1 to -1. For our example that is fine, we want the table speed to vary from +1 to -1 inches per second. However the scaling of the step pulse generator isn't quite right. By default, it generates an output frequency of 1 step per second with an input of 1.000. It is unlikely that one step per second will give us one inch per second of table movement. Let's assume instead that we have a 5 turn per inch leadscrew, connected to a 200 step per rev stepper with 10x microstepping. So it takes 2000 steps for one revolution of the screw, and 5 revolutions to travel one inch. that means the overall scaling is 10000 steps per inch. We need to multiply the velocity input to the step pulse generator by 10000 to get the proper output. That is exactly what the parameter \family typewriter freqgen.n.velocity-scale\family default  is for. In this case, both the X and Y axis have the same scaling, so we set the scaling parameters for both to 10000:\layout LyX-Codehalcmd:\series bold  setp freqgen.0.velocity-scale 10000\newline \series default halcmd:\series bold  setp freqgen.1.velocity-scale 10000\layout StandardThis velocity scaling means that when the pin \family typewriter freqgen.0.velocity\family default  is 1.000, the step generator will generate 10000 pulses per second (10KHz). With the motor and leadscrew described above, that will result in the axis moving at exactly 1.000 inches per second. This illustrates a key HAL concept - things like scaling are done at the lowest possible level, in this case in the step pulse generator. The internal signal \family typewriter X_vel\family default  is the velocity of the table in inches per second, and other components such as \family typewriter siggen\family default  don't know (or care) about the scaling at all. If we changed the leadscrew, or motor, we would change only the scaling parameter of the step pulse generator.\layout SubsectionRun it!\layout StandardWe now have everything configured and are ready to start it up. Just like in the first example, we use the \family typewriter start\family default  command:\layout LyX-Codehalcmd:\series bold  start\layout StandardAlthough nothing appears to happen, inside the computer the step pulse generator is cranking out step pulses, varying from 10KHz forward to 10KHz reverse and back again every second. Later in this tutorial we'll see how to bring those internal signals out to run motors in the real world, but first we want to look at them and see what is happening.\layout Section\begin_inset LatexCommand \label{sec:Tutorial - Halscope}\end_inset Taking a closer look with halscope.\layout StandardThe previous example generates some very interesting signals. But much of what happens is far too fast to see with halmeter. To take a closer look at what is going on inside the HAL, we want an oscilloscope. Fortunately HAL has one, called halscope.\layout SubsectionStarting Halscope\layout StandardHalscope has two parts - a realtime part that is loaded as a kernel module, and a user part that supplies the GUI and display. However, you don't need to worry about this, because the userspace portion will automatically request that the realtime part be loaded.\layout LyX-Codehalcmd:\series bold  loadusr halscope\layout StandardThe scope GUI window will open, immediately followed by a \begin_inset Quotes eld\end_inset Realtime function not linked\begin_inset Quotes erd\end_inset  dialog that looks like figure \begin_inset LatexCommand \ref{fig:Halscope-demo-1}\end_inset \begin_inset Footcollapsed true\layout StandardSeveral of these screen captures refer to threads named \begin_inset Quotes eld\end_inset siggen.thread\begin_inset Quotes erd\end_inset  and \begin_inset Quotes eld\end_inset stepgen.thread\begin_inset Quotes erd\end_inset  instead of \begin_inset Quotes eld\end_inset slow\begin_inset Quotes erd\end_inset  and \begin_inset Quotes eld\end_inset fast\begin_inset Quotes erd\end_inset . When the screenshots were captured, the \begin_inset Quotes eld\end_inset threads\begin_inset Quotes erd\end_inset  component didn't exist, and a different method was used to create threads, giving them different names. Also, the screenshots show pins, etc, as \begin_inset Quotes eld\end_inset stepgen.xxx\begin_inset Quotes erd\end_inset  rather than \begin_inset Quotes eld\end_inset freqgen.xxx\begin_inset Quotes erd\end_inset . The original name of the freqgen module was stepgen, and I haven't gotten around to re-doing all the screen shots since it was renamed. The name \begin_inset Quotes eld\end_inset stepgen\begin_inset Quotes erd\end_inset  now refers to a different step pulse generator, one that accepts position instead of velocity commands. Both are described in detail later in this document.\end_inset .\layout Standard\begin_inset Float figurewide falsecollapsed false\layout Standard\align center \begin_inset Graphics	filename halscope-demo-1.png\end_inset \layout Caption\begin_inset LatexCommand \label{fig:Halscope-demo-1}\end_inset \begin_inset Quotes eld\end_inset Realtime function not linked\begin_inset Quotes erd\end_inset  dialog\end_inset \layout StandardThis dialog is where you set the sampling rate for the oscilloscope. For now we want to sample once per millisecond, so click on the 1.03mS thread \begin_inset Quotes eld\end_inset slow\begin_inset Quotes erd\end_inset  (formerly \begin_inset Quotes eld\end_inset siggen.thread\begin_inset Quotes erd\end_inset , see footnote), and leave the multiplier at 1. We will also leave the record length at 4047 samples, so that we can use up to four channels at one time. When you select a thread and then click \begin_inset Quotes eld\end_inset OK\begin_inset Quotes erd\end_inset , the dialog disappears, and the scope window looks something like figure \begin_inset LatexCommand \ref{fig:Halscope-demo-2}\end_inset .\layout Standard\begin_inset Float figurewide falsecollapsed false\layout Standard\align center \begin_inset Graphics	filename halscope-demo-2.png\end_inset \layout Caption\begin_inset LatexCommand \label{fig:Halscope-demo-2}\end_inset Initial scope window\end_inset \layout Standard\begin_inset ERTstatus Collapsed\layout Standard\backslash clearpage\end_inset \layout SubsectionHooking up the \begin_inset Quotes eld

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -