LinuxCNC Configuration

Some tidbits that will help with LinuxCNC Configuration that I learned along the way, and my own current LCNC Config for an XYYZ kinematics machine.
My LinuxCNC Configuration and some tips/tricks I've discovered along the way
GitHub Link to my configuration
Stepgen PID
Your Stepgen P value, which shows up in your .hal file -
STEPGEN_MAXVEL = 208.33
STEPGEN_MAXACCEL = 7000
P = 500.0
I = 0.0
D = 0.0
FF0 = 0.0
FF1 = 1.0
FF2 = 0.0
BIAS = 0.0
DEADBAND = 0.0
MAX_OUTPUT = 0.0
Is inversely proportional to your servo period value.
SERVO_PERIOD = 2000000
E.g. If you have a SERVO_PERIOD of 1000000, which corresponds to 1ms, then the P is 1000. If you have a 2ms SERVO_PERIOD, then P should be 500, and so on.
As best I understand, this has to do with how LinuxCNC compensates for error between the PC and the Mesa card.
Slow Jogging
# *** Slow Jogging***
loadrt mux2 names=xmux,ymux,zmux
addf xmux servo-thread
addf ymux servo-thread
addf zmux servo-thread
net slowselect <= halui.mode.is-manual
net slowselect => xmux.sel => ymux.sel => zmux.sel
setp xmux.in0 [AXIS_X]MAX_ACCELERATION
setp ymux.in0 [AXIS_Y]MAX_ACCELERATION
setp zmux.in0 [AXIS_Z]MAX_ACCELERATION
setp xmux.in1 1000.0
setp ymux.in1 1000.0
setp zmux.in1 500.0
net xmux-sig xmux.out => ini.x.max_acceleration
net ymux-sig ymux.out => ini.y.max_acceleration
net zmux-sig zmux.out => ini.z.max_acceleration
This code snippet can be added to custom_postgui.hal in order to use different accel values when in jogging mode. This can be useful since the trapezoidal trajectory planner that LCNC currently uses can result in jerky movements, whether you are using a keyboard or an MPG.
Time for Probe Basic
# *** Add Time ***
loadrt time
loadrt not
addf time.0 servo-thread
addf not.0 servo-thread
net prog-running not.0.in <= halui.program.is-idle
net cycle-timer time.0.start <= not.0.out
net cycle-seconds qtpyvcp.timerseconds.in <= time.0.seconds
net cycle-minutes qtpyvcp.timerminutes.in <= time.0.minutes
net cycle-hours qtpyvcp.timerhours.in <= time.0.hours
If you're using Probe basic, this makes the timer field work properly
Spindle Load Percentage
More details on the LinuxCNC Forum, but this (in combination with the the manually made load_conv.comp mentioned on the forum) makes the spindle load meter work properly.
For instance, my load_conv.comp file looks like
component load_conv "calculates percentage of load based on motor Amps";
pin in float amps;
pin out float percent;
function _;
license "GPL"; // indicates GPL v2 or later
;;
#include <rtapi_math.h>
percent = round(amps/0.12);
Change 0.12 to be how many amps your spindle can handle at max load (0.12 is 12a in my case)
Open terminal and run
halcompile --install load_conv.comp`
If HalCompile isn't installed, make sure to install the linuxcnc-dev
tools package
Then add the following to your HAL.
A couple notes:
- The compiled file saved to /usr/lib/linuxcnc/modules is named load_conv.so, and it must be loaded in HAL as load_conv. However, the pin added with addf must be load-conv, with a hyphen instead of an underscore.
- The pins are load-conv.0.amps and load-conv.0.percent
# *** Spindle Load Percent ***
loadrt load_conv
addf load-conv.0 servo-thread
setp qtpyvcp.spindle-load-indicator.max-val 100
net spindle-current => load-conv.0.amps
net spindle-load qtpyvcp.spindle-load-indicator.in-f <= load-conv.0.percent
net spindle-speed-fb => qtpyvcp.spindle-encoder-rpm.in
Probing Hardware
This enables me to use both the tool setter and the probe with LinuxCNC. I use the subroutine from TooTall18T that's available on GitHub
# *** Probe HAL ***
loadrt or2 count=2
addf or2.0 servo-thread
addf or2.1 servo-thread
# or2.1 belongs to mpg.hal
net tool_sensor-in <= hm2_7i76e.0.7i76.0.0.input-14-not
net probe-in <= hm2_7i76e.0.7i76.0.0.input-13-not
net estop-ext <= hm2_7i76e.0.7i76.0.0.input-15-not
net tool_sensor-in => or2.0.in0
net probe-in => or2.0.in1
net probe-tool or2.0.out
net probe-tool => motion.probe-input