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
08e9e131
Commit
08e9e131
authored
5 years ago
by
Maximilian Gruber
Browse files
Options
Downloads
Patches
Plain Diff
Added translation and rotation to animation
parent
c17a6ff6
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
+34
-75
34 additions, 75 deletions
base.py
main.py
+2
-3
2 additions, 3 deletions
main.py
with
36 additions
and
78 deletions
base.py
+
34
−
75
View file @
08e9e131
...
@@ -82,116 +82,75 @@ class VehicleInteractor:
...
@@ -82,116 +82,75 @@ class VehicleInteractor:
self
.
vehicle
=
vehicle
self
.
vehicle
=
vehicle
self
.
pc
=
pc
self
.
pc
=
pc
self
.
shape_
press_active
=
False
self
.
press_active
=
False
self
.
arrow_press
_active
=
False
self
.
ctrl_key
_active
=
False
def
get_shape
_and_arrow
(
self
):
def
get_shape
(
self
):
# represent vehicle by a rectangle from wheel positions
# represent vehicle by a rectangle from wheel positions
shape
=
mpl
.
patches
.
Polygon
(
self
.
vehicle
.
get_wheel_positions
(),
fill
=
False
)
shape
=
mpl
.
patches
.
Polygon
(
self
.
vehicle
.
get_wheel_positions
(),
fill
=
False
)
# arrow direction
return
shape
xy
=
self
.
vehicle
.
position
dxy
=
np
.
array
([
np
.
cos
(
self
.
vehicle
.
rotation
-
np
.
pi
/
2
),
np
.
sin
(
self
.
vehicle
.
rotation
-
np
.
pi
/
2
)])
arrow
=
mpl
.
patches
.
Arrow
(
xy
[
0
],
xy
[
1
],
dxy
[
0
],
dxy
[
1
],
linewidth
=
0.5
,
fill
=
False
)
def
connect
(
self
,
shape
):
return
shape
,
arrow
def
update_representation
(
self
,
shape
,
arrow
):
pass
def
connect
(
self
,
shape
,
arrow
):
self
.
shape
=
shape
self
.
shape
=
shape
self
.
arrow
=
arrow
# translation
# translation
and rotation
self
.
shape_press
=
self
.
shape
.
figure
.
canvas
.
mpl_connect
(
'
button_press_event
'
,
self
.
on_shape_press
)
self
.
shape_press
=
self
.
shape
.
figure
.
canvas
.
mpl_connect
(
'
button_press_event
'
,
self
.
on_shape_press
)
self
.
shape_release
=
self
.
shape
.
figure
.
canvas
.
mpl_connect
(
'
button_release_event
'
,
self
.
on_shape_release
)
self
.
shape_release
=
self
.
shape
.
figure
.
canvas
.
mpl_connect
(
'
button_release_event
'
,
self
.
on_shape_release
)
self
.
shape_motion
=
self
.
shape
.
figure
.
canvas
.
mpl_connect
(
'
motion_notify_event
'
,
self
.
on_shape_motion
)
self
.
shape_motion
=
self
.
shape
.
figure
.
canvas
.
mpl_connect
(
'
motion_notify_event
'
,
self
.
on_shape_motion
)
# rotation
# keypress
self
.
arrow_press
=
self
.
arrow
.
figure
.
canvas
.
mpl_connect
(
'
button_press_event
'
,
self
.
on_arrow_press
)
self
.
key_press
=
self
.
shape
.
figure
.
canvas
.
mpl_connect
(
'
key_press_event
'
,
self
.
on_key_press
)
self
.
arrow_release
=
self
.
arrow
.
figure
.
canvas
.
mpl_connect
(
'
button_release_event
'
,
self
.
on_arrow_release
)
self
.
key_release
=
self
.
shape
.
figure
.
canvas
.
mpl_connect
(
'
key_release_event
'
,
self
.
on_key_release
)
self
.
arrow_motion
=
self
.
arrow
.
figure
.
canvas
.
mpl_connect
(
'
motion_notify_event
'
,
self
.
on_arrow_motion
)
def
on_shape_press
(
self
,
event
):
def
on_shape_press
(
self
,
event
):
if
event
.
inaxes
!=
self
.
shape
.
axes
:
return
if
event
.
inaxes
!=
self
.
shape
.
axes
:
return
contains
,
attrd
=
self
.
shape
.
contains
(
event
)
contains
,
attrd
=
self
.
shape
.
contains
(
event
)
if
not
contains
:
return
if
not
contains
:
return
self
.
shape_
press_active
=
True
self
.
press_active
=
True
def
on_shape_motion
(
self
,
event
):
def
on_shape_motion
(
self
,
event
):
if
event
.
inaxes
!=
self
.
shape
.
axes
:
return
if
event
.
inaxes
!=
self
.
shape
.
axes
:
return
if
not
self
.
shape_press_active
:
return
if
not
self
.
press_active
:
return
# set vehicle
if
self
.
ctrl_key_active
:
self
.
vehicle
.
position
=
np
.
array
([
event
.
xdata
,
event
.
ydata
])
# rotation
xy
=
self
.
vehicle
.
position
# calculate new arrow position
dx
=
event
.
xdata
-
xy
[
0
]
xy
=
self
.
vehicle
.
position
dy
=
event
.
ydata
-
xy
[
1
]
dxy
=
np
.
array
([
np
.
cos
(
self
.
vehicle
.
rotation
-
np
.
pi
/
2
),
np
.
sin
(
self
.
vehicle
.
rotation
-
np
.
pi
/
2
)])
self
.
vehicle
.
rotation
=
np
.
array
(
np
.
arctan2
(
dy
,
dx
))
-
np
.
pi
/
2
arrow_new
=
mpl
.
patches
.
Arrow
(
xy
[
0
],
xy
[
1
],
dxy
[
0
],
dxy
[
1
],
linewidth
=
0.5
,
fill
=
False
)
else
:
# translation
# HERE IS SOME ERROR!
self
.
vehicle
.
position
=
np
.
array
([
event
.
xdata
,
event
.
ydata
])
print
(
arrow_new
.
_path
.
vertices
)
print
(
self
.
arrow
.
_path
.
vertices
)
# set representation of vehicle
# set representation of vehicle
self
.
shape
.
set_xy
(
self
.
vehicle
.
get_wheel_positions
(
cyclic
=
True
))
self
.
shape
.
set_xy
(
self
.
vehicle
.
get_wheel_positions
(
cyclic
=
True
))
self
.
arrow
.
_path
.
vertices
=
arrow_new
.
_path
.
vertices
self
.
shape
.
figure
.
canvas
.
draw
()
def
on_shape_release
(
self
,
event
):
# update canvas
self
.
shape_press_active
=
False
self
.
vehicle
.
update_floor
()
self
.
pc
.
set_array
(
self
.
vehicle
.
floor
.
get_tile_values
().
ravel
())
self
.
shape
.
figure
.
canvas
.
draw
()
self
.
shape
.
figure
.
canvas
.
draw
()
def
on_arrow_press
(
self
,
event
):
def
on_key_press
(
self
,
event
):
if
event
.
inaxes
!=
self
.
arrow
.
axes
:
return
if
event
.
key
==
"
control
"
:
contains
,
attrd
=
self
.
arrow
.
contains
(
event
)
self
.
ctrl_key_active
=
True
if
not
contains
:
return
print
(
"
Arrow pressed
"
)
self
.
arrow_press_active
=
True
def
on_key_release
(
self
,
event
):
if
event
.
key
==
"
control
"
:
def
on_arrow_motion
(
self
,
event
):
self
.
ctrl_key_active
=
False
if
event
.
inaxes
!=
self
.
arrow
.
axes
:
return
if
not
self
.
arrow_press_active
:
return
def
on_shape_release
(
self
,
event
):
self
.
press_active
=
False
# set vehicle
xy
=
self
.
vehicle
.
position
dx
=
event
.
xdata
-
xy
[
0
]
dy
=
event
.
ydata
-
xy
[
1
]
self
.
vehicle
.
rotation
=
np
.
array
(
np
.
arctan2
(
dy
,
dx
))
-
np
.
pi
/
2
# new dummy arrow
dxy
=
np
.
array
([
dx
,
dy
])
dxy
=
dxy
/
np
.
linalg
.
norm
(
dxy
)
arrow_new
=
mpl
.
patches
.
Arrow
(
xy
[
0
],
xy
[
1
],
dxy
[
0
],
dxy
[
1
],
linewidth
=
0.5
,
fill
=
False
)
# set representation of vehicle
self
.
shape
.
set_xy
(
self
.
vehicle
.
get_wheel_positions
(
cyclic
=
True
))
self
.
arrow
.
_path
.
vertices
=
arrow_new
.
_path
.
vertices
self
.
shape
.
figure
.
canvas
.
draw
()
def
on_arrow_release
(
self
,
event
):
self
.
arrow_press_active
=
False
self
.
vehicle
.
update_floor
()
self
.
vehicle
.
update_floor
()
self
.
pc
.
set_array
(
self
.
vehicle
.
floor
.
get_tile_values
().
ravel
())
self
.
pc
.
set_array
(
self
.
vehicle
.
floor
.
get_tile_values
().
ravel
())
self
.
arrow
.
figure
.
canvas
.
draw
()
self
.
shape
.
figure
.
canvas
.
draw
()
def
disconnect
(
self
):
def
disconnect
(
self
):
self
.
shape
.
figure
.
canvas
.
mpl_disconnect
(
self
.
shape_press
)
self
.
shape
.
figure
.
canvas
.
mpl_disconnect
(
self
.
shape_press
)
self
.
shape
.
figure
.
canvas
.
mpl_disconnect
(
self
.
shape_motion
)
self
.
shape
.
figure
.
canvas
.
mpl_disconnect
(
self
.
shape_motion
)
self
.
shape
.
figure
.
canvas
.
mpl_disconnect
(
self
.
shape_release
)
self
.
shape
.
figure
.
canvas
.
mpl_disconnect
(
self
.
shape_release
)
self
.
shape
.
figure
.
canvas
.
mpl_disconnect
(
self
.
key_press
)
self
.
arrow
.
figure
.
canvas
.
mpl_disconnect
(
self
.
arrow_press
)
self
.
shape
.
figure
.
canvas
.
mpl_disconnect
(
self
.
key_release
)
self
.
arrow
.
figure
.
canvas
.
mpl_disconnect
(
self
.
arrow_motion
)
self
.
arrow
.
figure
.
canvas
.
mpl_disconnect
(
self
.
arrow_release
)
class
Floor
():
class
Floor
():
...
...
This diff is collapsed.
Click to expand it.
main.py
+
2
−
3
View file @
08e9e131
...
@@ -21,12 +21,11 @@ pc = ax.pcolormesh(fx, fy, fc, cmap="Greens")
...
@@ -21,12 +21,11 @@ pc = ax.pcolormesh(fx, fy, fc, cmap="Greens")
# vehicle representation
# vehicle representation
vi
=
VehicleInteractor
(
v
,
pc
)
vi
=
VehicleInteractor
(
v
,
pc
)
shape
,
arrow
=
vi
.
get_shape
_and_arrow
()
shape
=
vi
.
get_shape
()
shape_patch
=
ax
.
add_patch
(
shape
)
shape_patch
=
ax
.
add_patch
(
shape
)
arrow_patch
=
ax
.
add_patch
(
arrow
)
vi
.
connect
(
shape_patch
,
arrow_patch
)
vi
.
connect
(
shape_patch
)
# plot the scene
# plot the scene
ax
.
set_xlim
(
*
f
.
draw_limits
[
0
])
ax
.
set_xlim
(
*
f
.
draw_limits
[
0
])
...
...
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