def generate_links_and_joints(parent_pose_bone, links=[], joints=[]):
    try:
        if (len(visited_joints) == 0):
            global visited_joints
            visited_joints = {}
    except NameError:
        global visited_joints
        visited_joints = {}
    print(len(visited_joints))
    visited_joints[parent_pose_bone.name] = True
    if is_joint(parent_pose_bone):
        parent_edit_bone = parent_pose_bone.bone
        for child_pose_bone in parent_pose_bone.children:
            child_edit_bone = child_pose_bone.bone
            if (is_joint(child_pose_bone) and (child_pose_bone.name not in visited_joints)):
                parent_link = LinkRef(Joint.to_link_name(parent_pose_bone.name), 'parent')
                child_link = LinkRef(Joint.to_link_name(child_pose_bone.name), 'child')
                dX = round((parent_pose_bone.head[0] - child_pose_bone.head[0]), 4)
                dY = round((parent_pose_bone.head[1] - child_pose_bone.head[1]), 4)
                dZ = round((parent_pose_bone.head[2] - child_pose_bone.head[2]), 4)
                point = to_ros_coord(dX, dY, dZ)
                mat = child_pose_bone.id_data.matrix_world
                print(((('angle of ' + child_pose_bone.name) + ': ') + str((mat * child_pose_bone.matrix).to_euler())))
                origin = Origin(point[0], point[1], point[2], 0, 0, 0)
                axis = Axis(1, 0, 0)
                limit = Limit(0, 0, 0, 0)
                joint = Joint(child_pose_bone.name, 'revolute', parent_link, child_link, origin, axis, limit)
                joints.append(joint)
                link = Link(Joint.to_link_name(child_pose_bone.name))
                links.append(link)
                (joints, links) = generate_links_and_joints(child_pose_bone, links, joints)
                print('{0} to {1}: ({2}, {3}, {4}, {5})'.format(child_pose_bone.name, child_edit_bone.name, point[0], point[1], point[2], parent_pose_bone.vector))
    return (joints, links)
def generate_links_and_joints(parent_pose_bone, links=[], joints=[]):
    try:
        if (len(visited_joints) == 0):
            global visited_joints
            visited_joints = {}
    except NameError:
        global visited_joints
        visited_joints = {}
    print(len(visited_joints))
    visited_joints[parent_pose_bone.name] = True
    if is_joint(parent_pose_bone):
        parent_edit_bone = parent_pose_bone.bone
        for child_pose_bone in parent_pose_bone.children:
            child_edit_bone = child_pose_bone.bone
            if (is_joint(child_pose_bone) and (child_pose_bone.name not in visited_joints)):
                parent_link = LinkRef(Joint.to_link_name(parent_pose_bone.name), 'parent')
                child_link = LinkRef(Joint.to_link_name(child_pose_bone.name), 'child')
                dX = round((parent_pose_bone.head[0] - child_pose_bone.head[0]), 4)
                dY = round((parent_pose_bone.head[1] - child_pose_bone.head[1]), 4)
                dZ = round((parent_pose_bone.head[2] - child_pose_bone.head[2]), 4)
                point = to_ros_coord(dX, dY, dZ)
                mat = child_pose_bone.id_data.matrix_world
                print(((('angle of ' + child_pose_bone.name) + ': ') + str((mat * child_pose_bone.matrix).to_euler())))
                origin = Origin(point[0], point[1], point[2], 0, 0, 0)
                axis = Axis(1, 0, 0)
                limit = Limit(0, 0, 0, 0)
                joint = Joint(child_pose_bone.name, 'revolute', parent_link, child_link, origin, axis, limit)
                joints.append(joint)
                link = Link(Joint.to_link_name(child_pose_bone.name))
                links.append(link)
                (joints, links) = generate_links_and_joints(child_pose_bone, links, joints)
                print('{0} to {1}: ({2}, {3}, {4}, {5})'.format(child_pose_bone.name, child_edit_bone.name, point[0], point[1], point[2], parent_pose_bone.vector))
    return (joints, links)