-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcar_obs_website_video_mpc_tree.py
558 lines (478 loc) · 21.5 KB
/
car_obs_website_video_mpc_tree.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
## from ctypes import *
#ctypes.cdll.LoadLibrary('')
#lib1 = CDLL("deps/sparse_rrt/deps/trajopt/build/lib/libsco.so")
#lib2 = CDLL("deps/sparse_rrt/deps/trajopt/build/lib/libutils.so")
import sys
sys.path.append('/media/arclabdl1/HD1/YLmiao/YLmiao_from_unicorn/YLmiao/mpc-mpnet-cuda-yinglong/deps/sparse_rrt-1')
sys.path.append('.')
import matplotlib as mpl
mpl.use('Agg')
from sparse_rrt.planners import SST
#from env.cartpole_obs import CartPoleObs
#from env.cartpole import CartPole
#from sparse_rrt.systems import standard_cpp_systems
from sparse_rrt import _sst_module
import numpy as np
import time
from plan_utility.line_line_cc import *
import pickle
from sparse_rrt import _deep_smp_module, _sst_module
import os
obs_list = []
LENGTH = 20.
width = 6.
near = width * 1.2
# convert from obs to point cloud
# load generated point cloud
obs_list_total = []
obc_list_total = []
for i in range(10):
file = open('/media/arclabdl1/HD1/YLmiao/YLmiao_from_unicorn/YLmiao/data/kinodynamic/car_obs/obs_%d.pkl' % (i), 'rb')
obs_list_total.append(pickle.load(file))
file = open('/media/arclabdl1/HD1/YLmiao/YLmiao_from_unicorn/YLmiao/data/kinodynamic/car_obs/obc_%d.pkl' % (i), 'rb')
obc_list_total.append(pickle.load(file))
#[(0, 932), (1, 935), (2, 923), (8, 141), (5,931), (6, 969), (7, 927), (9, 911),]
# (5,931), (6, 286)
import sys
obs_idx = int(sys.argv[1])
p_idx = int(sys.argv[2])
# Create custom system
#obs_list = [[-10., -3.],
# [0., 3.],
# [10, -3.]]
obs_list = obs_list_total[obs_idx]
obc_list = obc_list_total[obs_idx]
print('generated.')
print(obs_list.shape)
params = {
'solver_type' : "cem",
'n_problem': 1,
'n_sample': 1024,
'n_elite': 128,
'n_t': 1,
'max_it': 150,
'converge_r': 1e-10,
'dt': 2e-3,
'mu_u': np.array([1., 1.]) ,
'sigma_u': np.array([1., 0.5]),
'mu_t': 1.,
'sigma_t': 1.,
't_max': 2.,
'verbose': False,#True,#
'step_size': 0.8,
"goal_radius": 2.0,
"sst_delta_near": .001,
"sst_delta_drain": .0005,
"goal_bias": 0.08,
"width": 8,
"hybrid": False,
"hybrid_p": 0.0,
"cost_samples": 1,
"mpnet_weight_path":"/media/arclabdl1/HD1/YLmiao/YLmiao_from_unicorn/YLmiao/mpc-mpnet-cuda-yinglong/mpnet/exported/output/car_obs/mpnet_10k_external_small_model.pt",
#"mpnet_weight_path":"mpnet/exported/output/cartpole_obs/mpnet_10k_external_v2_deep.pt",
#"mpnet_weight_path":"mpnet/exported/output/cartpole_obs/mpnet_10k.pt",
# "mpnet_weight_path":"mpnet/exported/output/cartpole_obs/mpnet_10k_nonorm.pt",
# "mpnet_weight_path":"mpnet/exported/output/cartpole_obs/mpnet_subsample0.5_10k.pt",
"cost_predictor_weight_path": "/media/arclabdl1/HD1/YLmiao/YLmiao_from_unicorn/YLmiao/mpc-mpnet-cuda-yinglong/mpnet/exported/output/cartpole_obs/cost_10k.pt",
"cost_to_go_predictor_weight_path": "/media/arclabdl1/HD1/YLmiao/YLmiao_from_unicorn/YLmiao/mpc-mpnet-cuda-yinglong/mpnet/exported/output/cartpole_obs/cost_to_go_10k.pt",
"refine": False,
"using_one_step_cost": False,
"refine_lr": 0,
"refine_threshold": 0,
"device_id": "cuda:3",
"cost_reselection": False,
"number_of_iterations": 5000,
"weights_array": [1, 1.0, .5],
}
path, control, time = np.load('/media/arclabdl1/HD1/YLmiao/YLmiao_from_unicorn/YLmiao/mpc-mpnet-cuda-yinglong/results/cpp_full/car_obs/default/paths/path_%d_%d.npy' % (obs_idx, p_idx),
allow_pickle=True)
sgs = open('/media/arclabdl1/HD1/YLmiao/YLmiao_from_unicorn/YLmiao/data/kinodynamic/car_obs/%d/start_goal_%d.pkl' % (obs_idx, p_idx), 'rb')
sgs = pickle.load(sgs)
planner = _deep_smp_module.DSSTMPCWrapper(
system_type='car_obs',
solver_type="cem",
start_state=np.array(path[0]),
# goal_state=np.array(ref_path[-1]),
goal_state=np.array(sgs[-1]),
goal_radius=params['goal_radius'],
random_seed=0,
sst_delta_near=params['sst_delta_near'],
sst_delta_drain=params['sst_delta_drain'],
obs_list=obs_list,
width=params['width'],
verbose=params['verbose'],
mpnet_weight_path=params['mpnet_weight_path'],
cost_predictor_weight_path=params['cost_predictor_weight_path'],
cost_to_go_predictor_weight_path=params['cost_to_go_predictor_weight_path'],
num_sample=params['cost_samples'],
np=params['n_problem'], ns=params['n_sample'], nt=params['n_t'], ne=params['n_elite'], max_it=params['max_it'],
converge_r=params['converge_r'], mu_u=params['mu_u'], std_u=params['sigma_u'], mu_t=params['mu_t'],
std_t=params['sigma_t'], t_max=params['t_max'], step_size=params['step_size'], integration_step=params['dt'],
device_id=params['device_id'], refine_lr=params['refine_lr'],
weights_array=params['weights_array'],
obs_voxel_array=obc_list.reshape(-1)
)
def enforce_bounds(state):
'''
check if state satisfies the bound
apply threshold to velocity and angle
return a new state toward which the bound has been enforced
'''
WIDTH = 2.0
LENGTH = 1.0
STATE_X = 0
STATE_Y = 1
STATE_THETA = 2
MIN_X = -25
MAX_X = 25
MIN_Y = -35
MAX_Y = 35
new_state = np.array(state)
"""
if state[STATE_V] < MIN_V/30.:
new_state[STATE_V] = MIN_V/30.
elif state[STATE_V] > MAX_V/30.:
new_state[STATE_V] = MAX_V/30.
"""
if state[2] < -np.pi:
new_state[2] += 2*np.pi
elif state[2] > np.pi:
new_state[2] -= 2*np.pi
return new_state
def overlap(b1corner,b1axis,b1orign,b1dx,b1dy,b2corner,b2axis,b2orign,b2dx,b2dy):
# this only checks overlap of b1 w.r.t. b2
# a complete check should do in both directions
b2ds = [b2dx, b2dy]
for a in range(0,2):
t=b1corner[0][0]*b2axis[a][0]+b1corner[0][1]*b2axis[a][1] # project corner to the axis by inner product
tMin = t
tMax = t
for c in range(1,4):
t = b1corner[c][0]*b2axis[a][0]+b1corner[c][1]*b2axis[a][1] # project corner to the axis by inner product
# find range by [tMin, tMax]
if t < tMin:
tMin = t
elif t > tMax:
tMax = t
# since b2 the other corners (corner 1, 2, 3) are larger than b2orign (project of corner 0 to axis)
# specifically, the range is [b2orign[i], b2orign[i]+size(i)] (of the projected point by dot product)
# we only need to compare tMax with b2orign[i], and tMin with size(i)+b2orign[i]
if ((tMin > (b2ds[a] + b2orign[a])) or (tMax < b2orign[a])):
return False
return True
def IsInCollision(x, obc, obc_width=4.):
car_width = 2.0
car_len = 1.0
width = 8.0
WIDTH = car_width
LENGTH = car_len
STATE_X = 0
STATE_Y = 1
STATE_THETA = 2
MIN_X = -25
MAX_X = 25
MIN_Y = -35
MAX_Y = 35
if x[0] < MIN_X or x[0] > MAX_X or x[1] < MIN_Y or x[1] > MAX_Y:
return True
robot_corner=np.zeros((4,2),dtype=np.float32)
robot_axis=np.zeros((2,2),dtype=np.float32)
robot_orign=np.zeros(2,dtype=np.float32)
length=np.zeros(2,dtype=np.float32)
X1=np.zeros(2,dtype=np.float32)
Y1=np.zeros(2,dtype=np.float32)
X1[0]=np.cos(x[STATE_THETA])*(WIDTH/2.0)
X1[1]=-np.sin(x[STATE_THETA])*(WIDTH/2.0)
Y1[0]=np.sin(x[STATE_THETA])*(LENGTH/2.0)
Y1[1]=np.cos(x[STATE_THETA])*(LENGTH/2.0)
for j in range(0,2):
# order: (left-bottom, right-bottom, right-upper, left-upper)
# assume angle (state_theta) is clockwise
robot_corner[0][j]=x[j]-X1[j]-Y1[j]
robot_corner[1][j]=x[j]+X1[j]-Y1[j]
robot_corner[2][j]=x[j]+X1[j]+Y1[j]
robot_corner[3][j]=x[j]-X1[j]+Y1[j]
# axis: horizontal and vertical
robot_axis[0][j] = robot_corner[1][j] - robot_corner[0][j]
robot_axis[1][j] = robot_corner[3][j] - robot_corner[0][j]
#print('robot corners:')
#print(robot_corner)
length[0]=np.sqrt(robot_axis[0][0]*robot_axis[0][0]+robot_axis[0][1]*robot_axis[0][1])
length[1]=np.sqrt(robot_axis[1][0]*robot_axis[1][0]+robot_axis[1][1]*robot_axis[1][1])
# normalize the axis
for i in range(0,2):
for j in range(0,2):
robot_axis[i][j]=robot_axis[i][j]/float(length[i])
# obtain the projection of the left-bottom corner to the axis, to obtain the minimal projection length
robot_orign[0]=robot_corner[0][0]*robot_axis[0][0]+ robot_corner[0][1]*robot_axis[0][1]
robot_orign[1]=robot_corner[0][0]*robot_axis[1][0]+ robot_corner[0][1]*robot_axis[1][1]
#print('robot orign:')
#print(robot_orign)
for i in range(len(obc)):
cf=True
obs_corner=np.zeros((4,2),dtype=np.float32)
obs_axis=np.zeros((2,2),dtype=np.float32)
obs_orign=np.zeros(2,dtype=np.float32)
length2=np.zeros(2,dtype=np.float32)
for j in range(0,2):
# order: (left-bottom, right-bottom, right-upper, left-upper)
obs_corner[0][j] = obc[i][j]
obs_corner[1][j] = obc[i][2+j]
obs_corner[2][j] = obc[i][2*2+j]
obs_corner[3][j] = obc[i][3*2+j]
# horizontal axis and vertical
obs_axis[0][j] = obs_corner[1][j] - obs_corner[0][j]
obs_axis[1][j] = obs_corner[3][j] - obs_corner[0][j]
#obs_axis[0][j] = obs_corner[3][j] - obs_corner[0][j]
#obs_axis[1][j] = obs_corner[1][j] - obs_corner[0][j]
length2[0]=np.sqrt(obs_axis[0][0]*obs_axis[0][0]+obs_axis[0][1]*obs_axis[0][1])
length2[1]=np.sqrt(obs_axis[1][0]*obs_axis[1][0]+obs_axis[1][1]*obs_axis[1][1])
# normalize the axis
for i1 in range(0,2):
for j1 in range(0,2):
obs_axis[i1][j1]=obs_axis[i1][j1]/float(length2[i1])
# obtain the inner product of the left-bottom corner with the axis to obtain the minimal of projection value
obs_orign[0]=obs_corner[0][0]*obs_axis[0][0]+ obs_corner[0][1]*obs_axis[0][1] # dot product at 0-th corner
obs_orign[1]=obs_corner[0][0]*obs_axis[1][0]+ obs_corner[0][1]*obs_axis[1][1]
# do checking in both direction (b1 -> b2, b2 -> b1). If at least one shows not-overlapping, then it is not overlapping
cf=overlap(robot_corner,robot_axis,robot_orign,car_width,car_len,obs_corner,obs_axis,obs_orign,width,width)
cf=cf and overlap(obs_corner,obs_axis,obs_orign,width,width,robot_corner,robot_axis,robot_orign,car_width,car_len)
if cf==True:
return True
return False
def wrap_angle(x, system):
circular = system.is_circular_topology()
res = np.array(x)
for i in range(len(x)):
if circular[i]:
# use our previously saved version
res[i] = x[i] - np.floor(x[i] / (2*np.pi))*(2*np.pi)
if res[i] > np.pi:
res[i] = res[i] - 2*np.pi
return res
from visual.visualizer import Visualizer
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib as mpl
import matplotlib.patches as patches
from matplotlib.colors import LinearSegmentedColormap
padding = 3
class CarVisualizer(Visualizer):
def __init__(self, system, params):
super(CarVisualizer, self).__init__(system, params)
self.dt = 2
self.fig = plt.gcf()
self.fig.set_figheight(10)
self.fig.set_figwidth(10)
self.ax1 = plt.subplot(111)
def _init(self):
ax = self.ax1
ax.clear()
ax.set_xlim(-25-padding, 25+padding)
ax.set_ylim(-35, 35)
# add patches
state = self.states[0]
self.car = patches.Rectangle((state[0]-self.params['car_w']/2,state[1]-self.params['car_l']/2),\
self.params['car_w'],self.params['car_l'],\
linewidth=.5,edgecolor=self.color_dict['car_intermediate_color'],\
facecolor=self.color_dict['car_intermediate_color'])
self.car_direction = patches.Arrow(state[0],state[1],\
self.params['car_w']*2.,0,\
linewidth=0., width=1.5,\
facecolor=self.color_dict['direction_intermediate_color'])
self.recs = []
self.recs.append(self.car)
self.recs.append(self.car_direction)
for i in range(len(self.obs)):
x, y = self.obs[i]
obs = patches.Rectangle((x-self.params['obs_w']/2,y-params['obs_h']/2),\
self.params['obs_w'],self.params['obs_h'],\
linewidth=.5,edgecolor=self.color_dict['obstacle_color'],\
facecolor=self.color_dict['obstacle_color'])
self.recs.append(obs)
ax.add_patch(obs)
# transform pole according to state
t = mpl.transforms.Affine2D().rotate_deg_around(state[0], state[1], \
-state[2]/np.pi * 180) + ax.transData
self.car.set_transform(t)
ax.add_patch(self.car)
self.car_direction.set_transform(t)
self.car_direction_patch = ax.add_patch(self.car_direction)
# add goal patch
state = self.sgs[1]
self.car_goal = patches.Rectangle((state[0]-self.params['car_w']/2,state[1]-self.params['car_l']/2),\
self.params['car_w'],self.params['car_l'],\
linewidth=.5,edgecolor=self.color_dict['car_goal_color'],\
facecolor=self.color_dict['car_goal_color'])
self.car_direction_goal = patches.Arrow(state[0],state[1],\
self.params['car_w'] * 2.,0,\
linewidth=0, width=1.5, \
facecolor=self.color_dict['direction_goal_color'])
self.recs.append(self.car_goal)
self.recs.append(self.car_direction_goal)
# transform pole according to state
t = mpl.transforms.Affine2D().rotate_deg_around(state[0], state[1], \
-state[2]/np.pi * 180) + ax.transData
self.car_goal.set_transform(t)
ax.add_patch(self.car_goal)
self.car_direction_goal.set_transform(t)
self.car_direction_goal_patch = ax.add_patch(self.car_direction_goal)
return self.recs
def _animate(self, i):
print('animating, frame %d/%d' % (i, self.total))
ax = self.ax1
ax.set_xlim(-25-padding, 25+padding)
ax.set_ylim(-35, 35)
state = self.states[i]
self.recs[0].set_xy((state[0]-self.params['car_w']/2,state[1]-self.params['car_l']/2))
t = mpl.transforms.Affine2D().rotate_deg_around(state[0], state[1], \
-state[2]/np.pi * 180) + ax.transData
self.recs[0].set_transform(t)
# modify car_direction
self.car_direction_patch.remove()
self.car_direction = patches.Arrow(state[0],state[1],\
self.params['car_w']*2.,0,\
linewidth=0., width=1.5,\
facecolor=self.color_dict['direction_intermediate_color'])
self.recs[1] = self.car_direction
t = mpl.transforms.Affine2D().rotate_deg_around(state[0], state[1], \
-state[2]/np.pi * 180) + ax.transData
self.recs[1].set_transform(t)
self.car_direction_patch = ax.add_patch(self.car_direction)
return self.recs
def animate(self, states, actions, costs, obstacles, sg, wrap_system):
'''
given a list of states, actions and obstacles, animate the robot
'''
new_obs_i = []
obs_width = 8.0
for k in range(len(obstacles)):
obs_pt = []
obs_pt.append(obstacles[k][0]-obs_width/2)
obs_pt.append(obstacles[k][1]-obs_width/2)
obs_pt.append(obstacles[k][0]+obs_width/2)
obs_pt.append(obstacles[k][1]-obs_width/2)
obs_pt.append(obstacles[k][0]+obs_width/2)
obs_pt.append(obstacles[k][1]+obs_width/2)
obs_pt.append(obstacles[k][0]-obs_width/2)
obs_pt.append(obstacles[k][1]+obs_width/2)
new_obs_i.append(obs_pt)
obs_i = new_obs_i
self.cc_obs = obs_i
# transform the waypoint states and actions into trajectory
traj = []
s = states[0]
for i in range(len(states)-1):
s = states[i]
print('state: %d, remaining: %d' % (i, len(states)-i))
#action = actions[i]
# connect from this state to next
solution_u, solution_t = planner.steer_solution(states[i], states[i+1])
print('solution_u:')
print(solution_u)
print('solution_t:')
print(solution_t)
for j in range(len(solution_u)):
action = solution_u[j]
num_steps = int(np.round(solution_t[j]/self.params['integration_step']))
for k in range(num_steps):
traj.append(np.array(s))
#print("porpagating...")
#print(s)
#print('st:')
#print(sT)
s = self.system(s, action, self.params['integration_step'])
s = enforce_bounds(s)
#assert not IsInCollision(s, obs_i)
print('after propagation, state: ', s)
print('state to reach: ', states[i+1])
traj = np.array(traj)
return traj
def plot(self, traj, obstacles, sg, color_dict, wrap_system):
self.fig = plt.gcf()
self.fig.set_figheight(10)
self.fig.set_figwidth(10)
self.ax1 = plt.subplot(111)
self.color_dict = color_dict
print("animating...")
# animate
self.states = traj
self.obs = obstacles
print(len(self.states))
self.total = len(self.states)
self._init()
to_plot_list_x = []
to_plot_list_y = []
traj_recs = []
plot_step_sz = 500
for i in list(range(1,len(traj))) + [0]:
if i % plot_step_sz == 0:
# plot the scene change
if i == 0:
car_color = color_dict['car_start_color']#"green"
direction_color = color_dict['direction_start_color']#"yellow"
else:
car_color = color_dict['car_intermediate_color']#"blue"
direction_color = color_dict['direction_intermediate_color']#"yellow"
ax = self.ax1
ax.set_xlim(-25-padding, 25+padding)
ax.set_ylim(-35, 35)
state = traj[i]
car = patches.Rectangle((state[0]-self.params['car_w']/2,state[1]-self.params['car_l']/2),\
self.params['car_w'],self.params['car_l'],\
linewidth=.5,edgecolor=car_color,facecolor=car_color)
car_direction = patches.Arrow(state[0],state[1],\
self.params['car_w']/2,0,\
linewidth=1.0, edgecolor=direction_color)
t = mpl.transforms.Affine2D().rotate_deg_around(state[0], state[1], \
-state[2]/np.pi * 180) + ax.transData
car.set_transform(t)
ax.add_patch(car)
car_direction.set_transform(t)
car_direction_patch = ax.add_patch(car_direction)
traj_recs.append(car)
traj_recs.append(car_direction)
ax.add_patch(self.car_goal)
ax.add_patch(self.car_direction_goal)
plt.axis('off')
return self.fig
def gen_video(self, traj, obs_list, sgs, color_dict, system):
self.states = traj
self.obs_list = obs_list
self.obs = obs_list
self.color_dict = color_dict
self.total = len(self.states)
self.sgs = sgs
ani = animation.FuncAnimation(self.fig, self._animate, range(0, len(self.states)),
interval=self.dt, blit=True, init_func=self._init,
repeat=True)
return ani
params = {}
car_width = 2.0
car_len = 1.0
width = 8.
params['car_w'] = car_width
params['car_l'] = car_len
params['obs_w'] = width
params['obs_h'] = width
params['integration_step'] = 0.002
system = _sst_module.Car()
cpp_propagator = _sst_module.SystemPropagator()
dynamics = lambda x, u, t: cpp_propagator.propagate(system, x, u, t)
vis = CarVisualizer(dynamics, params)
states = path
sgs[0] = wrap_angle(sgs[0], system)
sgs[1] = wrap_angle(sgs[1], system)
print('states:')
print(states)
traj = vis.animate(np.array(states), None, None, obs_list, np.array(sgs), system)
traj = traj[:-1:80].tolist() + [traj[-1]] # sub sample
traj = np.array(traj)
#HTML(anim.to_html5_video())
#anim.save('acrobot_env%d_path%d.mp4' % (obs_idx, p_idx))
color_dict = {'car_start_color': 'springgreen', 'direction_start_color': 'dodgerblue',
'car_intermediate_color': 'dodgerblue', 'direction_intermediate_color': 'dodgerblue',
'car_goal_color': 'red', 'direction_goal_color': 'red',
'obstacle_color': 'slategray'}
ani = vis.gen_video(traj, obs_list, np.array(sgs), color_dict, system)
ani.save('car_env%d_path%d_mpc_tree.mp4' % (obs_idx, p_idx), fps=50)