SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/usr/bin/python | |
| 2 | ||
| 3 | import sys, io, time | |
| 4 | import gettext | |
| 5 | import linuxcnc, hal | |
| 6 | ||
| 7 | - | h = None |
| 7 | + | # These libraries not found - copied from stdglue.py |
| 8 | import emccanon | |
| 9 | from interpreter import * | |
| 10 | ||
| 11 | h = None | |
| 12 | ||
| 13 | # Magic numbers snooped from stdglue.py | |
| 14 | # TODO replace with proper imported references | |
| 15 | INTERP_ERROR = 5 | |
| 16 | INTERP_OK = 0 | |
| 17 | ||
| 18 | rack_params = {
| |
| 19 | "RACK_POSITION_X": 0, | |
| 20 | "RACK_POSITION_Y": 0, | |
| 21 | "POCKET_SEPARATION_X": 75, | |
| 22 | "POCKET_SEPARATION_Y": 75, | |
| 23 | "ROWS": 2, | |
| 24 | "COLUMNS": 7, | |
| 25 | "DROP_HEIGHT": -100, | |
| 26 | "GRAB_HEIGHT": -105, | |
| 27 | "PDB_CODE": "P2", | |
| 28 | "BLOW_CODE": "P1", | |
| 29 | "Z_RETRACT_SPEED": 2000 | |
| 30 | } | |
| 31 | ||
| 32 | def move_to_pocket(interpreter, pocket): | |
| 33 | pocket = int(pocket) | |
| 34 | print 'moving to pocket %i' % pocket | |
| 35 | x_pos = (pocket / rack_params["COLUMNS"])*rack_params["POCKET_SEPARATION_X"] + rack_params["RACK_POSITION_X"] | |
| 36 | y_pos = (pocket % rack_params["COLUMNS"])*rack_params["POCKET_SEPARATION_Y"] + rack_params["RACK_POSITION_Y"] | |
| 37 | print 'calculated coords %i, %i' % (x_pos, y_pos) | |
| 38 | interpreter.execute("G53 G1 X%i Y%i F%i" % (x_pos, y_pos, rack_params["Z_RETRACT_SPEED"]))
| |
| 39 | ||
| 40 | ||
| 41 | ||
| 42 | def drop_tool(interpreter, tool): | |
| 43 | print 'dropping tool %i' % tool | |
| 44 | move_to_pocket(intepreter, tool) | |
| 45 | ||
| 46 | def pickup_tool(interpreter, tool): | |
| 47 | print 'picking up tool %i' % tool | |
| 48 | move_to_pocket(interpreter, tool) | |
| 49 | ||
| 50 | # interpreter.execute("G53 G1 Z%i F%i" % (rack_params["DROP_HEIGHT"], rack_params["DROP_SPEED"]))
| |
| 51 | # interpreter.execute("M64 %s" % (rack_params["PDB_COLD"]))
| |
| 52 | ||
| 53 | def setup_pins(): | |
| 54 | global h | |
| 55 | h = hal.component("hal_racktoolchange")
| |
| 56 | h.newpin("toolnumber", hal.HAL_S32, hal.HAL_IN)
| |
| 57 | h.newpin("change", hal.HAL_BIT, hal.HAL_IN)
| |
| 58 | h.newpin("changed", hal.HAL_BIT, hal.HAL_OUT)
| |
| 59 | h.newpin("spindle_stopped", hal.HAL_BIT, hal.HAL_IN)
| |
| 60 | h.newpin("tool_secure", hal.HAL_BIT, hal.HAL_IN)
| |
| 61 | h.newpin("tool_released", hal.HAL_BIT, hal.HAL_IN)
| |
| 62 | h.newpin("drawbar", hal.HAL_BIT, hal.HAL_OUT)
| |
| 63 | h.newpin("blow", hal.HAL_BIT, hal.HAL_OUT)
| |
| 64 | return h | |
| 65 | ||
| 66 | def spindle_off(interpreter): | |
| 67 | print("turning spindle off")
| |
| 68 | interpreter.execute("M5")
| |
| 69 | ||
| 70 | def quill_up(interpreter): | |
| 71 | print 'executing quill up' | |
| 72 | interpreter.execute("G53 G1 Z0 F%i" % rack_params["Z_RETRACT_SPEED"])
| |
| 73 | ||
| 74 | def toolchange(interpreter): | |
| 75 | # if interpreter.selected_pocket < 0: | |
| 76 | # interpreter.set_errormsg("M6: No tool prepared.")
| |
| 77 | # return 0 | |
| 78 | ||
| 79 | spindle_off(interpreter) | |
| 80 | quill_up(interpreter) | |
| 81 | ||
| 82 | current_pos = (interpreter.current_x, interpreter.current_y,interpreter.current_z) | |
| 83 | current_tool = interpreter.params["tool_in_spindle"] | |
| 84 | requested_tool = interpreter.params["selected_tool"] | |
| 85 | print current_pos, current_tool, requested_tool | |
| 86 | if current_tool >= 0: | |
| 87 | drop_tool(interpreter, current_tool) | |
| 88 | if(requested_tool >= 0): | |
| 89 | pickup_tool(interpreter, requested_tool) | |
| 90 | return 1 |