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
4b4f1b4d
Commit
4b4f1b4d
authored
1 year ago
by
Annika Österdiekhoff
Browse files
Options
Downloads
Patches
Plain Diff
fix joystick movement
parent
0f60e951
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!45
Resolve "Controller Support"
Pipeline
#45988
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
+19
-17
19 additions, 17 deletions
overcooked_simulator/gui_2d_vis/overcooked_gui.py
with
19 additions
and
17 deletions
overcooked_simulator/gui_2d_vis/overcooked_gui.py
+
19
−
17
View file @
4b4f1b4d
...
@@ -182,36 +182,38 @@ class PyGameGUI:
...
@@ -182,36 +182,38 @@ class PyGameGUI:
if
np
.
linalg
.
norm
(
move_vec
)
!=
0
:
if
np
.
linalg
.
norm
(
move_vec
)
!=
0
:
move_vec
=
move_vec
/
np
.
linalg
.
norm
(
move_vec
)
move_vec
=
move_vec
/
np
.
linalg
.
norm
(
move_vec
)
print
(
"
move_vec keys
"
,
move_vec
)
action
=
Action
(
action
=
Action
(
key_set
.
name
,
ActionType
.
MOVEMENT
,
move_vec
,
duration
=
1
/
self
.
FPS
key_set
.
name
,
ActionType
.
MOVEMENT
,
move_vec
,
duration
=
1
/
self
.
FPS
)
)
self
.
send_action
(
action
)
self
.
send_action
(
action
)
def
handle_joy_stick_input
(
self
,
joysticks
):
def
handle_joy_stick_input
(
self
,
joysticks
):
"""
MISSING
"""
Handles joystick inputs for movement every frame
Args:
joysticks: list of joysticks
"""
"""
# Axis 0: joy stick left: -1 = left, ~0 = center, 1 = right
# Axis 1: joy stick left: -1 = up, ~0 = center, 1 = down
# see control stuff here (at the end of the page): https://www.pygame.org/docs/ref/joystick.html
# see control stuff here (at the end of the page): https://www.pygame.org/docs/ref/joystick.html
for
joystick
in
joysticks
.
values
():
for
joystick
in
joysticks
.
values
():
# Usually axis run in pairs, up/down for one, and left/right for
# Usually axis run in pairs, up/down for one, and left/right for the other. Triggers count as axes.
# the other. Triggers count as axes.
axes
=
joystick
.
get_numaxes
()
move_vec
=
np
.
zeros
(
2
)
move_vec
=
np
.
zeros
(
2
)
for
i
in
range
(
axes
):
# You may want to take into account some tolerance to handle jitter,
axis
=
joystick
.
get_axis
(
i
)
# and joystick drift may keep the joystick from centering at 0 or using the full range of position values.
print
(
"
axis key
"
,
axis
)
# FIXME: hardcoded threshold for tolerance
# joy stick left --> left & right
tolerance_threshold
=
0.2
if
axes
==
0
:
# axis 0 = joy stick left --> left & right
move_vec
[
0
]
+=
axis
axis_left_right
=
joystick
.
get_axis
(
0
)
# joy stick right --> up & down
if
abs
(
axis_left_right
)
>
tolerance_threshold
:
elif
axes
==
1
:
move_vec
[
0
]
+=
axis_left_right
move_vec
[
1
]
+=
axis
# axis 1 = joy stick right --> up & down
axis_up_down
=
joystick
.
get_axis
(
1
)
print
(
"
move_vec joystick before
"
,
move_vec
)
if
abs
(
axis_up_down
)
>
tolerance_threshold
:
move_vec
[
1
]
+=
axis_up_down
if
np
.
linalg
.
norm
(
move_vec
)
!=
0
:
if
np
.
linalg
.
norm
(
move_vec
)
!=
0
:
move_vec
=
move_vec
/
np
.
linalg
.
norm
(
move_vec
)
move_vec
=
move_vec
/
np
.
linalg
.
norm
(
move_vec
)
print
(
"
move_vec joystick
"
,
move_vec
)
action
=
Action
(
action
=
Action
(
"
0
"
,
ActionType
.
MOVEMENT
,
move_vec
,
duration
=
1
/
self
.
FPS
"
0
"
,
ActionType
.
MOVEMENT
,
move_vec
,
duration
=
1
/
self
.
FPS
)
)
...
...
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