|
20 | 20 | class ProbeRoutines(): |
21 | 21 | def __init__(self): |
22 | 22 | self.timeout = 30 |
23 | | - |
24 | 23 | ################## |
25 | 24 | # Helper Functions |
26 | 25 | ################## |
@@ -126,6 +125,47 @@ def probe(self, name): |
126 | 125 | return 'Probe {} failed: {}'.format(name, rtn) |
127 | 126 | return 1 |
128 | 127 |
|
| 128 | + def goto_toolsetter(self): |
| 129 | + try: |
| 130 | + # basic sanity checks |
| 131 | + for test in('z_max_clear','ts_x','ts_y','ts_z','ts_max'): |
| 132 | + if self['data_{}'.format(test)] is None: |
| 133 | + return'Missing toolsetter setting: {}'.format(test) |
| 134 | + if self.data_tool_diameter is None: |
| 135 | + return 'No tool diameter found' |
| 136 | + |
| 137 | + # raise to safe Z height |
| 138 | + # move to tool setter (XY then Z) |
| 139 | + # offset X by tool radius (from toolfile) |
| 140 | + # probe Z |
| 141 | + # raise z clear |
| 142 | + # move back X by tool radius |
| 143 | + |
| 144 | + cmdList = [] |
| 145 | + cmdList.append('F{}'.format(self.data_rapid_vel)) |
| 146 | + cmdList.append('G53 G1 Z{}'.format(self.data_z_max_clear)) |
| 147 | + cmdList.append('G53 G1 X{} Y{}'.format(self.data_ts_x, self.data_ts_y)) |
| 148 | + cmdList.append('G53 G1 Z{}'.format(self.data_ts_z)) |
| 149 | + cmdList.append('G91 ') |
| 150 | + cmdList.append('G1 X{}'.format(self.data_tool_diameter/2)) |
| 151 | + cmdList.append('G38.2 Z{} F{}'.format(self.data_ts_max,self.data_search_vel)) |
| 152 | + cmdList.append('G1 Z{} F{}'.format(self.data_latch_return_dist, self.data_rapid_vel)) |
| 153 | + cmdList.append('F{} G4 P0.5'.format(self.data_probe_vel)) |
| 154 | + cmdList.append('G38.2 Z-{}'.format(self.data_latch_return_dist*2)) |
| 155 | + cmdList.append('G1 Z{} F{}'.format(self.data_z_clearance, self.data_rapid_vel)) |
| 156 | + cmdList.append('G1 X-{}'.format(self.data_tool_diameter/2)) |
| 157 | + cmdList.append('G90') |
| 158 | + |
| 159 | + # call each command - if fail report the error and gcode command |
| 160 | + for s in cmdList: |
| 161 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 162 | + if rtn != 1: |
| 163 | + return 'failed: {} cmd: {}'.format(rtn, s) |
| 164 | + # report success |
| 165 | + return 1 |
| 166 | + except Exception as e: |
| 167 | + return e |
| 168 | + |
129 | 169 | def CALL_MDI_WAIT(self, code, timeout = 5): |
130 | 170 | LOG.debug('MDI_WAIT_COMMAND= {}, maxt = {}'.format(code, timeout)) |
131 | 171 | for l in code.split("\n"): |
@@ -1483,7 +1523,7 @@ def probe_valley_y(self): |
1483 | 1523 | def probe_cal_round_pocket(self): |
1484 | 1524 | if self.data_cal_diameter_hint <= 0 : |
1485 | 1525 | return 'Calibration diameter hint must be larger then 0' |
1486 | | - if self.data_probe_diameter >= self.data_cal_diameter_hint: |
| 1526 | + if self.data_probe_diam >= self.data_cal_diameter_hint: |
1487 | 1527 | return 'Probe diameter too large for Calibration diameter hint' |
1488 | 1528 |
|
1489 | 1529 | self.data_side_edge_length = self.data_cal_diameter / 2 |
@@ -1631,3 +1671,154 @@ def probe_angle_right(self): |
1631 | 1671 | self.status_a = math.degrees(math.atan2(self.status_delta, self.data_side_edge_length)) |
1632 | 1672 | self.rotate_coord_system(self.status_a) |
1633 | 1673 | return error |
| 1674 | + |
| 1675 | + # TOOL setter Diameter/height |
| 1676 | + # returns 1 for success or a string error message for failure |
| 1677 | + def probe_tool_z_d(self): |
| 1678 | + try: |
| 1679 | + # move XY to Tool Setter point |
| 1680 | + # Start goto ts (probes Z height too) |
| 1681 | + rtn = self.goto_toolsetter() |
| 1682 | + if rtn != 1: |
| 1683 | + return 'failed: {}'.format(rtn) |
| 1684 | + # move X - edge_length- xy_clearance |
| 1685 | + s="""G91 |
| 1686 | + G1 F%s X-%f |
| 1687 | + G90""" % (self.data_rapid_vel, 0.5 * self.data_ts_diam + self.data_xy_clearance) |
| 1688 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 1689 | + if rtn != 1: |
| 1690 | + return 'failed: {}'.format(rtn) |
| 1691 | + rtn = self.z_clearance_down() |
| 1692 | + if rtn != 1: |
| 1693 | + return 'failed: {}'.format(rtn) |
| 1694 | + |
| 1695 | + # Start xplus |
| 1696 | + rtn = self.probe('xplus') |
| 1697 | + if rtn != 1: |
| 1698 | + return 'failed: {}'.format(rtn) |
| 1699 | + |
| 1700 | + # show X result |
| 1701 | + a = STATUS.get_probed_position_with_offsets() |
| 1702 | + xpres=float(a[0])+0.5*self.data_probe_diam |
| 1703 | + |
| 1704 | + # move Z to start point up |
| 1705 | + rtn = self.z_clearance_up() |
| 1706 | + if rtn != 1: |
| 1707 | + return 'failed: {}'.format(rtn) |
| 1708 | + |
| 1709 | + # move to finded point X |
| 1710 | + s = "G1 F%s X%f" % (self.data_rapid_vel, xpres) |
| 1711 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 1712 | + if rtn != 1: |
| 1713 | + return 'failed: {}'.format(rtn) |
| 1714 | + |
| 1715 | + # move X + data_ts_diam + xy_clearance |
| 1716 | + aa=self.data_ts_diam+self.data_xy_clearance |
| 1717 | + s="""G91 |
| 1718 | + G1 X%f |
| 1719 | + G90""" % (aa) |
| 1720 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 1721 | + if rtn != 1: |
| 1722 | + return 'failed: {}'.format(rtn) |
| 1723 | + |
| 1724 | + rtn = self.z_clearance_down() |
| 1725 | + if rtn != 1: |
| 1726 | + return 'failed: {}'.format(rtn) |
| 1727 | + |
| 1728 | + # Start xminus |
| 1729 | + rtn = self.probe('xminus') |
| 1730 | + if rtn != 1: |
| 1731 | + return 'failed: {}'.format(rtn) |
| 1732 | + |
| 1733 | + # show X result |
| 1734 | + a = STATUS.get_probed_position_with_offsets() |
| 1735 | + xmres=float(a[0])-0.5*self.data_probe_diam |
| 1736 | + self.length_x() |
| 1737 | + xcres=0.5*(xpres+xmres) |
| 1738 | + self.status_xc = xcres |
| 1739 | + |
| 1740 | + # move Z to start point up |
| 1741 | + rtn = self.z_clearance_up() |
| 1742 | + if rtn != 1: |
| 1743 | + return 'failed: {}'.format(rtn) |
| 1744 | + |
| 1745 | + # go to the new center of X |
| 1746 | + s = "G1 F%s X%f" % (self.data_rapid_vel, xcres) |
| 1747 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 1748 | + if rtn != 1: |
| 1749 | + return 'failed: {}'.format(rtn) |
| 1750 | + |
| 1751 | + # move Y - data_ts_diam/2 - xy_clearance |
| 1752 | + a=0.5*self.data_ts_diam+self.data_xy_clearance |
| 1753 | + s="""G91 |
| 1754 | + G1 Y-%f |
| 1755 | + G90""" % a |
| 1756 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 1757 | + if rtn != 1: |
| 1758 | + return 'failed: {}'.format(rtn) |
| 1759 | + |
| 1760 | + rtn = self.z_clearance_down() |
| 1761 | + if rtn != 1: |
| 1762 | + return 'failed: {}'.format(rtn) |
| 1763 | + |
| 1764 | + # Start yplus |
| 1765 | + rtn = self.probe('yplus') |
| 1766 | + if rtn != 1: |
| 1767 | + return 'failed: {}'.format(rtn) |
| 1768 | + |
| 1769 | + # show Y result |
| 1770 | + a = STATUS.get_probed_position_with_offsets() |
| 1771 | + ypres=float(a[1])+0.5*self.data_probe_diam |
| 1772 | + # move Z to start point up |
| 1773 | + if self.z_clearance_up() == -1: |
| 1774 | + return |
| 1775 | + |
| 1776 | + # move to found point Y |
| 1777 | + s = "G1 Y%f" % ypres |
| 1778 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 1779 | + if rtn != 1: |
| 1780 | + return 'failed: {}'.format(rtn) |
| 1781 | + |
| 1782 | + # move Y + data_ts_diam + xy_clearance |
| 1783 | + aa=self.data_ts_diam+self.data_xy_clearance |
| 1784 | + s="""G91 |
| 1785 | + G1 Y%f |
| 1786 | + G90""" % (aa) |
| 1787 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 1788 | + if rtn != 1: |
| 1789 | + return 'failed: {}'.format(rtn) |
| 1790 | + rtn = self.z_clearance_down() |
| 1791 | + if rtn != 1: |
| 1792 | + return 'failed: {}'.format(rtn) |
| 1793 | + |
| 1794 | + # Start yminus |
| 1795 | + rtn = self.probe('yminus') |
| 1796 | + if rtn != 1: |
| 1797 | + return 'failed: {}'.format(rtn) |
| 1798 | + # show Y result |
| 1799 | + a = STATUS.get_probed_position_with_offsets() |
| 1800 | + ymres=float(a[1])-0.5*self.data_probe_diam |
| 1801 | + self.length_y() |
| 1802 | + |
| 1803 | + # find, show and move to finded point |
| 1804 | + ycres=0.5*(ypres+ymres) |
| 1805 | + self.status_yc = ycres |
| 1806 | + diam=self.data_probe_diam + (ymres-ypres-self.data_ts_diam) |
| 1807 | + self.status_d = diam |
| 1808 | + |
| 1809 | + # move Z to start point up |
| 1810 | + rtn = self.z_clearance_up() |
| 1811 | + if rtn != 1: |
| 1812 | + return 'failed: {}'.format(rtn) |
| 1813 | + tmpz=STATUS.stat.position[2] - self.data_z_clearance |
| 1814 | + self.status_z=tmpz |
| 1815 | + self.add_history('Tool diameter',"XcYcZD",0,xcres,0,0,0,ycres,0,0,tmpz,diam,0) |
| 1816 | + # move to finded point |
| 1817 | + s = "G1 Y%f" % ycres |
| 1818 | + rtn = self.CALL_MDI_WAIT(s, self.timeout) |
| 1819 | + if rtn != 1: |
| 1820 | + return 'failed: {}'.format(rtn) |
| 1821 | + # success |
| 1822 | + return 1 |
| 1823 | + except Exception as e: |
| 1824 | + return e |
0 commit comments