add option to plot location
This commit is contained in:
parent
73b2050919
commit
5471f77e89
|
|
@ -129,20 +129,11 @@ def trilateration2d(mydict, bounds=None, verbose=False):
|
|||
tmp = loc.split(',')
|
||||
p = Point(tmp[0], tmp[1])
|
||||
points.append(p)
|
||||
circles.append(Circle(p, mydict[loc][0]))
|
||||
# print(len(points), len(circles))
|
||||
inner_points = calcInnerPoints(circles, bounds)
|
||||
if len(inner_points) is 0:
|
||||
# if empty, create multiple circles based on std
|
||||
circles = []
|
||||
for loc in mydict:
|
||||
tmp = loc.split(',')
|
||||
p = Point(tmp[0], tmp[1])
|
||||
if mydict[loc][1]:
|
||||
for r in arange(
|
||||
max(mydict[loc][0] - mydict[loc][1], 0.01),
|
||||
max(mydict[loc][0] - mydict[loc][1], 0.001),
|
||||
mydict[loc][0] + mydict[loc][1],
|
||||
10
|
||||
1
|
||||
):
|
||||
circles.append(Circle(p, r))
|
||||
else:
|
||||
|
|
@ -182,6 +173,15 @@ def deriveLocation(args, results):
|
|||
return loc
|
||||
|
||||
|
||||
def plotLocation(loc):
|
||||
handler = None
|
||||
try:
|
||||
handler = plt.scatter(loc[0], loc[1])
|
||||
plt.pause(0.01)
|
||||
except Exception:
|
||||
pass
|
||||
return handler
|
||||
|
||||
if __name__ == '__main__':
|
||||
loc = deriveLocation(
|
||||
{
|
||||
|
|
@ -202,4 +202,26 @@ if __name__ == '__main__':
|
|||
'34:f6:4b:5e:69:1e': (50, 50)
|
||||
}
|
||||
)
|
||||
print(loc)
|
||||
flagPlot = False
|
||||
try:
|
||||
import matplotlib.pyplot as plt
|
||||
flagPlot = True
|
||||
except Exception:
|
||||
pass
|
||||
if flagPlot:
|
||||
fig = plt.figure()
|
||||
plt.ion()
|
||||
plt.xlim([-100, 300])
|
||||
plt.ylim([-10, 500])
|
||||
while 1:
|
||||
try:
|
||||
handler = plotLocation(loc)
|
||||
if handler is None:
|
||||
plt.close(fig)
|
||||
break
|
||||
handler.remove()
|
||||
except KeyboardInterrupt:
|
||||
plt.close(fig)
|
||||
break
|
||||
except Exception:
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -197,6 +197,18 @@ def wrapper(args):
|
|||
}
|
||||
}
|
||||
counter = 1
|
||||
if args['plot']:
|
||||
try:
|
||||
import matplotlib.pyplot as plt
|
||||
from libLocalization import plotLocation
|
||||
args['plot'] = False
|
||||
handler = None
|
||||
fig = plt.figure()
|
||||
plt.ion()
|
||||
plt.xlim([-100, 500])
|
||||
plt.ylim([-10, 500])
|
||||
except Exception:
|
||||
print('Cannot plot because lacking matplotlib!')
|
||||
with Measurement(
|
||||
args['interface'],
|
||||
ofp=args['filepath'], cali=args['cali']
|
||||
|
|
@ -221,6 +233,18 @@ def wrapper(args):
|
|||
'* Derived location: ({0:.3f}, {1:.3f})'
|
||||
.format(loc[0], loc[1])
|
||||
)
|
||||
if args['plot']:
|
||||
try:
|
||||
if handler is not None:
|
||||
handler.remove()
|
||||
handler = plotLocation(loc)
|
||||
if handler is None:
|
||||
plt.close(fig)
|
||||
except KeyboardInterrupt:
|
||||
plt.close(fig)
|
||||
break
|
||||
except Exception:
|
||||
raise
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
except Exception as e:
|
||||
|
|
@ -279,10 +303,13 @@ def main():
|
|||
'--locs',
|
||||
default=False,
|
||||
action="store_true",
|
||||
help=(
|
||||
"if set, derive location" +
|
||||
"and store it to file"
|
||||
help="if set, derive location and store it to file"
|
||||
)
|
||||
p.add_argument(
|
||||
'--plot',
|
||||
default=False,
|
||||
action="store_true",
|
||||
help="if set, will plot the derived location in realtime"
|
||||
)
|
||||
try:
|
||||
args = vars(p.parse_args())
|
||||
|
|
|
|||
Loading…
Reference in New Issue