-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserialize_in_test.py
78 lines (62 loc) · 2.59 KB
/
serialize_in_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import sys
from functools import partial
import time
import pybullet as p
if os.environ.get('ROS_DISTRO'):
import rospy
import numpy as np
from cairo_simulator.core.sim_context import SawyerSimContext
from cairo_planning.collisions import DisabledCollisionsContext
from cairo_planning.local.interpolation import parametric_lerp
from cairo_planning.planners import LazyPRM
from cairo_planning.local.curve import JointTrajectoryCurve
from cairo_planning.core.serialization import load_PRM
def main():
# Reload the samples and configuration
prm_data = load_PRM(os.path.dirname(os.path.abspath(__file__)))
# Generate a new plan
sim_context = SawyerSimContext(configuration=prm_data["config"])
sim = sim_context.get_sim_instance()
logger = sim_context.get_logger()
state_space = sim_context.get_state_space()
svc = sim_context.get_state_validity()
sawyer_robot = sim_context.get_robot()
_ = sawyer_robot.get_simulator_id()
_ = sim_context.get_sim_objects(['Ground'])[0]
sawyer_robot.move_to_joint_pos([0, 0, 0, 0, 0, 0, 0])
time.sleep(1)
with DisabledCollisionsContext(sim, [], []):
#######
# LazyPRM #
#######
# Use parametric linear interpolation with 10 steps between points.
interp = partial(parametric_lerp, steps=10)
# See params for PRM specific parameters
prm = LazyPRM(state_space, svc, interp, params={
'n_samples': 4000, 'k': 8, 'ball_radius': 2.5})
prm.samples = prm_data["samples"]
logger.info("Planning....")
plan = prm.plan(np.array([0, 0, 0, 0, 0, 0, 0]), np.array([1.5262755737449423, -0.1698540226273928,
2.7788151824762055, 2.4546623466066135, 0.7146948867821279, 2.7671787952787184, 2.606128412644311]))
# get_path() reuses the interp function to get the path between vertices of a successful plan
path = prm.get_path(plan)
if len(path) == 0:
logger.info("Planning failed....")
sys.exit(1)
logger.info("Plan found....")
# splining uses numpy array so needs to be converted
path = [np.array(p) for p in path]
# Create a MinJerk spline trajectory using JointTrajectoryCurve and execute
jtc = JointTrajectoryCurve()
traj = jtc.generate_trajectory(path, move_time=2)
sawyer_robot.execute_trajectory(traj)
key = input("Press any key to excute plan.")
try:
while True:
sim.step()
except KeyboardInterrupt:
p.disconnect()
sys.exit(0)
if __name__ == "__main__":
main()