IK with ManipulabilityΒΆ

Inverse Kinematics with Manipulability using PyRoKi.

All examples can be run by first cloning the PyRoki repository, which includes the pyroki_snippets implementation details.

 1import time
 2import viser
 3from robot_descriptions.loaders.yourdfpy import load_robot_description
 4import numpy as np
 5
 6import pyroki as pk
 7from viser.extras import ViserUrdf
 8import pyroki_snippets as pks
 9
10
11def main():
12    """Main function for basic IK."""
13
14    urdf = load_robot_description("panda_description")
15    target_link_name = "panda_hand"
16
17    # Create robot.
18    robot = pk.Robot.from_urdf(urdf)
19
20    # Set up visualizer.
21    server = viser.ViserServer()
22    server.scene.add_grid("/ground", width=2, height=2)
23    urdf_vis = ViserUrdf(server, urdf, root_node_name="/base")
24
25    # Create interactive controller with initial position.
26    ik_target = server.scene.add_transform_controls(
27        "/ik_target", scale=0.2, position=(0.61, 0.0, 0.56), wxyz=(0, 0, 1, 0)
28    )
29    timing_handle = server.gui.add_number("Elapsed (ms)", 0.001, disabled=True)
30    value_handle = server.gui.add_number("Yoshikawa Index", 0.001, disabled=True)
31    weight_handle = server.gui.add_slider(
32        "Manipulability Weight", 0.0, 10.0, 0.001, 0.0
33    )
34    manip_ellipse = pk.viewer.ManipulabilityEllipse(
35        server,
36        robot,
37        root_node_name="/manipulability",
38        target_link_name=target_link_name,
39    )
40
41    while True:
42        # Solve IK.
43        start_time = time.time()
44        solution = pks.solve_ik_with_manipulability(
45            robot=robot,
46            target_link_name=target_link_name,
47            target_position=np.array(ik_target.position),
48            target_wxyz=np.array(ik_target.wxyz),
49            manipulability_weight=weight_handle.value,
50        )
51
52        manip_ellipse.update(solution)
53        value_handle.value = manip_ellipse.manipulability
54
55        # Update timing handle.
56        elapsed_time = time.time() - start_time
57        timing_handle.value = 0.99 * timing_handle.value + 0.01 * (elapsed_time * 1000)
58
59        # Update visualizer.
60        urdf_vis.update_cfg(solution)
61
62
63if __name__ == "__main__":
64    main()