📄 tutorial.lyx
字号:
Owner Type Dir Value Name\newline 32769 float OUT 5.19530e-01 siggen.0.cosine\newline 32769 float OUT 6.73893e-01 siggen.0.sawtooth\newline 32769 float OUT -8.54452e-01 siggen.0.sine\newline 32769 float OUT 1.00000e+00 siggen.0.square\newline 32769 float OUT 3.47785e-01 siggen.0.triangle\layout StandardWe did two \family typewriter show pin\family default commands in quick succession, and you can see that the outputs are no longer zero. The sine, cosine, sawtooth, and triangle outputs are changing constantly. The square output is also working, however it simply switches from +1.0 to -1.0 every cycle.\layout SubsectionChanging parameters\layout StandardThe real power of HAL is that you can change things. For example, we can use the \family typewriter setp\family default command to set the value of a parameter. Let's change the amplitude of the signal generator from 1.0 to 5.0:\layout LyX-Codehalcmd:\series bold setp siggen.0.amplitude 5\series default \newline emc2$\layout StandardCheck the parameters and pins again:\layout LyX-Codehalcmd: setp siggen.0.amplitude 5\newline halcmd: show param\newline Parameters:\newline Owner Type Dir Value Name\newline 32769 float RW 5.00000e+00 siggen.0.amplitude\newline 32769 float RW 1.00000e+00 siggen.0.frequency\newline 32769 float RW 0.00000e+00 siggen.0.offset\newline 32769 s32 RO 397 siggen.0.update.time\newline 32769 s32 RW 109100 siggen.0.update.tmax\newline halcmd: show pin\newline Component Pins:\newline Owner Type Dir Value Name\newline 32769 float OUT 4.78453e+00 siggen.0.cosine\newline 32769 float OUT -4.53106e+00 siggen.0.sawtooth\newline 32769 float OUT 1.45198e+00 siggen.0.sine\newline 32769 float OUT -5.00000e+00 siggen.0.square\newline 32769 float OUT 4.02213e+00 siggen.0.triangle\layout StandardNote that the value of parameter\family typewriter siggen.0.amplitude\family default has changed to 5.000, and that the pins now have larger values.\layout SubsectionSaving the HAL configuration\layout StandardMost of what we have done with \family typewriter halcmd\family default so far has simply been viewing things with the \family typewriter show\family default command. However two of the commands actually changed things. As we design more complex systems with HAL, we will use many commands to configure things just the way we want them. HAL has the memory of an elephant, and will retain that configuration until we shut it down. But what about next time? We don't want to manually enter a bunch of commands every time we want to use the system. We can save the configuration of the entire HAL with a single command:\layout LyX-Codehalcmd:\series bold save\series default \newline # components\newline loadrt threads name1=test-thread period1=1000000\newline loadrt siggen\newline # signals\newline # links\newline # parameter values\newline setp siggen.0.amplitude 5.00000e+00\newline setp siggen.0.frequency 1.00000e+00\newline setp siggen.0.offset 0.00000e+00\newline # realtime thread/function links\newline addf siggen.0.update test-thread\layout StandardThe output of the \family typewriter save\family default command is a sequence of HAL commands. If you start with an \begin_inset Quotes eld\end_inset empty\begin_inset Quotes erd\end_inset HAL and run all these commands, you will get the configuration that existed when the \family typewriter save\family default command was issued. To save these commands for later use, we simply redirect the output to a file:\layout LyX-Codehalcmd: \series bold save all saved.hal\layout SubsectionRestoring the HAL configuration\layout StandardTo restore the HAL configuration stored in \family typewriter saved.hal\family default , we need to execute all of those HAL commands. To do that, we use\family typewriter -f <filename>\family default which reads commands from a file, and \family typewriter -I\family default which shows the halcmd prompt after execiting the commands:\layout LyX-Codeemc2$ \series bold halrun -I -f saved.hal\layout StandardNotice that there is not a 'start' command in saved.hal. It's necessary to issue it again (or edit saved.hal to add it there):\layout LyX-Codehalcmd: \series bold start\layout Section\begin_inset LatexCommand \label{sec:Tutorial - Halmeter}\end_inset Looking at the HAL with halmeter\layout StandardYou can build very complex HAL systems without ever using a graphical interface. However there is something satisfying about seeing the result of your work. The first and simplest GUI tool for the HAL is halmeter. It is a very simple program that is the HAL equivalent of the handy Fluke multimeter (or Simpson analog meter for the old timers).\layout StandardWe will use the siggen component again to check out halmeter. If you just finished the previous example, then siggen is already loaded. If not, we can load it just like we did before:\layout LyX-Codeemc2$ \series bold halrun\newline \series default halcmd: \series bold loadrt siggen\newline \series default halcmd: \series bold loadrt threads name1=test-thread period1=1000000\newline \series default halcmd: \series bold addf siggen.0.update test-thread\newline \series default halcmd:\series bold start\newline \series default halcmd:\series bold setp siggen.0.amplitude 5\layout SubsectionStarting halmeter\layout StandardAt this point we have the siggen component loaded and running. It's time to start halmeter. Since halmeter is a GUI app, X must be running.\layout LyX-Codehalcmd: \series bold loadusr halmeter\layout StandardAt the same time, a halmeter window opens on your screen, looking something like figure \begin_inset LatexCommand \ref{fig:Halmeter-demo-1}\end_inset .\layout Standard\begin_inset Float figurewide falsecollapsed false\layout Standard\align center \begin_inset Graphics filename halmeter-demo-1.png\end_inset \layout Caption\begin_inset LatexCommand \label{fig:Halmeter-demo-1}\end_inset Halmeter at startup, nothing selected\end_inset \layout SubsectionUsing halmeter\layout StandardThe meter in figure \begin_inset LatexCommand \ref{fig:Halmeter-demo-1}\end_inset isn't very useful, because it isn't displaying anything. To change that, click on the 'Select' button, which will open the probe selection dialog (figure \begin_inset LatexCommand \ref{fig:Halmeter-demo-2}\end_inset ). \layout Standard\begin_inset Float figurewide falsecollapsed false\layout Standard\align center \begin_inset Graphics filename halmeter-demo-2.png\end_inset \layout Caption\begin_inset LatexCommand \label{fig:Halmeter-demo-2}\end_inset Halmeter source selection dialog\end_inset \layout StandardThis dialog has three tabs. The first tab displays all of the HAL pins in the system. The second one displays all the signals, and the third displays all the parameters. We would like to look at the pin \family typewriter siggen.0.triangle\family default first, so click on it then click the 'OK' button. The probe selection dialog will close, and the meter looks something like figure \begin_inset LatexCommand \ref{fig:Halmeter-demo-3}\end_inset .\layout Standard\begin_inset Float figurewide falsecollapsed false\layout Standard\align center \begin_inset Graphics filename halmeter-demo-3.png\end_inset \layout Caption\begin_inset LatexCommand \label{fig:Halmeter-demo-3}\end_inset Halmeter displaying the value of a pin\end_inset \layout StandardYou should see the value changing as siggen generates its triangle wave. Halmeter refreshes its display about 5 times per second. \layout StandardIf you want to quickly look at a number of pins, you can use the 'Accept' button in the source selection dialog. Click on 'Select' to open the dialog again. This time, click on another pin, like siggen.0.cosine, and then click 'Accept'. When you click 'Accept', the meter immediately begins to display the newly selected item, but the dialog does not close. Try displaying a parameter instead of a pin. Click on the 'Parameters' tab, then select a parameter and click 'Accept' again. You can very quickly move the \begin_inset Quotes eld\end_inset meter probes\begin_inset Quotes erd\end_inset from one item to the next with a couple of clicks.\layout StandardTo shut down halmeter, just click the exit button.\layout StandardIf you want to look at more than one pin, signal, or parameter at a time, you can just start more halmeters. The halmeter window was intentionally made very small so you could have a lot of them on the screen at once. \begin_inset Footcollapsed true\layout StandardHalmeter is due for a rewrite. The rewrite will do a number of things to make it nicer. Scientific notation will go away - it is a pain to read. Some form of ranging (including autoranging) will be added to allow it to display a wide range of numbers without using scientific notation. An \begin_inset Quotes eld\end_inset analog bar graph\begin_inset Quotes erd\end_inset display will also be added to give a quick indication of trends. When the rewrite is done, these screenshots and the accompanying text will be revised to match the new version.\end_inset \layout Standard\begin_inset ERTstatus Collapsed\layout Standard\backslash clearpage\end_inset \layout Section\begin_inset LatexCommand \label{sec:Tutorial - More Complex}\end_inset A slightly more complex example.\layout StandardUp till now we have only loaded one HAL component. But the whole idea behind the HAL is to allow you to load and connect a number of simple components to make up a complex system. The next example will use two components.\layout StandardBefore we can begin building this new example, we want to start with a clean slate. If you just finished one of the previous examples, we need to remove the all components and reload the RTAPI and HAL libraries:\layout LyX-Codehalcmd: \series bold exit\newline \series default emc2$ \series bold halrun\layout SubsectionInstalling the components\layout StandardNow we are going to load the step pulse generator component. For a detailed description of this component refer to section \begin_inset LatexCommand \ref{sec:Stepgen}\end_inset . For now, we can skip the details, and just run the following commands:\begin_inset Footcollapsed true\layout StandardThe \begin_inset Quotes eld\end_inset \backslash \begin_inset Quotes erd\end_inset at the end of a long line indicates line wrapping (needed for formatting this document). When entering the commands at the command line, simply skip the \begin_inset Quotes eld\end_inset \backslash \begin_inset Quotes erd\end_inset (do not hit enter) and keep typing from the following line.\end_inset \layout LyX-Codehalrun: \series bold loadrt freqgen step_type=0,0\newline \series default halcmd:\series bold loadrt siggen\newline \series default halcmd:\series bold loadrt threads name1=fast fp1=0 period1=50000 name2=slow period2=1000000\layout StandardThe first command loads two step generators, both configured to generate stepping type 0. The second command loads our old friend siggen, and the third one creates two threads, a fast one with a period of 50 micro-seconds and a slow one with a period of 1mS. The fast thread doesn't support floating point functions.\layout StandardAs before, we can use \family typewriter halcmd show\family default to take a look at the HAL. This time we have a lot more pins and parameters than before:\layout LyX-Codehalcmd:\series bold show pin\newline \series default Component Pins:\newline Owner Type Dir Value Name\newline 03 float -W 0.00000e+00 siggen.0.cosine\newline 03 float -W 0.00000e+00 siggen.0.sawtooth\newline 03 float -W 0.00000e+00 siggen.0.sine\newline 03 float -W 0.00000e+00 siggen.0.square\newline 03 float -W 0.00000e+00 siggen.0.triangle\newline 02 s32 -W 0 freqgen.0.counts\newline 02 bit -W FALSE freqgen.0.dir\newline 02 float -W 0.00000e+00 freqgen.0.position\newline 02 bit -W FALSE freqgen.0.step\newline 02 float R- 0.00000e+00 freqgen.0.velocity\newline 02 s32 -W 0 freqgen.1.counts\newline 02 bit -W FALSE freqgen.1.dir\newline 02 float -W 0.00000e+00 freqgen.1.position\newline 02 bit -W FALSE freqgen.1.step\newline 02 float R- 0.00000e+00 freqgen.1.velocity\newline halcmd:\series bold show param\newline \series default Parameters:\newline Owner Type Dir Value Name\newline 03 float -W 1.00000e+00 siggen.0.amplitude\newline 03 float -W 1.00000e+00 siggen.0.frequency\newline 03 float -W 0.00000e+00 siggen.0.offset\newline 02 u32 -W 000000001 freqgen.0.dirhold\newline 02 u32 -W 000000001 freqgen.0.dirsetup\newline 02 float R- 0.00000e+00 freqgen.0.frequency\newline 02 float -W 0.00000e+00 freqgen.0.maxaccel\newline 02 float -W 1.00000e+15 freqgen.0.maxfreq\newline 02 float -W 1.00000e+00 freqgen.0.position-scale\newline 02 s32 R- 0 freqgen.0.rawcounts\newline 02 u32 -W 000000001 freqgen.0.steplen\newline 02 u32 -W 000000001 freqgen.0.stepspace\newline 02 float -W 1.00000e+00 freqgen.0.velocity-scale\newline 02 u32 -W 000000001 freqgen.1.dirhold\newline 02 u32 -W 000000001 freqgen.1.dirsetup\newline 02 float R- 0.00000e+00 freqgen.1.frequency\newline 02 float -W 0.00000e+00 freqgen.1.maxaccel\newline 02 float -W 1.00000e+15 freqgen.1.maxfreq\newline 02 float -W 1.00000e+00 freqgen.1.position-scale\newline 02 s32 R- 0 freqgen.1.rawcounts\newline 02 u32 -W 000000001 freqgen.1.steplen\newline 02 u32 -W 000000001 freqgen.1.stepspace\newline 02 float -W 1.00000e+00 freqgen.1.velocity-scale\layout SubsectionConnecting pins with signals\layout StandardWhat we have is two step pulse generators, and a signal generator. Now it is time to create some HAL signals to connect the two components. We are going to pretend that the two step pulse generators are driving the X and Y axis of a machine. We want to move the table in circles. To do this, we will send a cosine signal to the X axis, and a sine signal to the Y axis. The siggen module creates the sine and cosine, but we need \begin_inset Quotes eld\end_inset wires\begin_inset Quotes erd\end_inset to connect the modules together. In the HAL, \begin_inset Quotes eld\end_inset wires\begin_inset Quotes erd\end_inset are called signals. We need to create two of them.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -