Skip to content

Commit 66212d1

Browse files
Add files via upload
1 parent d52f2ee commit 66212d1

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

scripts/rtime_gmapping_node.py

+35-18
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
from utils import *
1717

1818
P_prior = 0.5 # Prior occupancy probability
19-
P_occ = 0.9 # Probability that cell is occupied with total confidence
19+
P_occ = 0.9 # Probability that cell is occupied with total confidence
2020
P_free = 0.3 # Probability that cell is free with total confidence
2121

22-
RESOLUTION = 0.025 # Grid resolution in [m]
22+
RESOLUTION = 0.03 # Grid resolution in [m]
2323

24-
MAP_NAME = 'stage_4' # map name without extension
24+
MAP_NAME = 'world' # map name without extension
2525

2626
if __name__ == '__main__':
2727

@@ -49,9 +49,14 @@
4949

5050
# Create grid map
5151
gridMap = GridMap(X_lim = map_x_lim,
52-
Y_lim = map_y_lim,
53-
resolution = RESOLUTION,
54-
p = P_prior)
52+
Y_lim = map_y_lim,
53+
resolution = RESOLUTION,
54+
p = P_prior)
55+
56+
# Init time
57+
t_start = perf_counter()
58+
sim_time = 0
59+
step = 0
5560

5661
# Main loop
5762
while not rospy.is_shutdown():
@@ -109,50 +114,62 @@
109114
set_pixel_color(bgr_image, x, y, 'GREEN')
110115

111116
resized_image = cv2.resize(src = bgr_image,
112-
dsize = (500, 500),
113-
interpolation = cv2.INTER_AREA)
117+
dsize = (500, 500),
118+
interpolation = cv2.INTER_AREA)
114119

115120
rotated_image = cv2.rotate(src = resized_image,
116-
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE)
121+
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE)
117122

118123
cv2.imshow("Grid map", rotated_image)
119124
cv2.waitKey(1)
120125

126+
# Calculate step time in [s]
127+
t_step = perf_counter()
128+
step_time = t_step - t_start
129+
sim_time += step_time
130+
t_start = t_step
131+
step += 1
132+
133+
print('Step %d ==> %d [ms]' % (step, step_time * 1000))
134+
121135
rate.sleep()
122136

123137
except rospy.ROSInterruptException:
124138

125139
print('\r\nSIMULATION TERMINATED!')
140+
print('\nSimulation time: %.2f [s]' % sim_time)
141+
print('Average step time: %d [ms]' % (sim_time * 1000 / step))
142+
print('Frames per second: %.1f' % (step / sim_time))
126143

127144
# Saving Grid Map
128145
resized_image = cv2.resize(src = gridMap.to_BGR_image(),
129-
dsize = (500, 500),
130-
interpolation = cv2.INTER_AREA)
146+
dsize = (500, 500),
147+
interpolation = cv2.INTER_AREA)
131148

132149
rotated_image = cv2.rotate(src = resized_image,
133-
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE)
150+
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE)
134151

135152
flag_1 = cv2.imwrite(img = rotated_image * 255.0,
136-
filename = MAPS_PATH + '/' + MAP_NAME + '_GRID_MAP.png')
153+
filename = MAPS_PATH + '/' + MAP_NAME + '_grid_map_TEST.png')
137154

138155
# Calculating Maximum likelihood estimate of the map
139156
gridMap.calc_MLE()
140157

141158
# Saving MLE of the Grid Map
142159
resized_image_MLE = cv2.resize(src = gridMap.to_BGR_image(),
143-
dsize = (500, 500),
144-
interpolation = cv2.INTER_AREA)
160+
dsize = (500, 500),
161+
interpolation = cv2.INTER_AREA)
145162

146163
rotated_image_MLE = cv2.rotate(src = resized_image_MLE,
147-
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE)
164+
rotateCode = cv2.ROTATE_90_COUNTERCLOCKWISE)
148165

149166
flag_2 = cv2.imwrite(img = rotated_image_MLE * 255.0,
150-
filename = MAPS_PATH + '/' + MAP_NAME + '_GRID_MAP_MLE.png')
167+
filename = MAPS_PATH + '/' + MAP_NAME + '_grid_map_TEST_mle.png')
151168

152169
if flag_1 and flag_2:
153170
print('\nGrid map successfully saved!\n')
154171

155172
if cv2.waitKey(0) == 27:
156173
cv2.destroyAllWindows()
157174

158-
pass
175+
pass

0 commit comments

Comments
 (0)