Skip to content

Instantly share code, notes, and snippets.

@tcurdt

tcurdt/hal Secret

Last active July 11, 2022 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tcurdt/242330bc590b1b6d75d6ec9681c819d4 to your computer and use it in GitHub Desktop.
Save tcurdt/242330bc590b1b6d75d6ec9681c819d4 to your computer and use it in GitHub Desktop.
loadrt [KINS]KINEMATICS
loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[KINS]JOINTS
loadrt pid num_chan=4
loadrt hostmot2
loadrt hm2_eth board_ip="10.10.10.10" config="num_stepgens=5 num_encoders=0 num_pwmgens=0"
# loadrt debounce cfg=12
setp [MESA](CARD_0).watchdog.timeout_ns 5000000
#######################################
# threads
addf [MESA](CARD_0).read servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf pid.0.do-pid-calcs servo-thread
addf pid.1.do-pid-calcs servo-thread
addf pid.2.do-pid-calcs servo-thread
addf pid.3.do-pid-calcs servo-thread
# addf debounce.0 servo-thread
addf [MESA](CARD_0).write servo-thread
#######################################
# home/limit/probe
net x_home <= [MESA](CARD_0).gpio.031.in_not
net x_min <= [MESA](CARD_0).gpio.033.in_not
net x_max <= [MESA](CARD_0).gpio.032.in_not
net y1_home <= [MESA](CARD_0).gpio.028.in_not
net y1_min <= [MESA](CARD_0).gpio.030.in_not
net y1_max <= [MESA](CARD_0).gpio.029.in_not
net y2_home <= [MESA](CARD_0).gpio.025.in_not
net y2_min <= [MESA](CARD_0).gpio.027.in_not
net y2_max <= [MESA](CARD_0).gpio.026.in_not
net z_probe <= [MESA](CARD_0).gpio.023.in_not
net z_home <= [MESA](CARD_0).gpio.021.in_not
net t_home <= [MESA](CARD_0).gpio.019.in_not
# net in-min-x debounce.0.1.in <= [MESA](CARD_0).gpio.047.in
# net out-min-x debounce.0.1.out => joint.0.neg-lim-sw-in
#######################################
# joint 0 (X)
# pid
setp pid.0.Pgain [JOINT_0]P
setp pid.0.Igain [JOINT_0]I
setp pid.0.Dgain [JOINT_0]D
setp pid.0.bias [JOINT_0]BIAS
setp pid.0.FF0 [JOINT_0]FF0
setp pid.0.FF1 [JOINT_0]FF1
setp pid.0.FF2 [JOINT_0]FF2
setp pid.0.deadband [JOINT_0]DEADBAND
setp pid.0.maxoutput [JOINT_0]MAX_OUTPUT
setp pid.0.maxerror [JOINT_0]MAX_ERROR
setp pid.0.error-previous-target true
# enable
net joint-0-index-enable <=> pid.0.index-enable
net joint-0-enable <= joint.0.amp-enable-out
net joint-0-enable => pid.0.enable
net joint-0-enable => [JOINT_0](STEPGEN).enable
# stepgen
setp [JOINT_0](STEPGEN).dirsetup [DRIVER]DIRSETUP
setp [JOINT_0](STEPGEN).dirhold [DRIVER]DIRHOLD
setp [JOINT_0](STEPGEN).steplen [DRIVER]STEPLEN
setp [JOINT_0](STEPGEN).stepspace [DRIVER]STEPSPACE
setp [JOINT_0](STEPGEN).position-scale [DRIVER]SCALE
setp [JOINT_0](STEPGEN).maxvel [JOINT_0]STEPGEN_MAX_VELOCITY
setp [JOINT_0](STEPGEN).maxaccel [JOINT_0]STEPGEN_MAX_ACCELERATION
setp [JOINT_0](STEPGEN).step_type 0
setp [JOINT_0](STEPGEN).control-type 1
# feedback
net joint-0-pos-cmd <= joint.0.motor-pos-cmd
net joint-0-pos-cmd => pid.0.command
net joint-0-pos-fb <= [JOINT_0](STEPGEN).position-fb
net joint-0-pos-fb => joint.0.motor-pos-fb
net joint-0-pos-fb => pid.0.feedback
net joint.0.output <= pid.0.output
net joint.0.output => [JOINT_0](STEPGEN).velocity-cmd
# limit
net x_home => joint.0.home-sw-in
net x_min => joint.0.neg-lim-sw-in
net x_max => joint.0.pos-lim-sw-in
#######################################
# joint 1 (Y1)
# pid
setp pid.1.Pgain [JOINT_1]P
setp pid.1.Igain [JOINT_1]I
setp pid.1.Dgain [JOINT_1]D
setp pid.1.bias [JOINT_1]BIAS
setp pid.1.FF0 [JOINT_1]FF0
setp pid.1.FF1 [JOINT_1]FF1
setp pid.1.FF2 [JOINT_1]FF2
setp pid.1.deadband [JOINT_1]DEADBAND
setp pid.1.maxoutput [JOINT_1]MAX_OUTPUT
setp pid.1.maxerror [JOINT_1]MAX_ERROR
setp pid.1.error-previous-target true
# enable
net joint-1-index-enable <=> pid.1.index-enable
net joint-1-enable <= joint.1.amp-enable-out
net joint-1-enable => pid.1.enable
net joint-1-enable => [JOINT_1](STEPGEN).enable
# stepgen
setp [JOINT_1](STEPGEN).dirsetup [DRIVER]DIRSETUP
setp [JOINT_1](STEPGEN).dirhold [DRIVER]DIRHOLD
setp [JOINT_1](STEPGEN).steplen [DRIVER]STEPLEN
setp [JOINT_1](STEPGEN).stepspace [DRIVER]STEPSPACE
setp [JOINT_1](STEPGEN).position-scale [DRIVER]SCALE
setp [JOINT_1](STEPGEN).maxvel [JOINT_1]STEPGEN_MAX_VELOCITY
setp [JOINT_1](STEPGEN).maxaccel [JOINT_1]STEPGEN_MAX_ACCELERATION
setp [JOINT_1](STEPGEN).step_type 0
setp [JOINT_1](STEPGEN).control-type 1
# feedback
net joint-1-pos-cmd <= joint.1.motor-pos-cmd
net joint-1-pos-cmd => pid.1.command
net joint-1-pos-fb <= [JOINT_1](STEPGEN).position-fb
net joint-1-pos-fb => joint.1.motor-pos-fb
net joint-1-pos-fb => pid.1.feedback
net joint.1.output <= pid.1.output
net joint.1.output => [JOINT_1](STEPGEN).velocity-cmd
# limit
net y1_home => joint.1.home-sw-in
net y1_min => joint.1.neg-lim-sw-in
net y1_max => joint.1.pos-lim-sw-in
#######################################
# joint 2 (Y2)
# pid
setp pid.2.Pgain [JOINT_2]P
setp pid.2.Igain [JOINT_2]I
setp pid.2.Dgain [JOINT_2]D
setp pid.2.bias [JOINT_2]BIAS
setp pid.2.FF0 [JOINT_2]FF0
setp pid.2.FF1 [JOINT_2]FF1
setp pid.2.FF2 [JOINT_2]FF2
setp pid.2.deadband [JOINT_2]DEADBAND
setp pid.2.maxoutput [JOINT_2]MAX_OUTPUT
setp pid.2.maxerror [JOINT_2]MAX_ERROR
setp pid.2.error-previous-target true
# enable
net joint-2-index-enable <=> pid.2.index-enable
net joint-2-enable <= joint.2.amp-enable-out
net joint-2-enable => pid.2.enable
net joint-2-enable => [JOINT_2](STEPGEN).enable
# stepgen
setp [JOINT_2](STEPGEN).dirsetup [DRIVER]DIRSETUP
setp [JOINT_2](STEPGEN).dirhold [DRIVER]DIRHOLD
setp [JOINT_2](STEPGEN).steplen [DRIVER]STEPLEN
setp [JOINT_2](STEPGEN).stepspace [DRIVER]STEPSPACE
setp [JOINT_2](STEPGEN).position-scale [DRIVER]SCALE
setp [JOINT_2](STEPGEN).maxvel [JOINT_2]STEPGEN_MAX_VELOCITY
setp [JOINT_2](STEPGEN).maxaccel [JOINT_2]STEPGEN_MAX_ACCELERATION
setp [JOINT_2](STEPGEN).step_type 0
setp [JOINT_2](STEPGEN).control-type 1
# feedback
net joint-2-pos-cmd <= joint.2.motor-pos-cmd
net joint-2-pos-cmd => pid.2.command
net joint-2-pos-fb <= [JOINT_2](STEPGEN).position-fb
net joint-2-pos-fb => joint.2.motor-pos-fb
net joint-2-pos-fb => pid.2.feedback
net joint.2.output <= pid.2.output
net joint.2.output => [JOINT_2](STEPGEN).velocity-cmd
# limit
net y2_home => joint.2.home-sw-in
net y2_min => joint.2.neg-lim-sw-in
net y2_max => joint.2.pos-lim-sw-in
#######################################
# joint 3 (Z)
# pid
setp pid.3.Pgain [JOINT_3]P
setp pid.3.Igain [JOINT_3]I
setp pid.3.Dgain [JOINT_3]D
setp pid.3.bias [JOINT_3]BIAS
setp pid.3.FF0 [JOINT_3]FF0
setp pid.3.FF1 [JOINT_3]FF1
setp pid.3.FF2 [JOINT_3]FF2
setp pid.3.deadband [JOINT_3]DEADBAND
setp pid.3.maxoutput [JOINT_3]MAX_OUTPUT
setp pid.3.maxerror [JOINT_3]MAX_ERROR
setp pid.3.error-previous-target true
# enable
net joint-3-index-enable <=> pid.3.index-enable
net joint-3-enable <= joint.3.amp-enable-out
net joint-3-enable => pid.3.enable
net joint-3-enable => [JOINT_3](STEPGEN).enable
# stepgen
setp [JOINT_3](STEPGEN).dirsetup [DRIVER]DIRSETUP
setp [JOINT_3](STEPGEN).dirhold [DRIVER]DIRHOLD
setp [JOINT_3](STEPGEN).steplen [DRIVER]STEPLEN
setp [JOINT_3](STEPGEN).stepspace [DRIVER]STEPSPACE
setp [JOINT_3](STEPGEN).position-scale [DRIVER]SCALE
setp [JOINT_3](STEPGEN).maxvel [JOINT_3]STEPGEN_MAX_VELOCITY
setp [JOINT_3](STEPGEN).maxaccel [JOINT_3]STEPGEN_MAX_ACCELERATION
setp [JOINT_3](STEPGEN).step_type 0
setp [JOINT_3](STEPGEN).control-type 1
# feedback
net joint-3-pos-cmd <= joint.3.motor-pos-cmd
net joint-3-pos-cmd => pid.3.command
net joint-3-pos-fb <= [JOINT_3](STEPGEN).position-fb
net joint-3-pos-fb => joint.3.motor-pos-fb
net joint-3-pos-fb => pid.3.feedback
net joint.3.output <= pid.3.output
net joint.3.output => [JOINT_3](STEPGEN).velocity-cmd
# limit
net z_home => joint.3.home-sw-in
#######################################
# spindle
#######################################
# halui
# emergency
net estop-out <= iocontrol.0.user-enable-out
net estop-out => iocontrol.0.emc-enable-in
#net machine-is-on halui.machine.is-on
#net machine-is-enabled <= motion.motion-enabled
#net estop-loopback iocontrol.0.emc-enable-in <= iocontrol.0.user-enable-out
[EMC]
VERSION = 1.1
MACHINE = printnc
DEBUG = 0x00000000
[MESA]
CARD_0 = hm2_7i92.0
#FIRMWARE = 7i92_5ABOBx2D.bit
[DRIVER]
#STEPLEN = 10000
#STEPSPACE = 10000
#DIRHOLD = 10000
#DIRSETUP = 10000
STEPLEN = 5000
STEPSPACE = 5000
DIRHOLD = 5000
DIRSETUP = 5000
SCALE = 4000
[DISPLAY]
DISPLAY = axis
#DISPLAY = gmoccapy
#DISPLAY = qtpyvcp
#DISPLAY = touchy
#DISPLAY = qtvcp qtdragon
#PREFERENCE_FILE_PATH = /home/tcurdt/linuxcnc/qtdragon.pref
PROGRAM_PREFIX = /home/tcurdt/linuxcnc/nc_files
POSITION_OFFSET = RELATIVE
POSITION_FEEDBACK = COMMANDED
MAX_FEED_OVERRIDE = 1.2
MIN_VELOCITY = 0.0
DEFAULT_LINEAR_VELOCITY = 20.0
MAX_LINEAR_VELOCITY = 200.0
CYCLE_TIME = 0.1
INTRO_GRAPHIC = emc2.gif
INTRO_TIME = 0
#PYVCP = vfd.xml
[KINS]
KINEMATICS = trivkins coordinates=XYYZ kinstype=BOTH
JOINTS = 4
[EMCIO]
EMCIO = iov2
CYCLE_TIME = 0.100
TOOL_TABLE = tool.tbl
#TOOL_CHANGE_POSITION = 0 0 2
[RS274NGC]
PARAMETER_FILE = printnc.var
SUBROUTINE_PATH = /home/tcurdt/linuxcnc/subroutines
[EMCMOT]
EMCMOT = motmod
COMM_TIMEOUT = 1.0
SERVO_PERIOD = 1000000
[TASK]
TASK = milltask
CYCLE_TIME = 0.010
[TRAJ]
COORDINATES = XYYZ
LINEAR_UNITS = mm
ANGULAR_UNITS = degree
NO_FORCE_HOMING = 1
#DEFAULT_LINEAR_VELOCITY = 0.0167
#DEFAULT_LINEAR_ACCELERATION = 2.0
#MAX_LINEAR_VELOCITY = 5.0
#MAX_LINEAR_ACCELERATION = 20.0
#HOME = 0 0 0 0 0 0 0 0 0
[HAL]
HALUI = halui
HALFILE = printnc.hal
#HALFILE = modbus.hal
#HALFILE = tool.hal
#HALFILE = probe.hal
#POSTGUI_HALFILE = vfd.hal
#SHUTDOWN =
[HALUI]
[AXIS_X]
MAX_VELOCITY = 50.0
MAX_ACCELERATION = 50.0
MIN_LIMIT = -10
MAX_LIMIT = 1000
[AXIS_Y]
MAX_VELOCITY = 50.0
MAX_ACCELERATION = 50.0
MIN_LIMIT = -10
MAX_LIMIT = 800
[AXIS_Z]
MAX_VELOCITY = 50.0
MAX_ACCELERATION = 50.0
MIN_LIMIT = -10
MAX_LIMIT = 300
[JOINT_0]
AXIS = X
TYPE = LINEAR
#BACKLASH = 0
MAX_VELOCITY = 50.0
MAX_ACCELERATION = 50.0
MIN_LIMIT = -10
MAX_LIMIT = 1000
MIN_FERROR = 0.01
FERROR = 1.0
BIAS = 0
P = 1000
I = 0
D = 0
FF0 = 0
FF1 = 1
FF2 = 0
DEADBAND = 0.000015
MAX_OUTPUT = 0
MAX_ERROR = 0.0127
STEPGEN = hm2_7i92.0.stepgen.04
STEPGEN_MAX_VELOCITY = 60.0
STEPGEN_MAX_ACCELERATION = 60.0
#HOME = 0.0
#HOME_FINAL_VEL = 0.0
HOME_OFFSET = 0
HOME_SEARCH_VEL = 0
HOME_LATCH_VEL = 0
HOME_USE_INDEX = NO
#HOME_SEQUENCE = 1
HOME_SEQUENCE = 0
[JOINT_1]
AXIS = Y
TYPE = LINEAR
#BACKLASH = 0
MAX_VELOCITY = 50.0
MAX_ACCELERATION = 50.0
MIN_LIMIT = -10
MAX_LIMIT = 800
MIN_FERROR = 0.01
FERROR = 1.0
BIAS = 0
P = 1000
I = 0
D = 0
FF0 = 0
FF1 = 1
FF2 = 0
DEADBAND = 0.000015
MAX_OUTPUT = 0
MAX_ERROR = 0.0127
STEPGEN = hm2_7i92.0.stepgen.03
STEPGEN_MAX_VELOCITY = 60.0
STEPGEN_MAX_ACCELERATION = 60.0
#HOME = 0.0
#HOME_FINAL_VEL = 0.0
HOME_OFFSET = 0
HOME_SEARCH_VEL = 0
HOME_LATCH_VEL = 0
HOME_USE_INDEX = NO
#HOME_SEQUENCE = -1
HOME_SEQUENCE = 0
[JOINT_2]
AXIS = Y
TYPE = LINEAR
#BACKLASH = 0
MAX_VELOCITY = 50.0
MAX_ACCELERATION = 50.0
MIN_LIMIT = -10
MAX_LIMIT = 800
MIN_FERROR = 0.01
FERROR = 1.0
BIAS = 0
P = 1000
I = 0
D = 0
FF0 = 0
FF1 = 1
FF2 = 0
DEADBAND = 0.000015
MAX_OUTPUT = 0
MAX_ERROR = 0.0127
STEPGEN = hm2_7i92.0.stepgen.02
STEPGEN_MAX_VELOCITY = 60.0
STEPGEN_MAX_ACCELERATION = 60.0
#HOME = 0.0
#HOME_FINAL_VEL = 0.0
HOME_OFFSET = 0
HOME_SEARCH_VEL = 0
HOME_LATCH_VEL = 0
HOME_USE_INDEX = NO
#HOME_SEQUENCE = -1
HOME_SEQUENCE = 0
[JOINT_3]
AXIS = Z
TYPE = LINEAR
#BACKLASH = 0
MAX_VELOCITY = 50.0
MAX_ACCELERATION = 50.0
MIN_LIMIT = -10
MAX_LIMIT = 300
MIN_FERROR = 0.01
FERROR = 1.0
BIAS = 0
P = 1000
I = 0
D = 0
FF0 = 0
FF1 = 1
FF2 = 0
DEADBAND = 0.000015
MAX_OUTPUT = 0
MAX_ERROR = 0.0127
STEPGEN = hm2_7i92.0.stepgen.01
STEPGEN_MAX_VELOCITY = 60.0
STEPGEN_MAX_ACCELERATION = 60.0
#HOME = 0.0
#HOME_FINAL_VEL = 0.0
HOME_OFFSET = 0
HOME_SEARCH_VEL = 0
HOME_LATCH_VEL = 0
HOME_USE_INDEX = NO
HOME_SEQUENCE = 0
$ mesaflash --device 7i92 --addr 10.10.10.10 --readhmid
Configuration Name: HOSTMOT2
General configuration information:
BoardName : MESA7I92
FPGA Size: 9 KGates
FPGA Pins: 144
Number of IO Ports: 2
Width of one I/O port: 17
Clock Low frequency: 100.0000 MHz
Clock High frequency: 200.0000 MHz
IDROM Type: 3
Instance Stride 0: 4
Instance Stride 1: 64
Register Stride 0: 256
Register Stride 1: 256
Modules in configuration:
Module: DPLL
There are 1 of DPLL in configuration
Version: 0
Registers: 7
BaseAddress: 7000
ClockFrequency: 100.000 MHz
Register Stride: 256 bytes
Instance Stride: 4 bytes
Module: WatchDog
There are 1 of WatchDog in configuration
Version: 0
Registers: 3
BaseAddress: 0C00
ClockFrequency: 100.000 MHz
Register Stride: 256 bytes
Instance Stride: 4 bytes
Module: IOPort
There are 2 of IOPort in configuration
Version: 0
Registers: 5
BaseAddress: 1000
ClockFrequency: 100.000 MHz
Register Stride: 256 bytes
Instance Stride: 4 bytes
Module: QCount
There are 6 of QCount in configuration
Version: 2
Registers: 5
BaseAddress: 3000
ClockFrequency: 100.000 MHz
Register Stride: 256 bytes
Instance Stride: 4 bytes
Module: StepGen
There are 5 of StepGen in configuration
Version: 2
Registers: 10
BaseAddress: 2000
ClockFrequency: 100.000 MHz
Register Stride: 256 bytes
Instance Stride: 4 bytes
Module: PWM
There are 1 of PWM in configuration
Version: 0
Registers: 5
BaseAddress: 4100
ClockFrequency: 200.000 MHz
Register Stride: 256 bytes
Instance Stride: 4 bytes
Module: LED
There are 1 of LED in configuration
Version: 0
Registers: 1
BaseAddress: 0200
ClockFrequency: 100.000 MHz
Register Stride: 256 bytes
Instance Stride: 4 bytes
Configuration pin-out:
IO Connections for P2
Pin# I/O Pri. func Sec. func Chan Pin func Pin Dir
1 0 IOPort PWM 0 PWM (Out)
14 1 IOPort None
2 2 IOPort StepGen 0 Step/Table1 (Out)
15 3 IOPort None
3 4 IOPort StepGen 0 Dir/Table2 (Out)
16 5 IOPort StepGen 4 Step/Table1 (Out)
4 6 IOPort StepGen 1 Step/Table1 (Out)
17 7 IOPort StepGen 4 Dir/Table2 (Out)
5 8 IOPort StepGen 1 Dir/Table2 (Out)
6 9 IOPort StepGen 2 Step/Table1 (Out)
7 10 IOPort StepGen 2 Dir/Table2 (Out)
8 11 IOPort StepGen 3 Step/Table1 (Out)
9 12 IOPort StepGen 3 Dir/Table2 (Out)
10 13 IOPort None
11 14 IOPort QCount 0 Quad-A (In)
12 15 IOPort QCount 0 Quad-B (In)
13 16 IOPort QCount 0 Quad-IDX (In)
IO Connections for P1
Pin# I/O Pri. func Sec. func Chan Pin func Pin Dir
1 17 IOPort QCount 1 Quad-A (In)
14 18 IOPort QCount 1 Quad-B (In)
2 19 IOPort QCount 1 Quad-IDX (In)
15 20 IOPort QCount 2 Quad-A (In)
3 21 IOPort QCount 2 Quad-B (In)
16 22 IOPort QCount 2 Quad-IDX (In)
4 23 IOPort QCount 3 Quad-A (In)
17 24 IOPort QCount 3 Quad-B (In)
5 25 IOPort QCount 3 Quad-IDX (In)
6 26 IOPort QCount 4 Quad-A (In)
7 27 IOPort QCount 4 Quad-B (In)
8 28 IOPort QCount 4 Quad-IDX (In)
9 29 IOPort QCount 5 Quad-A (In)
10 30 IOPort QCount 5 Quad-B (In)
11 31 IOPort QCount 5 Quad-IDX (In)
12 32 IOPort None
13 33 IOPort None
stepgen00 (T1)
stp=io02
dir=io04
stepgen01 (Z1)
stp=io06
dir=io08
stepgen02 (Y2)
stp=io09
dir=io10
stepgen03 (Y1)
stp=io11
dir=io12
stepgen04 (X1)
stp=io05
dir=io07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment