Guest User

hal

a guest
Jul 19th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.16 KB | None | 0 0
  1. # #######################################
  2. #
  3. # HAL file for HostMot2 with 3 servos
  4. #
  5. # Derived from Ted Hyde's original hm2-servo config
  6. #
  7. # Based up work and discussion with Seb & Peter & Jeff
  8. # GNU license references - insert here. www.linuxcnc.org
  9. #
  10. #
  11. # ########################################
  12. # Firmware files are in /lib/firmware/hm2/7i43/
  13. # Must symlink the hostmot2 firmware directory of sanbox to
  14. # /lib/firmware before running EMC2...
  15. # sudo ln -s $HOME/emc2-sandbox/src/hal/drivers/mesa-hostmot2/firmware /lib/firmware/hm2
  16. #
  17. # See also:
  18. # <http://www.linuxcnc.org/docs/devel/html/man/man9/hostmot2.9.html#config%20modparam>
  19. # and http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?HostMot2
  20. #
  21. # #####################################################################
  22.  
  23.  
  24. # ###################################
  25. # Core EMC/HAL Loads
  26. # ###################################
  27.  
  28. # kinematics
  29. loadrt trivkins
  30.  
  31. # motion controller, get name and thread periods from ini file
  32. loadrt [EMCMOT]EMCMOT servo_period_nsec=[EMCMOT]SERVO_PERIOD num_joints=[TRAJ]AXES
  33.  
  34. # standard components
  35. loadrt pid num_chan=3
  36.  
  37. # only the 7i43 needs this, but it doesnt hurt the others
  38. loadrt probe_parport
  39.  
  40. # hostmot2 driver
  41. # if you have any firmware trouble, enable the debug flags here and see what's going on in the syslog
  42. #loadrt hostmot2 debug_idrom=1 debug_module_descriptors=1 debug_pin_descriptors=1 debug_modules=1
  43. loadrt hostmot2
  44.  
  45. # load low-level driver
  46. loadrt [HOSTMOT2](DRIVER) config=[HOSTMOT2](CONFIG)
  47.  
  48. setp hm2_[HOSTMOT2](BOARD).0.pwmgen.pwm_frequency 40000
  49.  
  50.  
  51. # ################################################
  52. # THREADS
  53. # ################################################
  54.  
  55. addf hm2_[HOSTMOT2](BOARD).0.read servo-thread
  56.  
  57. addf motion-command-handler servo-thread
  58. addf motion-controller servo-thread
  59.  
  60. addf pid.0.do-pid-calcs servo-thread
  61. addf pid.1.do-pid-calcs servo-thread
  62. addf pid.2.do-pid-calcs servo-thread
  63.  
  64. addf hm2_[HOSTMOT2](BOARD).0.write servo-thread
  65. addf hm2_[HOSTMOT2](BOARD).0.pet_watchdog servo-thread
  66.  
  67.  
  68. # ######################################################
  69. # Axis-of-motion Specific Configs (not the GUI)
  70. # ######################################################
  71.  
  72.  
  73. # ################
  74. # X [0] Axis
  75. # ################
  76.  
  77. # axis enable chain
  78. newsig emcmot.00.enable bit
  79. sets emcmot.00.enable FALSE
  80. net emcmot.00.enable => pid.0.enable
  81. net emcmot.00.enable => hm2_[HOSTMOT2](BOARD).0.pwmgen.00.enable
  82. net emcmot.00.enable <= axis.0.amp-enable-out
  83.  
  84. # encoder feedback
  85. setp hm2_[HOSTMOT2](BOARD).0.encoder.00.counter-mode 0
  86. setp hm2_[HOSTMOT2](BOARD).0.encoder.00.filter 1
  87. setp hm2_[HOSTMOT2](BOARD).0.encoder.00.index-invert 0
  88. setp hm2_[HOSTMOT2](BOARD).0.encoder.00.index-mask 0
  89. setp hm2_[HOSTMOT2](BOARD).0.encoder.00.index-mask-invert 0
  90.  
  91. setp hm2_[HOSTMOT2](BOARD).0.encoder.00.scale [AXIS_0]INPUT_SCALE
  92. net motor.00.pos-fb hm2_[HOSTMOT2](BOARD).0.encoder.00.position => pid.0.feedback
  93. net motor.00.pos-fb => axis.0.motor-pos-fb #push copy back to Axis GUI
  94.  
  95. # set PID loop gains from inifile
  96. setp pid.0.Pgain [AXIS_0]P
  97. setp pid.0.Igain [AXIS_0]I
  98. setp pid.0.Dgain [AXIS_0]D
  99. setp pid.0.bias [AXIS_0]BIAS
  100. setp pid.0.FF0 [AXIS_0]FF0
  101. setp pid.0.FF1 [AXIS_0]FF1
  102. setp pid.0.FF2 [AXIS_0]FF2
  103. setp pid.0.deadband [AXIS_0]DEADBAND
  104. setp pid.0.maxoutput [AXIS_0]MAX_OUTPUT
  105.  
  106. # position command signals
  107. setp hm2_[HOSTMOT2](BOARD).0.pwmgen.00.output-type 1 #pwm on pin1, dir on pin2
  108. setp hm2_[HOSTMOT2](BOARD).0.pwmgen.00.scale [AXIS_0]OUTPUT_SCALE
  109.  
  110. net emcmot.00.pos-cmd axis.0.motor-pos-cmd => pid.0.command
  111. net motor.00.command pid.0.output => hm2_[HOSTMOT2](BOARD).0.pwmgen.00.value
  112.  
  113.  
  114. # ################
  115. # Y [1] Axis
  116. # ################
  117.  
  118. # axis enable chain
  119. newsig emcmot.01.enable bit
  120. sets emcmot.01.enable FALSE
  121. net emcmot.01.enable => pid.1.enable
  122. net emcmot.01.enable => hm2_[HOSTMOT2](BOARD).0.pwmgen.01.enable
  123. net emcmot.01.enable <= axis.1.amp-enable-out
  124.  
  125. # encoder feedback
  126. setp hm2_[HOSTMOT2](BOARD).0.encoder.01.counter-mode 0
  127. setp hm2_[HOSTMOT2](BOARD).0.encoder.01.filter 1
  128. setp hm2_[HOSTMOT2](BOARD).0.encoder.01.index-invert 0
  129. setp hm2_[HOSTMOT2](BOARD).0.encoder.01.index-mask 0
  130. setp hm2_[HOSTMOT2](BOARD).0.encoder.01.index-mask-invert 0
  131.  
  132. setp hm2_[HOSTMOT2](BOARD).0.encoder.01.scale [AXIS_1]INPUT_SCALE
  133. net motor.01.pos-fb hm2_[HOSTMOT2](BOARD).0.encoder.01.position => pid.1.feedback
  134. net motor.01.pos-fb => axis.1.motor-pos-fb #push copy back to Axis GUI
  135.  
  136. # set PID loop gains from inifile
  137. setp pid.1.Pgain [AXIS_1]P
  138. setp pid.1.Igain [AXIS_1]I
  139. setp pid.1.Dgain [AXIS_1]D
  140. setp pid.1.bias [AXIS_1]BIAS
  141. setp pid.1.FF0 [AXIS_1]FF0
  142. setp pid.1.FF1 [AXIS_1]FF1
  143. setp pid.1.FF2 [AXIS_1]FF2
  144. setp pid.1.deadband [AXIS_1]DEADBAND
  145. setp pid.1.maxoutput [AXIS_1]MAX_OUTPUT
  146.  
  147. # position command signals
  148. setp hm2_[HOSTMOT2](BOARD).0.pwmgen.01.output-type 1 #pwm on pin1, dir on pin2
  149. setp hm2_[HOSTMOT2](BOARD).0.pwmgen.01.scale [AXIS_1]OUTPUT_SCALE
  150.  
  151. net emcmot.01.pos-cmd axis.1.motor-pos-cmd => pid.1.command
  152. net motor.01.command pid.1.output => hm2_[HOSTMOT2](BOARD).0.pwmgen.01.value
  153.  
  154.  
  155. # ################
  156. # Z [2] Axis
  157. # ################
  158.  
  159. # axis enable chain
  160. newsig emcmot.02.enable bit
  161. sets emcmot.02.enable FALSE
  162. net emcmot.02.enable => pid.2.enable
  163. net emcmot.02.enable => hm2_[HOSTMOT2](BOARD).0.pwmgen.02.enable
  164. net emcmot.02.enable <= axis.2.amp-enable-out
  165.  
  166. # encoder feedback
  167. setp hm2_[HOSTMOT2](BOARD).0.encoder.02.counter-mode 0
  168. setp hm2_[HOSTMOT2](BOARD).0.encoder.02.filter 1
  169. setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-invert 0
  170. setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-mask 0
  171. setp hm2_[HOSTMOT2](BOARD).0.encoder.02.index-mask-invert 0
  172.  
  173. setp hm2_[HOSTMOT2](BOARD).0.encoder.02.scale [AXIS_2]INPUT_SCALE
  174. net motor.02.pos-fb hm2_[HOSTMOT2](BOARD).0.encoder.02.position => pid.2.feedback
  175. net motor.02.pos-fb => axis.2.motor-pos-fb #push copy back to Axis GUI
  176.  
  177. # set PID loop gains from inifile
  178. setp pid.2.Pgain [AXIS_2]P
  179. setp pid.2.Igain [AXIS_2]I
  180. setp pid.2.Dgain [AXIS_2]D
  181. setp pid.2.bias [AXIS_2]BIAS
  182. setp pid.2.FF0 [AXIS_2]FF0
  183. setp pid.2.FF1 [AXIS_2]FF1
  184. setp pid.2.FF2 [AXIS_2]FF2
  185. setp pid.2.deadband [AXIS_2]DEADBAND
  186. setp pid.2.maxoutput [AXIS_2]MAX_OUTPUT
  187.  
  188. # position command signals
  189. setp hm2_[HOSTMOT2](BOARD).0.pwmgen.02.output-type 1 #pwm on pin1, dir on pin2
  190. setp hm2_[HOSTMOT2](BOARD).0.pwmgen.02.scale [AXIS_2]OUTPUT_SCALE
  191.  
  192. net emcmot.02.pos-cmd axis.2.motor-pos-cmd => pid.2.command
  193. net motor.02.command pid.2.output => hm2_[HOSTMOT2](BOARD).0.pwmgen.02.value
  194.  
  195.  
  196.  
  197. ###########################################################
  198. ###########################################################
  199. setp hm2_[HOSTMOT2](BOARD).0.encoder.03.counter-mode 1
  200.  
  201. #############
  202. setp hm2_5i20.0.encoder.03.scale 100
  203.  
  204. ############################
  205. loadrt scale count=1
  206.  
  207.  
  208.  
  209. addf scale.0 servo-thread
  210.  
  211.  
  212.  
  213. ####################################
  214.  
  215. setp scale.0.gain 0.00034483
  216.  
  217. setp scale.0.offset -0.4172
  218.  
  219. net scaled-percent scale.0.out => motion.adaptive-feed
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226. ################################################################
  227. ###################################################################
  228. #net X-home-sw <= m5i20.0.in-02
  229. ###net Y-home-sw<=m5i20.0.in-06
  230. ###net Z-home-sw<=m5i20.0.in-10
  231.  
  232. ##read home switch input from 1/0 card
  233. net X-home-sw <= hm2_5i20.0.gpio.026.in
  234. net Y-home-sw <= hm2_5i20.0.gpio.030.in
  235. net Z-home-sw <= hm2_5i20.0.gpio.034.in
  236.  
  237.  
  238.  
  239.  
  240. net X-home-sw => axis.0.home-sw-in
  241. net Y-home-sw => axis.1.home-sw-in
  242. net Z-home-sw => axis.2.home-sw-in
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252. #####################################################################
  253. ########################################################################
  254.  
  255.  
  256.  
  257.  
  258.  
  259. # ##################################################
  260. # Standard I/O Block - EStop, Etc
  261. # ##################################################
  262.  
  263. # create a signal for the estop loopback
  264. net estop-loop iocontrol.0.user-enable-out => iocontrol.0.emc-enable-in
  265.  
  266. # create signals for tool loading loopback
  267. net tool-prep-loop iocontrol.0.tool-prepare => iocontrol.0.tool-prepared
  268. net tool-change-loop iocontrol.0.tool-change => iocontrol.0.tool-changed
  269.  
  270.  
  271. #
  272. # homing
  273. #
  274.  
  275. #
  276. # In this example, each of the three axes have their own home switch. All
  277. # home switches are connected to GPIO 25, though hostmot2 boards generally
  278. # have enough GPIO pins to put each axis' home switch on its own pin.
  279. #
  280. # Each switch is normally open, momentarily closed. When the switch is open,
  281. # GPIO 25 floats high (because that is the hostmot2 way). When the switch is
  282. # closed, it shorts GPIO 25 to ground.
  283. #
  284. # EMC expects the value on the .home-sw-in HAL pin to be active high, ie
  285. # True when the switch is closed and False when the switch is open.
  286. # We get this behavior by linking the GPIO .in_not pin instead of the .in
  287. # pin.
  288. #
  289.  
  290. ####net home-switch <= hm2_[HOSTMOT2](BOARD).0.gpio.025.in_not
  291. ###net home-switch => axis.0.home-sw-in
  292. ###net home-switch => axis.1.home-sw-in
  293. ###net home-switch => axis.2.home-sw-in
  294.  
  295. # only the Y servo has an index, X and Z home without using the index
  296. #net y-index-enable hm2_[HOSTMOT2](BOARD).0.encoder.01.index-enable <=> axis.1.index-enable
Advertisement
Add Comment
Please, Sign In to add comment