-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo.py
120 lines (94 loc) · 4.05 KB
/
demo.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from __future__ import division
import pybullet as p
import pybullet_data
import numpy as np
import time
import argparse
UR5_JOINT_INDICES = [0, 1, 2]
def set_joint_positions(body, joints, values):
assert len(joints) == len(values)
for joint, value in zip(joints, values):
p.resetJointState(body, joint, value)
def draw_sphere_marker(position, radius, color):
vs_id = p.createVisualShape(p.GEOM_SPHERE, radius=radius, rgbaColor=color)
marker_id = p.createMultiBody(basePosition=position, baseCollisionShapeIndex=-1, baseVisualShapeIndex=vs_id)
return marker_id
def remove_marker(marker_id):
p.removeBody(marker_id)
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--birrt', action='store_true', default=False)
parser.add_argument('--smoothing', action='store_true', default=False)
args = parser.parse_args()
return args
def rrt():
###############################################
# TODO your code to implement the rrt algorithm
###############################################
pass
def birrt():
#################################################
# TODO your code to implement the birrt algorithm
#################################################
pass
def birrt_smoothing():
################################################################
# TODO your code to implement the birrt algorithm with smoothing
################################################################
pass
if __name__ == "__main__":
args = get_args()
# set up simulator
physicsClient = p.connect(p.GUI)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.setPhysicsEngineParameter(enableFileCaching=0)
p.setGravity(0, 0, -9.8)
p.configureDebugVisualizer(p.COV_ENABLE_GUI, False)
p.configureDebugVisualizer(p.COV_ENABLE_SHADOWS, True)
p.resetDebugVisualizerCamera(cameraDistance=1.400, cameraYaw=58.000, cameraPitch=-42.200, cameraTargetPosition=(0.0, 0.0, 0.0))
# load objects
plane = p.loadURDF("plane.urdf")
ur5 = p.loadURDF('assets/ur5/ur5.urdf', basePosition=[0, 0, 0.02], useFixedBase=True)
obstacle1 = p.loadURDF('assets/block.urdf',
basePosition=[1/4, 0, 1/2],
useFixedBase=True)
obstacle2 = p.loadURDF('assets/block.urdf',
basePosition=[2/4, 0, 2/3],
useFixedBase=True)
obstacles = [plane, obstacle1, obstacle2]
# start and goal
start_conf = (-0.813358794499552, -0.37120422397572495, -0.754454729356351)
start_position = (0.3998897969722748, -0.3993956744670868, 0.6173484325408936)
goal_conf = (0.7527214782907734, -0.6521867735052328, -0.4949270744967443)
goal_position = (0.35317009687423706, 0.35294029116630554, 0.7246701717376709)
goal_marker = draw_sphere_marker(position=goal_position, radius=0.02, color=[1, 0, 0, 1])
set_joint_positions(ur5, UR5_JOINT_INDICES, start_conf)
# place holder to save the solution path
path_conf = None
# get the collision checking function
from collision_utils import get_collision_fn
collision_fn = get_collision_fn(ur5, UR5_JOINT_INDICES, obstacles=obstacles,
attachments=[], self_collisions=True,
disabled_collisions=set())
if args.birrt:
if args.smoothing:
# using birrt with smoothing
path_conf = birrt_smoothing()
else:
# using birrt without smoothing
path_conf = birrt()
else:
# using rrt
path_conf = rrt()
if path_conf is None:
# pause here
raw_input("no collision-free path is found within the time budget, finish?")
else:
###############################################
# TODO your code to highlight the solution path
###############################################
# execute the path
while True:
for q in path_conf:
set_joint_positions(ur5, UR5_JOINT_INDICES, q)
time.sleep(0.5)