def get_cam_plane_with_tool_rot_WCS(self, rot_value_back): cam_plane_WCS = ghcomp.Transform(self.cam_plane, self.T) T_rot_back = rg.Transform.Rotation(m.radians(rot_value_back), self.plane_WCS.ZAxis, self.plane_WCS.Origin) cam_plane_WCS = ghcomp.Transform(cam_plane_WCS, T_rot_back) return cam_plane_WCS
def get_geo_with_rotated_joints_in_world_with_tool_rot( self, joint_values, tool_joint_values, extended=True): ''' the joint values (in degrees) serve as the input, the method returns the link geo (and tool geo) and tool0 plane transformed ''' # the angles in radians joint_values = [m.radians(j) for j in joint_values] a1, a2, a3, a4, a5, a6 = joint_values L1, L2, L3, L4, L5, L6 = self.link_geo # calculate transformations j1, j2, j3, j4, j5, j6 = [rg.Plane(jp) for jp in self.joint_planes] T1 = rg.Transform.Rotation(a1, j1.ZAxis, j1.Origin) T2 = T1 * rg.Transform.Rotation(a2, j2.ZAxis, j2.Origin) T3 = T2 * rg.Transform.Rotation(a3, j3.ZAxis, j3.Origin) T4 = T3 * rg.Transform.Rotation(a4, j4.ZAxis, j4.Origin) T5 = T4 * rg.Transform.Rotation(a5, j5.ZAxis, j5.Origin) T6 = T5 * rg.Transform.Rotation(a6, j6.ZAxis, j6.Origin) L1_t = ghcomp.Transform(L1, T1) L2_t = ghcomp.Transform(L2, T2) L3_t = ghcomp.Transform(L3, T3) L4_t = ghcomp.Transform(L4, T4) L5_t = ghcomp.Transform(L5, T5) L6_t = ghcomp.Transform(L6, T6) link_geo_transformed = [L1_t, L2_t, L3_t, L4_t, L5_t, L6_t] tool0_plane_transformed = ghcomp.Transform(j6, T6) self.T_R_TOOL0 = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, tool0_plane_transformed) link_geo_transformed_world = ghcomp.Transform(link_geo_transformed, self.T_W_R) tool0_plane_transformed_world = ghcomp.Transform( tool0_plane_transformed, self.T_W_R) base_geo_world = ghcomp.Transform(self.base_geo, self.T_W_R) self.T_W_TOOL0 = rg.Transform.PlaneToPlane( rg.Plane.WorldXY, tool0_plane_transformed_world) if self.tool: T = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, tool0_plane_transformed_world) tool_geo_trfd_world = self.tool.get_transformed_geo_with_tool_transformation( T, tool_joint_values[0], tool_joint_values[1], extended=extended) return [ base_geo_world, link_geo_transformed_world, tool_geo_trfd_world ] else: return [base_geo_world, link_geo_transformed_world]
def __init__(self, geo, gantry_plane): ''' gantry class for the rfl geo = gantry geometry as list plane = defined gantry plane - if default - [0,0,0,x,y] ''' self.geo = geo self.plane = gantry_plane self.frame = Frame(self.plane, draw_geo=True) self.T = rg.Transform.PlaneToPlane(self.plane, rg.Plane.WorldXY) self.geo_WCS = ghcomp.Transform(self.geo, self.T) # gantry aligned_with_WCS self.plane_WCS = ghcomp.Transform(self.plane, self.T) # should be WorldXY plane
def get_attachment_planes_for_cables(self, plane_transformer, plane_gripper, joint_values, tool_joint_values, extended=True, transformer_on_axis=3): tool0_plane_transformed_world = self.get_tool0_plane_from_joint_values_world( joint_values) # the angles in radians joint_values = [m.radians(j) for j in joint_values] a1, a2, a3, a4, a5, a6 = joint_values # calculate transformations j1, j2, j3, j4, j5, j6 = [rg.Plane(jp) for jp in self.joint_planes] T1 = rg.Transform.Rotation(a1, j1.ZAxis, j1.Origin) T2 = T1 * rg.Transform.Rotation(a2, j2.ZAxis, j2.Origin) T3 = T2 * rg.Transform.Rotation(a3, j3.ZAxis, j3.Origin) T4 = T3 * rg.Transform.Rotation(a4, j4.ZAxis, j4.Origin) T5 = T4 * rg.Transform.Rotation(a5, j5.ZAxis, j5.Origin) T6 = T5 * rg.Transform.Rotation(a6, j6.ZAxis, j6.Origin) if transformer_on_axis == 6: plane_transformer_transformed = ghcomp.Transform( plane_transformer, T6) if transformer_on_axis == 4: plane_transformer_transformed = ghcomp.Transform( plane_transformer, T4) if transformer_on_axis == 3: plane_transformer_transformed = ghcomp.Transform( plane_transformer, T3) plane_transformer_transformed_world = ghcomp.Transform( plane_transformer_transformed, self.T_W_R) T = rg.Transform.PlaneToPlane(rg.Plane.WorldXY, tool0_plane_transformed_world) plane_gripper_transformed_world = self.tool.get_transformed_plane_gripper( T, tool_joint_values[0], tool_joint_values[1], plane_gripper, extended=extended) return (plane_transformer_transformed_world, plane_gripper_transformed_world)
def get_transformed_geo_with_tool_transformation_WCS( self, T, rot_value_front, rot_value_back, extended=False): geo_WCS = self.apply_tool_transformation_WCS(rot_value_front, rot_value_back, extended=extended) return ghcomp.Transform(geo_WCS, T)
def set_robot_origin_with_measured_base(self, base_plane): ''' sets to origin plane of the robot based on a manual measured base ''' T = rg.Transform.PlaneToPlane(base_plane, rg.Plane.WorldXY) plane = ghcomp.Transform(rg.Plane.WorldXY, T) self.set_robot_origin(plane)
def get_tool_plane_in_RCS(self, tool_plane_WCS, rob_num): ''' returns the tool plane in the robot coordinate system from a plane in the world cs''' T_R_W = self.T_R_W_1 if rob_num == 1 else self.T_R_W_2 if rob_num == 2 else self.T_R_W_3 if rob_num == 3 else self.T_R_W_4 if rob_num == 4 else None tool_plane_RCS = ghcomp.Transform(tool_plane_WCS, T_R_W) return tool_plane_RCS
def get_frame_axes_as_lines_WCS(self): ''' this method allows you to visualize the tool axes as lines and gh colors transformed into the WCS''' tool_axes, tool_axes_colors = self.get_frame_axes_as_lines() tool_axes = ghcomp.Transform(tool_axes, self.T) # aligned_with_WCS return tool_axes, tool_axes_colors
def get_tool0_plane_from_joint_values_world(self, joint_values): ''' the joint values (in degrees)''' tool0_plane_transformed = self.get_tool0_plane_from_joint_values( joint_values) tool0_plane_transformed_world = ghcomp.Transform( tool0_plane_transformed, self.T_W_R) return tool0_plane_transformed_world
def apply_coll_geo_transformation(self, rot_value_back): """ for transforming the collision geo which is in zero """ trot_plane = rg.Plane(self.plane) T_rot_back = rg.Transform.Rotation(m.radians(rot_value_back), trot_plane.ZAxis, trot_plane.Origin) collision_geo_trfd = ghcomp.Transform(self.collision_geo, T_rot_back) return collision_geo_trfd
def get_transformed_plane_gripper(self, T, rot_value_front, rot_value_back, plane_gripper, extended=False): ''' intermediary function to check the cable routing for the welder... ''' trot_plane = rg.Plane(self.plane) T_rot_back = rg.Transform.Rotation(m.radians(rot_value_back), trot_plane.ZAxis, trot_plane.Origin) plane_gripper = ghcomp.Transform(plane_gripper, T_rot_back) if extended == True: return ghcomp.Transform(plane_gripper, T) else: # maybe add a translation return ghcomp.Transform(plane_gripper, T)
def get_tool0_plane_from_joint_values_world(self, joint_values, rob_num): ''' the joint values (in degrees)''' T_W_R = self.T_W_R_1 if rob_num == 1 else self.T_W_R_2 if rob_num == 2 else self.T_W_R_3 if rob_num == 3 else self.T_W_R_4 if rob_num == 4 else None tool0_plane_transformed = self.get_tool0_plane_from_joint_values( joint_values) tool0_plane_transformed_world = ghcomp.Transform( tool0_plane_transformed, T_W_R) return tool0_plane_transformed_world
def apply_tool_transformation_WCS(self, rot_value_front, rot_value_back, extended=False): """ for transforming the tool which is aligned to the tool plane """ geo = self.apply_tool_transformation(rot_value_front, rot_value_back, extended=extended) geo_WCS = ghcomp.Transform(geo, self.T) # tool aligned_with_WCS return geo_WCS
def get_footprint(_surfaces): # Finds the 'footprint' of the building for 'Primary Energy Renewable' reference # 1) Re-build the Opaque Surfaces # 2) Join all the surface Breps into a single brep # 3) Find the 'box' for the single joined brep # 4) Find the lowest Z points on the box, offset another 10 units 'down' # 5) Make a new Plane at this new location # 6) Projects the brep edges onto the new Plane # 7) Split a surface using the edges, combine back into a single surface Footprint = namedtuple('Footprint', ['Footprint_surface', 'Footprint_area']) #----- Build brep surfaces = (from_face3d(surface.Srfc) for surface in _surfaces) bldg_mass = ghc.BrepJoin(surfaces).breps bldg_mass = ghc.BoundaryVolume(bldg_mass) if not bldg_mass: return Footprint(None, None) #------- Find Corners, Find 'bottom' (lowest Z) bldg_mass_corners = [v for v in ghc.BoxCorners(bldg_mass)] bldg_mass_corners.sort(reverse=False, key=lambda point3D: point3D.Z) rect_pts = bldg_mass_corners[0:3] #------- Projection Plane projection_plane1 = ghc.Plane3Pt(rect_pts[0], rect_pts[1], rect_pts[2]) projection_plane2 = ghc.Move(projection_plane1, ghc.UnitZ(-10)).geometry matrix = rs.XformPlanarProjection(projection_plane2) #------- Project Edges onto Projection Plane projected_edges = [] for edge in ghc.DeconstructBrep(bldg_mass).edges: projected_edges.append(ghc.Transform(edge, matrix)) #------- Split the projection surface using the curves l1 = ghc.Line(rect_pts[0], rect_pts[1]) l2 = ghc.Line(rect_pts[0], rect_pts[2]) max_length = max(ghc.Length(l1), ghc.Length(l2)) projection_surface = ghc.Polygon(projection_plane2, max_length * 100, 4, 0).polygon projected_surfaces = ghc.SurfaceSplit(projection_surface, projected_edges) #------- Remove the biggest surface from the set(the background srfc) projected_surfaces.sort(key=lambda x: x.GetArea()) projected_surfaces.pop(-1) #------- Join the new srfcs back together into a single one unioned_NURB = ghc.RegionUnion(projected_surfaces) unioned_surface = ghc.BoundarySurfaces(unioned_NURB) return Footprint(unioned_surface, unioned_surface.GetArea())
def get_transformed_geo(self, plane_new, rob_nr): self.plane = plane_new geo_z1, geo_z2, geo_y, geo_x, geo_fix = self.geo plane_0 = rg.Plane(rg.Point3d(0,0,0), rg.Vector3d(1,0,0), rg.Vector3d(0,1,0)) #self.plane.YAxis.Reverse() #self.plane.XAxis.Reverse() vec_trans_1 = rg.Vector3d.Subtract(rg.Vector3d(self.plane.Origin), rg.Vector3d(rg.Plane.WorldXY.Origin)) T1 = rg.Transform.Translation(vec_trans_1) T_rot = rg.Transform.Rotation(m.pi, rg.Vector3d.ZAxis, self.plane.Origin) T_mirr = rg.Transform.Mirror(self.plane.Origin, rg.Vector3d.XAxis) z_max = 4500 vec_trans_2_z = ((z_max - vec_trans_1.Z)/2) + vec_trans_1.Z vec_trans_2 = vec_trans_1 vec_trans_2.Z = vec_trans_2_z T2 = rg.Transform.Translation(vec_trans_2) vec_trans_3 = rg.Vector3d(vec_trans_1.X, vec_trans_1.Y, 0) T3 = rg.Transform.Translation(vec_trans_3) vec_trans_4 = rg.Vector3d(vec_trans_1.X, 0, 0) T4 = rg.Transform.Translation(vec_trans_4) geo_z1_WCS = ghcomp.Transform(geo_z1, T1) geo_z2_WCS = ghcomp.Transform(geo_z2, T2) geo_y_WCS = ghcomp.Transform(geo_y, T3) if rob_nr == 1 or rob_nr == 3: geo_x_WCS = ghcomp.Transform(geo_x, T4) else: geo_x_WCS = None if rob_nr == 2 or rob_nr == 4: geo_z1_WCS = ghcomp.Transform(geo_z1_WCS, T_rot) geo_z2_WCS = ghcomp.Transform(geo_z2_WCS, T_rot) if rob_nr == 3 or rob_nr == 4: geo_y_WCS = ghcomp.Transform(geo_y_WCS, T_rot) if rob_nr == 3: geo_x_WCS = ghcomp.Transform(geo_x_WCS, T_mirr) geo_gantry = [geo_z1_WCS, geo_z2_WCS, geo_y_WCS, geo_x_WCS, geo_fix] return geo_gantry
def __init__(self, geo, tool_plane): ''' tool class for the robot geo = tool geometry as list plane = defined tool plane geo_trfd = tool geometry transformed that the defined tool plane is aligned with the world xy plane ''' self.geo = geo self.plane = tool_plane self.frame = Frame(self.plane, draw_geo=True) self.T = rg.Transform.PlaneToPlane(self.plane, rg.Plane.WorldXY) self.geo_WCS = ghcomp.Transform(self.geo, self.T) # tool aligned_with_WCS self.plane_WCS = ghcomp.Transform(self.plane, self.T) # should be WorldXY plane self.collision_geo = self.geo self.colors = [ ghcomp.ColourRGB(100, 100, 150, 200) for i, part in enumerate(self.geo) ]
def apply_tool_transformation(self, rot_value_front, rot_value_back, extended=False): """ for transforming the tool which is in zero """ #self.p1_fixed, self.p2_rotfront, self.p3_rotback_frame, self.p3_rotback_gripper_ret, self.p3_rotback_gripper_ext, self.collision_geo = self.geo trot_plane = rg.Plane(self.plane) T_rot_front = rg.Transform.Rotation(m.radians(rot_value_front), trot_plane.ZAxis, trot_plane.Origin) p2_rotfront_trfd = ghcomp.Transform(self.p2_rotfront, T_rot_front) T_rot_back = rg.Transform.Rotation(m.radians(rot_value_back), trot_plane.ZAxis, trot_plane.Origin) p3_rotback_frame_trfd = ghcomp.Transform(self.p3_rotback_frame, T_rot_back) p3_rotback_gripper_ret_trfd = ghcomp.Transform( self.p3_rotback_gripper_ret, T_rot_back) p3_rotback_gripper_ext_trfd = ghcomp.Transform( self.p3_rotback_gripper_ext, T_rot_back) collision_geo_trfd = ghcomp.Transform(self.collision_geo, T_rot_back) if extended == True: return [ self.p1_fixed, p2_rotfront_trfd, p3_rotback_frame_trfd, p3_rotback_gripper_ext_trfd, collision_geo_trfd ] else: return [ self.p1_fixed, p2_rotfront_trfd, p3_rotback_frame_trfd, p3_rotback_gripper_ret_trfd, collision_geo_trfd ]
def get_tool0_plane_from_joint_values(self, joint_values): ''' the joint values (in degrees)''' # the angles in radians joint_values = [m.radians(j) for j in joint_values] a1, a2, a3, a4, a5, a6 = joint_values # calculate transformations j1, j2, j3, j4, j5, j6 = [rg.Plane(jp) for jp in self.joint_planes] T1 = rg.Transform.Rotation(a1, j1.ZAxis, j1.Origin) T2 = T1 * rg.Transform.Rotation(a2, j2.ZAxis, j2.Origin) T3 = T2 * rg.Transform.Rotation(a3, j3.ZAxis, j3.Origin) T4 = T3 * rg.Transform.Rotation(a4, j4.ZAxis, j4.Origin) T5 = T4 * rg.Transform.Rotation(a5, j5.ZAxis, j5.Origin) T6 = T5 * rg.Transform.Rotation(a6, j6.ZAxis, j6.Origin) tool0_plane_transformed = ghcomp.Transform(j6, T6) return tool0_plane_transformed
def apply_coll_geo_transformation_WCS(self, rot_value_back): """ for transforming the collgeo which is aligned to the tool plane """ coll_geo = self.apply_coll_geo_transformation(rot_value_back) coll_geo_WCS = ghcomp.Transform(coll_geo, self.T) # tool aligned_with_WCS return coll_geo_WCS
warning = "Looks like there are two Detail Views on your Layout Page? This Probably will not work right with more than one view on a page." ghenv.Component.AddRuntimeMessage( ghK.GH_RuntimeMessageLevel.Warning, warning) # > Find the note's Paperspace location noteCP_transformed = [] if _noteLocations.BranchCount > 0: for eachCP in _noteLocations.Branch(branchNum): noteCP_transformed.append( ghc.Transform(eachCP, dtlViewTransforms[0])) txtBoxes = [] # the note bounding boxes for noteNum, eachNote in enumerate(_notesToBake.Branch(branchNum)): txtBox = bakeText(_txt=eachNote, _txtLocation=noteCP_transformed[noteNum], _layer=tempLayer_Notes, _txtSize=float(noteTxtSize_), _neighbors=txtBoxes, _avoidCollisions=True) txtBoxes.append(txtBox) # > Layout Page Titleblock Text Objects
def get_tool_plane_in_RCS(self, tool_plane_WCS): ''' returns the tool plane in the robot coordinate system from a plane in the world cs''' tool_plane_RCS = ghcomp.Transform(tool_plane_WCS, self.T_R_W) return tool_plane_RCS
def get_transformed_coll_geo_with_tool_transformation_WCS( self, T, rot_value_back): coll_geo_WCS = self.apply_coll_geo_transformation_WCS(rot_value_back) return ghcomp.Transform(coll_geo_WCS, T)
def set_collision_geo(self, collision_geo): """ collision geo of the LWS tool""" self.collison_geo = collision_geo self.collison_geo_WCS = ghcomp.Transform(self.collison_geo, self.T)
def get_transformed_plane(self, T): ''' returns the tool plane transformed by the input transformation matrix ''' return ghcomp.Transform(self.plane, T)
def get_transformed_geo(self, T): ''' returns the tool geo transformed by the input transformation matrix ''' return ghcomp.Transform(self.geo, T)