pybullet.calculateInverseKinematics2 memory leak?

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
jsung
Posts: 1
Joined: Sat Feb 19, 2022 6:24 pm

pybullet.calculateInverseKinematics2 memory leak?

Post by jsung »

Hi, I have a problem with the "pybullet.calculateInverseKinematics2" function. Whenever I call it, the memory usage on my PC increases a little bit. I call this method multiple times a second and the memory seems to keep increasing even after I've exited the function. I replaced the function with its single end effector alternative "pybullet.calculateInverseKinematics" and the memory issue is fixed (it no longer increases). The problem with using the regular "pybullet.calculateInverseKinematics" is that there is computational overhead because now I'm manually calculating each end effector in a for loop and that slows down the processing. Is there a way I can use the multi-end-effector IK function without the memory issue? Thanks.

Code: Select all

def calculateIK3(feet_positions, jointDamping):
    pos_body = np.array(p.getBasePositionAndOrientation(hexapod_ID)[0])
    orn_body = p.getBasePositionAndOrientation(hexapod_ID)[1]

    rest_poses = []
    target_pos = []

    link_indexes = [x for x in range(3, 24, 4)]

    for j in range(6):
        rest_poses.append(pos_body + p.multiplyTransforms([0, 0, 0], orn_body, baseToEndEffectorConstVec[j], [0, 0, 0, 1])[0])
        tp = p.multiplyTransforms(rest_poses[j], orn_body, feet_positions[j], [0, 0, 0, 1])
        target_pos.append(tp[0])
    ik2 = [0] * 18
    # ik = p.calculateInverseKinematics2(
    #     hexapod_ID,
    #     [link_indexes[0]],
    #     [target_pos[0]],
    #     lowerLimits=ll,
    #     upperLimits=ul,
    #     jointRanges=jr,
    #     restPoses=rest_poses
    # )
    # print(ik, len(ik))
    iks = []
    for j in range(6):
        temp_ik = p.calculateInverseKinematics(
            hexapod_ID,
            link_indexes[j],
            target_pos[j]
        )
        temp_ik = list(temp_ik[(3 * j):3 + (3 * j)])
        # print(len(temp_ik), temp_ik)
        iks.extend(temp_ik)
    # print(iks)
    # iks = list(temp_ik[:3]) + [0] * 15
    return iks
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: pybullet.calculateInverseKinematics2 memory leak?

Post by Erwin Coumans »

This needs a full minimal reproduction case, not just a small code snippet.
Post Reply