Multiple encoders

More
19 Nov 2021 22:16 #227027 by polobear189
I am trying to set up a cnc lathe with an MPG to select and move axes.

The lathe already has an encoder set up for spindle index and 100 pulses per rev, but i add this custom.hal file for setting up the MPG and Linuxcnc gives me a problem on loading.

It seems like an encoder numbering problem? but i cannot see the problem, i wonder if someone could point me in the right direction?

Many Thanks!

=26pxDebug message

Print file information:
RUN_IN_PLACE=no
LINUXCNC_DIR=
LINUXCNC_BIN_DIR=/usr/bin
LINUXCNC_TCL_DIR=/usr/lib/tcltk/linuxcnc
LINUXCNC_SCRIPT_DIR=
LINUXCNC_RTLIB_DIR=/usr/realtime-3.4-9-rtai-686-pae/modules/linuxcnc
LINUXCNC_CONFIG_DIR=
LINUXCNC_LANG_DIR=/usr/share/linuxcnc/tcl/msgs
INIVAR=inivar
HALCMD=halcmd
LINUXCNC_EMCSH=/usr/bin/wish8.5
LINUXCNC - 2.7.15
Machine configuration directory is '/home/cnclathe/linuxcnc/configs/lathe'
Machine configuration file is 'lathe.ini'
INIFILE=/home/cnclathe/linuxcnc/configs/lathe/lathe.ini
PARAMETER_FILE=linuxcnc.var
TASK=milltask
HALUI=
DISPLAY=axis
Starting LinuxCNC...
Starting LinuxCNC server program: linuxcncsvr
Loading Real Time OS, RTAPI, and HAL_LIB modules
Starting LinuxCNC IO program: io
Found file(REL): ./lathe.hal
Found file(REL): ./custom.hal
Shutting down and cleaning up LinuxCNC...
Removing HAL_LIB, RTAPI, and Real Time OS modules
Removing NML shared memory segments

Debug file information:
Error: could not insert module /usr/realtime-3.4-9-rtai-686-pae/modules/linuxcnc/encoder.ko: File exists
./custom.hal:5: exit value: 1
./custom.hal:5: insmod for encoder failed, returned -1
See the output of 'dmesg' for more information.
3549
Stopping realtime threads
Unloading hal components
Traceback (most recent call last):
  File "/usr/bin/hal_manualtoolchange", line 62, in <module>
    app = Tkinter.Tk(className="AxisToolChanger")
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1712, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
KeyboardInterrupt


HAL FILE


# Generated by stepconf 1.1 at Fri Nov  5 17:05:26 2021
# If you make changes to this file, they will be
# overwritten when you run stepconf again
loadrt trivkins
loadrt [EMCMOT]EMCMOT base_period_nsec=[EMCMOT]BASE_PERIOD servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
loadrt hal_parport cfg="0x9400 out 0xac00 in"
setp parport.0.reset-time 1000
loadrt stepgen step_type=0,0,0,0
loadrt encoder num_chan=2
loadrt abs count=1
loadrt scale count=1
loadrt lowpass count=1
loadrt pwmgen output_type=1

addf parport.0.read base-thread
addf parport.1.read base-thread
addf stepgen.make-pulses base-thread
addf encoder.update-counters base-thread
addf pwmgen.make-pulses base-thread
addf parport.0.write base-thread
addf parport.0.reset base-thread
addf parport.1.write base-thread

addf stepgen.capture-position servo-thread
addf encoder.capture-position servo-thread
addf motion-command-handler servo-thread
addf motion-controller servo-thread
addf stepgen.update-freq servo-thread
addf pwmgen.update servo-thread
addf abs.0 servo-thread
addf scale.0 servo-thread
addf lowpass.0 servo-thread

net spindle-cmd-rpm => pwmgen.0.value
net spindle-on <= motion.spindle-on => pwmgen.0.enable
net spindle-pwm <= pwmgen.0.pwm
setp pwmgen.0.pwm-freq 100.0
setp pwmgen.0.scale 2350.0
setp pwmgen.0.offset 0.0
setp pwmgen.0.dither-pwm true
net spindle-cmd-rpm     <= motion.spindle-speed-out
net spindle-cmd-rpm-abs <= motion.spindle-speed-out-abs
net spindle-cmd-rps     <= motion.spindle-speed-out-rps
net spindle-cmd-rps-abs <= motion.spindle-speed-out-rps-abs
net spindle-at-speed    => motion.spindle-at-speed
net spindle-cw <= motion.spindle-forward
net spindle-ccw <= motion.spindle-reverse

setp encoder.0.position-scale 100.000000
setp encoder.0.counter-mode 1
net spindle-position encoder.0.position => motion.spindle-revs
net spindle-velocity-feedback-rps encoder.0.velocity => motion.spindle-speed-in
net spindle-index-enable encoder.0.index-enable <=> motion.spindle-index-enable
net spindle-phase-a encoder.0.phase-A
net spindle-phase-b encoder.0.phase-B
net spindle-index encoder.0.phase-Z

net spindle-ccw     => parport.0.pin-01-out
net xstep           => parport.0.pin-02-out
setp parport.0.pin-02-out-reset 1
net xdir            => parport.0.pin-03-out
net ystep           => parport.0.pin-04-out
setp parport.0.pin-04-out-reset 1
net ydir            => parport.0.pin-05-out
net zstep           => parport.0.pin-06-out
setp parport.0.pin-06-out-reset 1
net zdir            => parport.0.pin-07-out
net astep           => parport.1.pin-14-out
setp parport.1.pin-14-out-reset 1
net adir            => parport.1.pin-16-out
net spindle-pwm     => parport.0.pin-14-out
net spindle-cw      => parport.0.pin-17-out


net spindle-index   <= parport.0.pin-10-in-not
net spindle-phase-a <= parport.0.pin-11-in
net estop-ext       <= parport.0.pin-15-in-not



setp stepgen.0.position-scale [AXIS_0]SCALE
setp stepgen.0.steplen 1
setp stepgen.0.stepspace 0
setp stepgen.0.dirhold 50200
setp stepgen.0.dirsetup 50200
setp stepgen.0.maxaccel [AXIS_0]STEPGEN_MAXACCEL
net xpos-cmd axis.0.motor-pos-cmd => stepgen.0.position-cmd
net xpos-fb stepgen.0.position-fb => axis.0.motor-pos-fb
net xstep <= stepgen.0.step
net xdir <= stepgen.0.dir
net xenable axis.0.amp-enable-out => stepgen.0.enable

setp stepgen.1.position-scale [AXIS_1]SCALE
setp stepgen.1.steplen 1
setp stepgen.1.stepspace 0
setp stepgen.1.dirhold 50200
setp stepgen.1.dirsetup 50200
setp stepgen.1.maxaccel [AXIS_1]STEPGEN_MAXACCEL
net ypos-cmd axis.1.motor-pos-cmd => stepgen.1.position-cmd
net ypos-fb stepgen.1.position-fb => axis.1.motor-pos-fb
net ystep <= stepgen.1.step
net ydir <= stepgen.1.dir
net yenable axis.1.amp-enable-out => stepgen.1.enable

setp stepgen.2.position-scale [AXIS_2]SCALE
setp stepgen.2.steplen 1
setp stepgen.2.stepspace 0
setp stepgen.2.dirhold 50200
setp stepgen.2.dirsetup 50200
setp stepgen.2.maxaccel [AXIS_2]STEPGEN_MAXACCEL
net zpos-cmd axis.2.motor-pos-cmd => stepgen.2.position-cmd
net zpos-fb stepgen.2.position-fb => axis.2.motor-pos-fb
net zstep <= stepgen.2.step
net zdir <= stepgen.2.dir
net zenable axis.2.amp-enable-out => stepgen.2.enable

setp stepgen.3.position-scale [AXIS_3]SCALE
setp stepgen.3.steplen 1
setp stepgen.3.stepspace 0
setp stepgen.3.dirhold 50200
setp stepgen.3.dirsetup 50200
setp stepgen.3.maxaccel [AXIS_3]STEPGEN_MAXACCEL
net apos-cmd axis.3.motor-pos-cmd => stepgen.3.position-cmd
net apos-fb stepgen.3.position-fb => axis.3.motor-pos-fb
net astep <= stepgen.3.step
net adir <= stepgen.3.dir
net aenable axis.3.amp-enable-out => stepgen.3.enable

net estop-out <= iocontrol.0.user-enable-out
net estop-ext => iocontrol.0.emc-enable-in

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 tool-number iocontrol.0.tool-prep-number => hal_manualtoolchange.number
net tool-prepare-loopback iocontrol.0.tool-prepare => iocontrol.0.tool-prepared

=26pxcustom.hal
# Include your customized HAL commands here
# This file will not be overwritten when you run stepconf again# Include your customized HAL commands here
# This file will not be overwritten when you run stepconf again
# Jog Pendant
loadrt encoder num_chan=2
loadrt mux4 count=1
addf encoder.1.capture-position servo-thread
addf encoder.1.update-counters base-thread
addf mux4.0 servo-thread

# If your MPG outputs a quadrature signal per click set x4 to 1
# If your MPG puts out 1 pulse per click set x4 to 0
setp encoder.1.x4-mode 0

# For velocity mode, set to 1
# In velocity mode the axis stops when the dial is stopped
# even if that means the commanded motion is not completed,
# For position mode (the default), set to 0
# In position mode the axis will move exactly jog-scale
# units for each count, regardless of how long that might take,

setp axis.0.jog-vel-mode 0
setp axis.1.jog-vel-mode 0
setp axis.2.jog-vel-mode 0

# This sets the scale that will be used based on the input to the mux4
# mux4.0 inputs pport1pin02 pport1pin03 00-in0,01-in1,10-in2,11-in3
setp mux4.0.in0 0.1
setp mux4.0.in1 0.01
setp mux4.0.in2 0.001
setp mux4.0.in3 1.00

# The inputs to the mux4 component
net scale1 mux4.0.sel0 <= parport.1.pin-2-in
net scale2 mux4.0.sel1 <= parport.1.pin-3-in

# The output from the mux4 is sent to each axis jog scale
net mpg-scale <= mux4.0.out
net mpg-scale => axis.0.jog-scale
net mpg-scale => axis.1.jog-scale
net mpg-scale => axis.2.jog-scale

# The MPG inputs
net mpg-a encoder.1.phase-A <= parport.1.pin-10-in
net mpg-b encoder.1.phase-B <= parport.1.pin-11-in

# The Axis select inputs
net mpg-x axis.0.jog-enable <= parport.1.pin-12-in-not
net mpg-z axis.2.jog-enable <= parport.1.pin-13-in-not
net mpg-a axis.3.jog-enable <= parport.1.pin-13-in-not

# The encoder output counts to the axis. Only the selected axis will move.
net encoder-counts <= encoder.1.counts
net encoder-counts => axis.0.jog-counts
net encoder-counts => axis.3.jog-counts
net encoder-counts => axis.2.jog-counts 

  

Please Log in or Create an account to join the conversation.

More
19 Nov 2021 22:23 - 19 Nov 2021 22:25 #227029 by PCW
Replied by PCW on topic Multiple encoders
You have:

loadrt stepgen step_type=0,0,0,0
loadrt encoder num_chan=2
loadrt abs count=1

At the top of your hal file and then later:

# Jog Pendant
loadrt encoder num_chan=2

EDIT
I just noticed you only had 1 MPG so
loadrt encoder num_chan=2 at the top is fine

Then  delete the second loadrt encoder line
(and put all the encoder addf lines in the top so you can
see them all together)
Last edit: 19 Nov 2021 22:25 by PCW.

Please Log in or Create an account to join the conversation.

Time to create page: 0.067 seconds
Powered by Kunena Forum