|
| 1 | +import os |
| 2 | + |
| 3 | +import pytorch_kinematics as pk |
| 4 | + |
| 5 | +TEST_DIR = os.path.dirname(__file__) |
| 6 | + |
| 7 | +def test_limits(): |
| 8 | + chain = pk.build_serial_chain_from_urdf(open(os.path.join(TEST_DIR, "kuka_iiwa.urdf")).read(), "lbr_iiwa_link_7") |
| 9 | + iiwa_low_individual = [] |
| 10 | + iiwa_high_individual = [] |
| 11 | + for joint in chain.get_joints(): |
| 12 | + # Default velocity and effort limits for the iiwa arm |
| 13 | + assert joint.velocity_limits == (-10, 10) |
| 14 | + assert joint.effort_limits == (-300, 300) |
| 15 | + iiwa_low_individual.append(joint.limits[0]) |
| 16 | + iiwa_high_individual.append(joint.limits[1]) |
| 17 | + iiwa_low, iiwa_high = chain.get_joint_limits() |
| 18 | + assert iiwa_low == iiwa_low_individual |
| 19 | + assert iiwa_high == iiwa_high_individual |
| 20 | + chain = pk.build_chain_from_urdf(open(os.path.join(TEST_DIR, "joint_limit_robot.urdf")).read()) |
| 21 | + nums = [] |
| 22 | + for joint in chain.get_joints(): |
| 23 | + # Slice off the "joint" prefix to get just the number of the joint |
| 24 | + num = int(joint.name[5]) |
| 25 | + nums.append(num) |
| 26 | + # This robot is defined specifically to test joint limits. For joint |
| 27 | + # number `num`, it sets lower, upper, velocity, and effort limits to |
| 28 | + # `num+8`, `num+9`, `num`, and `num+4` respectively |
| 29 | + assert joint.limits == (num + 8, num + 9) |
| 30 | + assert joint.velocity_limits == (-num, num) |
| 31 | + assert joint.effort_limits == (-(num + 4), num + 4) |
| 32 | + low, high = chain.get_joint_limits() |
| 33 | + v_low, v_high = chain.get_joint_velocity_limits() |
| 34 | + e_low, e_high = chain.get_joint_effort_limits() |
| 35 | + assert low == [x + 8 for x in nums] |
| 36 | + assert high == [x + 9 for x in nums] |
| 37 | + assert v_low == [-x for x in nums] |
| 38 | + assert v_high == [x for x in nums] |
| 39 | + assert e_low == [-(x + 4) for x in nums] |
| 40 | + assert e_high == [x + 4 for x in nums] |
| 41 | + |
| 42 | + |
| 43 | +def test_empty_limits(): |
| 44 | + chain = pk.build_chain_from_urdf(open(os.path.join(TEST_DIR, "joint_no_limit_robot.urdf")).read()) |
| 45 | + nums = [] |
| 46 | + for joint in chain.get_joints(): |
| 47 | + # Slice off the "joint" prefix to get just the number of the joint |
| 48 | + num = int(joint.name[5]) |
| 49 | + nums.append(num) |
| 50 | + # This robot is defined specifically to test joint limits. For joint |
| 51 | + # number `num`, it sets velocity, and effort limits to |
| 52 | + # `num`, and `num+4` respectively, and leaves the lower and upper |
| 53 | + # limits undefined |
| 54 | + assert joint.limits == (0, 0) |
| 55 | + assert joint.velocity_limits == (-num, num) |
| 56 | + assert joint.effort_limits == (-(num + 4), num + 4) |
| 57 | + low, high = chain.get_joint_limits() |
| 58 | + v_low, v_high = chain.get_joint_velocity_limits() |
| 59 | + e_low, e_high = chain.get_joint_effort_limits() |
| 60 | + assert low == [0] * len(nums) |
| 61 | + assert high == [0] * len(nums) |
| 62 | + assert v_low == [-x for x in nums] |
| 63 | + assert v_high == [x for x in nums] |
| 64 | + assert e_low == [-(x + 4) for x in nums] |
| 65 | + assert e_high == [x + 4 for x in nums] |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == "__main__": |
| 69 | + test_limits() |
| 70 | + test_empty_limits() |
0 commit comments