Advertisement
Guest User

florian

a guest
Jan 28th, 2010
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. # joypad.hal -- hal configuration file to move a cnc machine using a joypad
  2.  
  3. # [JOG]
  4. # Components
  5.  
  6. # We will use hal_joystick to read the axis value (float) for X Y Z, we will send these values to the
  7. # speed pin of a sim-encoder component, for X Y Z, this component outputs Phase-A and Phase-B signal,
  8. # just like a real quadrature rotary encoder. We will decode those signals with an encoder component for X Y Z
  9. # and will send the result counts value to the axis jog pin for X Y Z.
  10.  
  11. # Load the hal_joystick component that creates joypad.axis.<n> and joypad.button.<n> pins
  12. loadusr hal_joystick -d /dev/input/js0 -p joypad
  13.  
  14. # Load three encoder and three sim_encoder components
  15. loadrt encoder num_chan=3
  16. loadrt sim_encoder num_chan=3
  17.  
  18. # Create links between the axis pins and the speed pin of the sim-encoder for X Y Z
  19. net velX joypad.axis.0 => sim-encoder.0.speed
  20. net velY joypad.axis.1 => sim-encoder.1.speed
  21. net velZ joypad.axis.3 => sim-encoder.2.speed
  22.  
  23. # Create links between sim-encoder Phase-A and Phase-B and encoder Phase-A and Phase-B for X Y Z
  24. net XA sim-encoder.0.phase-A => encoder.0.phase-A
  25. net XB sim-encoder.0.phase-B => encoder.0.phase-B
  26. net YA sim-encoder.1.phase-A => encoder.1.phase-A
  27. net YB sim-encoder.1.phase-B => encoder.1.phase-B
  28. net ZA sim-encoder.2.phase-A => encoder.2.phase-A
  29. net ZB sim-encoder.2.phase-B => encoder.2.phase-B
  30.  
  31. # Create links between encoder counts and jog counts for X Y Z
  32. net countX encoder.0.counts => axis.0.jog-counts
  33. net countY encoder.1.counts => axis.1.jog-counts
  34. net countZ encoder.2.counts => axis.2.jog-counts
  35.  
  36. # Set parameter values
  37. setp encoder.0.position-scale 1
  38. setp encoder.0.x4-mode TRUE
  39. setp encoder.1.position-scale 1
  40. setp encoder.1.x4-mode TRUE
  41. setp encoder.2.position-scale 1
  42. setp encoder.2.x4-mode TRUE
  43. setp encoder.capture-position.tmax 0
  44. setp encoder.update-counters.tmax 0
  45. setp sim-encoder.0.ppr 00000064
  46. setp sim-encoder.0.scale 1
  47. setp sim-encoder.1.ppr 00000064
  48. setp sim-encoder.1.scale -1
  49. setp sim-encoder.2.ppr 00000064
  50. setp sim-encoder.2.scale -1
  51. setp sim-encoder.make-pulses.tmax 0
  52. setp sim-encoder.update-speed.tmax 0
  53.  
  54. # Enable jog for X Y Z
  55. setp axis.0.jog-enable TRUE
  56. setp axis.1.jog-enable TRUE
  57. setp axis.2.jog-enable TRUE
  58.  
  59. # Attach realtime functions to threads
  60. addf encoder.capture-position servo-thread
  61. addf sim-encoder.update-speed servo-thread
  62. addf encoder.update-counters base-thread
  63. addf sim-encoder.make-pulses base-thread
  64.  
  65.  
  66.  
  67. # [BUTTON-SAMPLES]
  68.  
  69. # Here are two examples on how to attach some functions to joypad buttons. We will use Halui pins for the
  70. # second example.
  71.  
  72. # Scale button
  73.  
  74. # we set two buttons (6 and 4) to choose the jogscale value. Pressing button 6 will set the scale to 0.01
  75. # while pressing button 4 will set it to 0.1.
  76.  
  77. # Components
  78. # We will use a two values selector and a flipflop component
  79.  
  80. loadrt mux2
  81. loadrt flipflop
  82.  
  83. # Link between buttons and flipflop, flipflop will output TRUE when rising edge is detected on set pin, FALSE
  84. # when rising edge is on reset pin.
  85. net button4 joypad.button.4 => flipflop.0.reset
  86. net button6 joypad.button.5 => flipflop.0.set
  87.  
  88. # Link between flipflop and mux2, mux2 will output value mux2.0.in0 when mux2.0.sel is FALSE and mux2.0.in1
  89. # when TRUE.
  90. net selected flipflop.0.out => mux2.0.sel
  91.  
  92. # Link between the mux2 output and the jogscale pin for X Y Z
  93. net jogscale mux2.0.out => axis.0.jog-scale
  94. net jogscale mux2.0.out => axis.1.jog-scale
  95. net jogscale mux2.0.out => axis.2.jog-scale
  96.  
  97. # Set parameters values
  98. setp flipflop.0.tmax 3750
  99. setp mux2.0.tmax 3601
  100.  
  101. # Set the two scale values
  102. setp mux2.0.in0 0.1
  103. setp mux2.0.in1 0.01
  104.  
  105. # Attach realtime functions to threads
  106. addf flipflop.0 servo-thread
  107. addf mux2.0 servo-thread
  108.  
  109. # Flood button
  110.  
  111. # We will set a single button (button 7) to start and stop flood. We will use Halui pins for that.
  112.  
  113. # Components
  114. # We will use simply two and2 and 1 not components
  115.  
  116. loadrt and2 count=2
  117. loadrt not
  118.  
  119. # Flood-is-on halui pin is linked to the and2.0.in0 and the not-flood-is-on, generated using the not component
  120. # is linked to the and2.1.in0. So, if the flood is on, we will have and2.0.in0 TRUE and and2.1.in0 FALSE.
  121. net flood-is-on halui.flood.is-on => and2.0.in0
  122. net flood-is-on halui.flood.is-on => not.0.in
  123. net not-flood-is-on not.0.out => and2.1.in0
  124.  
  125. # Link between button 7 and and.0.in1 and and.1.in1. In this way, if the flood for example is on, when the
  126. # button is pressed TRUE will be sent to and2.0.in1 and and2.1.in1, while the in0 value for and2 components
  127. # will be TRUE for the first and2 and FALSE for the second. So the first and2 will output TRUE.
  128. net button7 joypad.button.7 => and2.0.in1
  129. net button7 joypad.button.7 => and2.1.in1
  130.  
  131. # Link between and2 outputs and halui pin flood on and off. So, as seen above, if the flood is on, the and2.0
  132. # will output TRUE and the flood will turn off.
  133. net floodOff and2.0.out => halui.flood.off
  134. net floodOn and2.1.out => halui.flood.on
  135.  
  136. # Attach realtime functions to threads
  137. addf and2.0 servo-thread
  138. addf and2.1 servo-thread
  139. addf not.0 servo-thread
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement