Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
floor_simulation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maximilian Gruber
floor_simulation
Commits
b3862497
Commit
b3862497
authored
5 years ago
by
Maximilian Gruber
Browse files
Options
Downloads
Patches
Plain Diff
Start working on simple estimation for position
parent
7feb10d8
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
base.py
+24
-1
24 additions, 1 deletion
base.py
estimate_position_offline.py
+86
-0
86 additions, 0 deletions
estimate_position_offline.py
with
110 additions
and
1 deletion
base.py
+
24
−
1
View file @
b3862497
...
...
@@ -111,7 +111,7 @@ class Simulation:
def
make_video
(
self
,
floor
,
vehicle_1
,
floor_arrays
,
wheel_positions_1
,
time_string
):
# init figure
fig
,
ax
=
plt
.
subplots
(
nrows
=
1
,
ncols
=
1
,
sharex
=
True
,
sharey
=
True
)
# draw floor
fx
,
fy
=
floor
.
get_grid
()
timestamp
,
fc
,
_
=
floor_arrays
.
popleft
()
...
...
@@ -246,6 +246,29 @@ class Floor():
sensor
=
tile
[
"
sensor
"
]
sensor
.
get_response
(
ts
,
input_value
=
sensor
.
_tmp
,
input_uncertainty
=
0.0
)
def
update_virtual
(
self
):
# reset every tile
for
it
,
tile
in
self
.
tiles
.
items
():
sensor
=
tile
[
"
sensor
"
]
sensor
.
_tmp
=
0.0
# sum the mass of all vehicles on the floor
for
vehicle
in
self
.
vehicles
:
# check in which tile a wheel is at the moment
# could be optimized by binary search tree and fixed length of sensor time-series
for
iw
,
wheel
in
enumerate
(
vehicle
.
get_wheel_positions
()):
for
it
,
tile
in
self
.
tiles
.
items
():
sensor
=
tile
[
"
sensor
"
]
if
self
.
is_inside
(
wheel
,
tile
):
sensor
.
_tmp
+=
vehicle
.
wheels_weight
[
iw
]
*
vehicle
.
mass
break
# one wheel can only be in one tile
# return array of _tmp values
C
=
np
.
zeros
(
self
.
shape
)
for
i
,
tile
in
self
.
tiles
.
items
():
C
[
tile
[
"
index
"
]]
=
tile
[
"
sensor
"
].
_tmp
return
C
def
is_inside
(
self
,
coordinates
,
tile
):
b
=
np
.
append
(
coordinates
,
1
)
c
=
tile
[
"
corners
"
]
...
...
This diff is collapsed.
Click to expand it.
estimate_position_offline.py
0 → 100644
+
86
−
0
View file @
b3862497
import
numpy
as
np
import
pandas
as
pd
import
scipy.optimize
as
opt
import
matplotlib.pyplot
as
plt
from
base
import
Vehicle
,
Floor
class
Estimation
:
def
__init__
(
self
,
filename
=
"
2020-01-03__10:06:17_output.csv
"
):
self
.
sensor_output
=
np
.
loadtxt
(
filename
,
delimiter
=
"
,
"
,
skiprows
=
1
)
# init virtual vehicle and floor
self
.
vehicle
=
Vehicle
(
init_position
=
[
0
,
0
])
self
.
floor
=
Floor
(
shape
=
(
4
,
3
),
tile_length
=
1.0
,
broadcast
=
False
,
vehicles
=
[
self
.
vehicle
])
# define fitness function
def
evaluate
(
self
,
parameters
,
sensor_output
):
self
.
vehicle
.
position
=
parameters
[
0
:
1
]
self
.
vehicle
.
rotation
=
parameters
[
2
]
self
.
vehicle
.
mass
=
parameters
[
3
]
virtual_output
=
self
.
floor
.
update_virtual
()
error
=
np
.
linalg
.
norm
(
virtual_output
-
sensor_output
)
print
(
parameters
,
error
)
return
error
# define fitness function
def
evaluate_gaussian
(
self
,
parameters
,
floor_grid
,
sensor_output
):
mean
,
std
,
weight
=
parameters
fx
,
fy
=
floor_grid
virtual_output
=
self
.
floor
.
get_grid
()
error
=
np
.
linalg
.
norm
(
virtual_output
-
sensor_output
)
print
(
parameters
,
error
)
return
error
if
__name__
==
"
__main__
"
:
est
=
Estimation
()
## # estimate position via optimization ( TURNS OUT TO BE NOT SUITABLE... )
## wanted_output = est.sensor_output[400,1:].reshape(est.floor.shape)
## # boundary settings
## lb = [0, 0, 0, 0]
## ub = [est.floor.shape[0]*est.floor.tile_length, est.floor.shape[0]*est.floor.tile_length, 2*np.pi, 2*est.vehicle.mass]
## bounds = opt.Bounds(lb, ub, keep_feasible=True)
## bounds_shgo = [(l,u) for l, u in zip(lb, ub)]
## print(bounds_shgo)
## # further optimization settings
## options = {"maxiter": 10}
## options_shgo = {"maxiter": 10, "local_iter": 5, "maxfev": 100}
## #result = opt.minimize(est.evaluate, [0,0,0,est.vehicle.mass], args=(wanted_output), method="SLSQP", bounds=bounds, options=options)
## result = opt.shgo(est.evaluate, bounds_shgo, args=(wanted_output,), options=options_shgo, n=10)
## print(result)
# estimate position via gaussian fitting
wanted_output
=
est
.
sensor_output
[
400
,
1
:].
reshape
(
est
.
floor
.
shape
)
floor_grid
=
est
.
floor
.
get_grid
()
# boundary settings
lb
=
[
0
,
0
,
0
,
0
]
ub
=
[
est
.
floor
.
shape
[
0
]
*
est
.
floor
.
tile_length
,
est
.
floor
.
shape
[
0
]
*
est
.
floor
.
tile_length
,
2
*
np
.
pi
,
2
*
est
.
vehicle
.
mass
]
bounds
=
opt
.
Bounds
(
lb
,
ub
,
keep_feasible
=
True
)
bounds_shgo
=
[(
l
,
u
)
for
l
,
u
in
zip
(
lb
,
ub
)]
print
(
bounds_shgo
)
# further optimization settings
options
=
{
"
maxiter
"
:
10
}
options_shgo
=
{
"
maxiter
"
:
10
,
"
local_iter
"
:
5
,
"
maxfev
"
:
100
}
#result = opt.minimize(est.evaluate, [0,0,0,est.vehicle.mass], args=(wanted_output), method="SLSQP", bounds=bounds, options=options)
result
=
opt
.
shgo
(
est
.
evaluate
,
bounds_shgo
,
args
=
(
wanted_output
,),
options
=
options_shgo
,
n
=
10
)
print
(
result
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment