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
ce222abe
Commit
ce222abe
authored
4 years ago
by
Zhiying Li
Browse files
Options
Downloads
Patches
Plain Diff
fix the bug
parent
d74db265
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Code/Control/Laptop_Code/main_zzl.py
+21
-10
21 additions, 10 deletions
Code/Control/Laptop_Code/main_zzl.py
with
21 additions
and
10 deletions
Code/Control/Laptop_Code/main_zzl.py
+
21
−
10
View file @
ce222abe
import
time
import
time
import
serial
import
serial
#
import ball_detection.ball_detection as ball_detection
import
ball_detection.ball_detection
as
ball_detection
import
simple_pid.PID
as
PID
import
simple_pid.PID
as
PID
import
timeit
import
timeit
...
@@ -102,7 +102,7 @@ def goal_detect(tx,ty):
...
@@ -102,7 +102,7 @@ def goal_detect(tx,ty):
'''
'''
return True if April Tag is detected
return True if April Tag is detected
'''
'''
if
tx
==
10000
0
and
ty
==
10000
0
:
if
tx
==
0
and
ty
==
0
:
return
False
return
False
else
:
else
:
return
True
return
True
...
@@ -285,8 +285,8 @@ def main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist, debugM):
...
@@ -285,8 +285,8 @@ def main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist, debugM):
goalDetect
=
goal_detect
(
tx
,
ty
)
goalDetect
=
goal_detect
(
tx
,
ty
)
# debug
# debug
ballCapture
=
1
#
ballCapture = 1
goalDetect
=
0
#
goalDetect = 0
if
ballCapture
:
# Ball captured
if
ballCapture
:
# Ball captured
if
goalDetect
:
# Goal detected
if
goalDetect
:
# Goal detected
# stop_all() # Debug
# stop_all() # Debug
...
@@ -305,7 +305,7 @@ def main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist, debugM):
...
@@ -305,7 +305,7 @@ def main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist, debugM):
def
auto_control
(
serial_port
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist
,
debugM
):
def
auto_control
(
serial_port
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist
,
debugM
):
# ===== STEP 1: TAKE ALL INPUT =====
# ===== STEP 1: TAKE ALL INPUT =====
#
gbx, gby, gb_dist = ball_detection.detectLive(model, minDetectionScore, showSight = True)
gbx
,
gby
,
gb_dist
=
ball_detection
.
detectLive
(
model
,
minDetectionScore
,
showSight
=
True
)
line
=
serial_port
.
readline
()
line
=
serial_port
.
readline
()
if
line
==
b
'
SERIAL_IN_START
\r\n
'
:
if
line
==
b
'
SERIAL_IN_START
\r\n
'
:
...
@@ -322,11 +322,19 @@ def auto_control(serial_port,gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_di
...
@@ -322,11 +322,19 @@ def auto_control(serial_port,gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_di
time
.
sleep
(
waitTime
)
time
.
sleep
(
waitTime
)
def
auto_init
(
init_count
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist
,
debugM
):
gbx
,
gby
,
gb_dist
=
ball_detection
.
detectLive
(
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_dist
,
debugM
)
serial_port_out
(
serial_port
,
pwm1
,
pwm2
,
pwm3
,
pwm4
,
dir1
,
dir2
,
dir3
,
dir4
)
init_count
+=
1
return
init_count
# ===== Main Function =====
# ===== Main Function =====
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
# =========== SET UP ============
# =========== SET UP ============
# Defining Variables for ESP 32 Serial I/O
# Defining Variables for ESP 32 Serial I/O
PORT
=
"
COM
22
"
# for Alienware
PORT
=
"
COM
6
"
# for Alienware
serial_port
=
serial
.
Serial
(
PORT
,
115200
)
serial_port
=
serial
.
Serial
(
PORT
,
115200
)
serial_port
.
close
()
serial_port
.
close
()
serial_port
.
open
()
serial_port
.
open
()
...
@@ -335,7 +343,7 @@ if __name__ == '__main__':
...
@@ -335,7 +343,7 @@ if __name__ == '__main__':
waitTime
=
0.05
waitTime
=
0.05
# Loading the PyTorch ML model for ball detection
# Loading the PyTorch ML model for ball detection
#
model = ball_detection.returnModel(device, labelSet, modelLoc, modelFile)
model
=
ball_detection
.
returnModel
(
device
,
labelSet
,
modelLoc
,
modelFile
)
# =========== DECLARE VARIABLES ===========
# =========== DECLARE VARIABLES ===========
# ESP CAM In
# ESP CAM In
...
@@ -353,11 +361,14 @@ if __name__ == '__main__':
...
@@ -353,11 +361,14 @@ if __name__ == '__main__':
dir1
,
dir2
,
dir3
,
dir4
=
'
+
'
,
'
+
'
,
'
+
'
,
'
+
'
dir1
,
dir2
,
dir3
,
dir4
=
'
+
'
,
'
+
'
,
'
+
'
,
'
+
'
# Trigger the ESP32_SLAVE to talk first
# Trigger the ESP32_SLAVE to talk first
# gbx, gby, gb_dist = ball_detection.detectLive(model, minDetectionScore, showSight = True)
"""
gbx, gby, gb_dist = ball_detection.detectLive(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_dist, debugM)
pwm1, pwm2, pwm3, pwm4, dir1, dir2, dir3, dir4 = main_control(gbx, gby, gb_dist, tx, ty, tz, rx, ry, rz, LIDAR_dist, debugM)
serial_port_out(serial_port, pwm1, pwm2, pwm3, pwm4, dir1, dir2, dir3, dir4)
serial_port_out(serial_port, pwm1, pwm2, pwm3, pwm4, dir1, dir2, dir3, dir4)
"""
init_count
=
0
# =========== LOOP FOREVER===========
# =========== LOOP FOREVER===========
while
True
:
while
True
:
if
init_count
==
0
:
init_count
=
auto_init
(
init_count
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist
,
debugM
)
auto_control
(
serial_port
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist
,
debugM
)
auto_control
(
serial_port
,
gbx
,
gby
,
gb_dist
,
tx
,
ty
,
tz
,
rx
,
ry
,
rz
,
LIDAR_dist
,
debugM
)
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