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
cc03b6b8
Commit
cc03b6b8
authored
3 years ago
by
Zhaoliang Zheng
Browse files
Options
Downloads
Patches
Plain Diff
test new keyboard function
parent
76c9b9a0
Branches
Branches containing commit
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Control/Laptop_Code/Test_keyboard/keyboard.py
+77
-11
77 additions, 11 deletions
Code/Control/Laptop_Code/Test_keyboard/keyboard.py
with
77 additions
and
11 deletions
Code/Control/Laptop_Code/Test_keyboard/keyboard.py
+
77
−
11
View file @
cc03b6b8
import
cv2
import
pygame
kpx
,
kix
,
kdx
=
1
,
0.2
,
0.5
def
auto_control
():
print
(
"
auto_control function
"
)
def
stop_all
():
print
(
"
stop_all function
"
)
def
manual_control
():
print
(
"
manual_control function
"
)
def
manual_command
(
val1
,
val2
,
val3
,
val4
,
sign1
,
sign2
,
sign3
,
sign4
):
pwm1
=
val1
pwm2
=
val2
pwm3
=
val3
pwm4
=
val4
dir1
=
sign1
dir2
=
sign2
dir3
=
sign3
dir4
=
sign4
return
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
def
manual_control
(
Ctl_com
):
if
get_key
(
"
w
"
):
val
=
start_speed
Ctl_com
=
manual_command
(
val
,
val
,
0
,
0
,
"
+
"
,
"
+
"
,
"
+
"
,
"
+
"
)
elif
get_key
(
"
s
"
):
val
=
start_speed
Ctl_com
=
manual_command
(
val
,
val
,
0
,
0
,
"
-
"
,
"
-
"
,
"
+
"
,
"
+
"
)
if
get_key
(
"
UP
"
):
val
=
start_speed
Ctl_com
=
manual_command
(
0
,
0
,
val
,
val
,
"
+
"
,
"
+
"
,
"
+
"
,
"
+
"
)
elif
get_key
(
"
DOWN
"
):
val
=
start_speed
Ctl_com
=
manual_command
(
0
,
0
,
val
,
val
,
"
+
"
,
"
+
"
,
"
-
"
,
"
-
"
)
elif
get_key
(
"
LEFT
"
):
val
=
start_speed
Ctl_com
=
manual_command
(
0
,
0
,
val
,
val
,
"
+
"
,
"
+
"
,
"
-
"
,
"
+
"
)
elif
get_key
(
"
RIGHT
"
):
val
=
start_speed
Ctl_com
=
manual_command
(
0
,
0
,
val
,
val
,
"
+
"
,
"
+
"
,
"
+
"
,
"
-
"
)
return
Ctl_com
# print("manual_control function")
def
variables_change
():
print
(
"
variables_change function
"
)
def
dynamic_variable
(
str_name_v
):
global
kpx
,
kix
,
kdx
,
start_speed
if
str_name_v
==
"
kpx
"
:
kpx
=
input
(
"
Enter your value:
"
)
print
(
"
kpx:{}
"
.
format
(
kpx
))
elif
str_name_v
==
"
kix
"
:
kix
=
input
(
"
Enter your value:
"
)
print
(
"
kix:{}
"
.
format
(
kix
))
elif
str_name_v
==
"
kdx
"
:
kdx
=
input
(
"
Enter your value:
"
)
print
(
"
kdx:{}
"
.
format
(
kdx
))
elif
str_name_v
==
"
stsp
"
:
start_speed
=
input
(
"
Enter your value:
"
)
print
(
"
start_speed:{}
"
.
format
(
start_speed
))
def
variables_change_once
():
str_name
=
input
(
"
Enter your variable:
"
)
dynamic_variable
(
str_name
)
# print("variables_change function")
def
init
():
pygame
.
init
()
...
...
@@ -29,17 +90,16 @@ def get_key(keyname):
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__
'
:
global
start_speed
start_speed
=
70
Ctl_com
=
[
0
,
0
,
0
,
0
,
"
+
"
,
"
+
"
,
"
+
"
,
"
+
"
]
flag
=
0
print_count
=
1
init
()
...
...
@@ -68,17 +128,23 @@ if __name__ == '__main__':
elif
get_key
(
'
m
'
):
flag
=
2
while
(
flag
==
2
):
manual_control
()
Ctl_command
=
manual_control
(
Ctl_com
)
print
(
"
Ctl_com:{}
"
.
format
(
Ctl_command
))
flag
,
print_count
=
keyboard_stop
(
flag
,
print_count
)
elif
get_key
(
'
v
'
):
flag
=
3
while
(
flag
==
3
):
variables_change
()
flag
,
print_count
=
keyboard_stop
(
flag
,
print_count
)
variables_change_once
()
flag
=
0
print_count
=
1
# flag, print_count = keyboard_stop(flag,print_count)
elif
get_key
(
'
k
'
):
break
if
print_count
is
not
0
:
print
(
"
No subsystem is running
"
)
print
(
"
kpx:{}
"
.
format
(
kpx
))
print
(
"
kix:{}
"
.
format
(
kix
))
print
(
"
kdx:{}
"
.
format
(
kdx
))
print_count
=
0
\ No newline at end of file
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