def _check_if_robot_is_attached_to_external_axis(robot_name): """ Checks if the robot is attached to an external axis controller :param robot_name: name of the robot being checked :return: bool, True if robot is attached to an external axis, False if otherwise """ if pm.objExists(mimic_utils.get_local_ctrl_path(robot_name) + '|localCTRL_externalAxisCTRL_parentConstraint'): return True else: return False
def _attach_robot_to_external_axis(robot, external_axis_CTRL): """ Parent Constrains the input robot's local_CTRL to the input external axis controller. This is primarily used for attaching robots to linear sliders :param robot: string, name pointing to selected robot :param external_axis_CTRL: string, name pointing to selected external axis ctrl """ # Create parent constraint between robot base's local control and # external axis control local_ctrl_path = mimic_utils.get_local_ctrl_path(robot) pm.parentConstraint(external_axis_CTRL, local_ctrl_path, maintainOffset=True, name='localCTRL_externalAxisCTRL_parentConstraint') # Hide robot's local_CTRL pm.setAttr(local_ctrl_path + '.v', 0)
def _sample_frame_get_pose(robot_name, frame): """ Get robot Pose from an animation frame. :param robot_name: Name of the robot :param frame: Frame to sample :return: """ # Set the time # TODO: Implement this in parent function pm.currentTime(frame) # tool_name = get_tool_name(robot_name) tool_name = mimic_utils.get_tool_ctrl_path(robot_name) try: # Try to grab the named tool tool_object = pm.ls(tool_name)[ 0] # Try to get tool, may raise an exception except IndexError: # No tool attached, use flange tool_name = mimic_utils.get_tcp_hdl_path(robot_name) # Local Base Frame controller (circle control at base of the robot). base_name = pm.ls(mimic_utils.get_local_ctrl_path(robot_name))[0] # Get name of the tcp and base world_matrix = '.worldMatrix' tcp_name_world_matrix = tool_name + world_matrix base_name_world_matrix = base_name + world_matrix # TRANSLATIONS # Get translation with respect to Maya's world frame tcp_translation = pm.xform(tool_name, query=True, rp=True, ws=True) base_translation = pm.xform(base_name, query=True, rp=True, ws=True) # ROTATIONS # Get TCP rotation with respect to Maya's world frame _tcp_matrix = pm.getAttr(tcp_name_world_matrix, time=frame) tcp_rotation = general_utils.matrix_get_rotations(_tcp_matrix) # Get Base rotation with respect to Maya's world frame _base_matrix = pm.getAttr(base_name_world_matrix, time=frame) base_rotation = general_utils.matrix_get_rotations(_base_matrix) # TRANSFORMATIONS # Compose 4x4 matrices using the rotation and translation from the above tcp_matrix_4x4 = general_utils.matrix_compose_4x4(tcp_rotation, tcp_translation) base_matrix_4x4 = general_utils.matrix_compose_4x4(base_rotation, base_translation) # Invert the base matrix base_matrix_4x4 = general_utils.matrix_get_inverse(base_matrix_4x4) # Get pose itself initial_pose_matrix = general_utils.matrix_multiply( base_matrix_4x4, tcp_matrix_4x4) # CONVERSIONS # Decompose the initial pose matrix initial_translation = general_utils.matrix_get_translation( initial_pose_matrix) initial_rotations = general_utils.matrix_get_rotations(initial_pose_matrix) # Rearrange from Maya CS (mcs) to Robot CS (rcs) indices = [2, 0, 1] new_translation = [initial_translation[i] * 10 for i in indices] # cm to mm new_rotation = [[initial_rotations[i][j] for j in indices] for i in indices] # Define rotation matrix and convert the rotations based robot type # Based on the orientation of the coordinate frame of the mounting flange # TODO: Integrate this with rigs, unclear and shouldn't be hardcoded robot_type = mimic_utils.get_robot_type(robot_name) if robot_type == 'ABB': conversion_rotation = [[0, 0, -1], [0, 1, 0], [1, 0, 0]] # elif robot_type == 'KUKA': # conversion_rotation = [ # [0, -1, 0], # [0, 0, 1], # [-1, 0, 0] # ] else: raise Exception('Robot type not supported for Pose movement') # Perform the conversion operation itself converted_rotation = general_utils.matrix_multiply(conversion_rotation, new_rotation) # Compose pose pose_matrix = general_utils.matrix_compose_4x4(converted_rotation, new_translation) # Decompose pose as expected for output pose = general_utils.matrix_decompose_4x4_completely(pose_matrix) return pose