This document provides a reference to the basics of HAL.
1. HAL Befehle
More detailed information can be found in the man page for halcmd: run man halcmd in a terminal window.
Um die HAL-Konfiguration zu sehen und den Status von Pins und Parametern zu überprüfen, verwenden Sie das Fenster HAL-Konfiguration im Menü Maschine in AXIS. Um den Status eines Pins zu überwachen, öffnen Sie die Registerkarte "Überwachen" und klicken Sie auf jeden Pin, den Sie überwachen möchten; er wird dann zum Überwachungsfenster hinzugefügt.
1.1. loadrt
The command loadrt loads a real time HAL component. Real time component functions need to be added to a thread to be updated at the rate of the thread. You cannot load a non-realtime component into the realtime space.
loadrt <component> <options>
loadrt mux4 count=1
1.2. addf
The addf command adds a function to a real-time thread. If the StepConf wizard was used to create the configuration, two threads have been created (``base-thread`` and ``servo-thread``).
addf fügt Funktion Funktionsname zu Thread Threadname hinzu. Standardmäßig wird die Funktion in der Reihenfolge hinzugefügt, in der sie in der Datei steht. Wenn Position angegeben ist, wird die Funktion an dieser Stelle des Threads hinzugefügt. Eine negative Position gibt die Position in Bezug auf das Ende des Threads an. Zum Beispiel 1 ist der Anfang des Threads, -1 ist das Ende des Threads, -3 ist das dritte Ende vom Ende.
Bei einigen Funktionen ist es wichtig, dass sie in einer bestimmten Reihenfolge geladen werden, wie z. B. die Parport-Lese- und Schreibfunktionen. Der Funktionsname ist normalerweise der Komponentenname plus eine Zahl. Im folgenden Beispiel wird die Komponente "or2" geladen und show function zeigt den Namen der or2-Funktion an.
$ halrun halcmd: loadrt or2 halcmd: show function Exported Functions: Owner CodeAddr Arg FP Users Name 00004 f8bc5000 f8f950c8 YES 0 or2.0
You have to add a function from a HAL real time component to a thread to get the function to update at the rate of the thread. Usually there are two threads as shown in this example.
|
Note
|
The |
$ halrun
halcmd: loadrt motmod base_period_nsec=55555 servo_period_nsec=1000000 num_joints=3
halcmd: show thread
Realtime Threads:
Period FP Name ( Time, Max-Time )
995976 YES servo-thread ( 0, 0 )
55332 YES base-thread ( 0, 0 )
-
base-thread (the high-speed thread): This thread handles items that need a fast response, like making step pulses, and reading and writing the parallel port.
-
servo-thread (the slow-speed thread): This thread handles items that can tolerate a slower response, like the motion controller, ClassicLadder, and the motion command handler.
addf <function> <thread>
addf mux4.0 servo-thread
1.3. initf
The initf command registers a function to run once in realtime context, on a dedicated init cycle of the thread before the cyclic function list runs. It is the realtime-thread analogue of addf, intended for one-shot setup that must execute in the realtime task (for example EtherCAT master activation via lcec.activate).
initf adds function functname to the init list of thread threadname. The init list runs once on the first cycle after start, then is drained. The cyclic list begins on the following period. Once the init cycle has run, further initf calls on that thread are rejected. position has the same meaning as in addf.
initf <function> <thread>
initf lcec.activate servo-thread
1.4. loadusr
The command loadusr loads a non-realtime HAL component. Non-realtime programs are their own separate processes, which optionally talk to other HAL components via pins and parameters. You cannot load realtime components into non-realtime space.
Flags können eine oder mehrere der folgenden sein:
| -W |
um auf die Bereitschaft der Komponente zu warten. Es wird davon ausgegangen, dass die Komponente denselben Namen hat wie das erste Argument des Befehls. |
| -Wn <Name> |
um auf die Komponente zu warten, die den angegebenen <Name> haben wird. Dies gilt nur, wenn die Komponente eine Namensoption hat. |
| -w |
um zu warten, bis das Programm beendet wird |
| -i |
um den Rückgabewert des Programms zu ignorieren (mit -w) |
| -n |
Benennt eine Komponente, sofern dies eine zulässige Option für diese Komponente ist. |
loadusrloadusr <component> <options>
loadusr halui
loadusr -Wn spindle gs2_vfd -n spindle
Auf Deutsch bedeutet es loadusr wartet auf Name Spindel Komponente gs2_vfd mit Namen Spindel.
1.5. net
The command net creates a connection between a signal and one or more pins. If the signal does not exist net creates the new signal. This replaces the need to use the command newsig. The optional direction arrows <=, => and <=> make it easier to follow the logic when reading a net command line and are not used by the net command. The direction arrows must be separated by a space from the pin names.
netnet signal-name pin-name <optional arrow> <optional second pin-name>
net home-x joint.0.home-sw-in <= parport.0.pin-11-in
Im obigen Beispiel ist home-x der Signalname, joint.0.home-sw-in ist ein Direction IN-Pin, <= ist der optionale Richtungspfeil, und parport.0.pin-11-in ist ein Direction OUT-Pin. Dies mag verwirrend erscheinen, aber die Bezeichnungen "in" und "out" für einen Parallelport-Pin geben die physikalische Funktionsweise des Pins an, nicht wie er in HAL gehandhabt wird.
Ein Pin kann mit einem Signal verbunden werden, wenn er die folgenden Regeln beachtet:
-
Ein IN-Pin kann immer mit einem Signal verbunden werden.
-
Ein IO-Pin kann angeschlossen werden, sofern kein ein OUT-Pin am Signal anliegt.
-
Ein OUT-Pin kann nur angeschlossen werden, wenn es keine anderen OUT- oder IO-Pins am Signal gibt.
Derselbe Signal-Name kann in mehreren Netzbefehlen verwendet werden, um zusätzliche Pins zu verbinden, solange die obigen Regeln beachtet werden.
Dieses Beispiel zeigt das Signal xStep mit der Quelle stepgen.0.out und mit zwei Lesern, parport.0.pin-02-out und parport.0.pin-08-out. Im Grunde genommen wird der Wert von stepgen.0.out an das Signal xStep gesendet und dieser Wert wird dann an parport.0.pin-02-out und parport.0.pin-08-out gesendet.
# Signal Ursprung Destination Destination
net xStep stepgen.0.out => parport.0.pin-02-out parport.0.pin-08-out
Da das Signal xStep den Wert von stepgen.0.out (die Quelle/Ursprung (engl. source) ) enthält, können Sie dasselbe Signal erneut verwenden, um den Wert an einen anderen Leser zu senden. Verwenden Sie dazu einfach das Signal mit den Lesern in einer anderen Zeile.
# Signal Destination2
net xStep => parport.0.pin-06-out
Ein E/A-Pin wie ein Encoder. N.index-enable kann gelesen oder so eingestellt werden, wie es die Komponente zulässt.
1.6. setp
The command setp sets the value of a pin or parameter. The valid values will depend on the type of the pin or parameter. It is an error if the data types do not match.
Einige Komponenten haben Parameter, die vor der Verwendung eingestellt werden müssen. Die Parameter können je nach Bedarf vor der Verwendung oder während der Ausführung gesetzt werden. Sie können setp nicht auf einen Pin anwenden, der mit einem Signal verbunden ist.
setpsetp <pin/parameter-name> <value>
setp parport.0.pin-08-out TRUE
1.7. sets
The command sets sets the value of a signal.
setssets <signal-name> <value>
net mysignal and2.0.in0 pyvcp.my-led
sets mysignal 1
Es ist ein Fehler, wenn:
-
Der Signal-Name existiert nicht
-
Wenn das Signal bereits einen Schreiber (engl. writer) hat
-
Wenn Wert nicht der richtige Typ für das Signal ist
1.8. unlinkp
The command unlinkp unlinks a pin from the connected signal. If no signal was connected to the pin prior running the command, nothing happens. The unlinkp command is useful for trouble shooting.
unlinkpunlinkp <pin-name>
unlinkp parport.0.pin-02-out
1.9. Veraltete Befehle
Die folgenden Befehle sind veraltet und werden möglicherweise aus zukünftigen Versionen entfernt. Jede neue Konfiguration sollte den Befehl net verwenden. Diese Befehle sind enthalten, damit ältere Konfigurationen noch funktionieren.
1.9.1. linksp (veraltet)
Der Befehl linksp stellt eine Verbindung (engl. connection) zwischen einem Signal und einem Pin her.
linksplinksp <signal-name> <pin-name>
linksp X-step parport.0.pin-02-out
The linksp command has been superseded by the net command.
1.9.2. linkps (veraltet)
Der Befehl linkps stellt eine Verbindung zwischen einem Pin und einem Signal her. Er ist der gleiche wie linksp, aber die Argumente sind umgekehrt.
linkpslinkps <pin-name> <signal-name>
linkps parport.0.pin-02-out X-Step
The linkps command has been superseded by the net command.
1.9.3. newsig
the command newsig creates a new HAL signal by the name <signame> and the data type of <type>. Type must be bool, sint, uint or real. Error if <signame> already exists.
newsignewsig <signame> <type>
newsig Xstep bool
Weitere Informationen finden Sie im HAL-Handbuch oder in den Man Pages für halrun.
2. HAL Daten
2.1. bool
A bool value is an on or off.
-
bool values = true or 1 and false or 0 (True, TRUE, true are all valid)
2.2. real
A real is a floating point number. In other words the decimal point can move as needed.
-
real values = a double precision floating point value, with approximately 53 bits of resolution and over 210 (~ 1000) bits of dynamic range.
Weitere Informationen über Gleitkommazahlen finden Sie unter:
2.3. sint
An sint number is a whole number that can have a negative or positive value.
-
sint values = integer numbers from -9223372036854775808 to 9223372036854775807
2.4. uint
A uint number is a whole number that is positive only.
-
uint values = integer numbers from 0 to 18446744073709551615
3. HAL Dateien
If you used the Stepper Config Wizard to generate your config you will have up to three HAL files in your config directory.
-
my-mill.hal (wenn Ihre Konfiguration my-mill heißt) Diese Datei wird zuerst geladen und sollte nicht geändert werden, wenn Sie den Stepper-Konfigurationsassistenten verwendet haben.
-
custom.hal Diese Datei wird als nächstes und vor dem Laden der grafischen Benutzeroberfläche geladen. Hier legen Sie Ihre benutzerdefinierten HAL-Befehle ab, die vor dem Laden der grafischen Benutzeroberfläche geladen werden sollen.
-
custom_postgui.hal Diese Datei wird geladen, nachdem die grafische Benutzeroberfläche geladen wurde. Hier werden die benutzerdefinierten HAL-Befehle abgelegt, die nach dem Laden der grafischen Benutzeroberfläche geladen werden sollen. Alle HAL-Befehle, die PyVCP-Widgets verwenden, müssen hier abgelegt werden.
4. HAL Parameter
One pin and two parameters are automatically added to each HAL component when it is created. These allow you to scope the execution time of a component.
.time
|
Pin time shows in ns how long it took to execute the function. |
.tmax
|
Parameter tmax is the maximum time in ns it took to execute the function. |
.tmax-increased
|
This parameter is set to true for one cycle if tmax increased. |
tmax" ist ein Lese-/Schreibparameter, so dass der Benutzer ihn auf 0 setzen kann, um die erste Initialisierung der Ausführungszeit der Funktion loszuwerden.
5. Grundlegende Logik-Komponenten
HAL contains several real time logic components. Logic components follow a Truth Table that states what the output is for any given input. Typically these are bit manipulators and follow electrical logic gate truth tables.
Für weitere Komponenten siehe HAL Components List oder die man pages.
5.1. and2
The and2 component is a two input and-gate. The truth table below shows the output based on each combination of input.
and2 [count=N] | [names=name1[,name2...]]
and2.n
and2.N.in0 (bool, in) and2.N.in1 (bool, in) and2.N.out (bool, out)
| in0 | in1 | out |
|---|---|---|
False |
False |
False |
True |
False |
False |
False |
True |
False |
True |
True |
True |
5.2. not
The not component is a boolean inverter.
not [count=n] | [names=name1[,name2...]]
not.all not.n
not.n.in (bool, in) not.n.out (bool, out)
| in | out |
|---|---|
True |
False |
False |
True |
5.3. or2
The or2 component is a two input or-gate.
or2[count=n] | [names=name1[,name2...]]
or2.n
or2.n.in0 (bool, in) or2.n.in1 (bool, in) or2.n.out (bool, out)
| in0 | in1 | out |
|---|---|---|
True |
False |
True |
True |
True |
True |
False |
True |
True |
False |
False |
False |
5.4. xor2
The xor2 component is a two input xor (exclusive or)-gate.
xor2[count=n] | [names=name1[,name2...]]
xor2.n
xor2.n.in0 (bool, in) xor2.n.in1 (bool, in) xor2.n.out (bool, out)
| in0 | in1 | out |
|---|---|---|
True |
False |
True |
True |
True |
False |
False |
True |
True |
False |
False |
False |
6. Logik-Beispiele
.Example using and2
loadrt and2 count=1
addf and2.0 servo-thread
net my-sigin1 and2.0.in0 <= parport.0.pin-11-in
net my-sigin2 and2.0.in1 <= parport.0.pin-12-in
net both-on parport.0.pin-14-out <= and2.0.out
In the above example one copy of and2 is loaded into real time space and added to the servo thread. Next pin-11 of the parallel port is connected to the in0 input of the and gate. Next pin-12 is connected to the in1 input of the and gate. Last we connect the and2 output to the parallel port pin-14. So following the truth table for and2 if pin 11 and pin 12 are on then the output pin 14 will be on.
7. Umwandlungs (engl. conversions)-Komponenten
7.1. weighted_sum
The weighted sum converts a group of booleans into an integer. The conversion is the sum of the weights of the booleans present plus any offset. It’s similar to binary coded decimal but with more options. The hold input interrupts the input processing, so that the sum value no longer changes.
weighted_sumloadrt weighted_sum wsum_sizes=size[,size,...]
Creates groups of ``weighted_sum``s, each with the given number of input booleans (size).
Um die "weighted_sum" zu aktualisieren, muss der "process_wsums" an einen Thread angehängt werden.
process_wsums zum Servo-Threadaddf process_wsums servo-thread
Which updates the weighted_sum component.
In the following example, a copy of the AXIS HAL configuration window, bools 0 and 2 are TRUE, they have no offset. The weight (weight) of bool 0 is 1, that of bool 2 is 4, so the sum is 5.
| Eigentümer (engl. owner) | Typ | Richt | Wert | Name |
|---|---|---|---|---|
10 |
bool |
In |
TRUE |
|
10 |
sint |
E/A (engl. I/O) |
1 |
|
10 |
bool |
In |
FALSE |
|
10 |
sint |
E/A (engl. I/O) |
2 |
|
10 |
bool |
In |
TRUE |
|
10 |
sint |
E/A (engl. I/O) |
4 |
|
10 |
bool |
In |
FALSE |
|
10 |
sint |
E/A (engl. I/O) |
8 |
|
10 |
bool |
In |
FALSE |
|
10 |
sint |
E/A (engl. I/O) |
0 |
|
10 |
sint |
Out |
5 |
|