generic gcode Point with 5-axis aspects added/modified
| 4 | import numpy as np |
| 5 | |
| 6 | class Point(BasePoint): |
| 7 | 'generic gcode Point with 5-axis aspects added/modified' |
| 8 | b: Optional[float] = None |
| 9 | c: Optional[float] = None |
| 10 | |
| 11 | def XYZBC_gcode(self, self_systemXYZ, p) -> float: |
| 12 | 'generate XYZBC gcode string to move from a point p to this point. return XYZBC string' |
| 13 | s = '' |
| 14 | if self_systemXYZ.x != None and self_systemXYZ.x != p.x: |
| 15 | s += f'X{round(self_systemXYZ.x, 6):.6} ' |
| 16 | if self_systemXYZ.y != None and self_systemXYZ.y != p.y: |
| 17 | s += f'Y{round(self_systemXYZ.y, 6):.6} ' |
| 18 | if self_systemXYZ.z != None and self_systemXYZ.z != p.z: |
| 19 | s += f'Z{round(self_systemXYZ.z, 6):.6} ' |
| 20 | if self_systemXYZ.b != None and self_systemXYZ.b != p.b: |
| 21 | s += f'B{round(self_systemXYZ.b, 6):.6} ' |
| 22 | if self_systemXYZ.c != None and self_systemXYZ.c != p.c: |
| 23 | s += f'C{round(self_systemXYZ.c, 6):.6} ' |
| 24 | return s if s != '' else None |
| 25 | |
| 26 | def inverse_kinematics(self, state): |
| 27 | 'calcualte system XYZ for the current point XYZ (in part coordinates)' |
| 28 | |
| 29 | def model2system(model_point, state, system_type: str): |
| 30 | from math import cos, sin, tau |
| 31 | system_point = deepcopy(model_point) |
| 32 | if system_type == 'bc_bed': |
| 33 | # # calculate XYZ as if B=0 first: |
| 34 | # x_for_b0 = model_point.x*cos(model_point.c*tau/360) + model_point.y*-sin(model_point.c*tau/360) |
| 35 | # y_for_b0 = model_point.y*cos(model_point.c*tau/360) + model_point.x*sin(model_point.c*tau/360) |
| 36 | # z_for_b0 = model_point.z |
| 37 | # # now calculate XYZ with effects of B rotation: |
| 38 | # x_with_b = x_for_b0*cos(model_point.b*tau/360) + z_for_b0*sin(model_point.b*tau/360) |
| 39 | # y_with_b = y_for_b0 |
| 40 | # z_with_b = z_for_b0*cos(model_point.b*tau/360) + x_for_b0*-sin(model_point.b*tau/360) |
| 41 | # # now offset XYZ so the origin is positioned at the bc_intercept point in system coordinates |
| 42 | # x_system = x_with_b + state.printer.bc_intercept.x |
| 43 | # y_system = y_with_b + state.printer.bc_intercept.y |
| 44 | # z_system = z_with_b + state.printer.bc_intercept.z |
| 45 | # Update according to case point 5.3.2. Inverse Transformation https://linuxcnc.org/docs/html/motion/5-axis-kinematics.html |
| 46 | inv_kin=np.zeros((3,3)) |
| 47 | inv_kin[0,:]= [cos(model_point.b*tau/360)*cos(model_point.c*tau/360), -sin(model_point.c*tau/360)*cos(model_point.b*tau/360), sin(model_point.b*tau/360)] |
| 48 | inv_kin[1,:]= [sin(model_point.c*tau/360), cos(model_point.c*tau/360),0] |
| 49 | inv_kin[2,:]= [-sin(model_point.b*tau/360)*cos(model_point.c*tau/360), sin(model_point.b*tau/360)*sin(model_point.c*tau/360), cos(model_point.b*tau/360)] |
| 50 | |
| 51 | inv_kin = np.matmul(inv_kin, np.array([model_point.x, model_point.y, model_point.z])) |
| 52 | x_system = inv_kin[0]+state.printer.bc_intercept.x - sin(model_point.b*tau/360)*state.printer.bc_intercept.z - cos(model_point.b*tau/360)*state.printer.bc_intercept.x |
| 53 | y_system = inv_kin[1] # +state.printer.bc_intercept.y |
| 54 | z_system = inv_kin[2]+state.printer.bc_intercept.z * (-cos(model_point.b*tau/360)+1) + sin(model_point.b*tau/360)*state.printer.bc_intercept.x |
| 55 | |
| 56 | system_point.x = round(x_system, 6) |
| 57 | system_point.y = round(y_system, 6) |
| 58 | system_point.z = round(z_system, 6) |
| 59 | return system_point |
| 60 | |
| 61 | # make sure undefined attributes of the current point (self) are taken from the point in state |
| 62 | model_point = deepcopy(state.point) |
| 63 | model_point.update_from(self) |
no outgoing calls
no test coverage detected