-
Notifications
You must be signed in to change notification settings - Fork 2
/
sim.py
52 lines (45 loc) · 950 Bytes
/
sim.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
import iRobotCreate
import numpy as np
import time
r = iRobotCreate.iRobotCreate(1)
dist = 0.2
r.trajectory()
r.set_trail_size(100)
x = 5
y = 2
xobst = np.zeros(4)
yobst = np.zeros(4)
xobst[0] = 3
yobst[0] = 1
xobst[1] = 3
yobst[1] = 0.6
xobst[2] = 3
yobst[2] = 0.2
xobst[3] = 3
yobst[3] = 0
time = 0
d=10000
r.forward(0.1)
print d
while dist<d and time<100:
[rx,ry,rt] = r.get_pose()
xt = x-rx
yt = y-ry
d = ((xt)**2+(yt)**2)**0.5
theta = np.arctan2(yt,xt)
xt = d*np.cos(theta - rt*3.1415/180)
yt = d*np.sin(theta - rt*3.1415/180)
xto = xobst-rx
yto = yobst-ry
d = ((xto)**2+(yto)**2)**0.5
theta = np.arctan2(yto,xto)
xto = d*np.cos(theta - rt*3.1415/180)
yto = d*np.sin(theta - rt*3.1415/180)
r.goToGoal(xt,yt,[xto,yto])
r.distance_sensor()
r.angle_sensor()
d = ((rx-x)**2+(ry-y)**2)**0.5
print xt,yt,rx,ry,rt,d
time+=1
obst = [xobst,yobst]
r.sim(obst)