-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_rvo.py
57 lines (50 loc) · 1.67 KB
/
run_rvo.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
import sys
from RVO import RVO_update_rvo, reach, compute_V_des_rvo, reach
from vis import visualize_traj_dynamic
#------------------------------
#define workspace model
ws_model = dict()
#robot radius
ws_model['robot_radius'] = 0.2
#circular obstacles, format [x,y,rad]
# no obstacles
ws_model['circular_obstacles'] = []
# with obstacles
# ws_model['circular_obstacles'] = [[-0.3, 2.5, 0.3], [1.5, 2.5, 0.3], [3.3, 2.5, 0.3], [5.1, 2.5, 0.3]]
#rectangular boundary, format [x,y,width/2,heigth/2]
ws_model['boundary'] = []
#------------------------------
#initialization for robot
# position of [x,y]
X = [[-0.5+1.0*i, 0.0] for i in range(7)] + [[-0.5+1.0*i, 5.0] for i in range(7)]
# velocity of [vx,vy]
V = [[0,0] for i in range(len(X))]
# maximal velocity norm
V_max = [1.0 for i in range(len(X))]
# goal of [x,y]
goal = [[5.5-1.0*i, 5.0] for i in range(7)] + [[5.5-1.0*i, 0.0] for i in range(7)]
#------------------------------
#simulation setup
# total simulation time (s)
total_time = 15
# simulation step
step = 0.01
#------------------------------
#simulation starts
t = 0
while t*step < total_time:
# compute desired vel to goal
V_des = compute_V_des_rvo(X, goal, V_max)
# compute the optimal vel to avoid collision
V = RVO_update_rvo(X, V_des, V, ws_model)
print(V)
# update position
for i in range(len(X)):
X[i][0] += V[i][0]*step
X[i][1] += V[i][1]*step
#----------------------------------------
# visualization
if t%10 == 0:
visualize_traj_dynamic(ws_model, X, V, goal, time=t*step, name='data/snap%s.png'%str(t/10))
#visualize_traj_dynamic(ws_model, X, V, goal, time=t*step, name='data/snap%s.png'%str(t/10))
t += 1