|
| 1 | +import numpy as np |
| 2 | +from viser import transforms as tf |
| 3 | +import os |
| 4 | +from viser_utils import setup_viser_with_robot, add_spheres, add_trajectory |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +import vamp |
| 8 | +from fire import Fire |
| 9 | + |
| 10 | + |
| 11 | +# Starting configuration |
| 12 | +a = [0.0, -0.785, 0.0, -2.356, 0.0, 1.571, 0.785] |
| 13 | + |
| 14 | +# Goal configuration |
| 15 | +b = [2.35, 1.0, 0.0, -0.8, 0, 2.5, 0.785] |
| 16 | + |
| 17 | + |
| 18 | +# Problem specification: a list of sphere centers |
| 19 | +problem = [ |
| 20 | + [0.55, 0, 0.25], |
| 21 | + [0.35, 0.35, 0.25], |
| 22 | + [0, 0.55, 0.25], |
| 23 | + [-0.55, 0, 0.25], |
| 24 | + [-0.35, -0.35, 0.25], |
| 25 | + [0, -0.55, 0.25], |
| 26 | + [0.35, -0.35, 0.25], |
| 27 | + [0.35, 0.35, 0.8], |
| 28 | + [0, 0.55, 0.8], |
| 29 | + [-0.35, 0.35, 0.8], |
| 30 | + [-0.55, 0, 0.8], |
| 31 | + [-0.35, -0.35, 0.8], |
| 32 | + [0, -0.55, 0.8], |
| 33 | + [0.35, -0.35, 0.8], |
| 34 | +] |
| 35 | + |
| 36 | + |
| 37 | +def main( |
| 38 | + obstacle_radius: float = 0.2, |
| 39 | + attachment_radius: float = 0.07, |
| 40 | + attachment_offset: float = 0.02, |
| 41 | + planner: str = "rrtc", |
| 42 | + **kwargs, |
| 43 | +): |
| 44 | + |
| 45 | + (vamp_module, planner_func, plan_settings, simp_settings) = ( |
| 46 | + vamp.configure_robot_and_planner_with_kwargs("panda", planner, **kwargs) |
| 47 | + ) |
| 48 | + |
| 49 | + # Create an attachment offset on the Z-axis from the end-effector frame |
| 50 | + tf = np.identity(4) |
| 51 | + tf[:3, 3] = np.array([0, 0, attachment_offset]) |
| 52 | + attachment = vamp.Attachment(tf) |
| 53 | + |
| 54 | + # Add a single sphere to the attachment - spheres are added in the attachment's local frame |
| 55 | + attachment.add_spheres([vamp.Sphere([0, 0, 0], attachment_radius)]) |
| 56 | + |
| 57 | + robot_dir = Path(__file__).parents[1] / "resources" / "panda" |
| 58 | + server, robot = setup_viser_with_robot(robot_dir, "panda_spherized.urdf") |
| 59 | + robot.update_cfg(a) |
| 60 | + |
| 61 | + e = vamp.Environment() |
| 62 | + for sphere in problem: |
| 63 | + e.add_sphere(vamp.Sphere(sphere, obstacle_radius)) |
| 64 | + |
| 65 | + _problem_sphere_handles = add_spheres( |
| 66 | + server, np.array(problem), np.array([obstacle_radius] * len(problem)) |
| 67 | + ) |
| 68 | + |
| 69 | + # Add the attchment to the VAMP environment |
| 70 | + e.attach(attachment) |
| 71 | + # Add attachment sphere to visualization |
| 72 | + attachment_sph = add_spheres( |
| 73 | + server, np.zeros((1, 3)), np.array([attachment_radius]), colors=[[0, 255, 0]] |
| 74 | + ) |
| 75 | + |
| 76 | + # Update attachment sphere positions corresponding to the waypoints. |
| 77 | + # this could also be made into a callable that can be called during trajectory viz |
| 78 | + def get_attachment_pos(configuration): |
| 79 | + attachment.set_ee_pose(vamp_module.eefk(configuration)) |
| 80 | + return np.array([attachment.posed_spheres[0].position]) |
| 81 | + |
| 82 | + # Plan and display |
| 83 | + sampler = vamp_module.halton() |
| 84 | + result = planner_func(a, b, e, plan_settings, sampler) |
| 85 | + simple = vamp_module.simplify(result.path, e, simp_settings, sampler) |
| 86 | + simple.path.interpolate_to_resolution(vamp.panda.resolution()) |
| 87 | + |
| 88 | + attachment_positions = [get_attachment_pos(pos) for pos in simple.path.numpy()] |
| 89 | + |
| 90 | + add_trajectory( |
| 91 | + server, simple.path.numpy(), robot, attachment_sph, attachment_positions |
| 92 | + ) |
| 93 | + |
| 94 | + # display |
| 95 | + while True: |
| 96 | + continue |
| 97 | + |
| 98 | + |
| 99 | +if __name__ == "__main__": |
| 100 | + Fire(main) |
0 commit comments