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
c26c2507
Commit
c26c2507
authored
3 years ago
by
Zhaoliang Zheng
Browse files
Options
Downloads
Patches
Plain Diff
add keyboard manually determine green ball capture state function
parent
2daf0eb4
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Control/Laptop_Code/main_keyboard.py
+27
-10
27 additions, 10 deletions
Code/Control/Laptop_Code/main_keyboard.py
with
27 additions
and
10 deletions
Code/Control/Laptop_Code/main_keyboard.py
+
27
−
10
View file @
c26c2507
...
...
@@ -408,7 +408,7 @@ def move2ball(gbx, gby, gb_dist):
# =========== Main Control ===========
def
main_control
(
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
):
def
main_control
(
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
,
bcap_man
):
'''
Description:
Given green ball information and AT information, the main control logic
...
...
@@ -429,14 +429,20 @@ def main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist1, LIDAR_d
dir1
,
dir2
,
dir3
,
dir4
=
'
+
'
,
'
-
'
,
'
+
'
,
'
-
'
ballDetect
=
ball_detect
(
gbx
,
gby
)
ballCapture
=
ball_capture
(
LIDAR_dist1
)
#
ballCapture = ball_capture(LIDAR_dist1)
goalDetect
=
goal_detect
(
tx
,
ty
)
ballCapture
=
0
# debug
ballCapture
=
1
# goalDetect = 0
if
bcap_man
==
1
:
ballCapture
=
1
# Manually determine Ball captured
elif
bcap_man
==
0
:
ballCapture
=
0
# Ball not captured
elif
bcap_man
==
-
1
:
ballCapture
=
ball_capture
(
LIDAR_dist1
)
# goalDetect = 0
# ballDetect = 0
if
ballCapture
:
# Ball captured
print
(
'
ballCapture TRUE
'
)
...
...
@@ -458,7 +464,7 @@ def main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist1, LIDAR_d
return
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
def
auto_control
(
serial_port
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
):
def
auto_control
(
serial_port
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
,
bcap_man
):
# ===== STEP 1: TAKE ALL INPUT =====
# print('in auto_control')
if
ml
==
1
:
...
...
@@ -482,7 +488,7 @@ def auto_control(serial_port,gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_di
# ===== STEP 2: MAIN CONTROL LOOP =====
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
=
main_control
(
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
)
debugM
,
count_h
,
bcap_man
)
# ===== STEP 3: FEED ALL OUTPUT =====
serial_port_out
(
serial_port
,
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
)
...
...
@@ -491,12 +497,13 @@ def auto_control(serial_port,gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_di
def
auto_init
(
init_count
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
):
count_h
=
0
bcap_man
=
-
1
# gbx, gby, gb_dist = ball_detection.detectLive(url_gb, model, minDetectionScore, showSight = True)
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
=
main_control
(
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
)
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
=
main_control
(
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
,
bcap_man
)
serial_port_out
(
serial_port
,
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
)
init_count
+=
1
return
init_count
,
count_h
return
init_count
,
count_h
,
bcap_man
def
init
():
pygame
.
init
()
...
...
@@ -680,6 +687,14 @@ def manual_return2auto(key_press):
flag_r
=
1
return
flag_r
def
manual_ballcapture
(
bcap_man
):
if
get_key
(
'
b
'
):
# the green ball is captured
bcap_man
=
1
elif
get_key
(
'
n
'
):
# no ball is captured
bcap_man
=
0
elif
get_key
(
'
v
'
):
# visual
bcap_man
=
-
1
return
bcap_man
# ===== Main Function =====
if
__name__
==
'
__main__
'
:
...
...
@@ -714,6 +729,7 @@ if __name__ == '__main__':
pwm1
,
pwm2
,
pwm3
,
pwm4
=
0
,
0
,
0
,
0
# Not moving
dir1
,
dir2
,
dir3
,
dir4
=
'
+
'
,
'
+
'
,
'
+
'
,
'
+
'
Ctl_com
=
[
0
,
0
,
0
,
0
,
"
+
"
,
"
+
"
,
"
+
"
,
"
+
"
]
# Trigger the ESP32_SLAVE to talk first
"""
gbx, gby, gb_dist = ball_detection.detectLive(url_gb, model, minDetectionScore, showSight = True)
...
...
@@ -733,11 +749,12 @@ if __name__ == '__main__':
flag
=
1
while
(
flag
==
1
):
if
init_count
==
0
:
init_count
,
count_h
=
auto_init
(
init_count
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
)
init_count
,
count_h
,
bcap_man
=
auto_init
(
init_count
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
)
print
(
'
auto_control
'
)
auto_control
(
serial_port
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
)
auto_control
(
serial_port
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist1
,
LIDAR_dist2
,
debugM
,
count_h
,
bcap_man
)
flag
,
print_count
=
keyboard_stop
(
flag
,
print_count
)
flag
=
manual_in_auto
(
Ctl_com
,
serial_port
)
bcap_man
=
manual_ballcapture
(
bcap_man
)
elif
get_key
(
'
s
'
):
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
=
stop_all
()
...
...
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