Conditionally loading a HAL file

71 views
Skip to first unread message

Paulo Sherring

unread,
Oct 1, 2018, 12:05:50 PM10/1/18
to Machinekit
Hey there! I am new to machinekit / linuxcnc and I have a question I couldn't find an answer. I have a joystick pluged in a BeagleBone Green and I use it to control a CNC router. The fact is that sometimes, I may have to use the machine without the controller - maybe its mal functioning or something of this sort.
Currently, I am loading a hal file that specifically sets up the relations between the buttons and the jog signals on my INI file, something like:
HALFILE = joystick.hal
What I need is to run some kind of check on my ini file to load it or not, something like
if [ -f /dev/input/js0]
then
HALFILE = joystick.hal
fi

Obviously, this could also be inside the hal file itself, but, I also don't know how to do it :(
Thanks in advance!
Paulo Sherring.

schoo...@gmail.com

unread,
Oct 2, 2018, 5:37:04 AM10/2/18
to machi...@googlegroups.com
The easiest thing to do would be to do this beforehand.

There is no conditional checking available within an ini file, since this file
is read by other programs and does not of itself do anything.

Run from a script and check for the existence of the joystick device, then
launch the relevant config.

eg.  launch.sh

# !/bin/bash

if [ -f /dev/input/js0] ; then
    machinekit ~/configs/myconfig/my-config-with-js.ini
else
    machinekit ~/configs/myconfig/my-config-without-js.ini
fi
--
website: http://www.machinekit.io blog: http://blog.machinekit.io github: https://github.com/machinekit
---
You received this message because you are subscribed to the Google Groups "Machinekit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to machinekit+...@googlegroups.com.
Visit this group at https://groups.google.com/group/machinekit.
For more options, visit https://groups.google.com/d/optout.

Paulo Sherring

unread,
Jul 18, 2019, 6:04:31 PM7/18/19
to Machinekit
Late solving here, just posting in case it helps someone someday :)

I created a small python code to test if the joystick file exists and called it with loadusr -w joystickLoader
In my case, i got these three files:

joystickLoader:
#!/usr/bin/python
import hal
import os

# load the HAL file 'joystickOptions.hal'
res = os.spawnvp(os.P_WAIT, "halcmd", ['halcmd' , '-k', '-Q', '-f', 'joystickOptions.hal'])
joyFileExists = os.path.isfile('/dev/js0')
if joyFileExists == True:
  print 'Joystick found! Initilizing...'
  # load the HAL file 'joystickOptions.hal'
  res = os.spawnvp(os.P_WAIT, "halcmd", ['halcmd' , '-k', '-Q', '-f', 'joystickOptions.hal'])
  if not res:
    res = os.spawnvp(os.P_WAIT, "halcmd", ['halcmd' ,"-f", "joystickSuccess.hal"])
    if res:
      print '**** TRY LOADER ERROR: try_sucess.hal file Error'
      raise SystemExit, res
else:
  print 'No joystick found'
exit()

joystickOptions.hal:
loadusr hal_input -KRAL 1

joystickSuccess.hal:
loadrt or2 count=2
loadrt mux4 count=2
addf or2.0 servo-thread
addf or2.1 servo-thread
addf mux4.0 servo-thread
# set the jog speed for the joypad again use numbers that make sense for your machine
setp mux4.0.in0 0 # this one must be 0 to prevent motion unless a button is pressed
setp mux4.0.in1 50
setp mux4.0.in2 300
setp mux4.0.in3 1800
# the following does the magic of setting the jog speeds
net remote-speed-slow or2.0.in0 input.0.btn-thumb2
net remote-speed-medium or2.1.in0 input.0.btn-thumb
net remote-speed-fast or2.0.in1 or2.1.in1 input.0.btn-joystick
net joy-speed-1 mux4.0.sel0 <= or2.0.out
net joy-speed-2 mux4.0.sel1 <= or2.1.out
net joy-speed-final halui.jog-speed <= mux4.0.out
net joy-x-jog halui.jog.0.analog <= input.0.abs-x-position
setp input.0.abs-y-scale -127.5
net joy-y-jog halui.jog.1.analog <= input.0.abs-y-position
addf mux4.1 servo-thread
setp mux4.1.in0 0
setp mux4.1.in1 -1
setp mux4.1.in2 1
setp mux4.1.in3 0
net joy-z-up mux4.1.sel0 <= input.0.btn-base
net joy-z-down mux4.1.sel1 <= input.0.btn-base2
net joy-z-jog halui.jog.2.analog <= mux4.1.out


Best Regards.
Paulo Sherring.
Reply all
Reply to author
Forward
0 new messages