Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Cooperative Cuisine Environment
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Social Cognitive Systems
CoCoSy
Cooperative Cuisine Environment
Commits
380c84cc
Commit
380c84cc
authored
1 year ago
by
Annika Österdiekhoff
Browse files
Options
Downloads
Patches
Plain Diff
fix slow down of keyboard movements when joy sticks are connected
parent
61b0e8a0
No related branches found
No related tags found
1 merge request
!45
Resolve "Controller Support"
Pipeline
#46200
passed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
overcooked_simulator/gui_2d_vis/overcooked_gui.py
+17
-14
17 additions, 14 deletions
overcooked_simulator/gui_2d_vis/overcooked_gui.py
with
17 additions
and
14 deletions
overcooked_simulator/gui_2d_vis/overcooked_gui.py
+
17
−
14
View file @
380c84cc
...
...
@@ -185,6 +185,7 @@ class PyGameGUI:
if
np
.
linalg
.
norm
(
move_vec
)
!=
0
:
move_vec
=
move_vec
/
np
.
linalg
.
norm
(
move_vec
)
print
(
"
move vector keys
"
,
move_vec
)
action
=
Action
(
key_set
.
name
,
ActionType
.
MOVEMENT
,
move_vec
,
duration
=
1
/
self
.
FPS
)
...
...
@@ -202,27 +203,29 @@ class PyGameGUI:
# if a joystick is connected for current player
if
joysticks
[
key_set
.
joystick
]:
# Usually axis run in pairs, up/down for one, and left/right for the other. Triggers count as axes.
move_vec
=
np
.
zeros
(
2
)
# You may want to take into account some tolerance to handle jitter, and
# joystick drift may keep the joystick from centering at 0 or using the full range of position values.
# FIXME: hardcoded threshold for tolerance
tolerance_threshold
=
0.2
# axis 0 = joy stick left --> left & right
axis_left_right
=
joysticks
[
key_set
.
joystick
].
get_axis
(
0
)
if
abs
(
axis_left_right
)
>
tolerance_threshold
:
move_vec
[
0
]
+=
axis_left_right
# axis 1 = joy stick right --> up & down
axis_up_down
=
joysticks
[
key_set
.
joystick
].
get_axis
(
1
)
if
abs
(
axis_up_down
)
>
tolerance_threshold
:
move_vec
[
1
]
+=
axis_up_down
if
np
.
linalg
.
norm
(
move_vec
)
!=
0
:
move_vec
=
move_vec
/
np
.
linalg
.
norm
(
move_vec
)
action
=
Action
(
str
(
key_set
.
joystick
),
ActionType
.
MOVEMENT
,
move_vec
,
duration
=
1
/
self
.
FPS
)
self
.
send_action
(
action
)
if
abs
(
axis_left_right
)
>
tolerance_threshold
or
abs
(
axis_up_down
)
>
tolerance_threshold
:
move_vec
=
np
.
zeros
(
2
)
if
abs
(
axis_left_right
)
>
tolerance_threshold
:
move_vec
[
0
]
+=
axis_left_right
# axis 1 = joy stick right --> up & down
if
abs
(
axis_up_down
)
>
tolerance_threshold
:
move_vec
[
1
]
+=
axis_up_down
if
np
.
linalg
.
norm
(
move_vec
)
!=
0
:
move_vec
=
move_vec
/
np
.
linalg
.
norm
(
move_vec
)
print
(
"
move_vec
"
,
move_vec
)
action
=
Action
(
str
(
key_set
.
joystick
),
ActionType
.
MOVEMENT
,
move_vec
,
duration
=
1
/
self
.
FPS
)
self
.
send_action
(
action
)
def
handle_key_event
(
self
,
event
):
"""
Handles key events for the pickup and interaction keys. Pickup is a single action,
...
...
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