Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
November 2021 Blimp Competition
Manage
Activity
Members
Labels
Plan
Issues
2
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Shahrul Kamil bin Hassan
November 2021 Blimp Competition
Commits
cb384acd
Commit
cb384acd
authored
3 years ago
by
Zhaoliang Zheng
Browse files
Options
Downloads
Patches
Plain Diff
fixed the key input bug
parent
b72f8495
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Control/Laptop_Code/Test_keyboard/keyboard.py
+45
-9
45 additions, 9 deletions
Code/Control/Laptop_Code/Test_keyboard/keyboard.py
with
45 additions
and
9 deletions
Code/Control/Laptop_Code/Test_keyboard/keyboard.py
+
45
−
9
View file @
cb384acd
...
@@ -13,35 +13,71 @@ def manual_control():
...
@@ -13,35 +13,71 @@ def manual_control():
def
variables_change
():
def
variables_change
():
print
(
"
variables_change function
"
)
print
(
"
variables_change function
"
)
def
init
():
pygame
.
init
()
win
=
pygame
.
display
.
set_mode
((
400
,
400
))
def
keyboard_stop
(
flag_s
,
print_count_s
):
if
get_key
(
'
q
'
):
flag_s
=
0
print_count_s
=
1
return
flag_s
,
print_count_s
def
get_key
(
keyname
):
ans
=
False
for
eve
in
pygame
.
event
.
get
():
pass
keyInput
=
pygame
.
key
.
get_pressed
()
myKey
=
getattr
(
pygame
,
'
K_{}
'
.
format
(
keyname
))
# K_{LEFT}
if
keyInput
[
myKey
]:
ans
=
True
pygame
.
display
.
update
()
return
ans
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
flag
=
0
flag
=
0
print_count
=
1
print_count
=
1
init
()
while
True
:
while
True
:
key
=
cv2
.
waitKey
(
5
)
if
key
==
ord
(
'
a
'
):
if
get_key
(
'
a
'
):
flag
=
1
flag
=
1
while
(
flag
==
1
):
while
(
flag
==
1
):
auto_control
()
auto_control
()
flag
,
print_count
=
keyboard_stop
()
elif
key
==
ord
(
'
s
'
):
cap
=
cv2
.
VideoCapture
(
0
)
ret
,
frame
=
cap
.
read
()
if
not
ret
:
continue
cv2
.
imshow
(
"
image
"
,
frame
)
flag
,
print_count
=
keyboard_stop
(
flag
,
print_count
)
if
flag
==
0
:
cap
.
release
()
cv2
.
destroyAllWindows
()
elif
get_key
(
'
s
'
):
stop_all
()
stop_all
()
print
(
"
stop all motors
"
)
print
(
"
stop all motors
"
)
elif
key
==
ord
(
'
c
'
):
elif
get_key
(
'
m
'
):
flag
=
2
flag
=
2
while
(
flag
==
2
):
while
(
flag
==
2
):
manual_control
()
manual_control
()
flag
,
print_count
=
keyboard_stop
()
flag
,
print_count
=
keyboard_stop
(
flag
,
print_count
)
elif
key
==
ord
(
'
v
'
):
elif
get_key
(
'
v
'
):
flag
=
3
flag
=
3
while
(
flag
==
3
):
while
(
flag
==
3
):
variables_change
()
variables_change
()
flag
,
print_count
=
keyboard_stop
()
flag
,
print_count
=
keyboard_stop
(
flag
,
print_count
)
elif
get_key
(
'
k
'
):
break
if
print_count
is
not
0
:
if
print_count
is
not
0
:
print
(
"
No subsystem is running
"
)
print
(
"
No subsystem is running
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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