/ docs / src / examples / mpg.txt
mpg.txt
  1  [[cha:mpg-pendant]]
  2  
  3  = MPG Pendant
  4  
  5  This example is to explain how to hook up the common MPG pendants
  6  found on the market today. This example uses an MPG3 pendant and a
  7  C22 pendant interface card from CNC4PC connected to a second parallel
  8  port plugged into the PCI slot. This example gives you 3 axes with 3
  9  step increments of 0.1, 0.01, 0.001
 10  
 11  In your custom.hal file or jog.hal file add the following, making
 12  sure you don't have mux4 or an encoder already in use. If you do just
 13  increase the counts and change the reference numbers. More information
 14  about mux4 and encoder can be found in the HAL manual or the man page.
 15  
 16  See the <<sec:hal-section,HAL Ini Section>> of the manual for more
 17  information on adding a hal file.
 18  
 19  Jog management pins are provided for each joint and all coordinate
 20  letters.  This example uses the axis jog pins for jogging in world
 21  mode.  Machines with non-identity kinematics may need use additional
 22  connections for jogging in joint mode.
 23  
 24  .jog.hal
 25  ----
 26  # Jog Pendant 
 27  loadrt encoder num_chan=1 
 28  loadrt mux4 count=1 
 29  addf encoder.capture-position servo-thread 
 30  addf encoder.update-counters base-thread 
 31  addf mux4.0 servo-thread
 32  
 33  # If your MPG outputs a quadrature signal per click set x4 to 1  
 34  # If your MPG puts out 1 pulse per click set x4 to 0 
 35  setp encoder.0.x4-mode 0
 36  
 37  # For velocity mode, set to 1
 38  # In velocity mode the axis stops when the dial is stopped
 39  # even if that means the commanded motion is not completed,
 40  # For position mode (the default), set to 0
 41  # In position mode the axis will move exactly jog-scale
 42  # units for each count, regardless of how long that might take,
 43  setp axis.x.jog-vel-mode 0
 44  setp axis.y.jog-vel-mode 0
 45  setp axis.z.jog-vel-mode 0
 46  
 47  # This sets the scale that will be used based on the input to the mux4
 48  setp mux4.0.in0 0.1
 49  setp mux4.0.in1 0.01
 50  setp mux4.0.in2 0.001
 51  
 52  # The inputs to the mux4 component
 53  net scale1 mux4.0.sel0 <= parport.1.pin-09-in
 54  net scale2 mux4.0.sel1 <= parport.1.pin-10-in
 55  
 56  # The output from the mux4 is sent to each axis jog scale
 57  net mpg-scale <= mux4.0.out
 58  net mpg-scale => axis.x.jog-scale
 59  net mpg-scale => axis.y.jog-scale
 60  net mpg-scale => axis.z.jog-scale
 61  
 62  # The MPG inputs
 63  net mpg-a encoder.0.phase-A <= parport.1.pin-02-in
 64  net mpg-b encoder.0.phase-B <= parport.1.pin-03-in
 65  
 66  # The Axis select inputs
 67  net mpg-x axis.x.jog-enable <= parport.1.pin-04-in
 68  net mpg-y axis.y.jog-enable <= parport.1.pin-05-in
 69  net mpg-z axis.z.jog-enable <= parport.1.pin-06-in
 70  
 71  # The encoder output counts to the axis. Only the selected axis will move.
 72  net encoder-counts  <= encoder.0.counts
 73  net encoder-counts => axis.x.jog-counts
 74  net encoder-counts => axis.y.jog-counts
 75  net encoder-counts => axis.z.jog-counts
 76  ----
 77  
 78  If the machine is capable of high acceleration to smooth out the moves
 79  for each click of the MPG use the <<sec:ilowpass,ilowpass>> component to
 80  limit the acceleration.
 81  
 82  .jog.hal with ilowpass
 83  ----
 84  loadrt encoder num_chan=1 
 85  loadrt mux4 count=1 
 86  addf encoder.capture-position servo-thread 
 87  addf encoder.update-counters base-thread 
 88  addf mux4.0 servo-thread
 89  
 90  loadrt ilowpass
 91  addf ilowpass.0 servo-thread
 92  
 93  setp ilowpass.0.scale 1000
 94  setp ilowpass.0.gain 0.01
 95  
 96  
 97  # If your MPG outputs a quadrature signal per click set x4 to 1  
 98  # If your MPG puts out 1 pulse per click set x4 to 0 
 99  setp encoder.0.x4-mode 0
100  
101  # For velocity mode, set to 1
102  # In velocity mode the axis stops when the dial is stopped
103  # even if that means the commanded motion is not completed,
104  # For position mode (the default), set to 0
105  # In position mode the axis will move exactly jog-scale
106  # units for each count, regardless of how long that might take,
107  setp axis.x.jog-vel-mode 0
108  setp axis.y.jog-vel-mode 0
109  setp axis.z.jog-vel-mode 0
110  
111  # The inputs to the mux4 component
112  net scale1 mux4.0.sel0 <= parport.1.pin-09-in
113  net scale2 mux4.0.sel1 <= parport.1.pin-10-in
114  
115  # This sets the scale that will be used based on the input to the mux4
116  # The scale used here has to be multiplied by the ilowpass scale
117  setp mux4.0.in0 0.0001
118  setp mux4.0.in1 0.00001
119  setp mux4.0.in2 0.000001
120  
121  # The output from encoder counts is sent to ilowpass
122  net mpg-out ilowpass.0.in <= encoder.0.counts
123  
124  # The output from the mux4 is sent to each axis jog scale
125  net mpg-scale <= mux4.0.out
126  net mpg-scale => axis.x.jog-scale
127  net mpg-scale => axis.y.jog-scale
128  net mpg-scale => axis.z.jog-scale
129  
130  # The output from the ilowpass is sent to each axis jog count
131  # Only the selected axis will move.
132  net encoder-counts  <= ilowpass.0.out
133  net encoder-counts => axis.x.jog-counts
134  net encoder-counts => axis.y.jog-counts
135  net encoder-counts => axis.z.jog-counts
136  ----
137