Guest User

Untitled

a guest
Mar 31st, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys, io, time
  4. import gettext
  5. import linuxcnc, hal
  6.  
  7. h = None
  8.  
  9. rack_params = {
  10. "RACK_POSITION_X": 0,
  11. "RACK_POSITION_Y": 0,
  12. "POCKET_SEPARATION_X": 75,
  13. "POCKET_SEPARATION_Y": 75,
  14. "ROWS": 2,
  15. "COLUMNS": 7,
  16. "DROP_HEIGHT": -100,
  17. "GRAB_HEIGHT": -105,
  18. "PDB_CODE": "P2",
  19. "BLOW_CODE": "P1",
  20. "Z_RETRACT_SPEED": 2000
  21. }
  22.  
  23. def move_to_pocket(interpreter, pocket):
  24. pocket = int(pocket)
  25. print 'moving to pocket %i' % pocket
  26. x_pos = (pocket / rack_params["COLUMNS"])*rack_params["POCKET_SEPARATION_X"] + rack_params["RACK_POSITION_X"]
  27. y_pos = (pocket % rack_params["COLUMNS"])*rack_params["POCKET_SEPARATION_Y"] + rack_params["RACK_POSITION_Y"]
  28. print 'calculated coords %i, %i' % (x_pos, y_pos)
  29. interpreter.execute("G53 G1 X%i Y%i F%i" % (x_pos, y_pos, rack_params["Z_RETRACT_SPEED"]))
  30.  
  31.  
  32.  
  33. def drop_tool(interpreter, tool):
  34. print 'dropping tool %i' % tool
  35. move_to_pocket(intepreter, tool)
  36.  
  37. def pickup_tool(interpreter, tool):
  38. print 'picking up tool %i' % tool
  39. move_to_pocket(interpreter, tool)
  40.  
  41. # interpreter.execute("G53 G1 Z%i F%i" % (rack_params["DROP_HEIGHT"], rack_params["DROP_SPEED"]))
  42. # interpreter.execute("M64 %s" % (rack_params["PDB_COLD"]))
  43.  
  44. def setup_pins():
  45. global h
  46. h = hal.component("hal_racktoolchange")
  47. h.newpin("toolnumber", hal.HAL_S32, hal.HAL_IN)
  48. h.newpin("change", hal.HAL_BIT, hal.HAL_IN)
  49. h.newpin("changed", hal.HAL_BIT, hal.HAL_OUT)
  50. h.newpin("spindle_stopped", hal.HAL_BIT, hal.HAL_IN)
  51. h.newpin("tool_secure", hal.HAL_BIT, hal.HAL_IN)
  52. h.newpin("tool_released", hal.HAL_BIT, hal.HAL_IN)
  53. h.newpin("drawbar", hal.HAL_BIT, hal.HAL_OUT)
  54. h.newpin("blow", hal.HAL_BIT, hal.HAL_OUT)
  55. return h
  56.  
  57. def spindle_off(interpreter):
  58. print("turning spindle off")
  59. interpreter.execute("M5")
  60.  
  61. def quill_up(interpreter):
  62. print 'executing quill up'
  63. interpreter.execute("G53 G1 Z0 F%i" % rack_params["Z_RETRACT_SPEED"])
  64.  
  65. def toolchange(interpreter):
  66. # if interpreter.selected_pocket < 0:
  67. # interpreter.set_errormsg("M6: No tool prepared.")
  68. # return 0
  69.  
  70. spindle_off(interpreter)
  71. quill_up(interpreter)
  72.  
  73. current_pos = (interpreter.current_x, interpreter.current_y,interpreter.current_z)
  74. current_tool = interpreter.params["tool_in_spindle"]
  75. requested_tool = interpreter.params["selected_tool"]
  76. print current_pos, current_tool, requested_tool
  77. if current_tool >= 0:
  78. drop_tool(interpreter, current_tool)
  79. if(requested_tool >= 0):
  80. pickup_tool(interpreter, requested_tool)
  81. return 1
Advertisement
Add Comment
Please, Sign In to add comment