Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cs437
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
acaby2
cs437
Commits
ea290159
Commit
ea290159
authored
1 year ago
by
ssethia2
Browse files
Options
Downloads
Patches
Plain Diff
Fix reference before initialization
parent
df928996
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Lab2/object_location.py
+5
-4
5 additions, 4 deletions
Lab2/object_location.py
Lab2/test_self_driving.py
+3
-2
3 additions, 2 deletions
Lab2/test_self_driving.py
with
8 additions
and
6 deletions
Lab2/object_location.py
+
5
−
4
View file @
ea290159
...
@@ -15,7 +15,7 @@ array_map = np.zeros((grid_size, grid_size))
...
@@ -15,7 +15,7 @@ array_map = np.zeros((grid_size, grid_size))
np
.
set_printoptions
(
threshold
=
sys
.
maxsize
,
linewidth
=
sys
.
maxsize
)
np
.
set_printoptions
(
threshold
=
sys
.
maxsize
,
linewidth
=
sys
.
maxsize
)
def
padMap
(
map
):
def
padMap
(
map
):
padded_map
=
np
.
zeros
(
len
(
map
),
len
(
map
[
0
]))
padded_map
=
np
.
zeros
(
(
len
(
map
),
len
(
map
[
0
]))
)
for
i
in
range
(
len
(
map
)):
for
i
in
range
(
len
(
map
)):
for
j
in
range
(
len
(
map
[
0
])):
for
j
in
range
(
len
(
map
[
0
])):
...
@@ -43,7 +43,7 @@ def update_map():
...
@@ -43,7 +43,7 @@ def update_map():
time
.
sleep
(
0.3
)
time
.
sleep
(
0.3
)
# marking the car as 2 to distinguish location on array
# marking the car as 2 to distinguish location on array
array_map
[
car_location
]
=
2
#
array_map[car_location] = 2
# print(array_map)
# print(array_map)
while
angle
<=
90
:
while
angle
<=
90
:
distance
=
fc
.
get_distance_at
(
angle
)
distance
=
fc
.
get_distance_at
(
angle
)
...
@@ -79,12 +79,13 @@ def update_map():
...
@@ -79,12 +79,13 @@ def update_map():
# print(array_map)
# print(array_map)
padded_map
=
padMap
(
array_map
)
padded_map
=
padMap
(
array_map
)
padded_map
[
car_location
]
=
2
# Saving the array in a text file to see results
# Saving the array in a text file to see results
file
=
open
(
"
map.txt
"
,
"
w+
"
)
file
=
open
(
"
map.txt
"
,
"
w+
"
)
content
=
str
(
padded_map
)
content
=
str
(
padded_map
)
file
.
write
(
content
)
file
.
write
(
content
)
file
.
close
()
file
.
close
()
return
padded_map
# this function is used just for testing, enable it in main
# this function is used just for testing, enable it in main
def
object_locations
():
def
object_locations
():
...
@@ -125,4 +126,4 @@ if __name__ == '__main__':
...
@@ -125,4 +126,4 @@ if __name__ == '__main__':
# test()
# test()
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
fc
.
stop
()
fc
.
stop
()
exit
(
0
)
exit
(
0
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Lab2/test_self_driving.py
+
3
−
2
View file @
ea290159
...
@@ -39,9 +39,10 @@ def object_detection(interpreter, labels, stream):
...
@@ -39,9 +39,10 @@ def object_detection(interpreter, labels, stream):
frame
=
stream
.
read
()
frame
=
stream
.
read
()
frame
=
cv2
.
rotate
(
frame
,
cv2
.
ROTATE_180
)
frame
=
cv2
.
rotate
(
frame
,
cv2
.
ROTATE_180
)
input_details
=
interpreter
.
get_input_details
()
height
=
input_details
[
0
][
'
shape
'
][
1
]
height
=
input_details
[
0
][
'
shape
'
][
1
]
width
=
input_details
[
0
][
'
shape
'
][
2
]
width
=
input_details
[
0
][
'
shape
'
][
2
]
input_details
=
interpreter
.
get_input_details
()
#
input_details = interpreter.get_input_details()
output_details
=
interpreter
.
get_output_details
()
output_details
=
interpreter
.
get_output_details
()
# Run the current frame through the object detection model
# Run the current frame through the object detection model
...
@@ -165,7 +166,7 @@ def main():
...
@@ -165,7 +166,7 @@ def main():
while
True
:
while
True
:
# Step 1: Update the map with the latest sensor data
# Step 1: Update the map with the latest sensor data
update_map
()
array_map
=
update_map
()
# Step 2: Get the updated grid
# Step 2: Get the updated grid
grid
=
array_map
.
copy
()
grid
=
array_map
.
copy
()
...
...
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