Skip to content

Commit da306a9

Browse files
committed
keep coding
1 parent 7fbfe5b commit da306a9

1 file changed

Lines changed: 32 additions & 6 deletions

File tree

‎Localization/histogram_filter/histogram_filter.py‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import math
1010
import numpy as np
1111
import matplotlib.pyplot as plt
12+
import copy
1213
from scipy.stats import norm
1314

1415
EXTEND_AREA = 10.0 # [m] grid map extention length
@@ -95,7 +96,6 @@ def observation(xTrue, u, RFID):
9596
def normalize_probability(gmap):
9697

9798
sump = sum([sum(igmap) for igmap in gmap])
98-
print(sump)
9999

100100
for i in range(len(gmap)):
101101
for ii in range(len(gmap[i])):
@@ -119,15 +119,40 @@ def init_gmap(xyreso):
119119
return gmap, minx, maxx, miny, maxy,
120120

121121

122-
def motion_update(gmap, u, yaw, xyreso, minx, miny):
122+
def map_shift(gmap, xshift, yshift):
123123

124-
dx = DT * math.cos(yaw)
125-
dy = DT * math.sin(yaw)
126-
print(dx, dy)
124+
tgmap = copy.deepcopy(gmap)
125+
126+
lenx = len(gmap)
127+
leny = len(gmap[0])
128+
129+
for ix in range(lenx):
130+
for iy in range(leny):
131+
nix = ix + xshift
132+
niy = iy + yshift
133+
134+
if nix >= 0 and nix < lenx and niy >= 0 and niy < leny:
135+
gmap[ix + xshift][iy + yshift] = tgmap[ix][iy]
127136

128137
return gmap
129138

130139

140+
def motion_update(gmap, u, yaw, dx, dy, xyreso, minx, miny):
141+
142+
dx += DT * math.cos(yaw) * u[0]
143+
dy += DT * math.sin(yaw) * u[0]
144+
145+
xshift = dx // xyreso
146+
yshift = dy // xyreso
147+
148+
if abs(xshift) >= 1.0 or abs(yshift) >= 1.0:
149+
gmap = map_shift(gmap, int(xshift), int(yshift))
150+
dx -= xshift * xyreso
151+
dy -= yshift * xyreso
152+
153+
return gmap, dx, dy
154+
155+
131156
def main():
132157
print(__file__ + " start!!")
133158

@@ -154,7 +179,8 @@ def main():
154179
u = calc_input()
155180
xTrue, z = observation(xTrue, u, RFID)
156181

157-
gmap = motion_update(gmap, u, xTrue[2, 0], xyreso, minx, miny)
182+
gmap, dx, dy = motion_update(
183+
gmap, u, xTrue[2, 0], dx, dy, xyreso, minx, miny)
158184

159185
gmap = observation_update(gmap, z, STD, xyreso, minx, miny)
160186

0 commit comments

Comments
 (0)