-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparcour.py
228 lines (189 loc) · 11.3 KB
/
parcour.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import pybullet as p
import math
DEFAULT_POS = [0., 0., 0.]
DEFAULT_ORI = [0., 0., 0., 1.]
def tunnel(length, width, wall_width=0.05, position=DEFAULT_POS, orientation=DEFAULT_ORI):
# create a rectangular tunnel as a building block of an obstacle parcour
half_extents = [[length / 2, width / 2 + wall_width, wall_width / 2],
[length / 2, width / 2 + wall_width, wall_width / 2],
[length / 2, wall_width / 2, width / 2],
[length / 2, wall_width / 2, width / 2]]
positions = [[0, 0., -width / 2 - wall_width / 2],
[0, 0., width / 2 + wall_width / 2],
[0, -width / 2 - wall_width / 2, 0.],
[0, width / 2 + wall_width / 2, 0.]]
visual_shape_id = p.createVisualShapeArray(shapeTypes=[p.GEOM_BOX] * 4,
halfExtents=half_extents,
visualFramePositions=positions
)
collision_shape_id = p.createCollisionShapeArray(shapeTypes=[p.GEOM_BOX] * 4,
halfExtents=half_extents,
collisionFramePositions=positions
)
mb = p.createMultiBody(baseMass=0.,
baseInertialFramePosition=[0, 0, 0],
baseCollisionShapeIndex=collision_shape_id,
baseVisualShapeIndex=visual_shape_id,
basePosition=position,
baseOrientation=orientation,
useMaximalCoordinates=False)
p.changeVisualShape(mb, -1, rgbaColor=[1, 1, 1, 0.5], specularColor=[0.4, 0.4, 0])
return mb
def corner(width, wall_width=0.05, position=DEFAULT_POS, orientation=DEFAULT_ORI):
# create a corner (cube open at neg. x and pos. z) as a building block of an obstacle parcour
half_extents = [[width / 2, width / 2 + wall_width, wall_width / 2],
[width / 2, wall_width / 2, width / 2],
[width / 2, wall_width / 2, width / 2],
[wall_width / 2, width / 2 + wall_width, width / 2]]
positions = [[0, 0., -width / 2 - wall_width / 2],
[0, -width / 2 - wall_width / 2, 0.],
[0, width / 2 + wall_width / 2, 0.],
[width/2 + wall_width / 2, 0., 0.]]
visual_shape_id = p.createVisualShapeArray(shapeTypes=[p.GEOM_BOX] * 4,
halfExtents=half_extents,
visualFramePositions=positions
)
collision_shape_id = p.createCollisionShapeArray(shapeTypes=[p.GEOM_BOX] * 4,
halfExtents=half_extents,
collisionFramePositions=positions
)
mb = p.createMultiBody(baseMass=0.,
baseInertialFramePosition=[0, 0, 0],
baseCollisionShapeIndex=collision_shape_id,
baseVisualShapeIndex=visual_shape_id,
basePosition=position,
baseOrientation=orientation,
useMaximalCoordinates=False)
p.changeVisualShape(mb, -1, rgbaColor=[1, 1, 1, 0.5], specularColor=[0.4, 0.4, 0])
return mb
def cap(width, wall_width=0.05, position=DEFAULT_POS, orientation=DEFAULT_ORI):
# create a cap that can be used to close corners or tunnels.
# By default it is a wall in the y-z-plane that can be rotated and translated to the desired position
# create a corner (cube open at neg. x and pos. z) as a building block of an obstacle parcour
half_extents = [wall_width / 2, width / 2 + wall_width, width / 2]
pos = [0, 0., 0.]
visual_shape_id = p.createVisualShape(shapeType=p.GEOM_BOX,
halfExtents=half_extents,
visualFramePosition=pos
)
collision_shape_id = p.createCollisionShape(shapeType=p.GEOM_BOX,
halfExtents=half_extents,
collisionFramePosition=pos
)
mb = p.createMultiBody(baseMass=0.,
baseInertialFramePosition=[0, 0, 0],
baseCollisionShapeIndex=collision_shape_id,
baseVisualShapeIndex=visual_shape_id,
basePosition=position,
baseOrientation=orientation,
useMaximalCoordinates=False)
p.changeVisualShape(mb, -1, rgbaColor=[1, 1, 1, 0.5], specularColor=[0.4, 0.4, 0])
return mb
def trunk(x, y, width, height, orientation=DEFAULT_ORI):
half_extents = [width, width, height]
pos = [0, 0., 0.]
position = [x, y, height]
visual_shape_id = p.createVisualShape(shapeType=p.GEOM_BOX,
halfExtents=half_extents,
visualFramePosition=pos
)
collision_shape_id = p.createCollisionShape(shapeType=p.GEOM_BOX,
halfExtents=half_extents,
collisionFramePosition=pos
)
mb = p.createMultiBody(baseMass=0.,
baseInertialFramePosition=[0, 0, 0],
baseCollisionShapeIndex=collision_shape_id,
baseVisualShapeIndex=visual_shape_id,
basePosition=position,
baseOrientation=orientation,
useMaximalCoordinates=False)
p.changeVisualShape(mb, -1, rgbaColor=[1, 1, 1, 0.5], specularColor=[0.4, 0.4, 0])
return mb
def leaves(x, y, width, height, orientation=DEFAULT_ORI):
half_extents = [width * 1.4, width * 1.4, width * 0.8]
pos = [0, 0., 0.]
position = [x, y, height * 2 + width * 0.8]
visual_shape_id = p.createVisualShape(shapeType=p.GEOM_BOX,
halfExtents=half_extents,
visualFramePosition=pos
)
collision_shape_id = p.createCollisionShape(shapeType=p.GEOM_BOX,
halfExtents=half_extents,
collisionFramePosition=pos
)
mb = p.createMultiBody(baseMass=0.,
baseInertialFramePosition=[0, 0, 0],
baseCollisionShapeIndex=collision_shape_id,
baseVisualShapeIndex=visual_shape_id,
basePosition=position,
baseOrientation=orientation,
useMaximalCoordinates=False)
p.changeVisualShape(mb, -1, rgbaColor=[1, 1, 1, 0.5], specularColor=[0.4, 0.4, 0])
return mb
def tree(x=0., y=0., width=1., height=1., orientation=DEFAULT_ORI):
return leaves(x, y, width, height, orientation), trunk(x, y, width, height, orientation)
def rotate_z(angle):
return p.getQuaternionFromAxisAngle(axis=[0, 0, 1], angle=angle)
def trees(base_x=-3.5, base_y=-4.2):
tree(x=base_x + 1, y=base_y + 1, width=0.5, height=1, orientation=rotate_z(0.3))
tree(x=base_x - 1, y=base_y + 1, width=0.5, height=1.3)
tree(x=base_x, y= base_y + 3, width=0.4, height=0.9, orientation=rotate_z(0.4))
tree(x=base_x - 1.4, y=base_y + 4, width=0.6, height=1)
tree(x=base_x + 1.5, y=base_y + 4.1, width=0.5, height=1, orientation=rotate_z(0.1))
def tunnels():
# create an obstacle parcour
# width of the tunnels
width = 1
# create some orientation quaternions to rotate tunnels and corners
tunnel_ornx = [0., 0., 0., 1.]
tunnel_orny = p.getQuaternionFromAxisAngle(axis=[0, 0, 1], angle=math.pi / 2)
tunnel_ornz = p.getQuaternionFromAxisAngle(axis=[0, 1, 0], angle=math.pi / 2)
corner_negxposz = [0., 0., 0., 1.]
corner_negzposy = p.getQuaternionFromEuler([math.pi, 0.0, -math.pi / 2])
corner_negyposx = p.getQuaternionFromEuler([math.pi / 2, 0.0, math.pi / 2])
# create the parcour
cap(width=width, position=[-1., 0., 2.])
tunnel(length=5., width=width, position=[1.5, 0., 2.], orientation=tunnel_ornx)
corner(width=width, position=[4.5, 0., 2.], orientation=corner_negxposz)
tunnel(length=2., width=width, position=[4.5, 0.0, 3.5], orientation=tunnel_ornz)
corner(width=width, position=[4.5, 0., 5.0], orientation=corner_negzposy)
tunnel(length=4., width=width, position=[4.5, 2.5, 5], orientation=tunnel_orny)
corner(width=width, position=[4.5, 5., 5.], orientation=corner_negyposx)
tunnel(length=4., width=width, position=[7.0, 5.0, 5.], orientation=tunnel_ornx)
cap(width=width, position=[9., 5., 5.])
def wall(x=0., y=0., z=0., width=1., height=1., thickness=0.01, orientation=DEFAULT_ORI):
half_extents = [width / 2, thickness, height / 2]
position = [x, y, z + height / 2]
pos = [0, 0., 0.]
visual_shape_id = p.createVisualShape(shapeType=p.GEOM_BOX,
halfExtents=half_extents,
visualFramePosition=pos
)
collision_shape_id = p.createCollisionShape(shapeType=p.GEOM_BOX,
halfExtents=half_extents,
collisionFramePosition=pos
)
mb = p.createMultiBody(baseMass=0.,
baseInertialFramePosition=[0, 0, 0],
baseCollisionShapeIndex=collision_shape_id,
baseVisualShapeIndex=visual_shape_id,
basePosition=position,
baseOrientation=orientation,
useMaximalCoordinates=False)
p.changeVisualShape(mb, -1, rgbaColor=[1, 1, 1, 0.5], specularColor=[0.4, 0.4, 0])
return mb
def window(base_x=0., base_y=0., base_z=0., width=3., height=3.):
wall(x=base_x + width / 3, y=base_y, z=base_z + height / 3, width=width / 3, height=2 * height / 3)
wall(x=base_x + width / 6, y=base_y, z=base_z, width=2 * width / 3, height=height / 3)
wall(x=base_x - width / 6, y=base_y, z=base_z + 2 * height / 3, width=2 * width / 3, height=height / 3)
wall(x=base_x - width / 3, y=base_y, z=base_z, width=width / 3, height=height * 2 / 3)
def three_wall(base_x=0., base_y=0., width=1., height=1.):
wall(x=base_x - 2 * width, y=base_y, width=2 * width, height=height)
wall(x=base_x, y=base_y, width=width, height=height)
wall(x=base_x + 2 * width, y=base_y, width=2 * width, height=height)
def obstacle():
# three_wall(base_y=1.0)
# window(base_y=1.0, width=6.)
# trees()
tunnels()