6
6
7
7
"""
8
8
9
-
10
9
import matplotlib .pyplot as plt
11
10
import math
12
11
import random
@@ -53,12 +52,12 @@ def circle_fitting(x, y):
53
52
def get_sample_points (cx , cy , cr , angle_reso ):
54
53
x , y , angle , r = [], [], [], []
55
54
55
+ # points sampling
56
56
for theta in np .arange (0.0 , 2.0 * math .pi , angle_reso ):
57
- rn = cr * random .uniform (0.9 , 1.1 ) # add noize
58
- nx = cx + rn * math .cos (theta )
59
- ny = cy + rn * math .sin (theta )
57
+ nx = cx + cr * math .cos (theta )
58
+ ny = cy + cr * math .sin (theta )
60
59
nangle = math .atan2 (ny , nx )
61
- nr = math .hypot (nx , ny )
60
+ nr = math .hypot (nx , ny ) * random . uniform ( 0.95 , 1.05 )
62
61
63
62
x .append (nx )
64
63
y .append (ny )
@@ -84,7 +83,7 @@ def ray_casting_filter(xl, yl, thetal, rangel, angle_reso):
84
83
85
84
for i in range (len (rangedb )):
86
85
t = i * angle_reso
87
- if rangedb [i ] <= 1000.0 :
86
+ if rangedb [i ] != float ( "inf" ) :
88
87
rx .append (rangedb [i ] * math .cos (t ))
89
88
ry .append (rangedb [i ] * math .sin (t ))
90
89
@@ -101,14 +100,15 @@ def plot_circle(x, y, size, color="-b"):
101
100
102
101
def main ():
103
102
104
- simtime = 10.0
105
- dt = 1.0
103
+ # simulation parameters
104
+ simtime = 15.0 # simulation time
105
+ dt = 1.0 # time tick
106
106
107
- cx = - 2.0
108
- cy = - 8.0
109
- cr = 1.0
110
- theta = math .radians (30.0 )
111
- angle_reso = math .radians (3.0 )
107
+ cx = - 2.0 # initial x position of obstacle
108
+ cy = - 8.0 # initial y position of obstacle
109
+ cr = 1.0 # obstacle radious
110
+ theta = math .radians (30.0 ) # obstacle moving direction
111
+ angle_reso = math .radians (3.0 ) # sensor angle resolution
112
112
113
113
time = 0.0
114
114
while time <= simtime :
0 commit comments