All of these examples assume you are starting with a stepconf based configuration and have two threads base-thread and servo-thread. The stepconf wizard will create an empty custom.hal and a custom_postgui.hal file. The custom.hal file will be loaded after the configuration HAL file and the custom_postgui.hal file is loaded after the GUI has been loaded.

1. Verbinden von zwei Ausgängen

To connect two outputs to an input you can use the or2 component. The or2 works like this, if either input to or2 is on then the or2 output is on. If neither input to or2 is on the or2 output is off.

For example to have two PyVCP buttons both connected to one LED.

The .xml file to instruct PyVCP to prepare a GUI that features two buttons (named "button-1" and "button-2") and an LED (named "led-1").
    <text>"Button 1"</text>

    <text>"Button 2"</text>

The postgui.hal file, read after the GUI is set up and ports ready to accept the logic described in HAL.
loadrt or2
addf or2.0 servo-thread
net button-1 or2.0.in0 <= pyvcp.button-1
net button-2 or2.0.in1 <= pyvcp.button-2
net led-1 pyvcp.led-1 <= or2.0.out

When you run this example in an axis simulator created with the StepConf Wizard, you can open a terminal and see the pins created with loadrt or2 by typing in halcmd show pin or2 in the terminal.

Running halcmd on the UNIX command line to show the pins crafted with module or2.
$ halcmd show pin or2
Component Pins:
Owner   Type  Dir         Value  Name
    22  bit   IN          FALSE  or2.0.in0 <== button-1
    22  bit   IN          FALSE  or2.0.in1 <== button-2
    22  bit   OUT         FALSE  or2.0.out ==> led-1

You can see from the HAL command show pin or2 that the button-1 pin is connected to the or2.0.in0 pin. From the direction arrow you can see that the button is and output and the or2.0.in0 is an input. The output from or2 goes to the input of the LED.

2. Manueller Werkzeugwechsel

In this example it is assumed that you’re rolling your own configuration and wish to add the HAL Manual Toolchange window. The HAL Manual Toolchange is primarily useful if you have presettable tools and you store the offsets in the tool table. If you need to touch off for each tool change then it is best just to split up your G-code. To use the HAL Manual Toolchange window you basically have to

  1. load the hal_manualtoolchange component,

  2. then send the iocontrol tool change to the hal_manualtoolchange change and

  3. send the hal_manualtoolchange changed back to the iocontrol tool changed.

A pin is provided for an external input to indicate the tool change is complete.

Dies ist ein Beispiel für den manuellen Werkzeugwechsel mit der Komponente HAL Manual Toolchange:

loadusr -W hal_manualtoolchange
net tool-change iocontrol.0.tool-change => hal_manualtoolchange.change
net tool-changed iocontrol.0.tool-changed <= hal_manualtoolchange.changed
net external-tool-changed hal_manualtoolchange.change_button <=
net tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared

Dies ist ein Beispiel für den manuellen Werkzeugwechsel ohne die Komponente HAL Manual Toolchange:

net tool-number <= iocontrol.0.tool-prep-number
net tool-change-loopback iocontrol.0.tool-change => iocontrol.0.tool-changed
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared

3. Geschwindigkeit berechnen

This example uses ddt, mult2 and abs to compute the velocity of a single axis. For more information on the real time components see the man pages or the HAL Components List ([sec:hal-components]).

The first thing is to check your configuration to make sure you are not using any of the real time components all ready. You can do this by opening up the HAL Configuration window and look for the components in the pin section. If you are then find the HAL file that they are being loaded in and increase the counts and adjust the instance to the correct value. Add the following to your custom.hal file.

Laden der Echtzeitkomponenten.

loadrt ddt count=1
loadrt mult2 count=1
loadrt abs count=1

Fügen Sie die Funktionen in einen Thread ein, damit dieser aktualisiert wird.

addf ddt.0 servo-thread
addf mult2.0 servo-thread
addf abs.0 servo-thread

Herstellen der Verbindungen.

setp mult2.in1 60
net xpos-cmd
net X-IPS mult2.0.in0 <= ddt.0.out
net X-ABS <= mult2.0.out
net X-IPM abs.0.out

In this last section we are setting the mult2.0.in1 to 60 to convert the inch per second to inch per minute (IPM) that we get from the ddt.0.out.

The xpos-cmd sends the commanded position to the The ddt computes the derivative of the change of the input.

The ddt2.0.out is multiplied by 60 to give IPM.

The mult2.0.out is sent to the abs to get the absolute value.

The following figure shows the result when the X axis is moving at 15 IPM in the minus direction. Notice that we can get the absolute value from either the abs.0.out pin or the X-IPM signal.

HAL: Geschwindigkeitsbeispiel
Abbildung 1. HAL: Geschwindigkeitsbeispiel

4. Details zum Softstart

Dieses Beispiel zeigt, wie die HAL-Komponenten Tiefpass, limit2 oder limit3 verwendet werden können, um die Änderungsgeschwindigkeit eines Signals zu begrenzen.

In this example we have a servo motor driving a lathe spindle. If we just used the commanded spindle speeds on the servo it will try to go from present speed to commanded speed as fast as it can. This could cause a problem or damage the drive. To slow the rate of change we can send the spindle.N.speed-out through a limiter before the PID, so that the PID command value changes to new settings more slowly.

Die drei eingebauten Komponenten, die ein Signal begrenzen, sind:

  • limit2 begrenzt den Bereich und die erste Ableitung eines Signals.

  • limit3 begrenzt den Bereich, die erste und zweite Ableitung eines Signals.

  • Tiefpass verwendet einen exponentiell gewichteten gleitenden Durchschnitt, um ein Eingangssignal zu verfolgen.

Weitere Informationen über diese HAL-Komponenten finden Sie in den Man Pages.

Place the following in a text file called softstart.hal. If you’re not familiar with Linux place the file in your home directory.

loadrt threads period1=1000000 name1=thread
loadrt siggen
loadrt lowpass
loadrt limit2
loadrt limit3
net square siggen.0.square =>
net lowpass <= lowpass.0.out
net limit2 <= limit2.0.out
net limit3 <= limit3.0.out
setp siggen.0.frequency .1
setp lowpass.0.gain .01
setp limit2.0.maxv 2
setp limit3.0.maxv 2
setp limit3.0.maxa 10
addf siggen.0.update thread
addf lowpass.0 thread
addf limit2.0 thread
addf limit3.0 thread
loadusr halscope

Öffnen Sie ein Terminalfenster und führen Sie die Datei mit dem folgenden Befehl aus.

halrun -I softstart.hal

Wenn das HAL Oszilloskop zum ersten Mal startet, klicken Sie auf OK, um den Standardfaden zu akzeptieren.

Next you have to add the signals to the channels. Click on channel 1 then select square from the Signals tab. Repeat for channels 2-4 and add lowpass, limit2, and limit3.

Next to set up a trigger signal click on the Source None button and select square. The button will change to Source Chan 1.

Next click on Single in the Run Mode radio buttons box. This will start a run and when it finishes you will see your traces.

Um die Signale zu trennen, damit Sie sie besser sehen können, klicken Sie auf einen Kanal und verwenden Sie dann den Pos-Schieberegler im vertikalen Feld, um die Positionen festzulegen.


To see the effect of changing the set point values of any of the components you can change them in the terminal window. To see what different gain settings do for lowpass just type the following in the terminal window and try different settings.

setp lowpass.0.gain *.01

Nachdem Sie eine Einstellung geändert haben, lassen Sie das Oszilloskop erneut laufen, um die Änderung zu sehen.

When you’re finished type exit in the terminal window to shut down halrun and close the halscope. Don’t close the terminal window with halrun running as it might leave some things in memory that could prevent LinuxCNC from loading.

Weitere Informationen zu Halscope finden Sie im HAL-Handbuch und im Tutorial.

5. Stand-Alone HAL

In some cases you might want to run a GladeVCP screen with just HAL. For example say you had a stepper driven device that all you need is to run a stepper motor. A simple Start/Stop interface is all you need for your application so no need to load up and configure a full blown CNC application.

Im folgenden Beispiel haben wir ein einfaches GladeVCP-Panel mit einem Schrittmotor.

Grundlegende (engl. basic) Syntax
# Lädt die GUI und nennt diese winder
loadusr -Wn winder gladevcp -c winder -u

# load Echtzeit-Komponenten
loadrt threads name1=fast period1=50000 fp1=0 name2=slow period2=1000000
loadrt stepgen step_type=0 ctrl_type=v
loadrt hal_parport cfg="0x378 out"

# fügt Funktionen den Threads hinzu
addf stepgen.make-pulses fast
addf stepgen.update-freq slow
addf stepgen.capture-position slow
addf fast
addf parport.0.write fast

# Erstellt Verbindungen in HAL
net winder-step <= stepgen.0.step
net winder-dir <= stepgen.0.dir
net run-stepgen stepgen.0.enable <= winder.start_button

# Start der Threads

# kommentieren Sie die folgenden Zeilen beim Testen aus und verwenden Sie die interaktive
# option halrun -I -f start.hal, um Pins etc. anzeigen zu können.

# Warten, bis die GladeVCP-GUI namens winder beendet ist
waitusr winder

# Stop HAL threads

# "unload" aller Komponenten in HAL vor dem Beenden
unloadrt all