-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added 2021 Fall SEA x ENGRSL Workshop 2.
- Loading branch information
1 parent
9002213
commit 7576e12
Showing
26 changed files
with
949 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/checkpoints.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
0 | ||
74 | ||
324 | ||
1269 | ||
1769 | ||
2040 | ||
2306 | ||
2871 | ||
3112 | ||
3269 | ||
3510 | ||
3728 | ||
4041 | ||
4348 | ||
4593 | ||
4859 | ||
4945 | ||
5351 | ||
5405 | ||
5560 | ||
5710 | ||
6101 | ||
6195 | ||
6297 | ||
6459 | ||
6641 | ||
7034 | ||
7337 | ||
7634 | ||
7840 | ||
8106 | ||
8409 | ||
8820 | ||
9126 | ||
9383 |
32 changes: 32 additions & 0 deletions
32
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/code/s04a_s0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
distances = [] | ||
sptree = [] | ||
parents = [] | ||
|
||
for i in range(NETWORK_MAX_SIZE): | ||
distances.append(9999) | ||
sptree.append(0) | ||
parent.append(0) | ||
|
||
parent[0] = -1 | ||
distances[SRC] = 0 | ||
|
||
for i in range(NETWORK_MAX_SIZE-1): | ||
|
||
minimum = 9999 | ||
minIndx = -1 | ||
|
||
for j in range(NETWORK_MAX_SIZE): | ||
if sptree[j] == 0 and distances[j] <= minimum: | ||
minimum = distances[j] | ||
minIndx = j | ||
|
||
sptree[minimum] = 1 | ||
|
||
for j in range(NETWORK_MAX_SIZE): | ||
|
||
if (sptree[j] == 0 and cache.topology[minIndx][j] == 1 and | ||
distances[minIndx] + cache.topology[minIndx][j] < distances[j]): | ||
|
||
parent[j] = minIndx | ||
distances[j] = distances[minIndx] + cache.topology[minIndx][j] | ||
|
34 changes: 34 additions & 0 deletions
34
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/code/s04a_s1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
def dijkstra(): | ||
|
||
distances = [] | ||
sptree = [] | ||
parents = [] | ||
|
||
for i in range(NETWORK_MAX_SIZE): | ||
distances.append(9999) | ||
sptree.append(0) | ||
parent.append(0) | ||
|
||
parent[0] = -1 | ||
distances[SRC] = 0 | ||
|
||
for i in range(NETWORK_MAX_SIZE-1): | ||
|
||
minimum = 9999 | ||
minIndx = -1 | ||
|
||
for j in range(NETWORK_MAX_SIZE): | ||
if sptree[j] == 0 and distances[j] <= minimum: | ||
minimum = distances[j] | ||
minIndx = j | ||
|
||
sptree[minimum] = 1 | ||
|
||
for j in range(NETWORK_MAX_SIZE): | ||
|
||
if (sptree[j] == 0 and cache.topology[minIndx][j] == 1 and | ||
distances[minIndx] + cache.topology[minIndx][j] < distances[j]): | ||
|
||
parent[j] = minIndx | ||
distances[j] = distances[minIndx] + cache.topology[minIndx][j] | ||
|
2 changes: 2 additions & 0 deletions
2
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/code/s04b_s0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def function_name(): | ||
... |
2 changes: 2 additions & 0 deletions
2
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/code/s04b_s1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def function_name(x, y, z): | ||
... |
3 changes: 3 additions & 0 deletions
3
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/code/s04b_s2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def function_name(x, y, z): | ||
output = x**2 + y - z | ||
return output |
37 changes: 37 additions & 0 deletions
37
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/code/s07a_s0.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Get the drone off the ground. | ||
drone.takeoff() | ||
|
||
# Land the drone. | ||
drone.land() | ||
|
||
# In the following methods, n is an integer from [20, 500]. | ||
|
||
# Go forward n cm. | ||
drone.forward(n) | ||
|
||
# Go back n cm. | ||
drone.back(n) | ||
|
||
# Strafe left n cm. | ||
drone.left(n) | ||
|
||
# Strafe right n cm. | ||
drone.right(n) | ||
|
||
# Go up n cm. | ||
drone.up(n) | ||
|
||
# Go down n cm. | ||
drone.down(n) | ||
|
||
# Rotate x degrees clockwise. | ||
drone.cw(x) | ||
|
||
# Rotate x degrees counter-clockwise. | ||
drone.ccw(x) | ||
|
||
# This one is a bit more advanced! | ||
# Fly at a curve from a defined (x1, y1, z1) to a defined (x2, y2, z2) at | ||
# s cm/s. The arc radius must be [0.5, 10] m. All coordinates are [-500, 500], | ||
# and s is [10, 60]. | ||
drone.curve(x1, y1, z1, x2, y2, z2) |
20 changes: 20 additions & 0 deletions
20
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/compile.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
|
||
echo ":: Preparing for a fresh render..." | ||
rm -r media/ 2>/dev/null | ||
|
||
echo ":: Rendering scenes..." | ||
for file in $(find . -maxdepth 1 -name "s*.py"); do | ||
python -m manim $file | ||
done | ||
|
||
echo ":: Concatenating scenes..." | ||
mkdir -p ./render/scenes/ | ||
mv ./media/videos/*/1080p60/*.mp4 ./render/scenes/ | ||
ls -1 ./render/scenes/*.mp4 > ./tmp.txt | ||
sed "s/.*/file '&'/" ./tmp.txt > ./playlist.txt | ||
rm ./tmp.txt | ||
ffmpeg -f concat -safe 0 -i ./playlist.txt -c copy ./render/FINAL.mp4 | ||
|
||
echo ":: Final video written to ./render/FINAL.mp4" | ||
echo ":: Done." |
Binary file added
BIN
+133 KB
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/img/algo_def.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.8 KB
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/img/computer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+15.3 KB
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/img/switch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.5 KB
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/img/wap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions
129
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/play.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import cv2 | ||
import time | ||
|
||
from termcolor import colored | ||
|
||
# Set this to True if you want to find checkpoints. | ||
DEFINEMODE = True | ||
|
||
# Playback speed. | ||
SPEED = 2 | ||
|
||
def main(): | ||
|
||
# Make the display window fullscreen. | ||
cv2.namedWindow("Display", cv2.WND_PROP_FULLSCREEN) | ||
cv2.setWindowProperty("Display", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) | ||
|
||
# Open up the video and get the framerate. | ||
mp4 = cv2.VideoCapture("./render/FINAL.mp4") | ||
fps = int(mp4.get(cv2.CAP_PROP_FPS)) * SPEED | ||
|
||
# Make sure that it's open. | ||
assert mp4.isOpened, "Video doesn't exist. Is it in ./render/FINAL.mp4?" | ||
|
||
# Counter for the frame number. | ||
n = 0 | ||
|
||
# Checkpoints of n to pause at. | ||
checkpoints = [int(n.strip("\n")) for n in open("./checkpoints.txt", "r").readlines()] | ||
|
||
# Paused switch. | ||
paused = False | ||
|
||
# Loop to show. | ||
while mp4.isOpened(): | ||
|
||
# Show the frame if not paused. | ||
if not paused: | ||
|
||
ret, frame = mp4.read() | ||
|
||
# Display the frame. | ||
if ret: | ||
cv2.imshow("Display", frame) | ||
time.sleep(1/fps) | ||
else: | ||
break | ||
|
||
# Grab a key if pressed. | ||
key = cv2.waitKey(1) & 0xFF | ||
|
||
# Pause at designated checkpoints. | ||
if n in checkpoints: | ||
if not paused: | ||
print(f":: Hit breakpoint {checkpoints.index(n)}.") | ||
print(colored(":: Pausing.", "red")) | ||
paused = True | ||
|
||
# Press 'q' to quit. | ||
if key == ord('q'): | ||
|
||
print(colored(":: 'q' detected. Are you sure you want to quit?", "red")) | ||
print(colored(":: -> Type 'yes' in the controller console to quit.", "red")) | ||
|
||
if (input(":: >> ") == 'yes'): | ||
print(colored(":: Quitting.", "red")) | ||
break | ||
|
||
else: | ||
print(colored(":: Playing.", "green")) | ||
|
||
# Press ' ' to manually pause or unpause. | ||
elif key == ord(' '): | ||
if not paused: | ||
print(colored(":: Pausing.", "red")) | ||
paused = True | ||
else: | ||
print(colored(":: Playing.", "green")) | ||
paused = False | ||
|
||
# Press RIGHT to go to the next checkpoint. | ||
elif key == 83: | ||
print(colored(":: Going FORWARD a checkpoint.", "green")) | ||
paused = False | ||
|
||
# Press LEFT to go to the previous checkpoint. | ||
elif key == 81: | ||
|
||
print(colored(":: Going BACKWARD a checkpoint.", "red")) | ||
|
||
for i in range(n-1, -1, -1): | ||
|
||
if DEFINEMODE: | ||
print(colored(f"=> i={i}", "red")) | ||
|
||
if i in checkpoints: | ||
|
||
mp4.set(cv2.CAP_PROP_POS_FRAMES, i-1) | ||
n = i-1 | ||
break | ||
|
||
ret, frame = mp4.read() | ||
|
||
# Display the frame. | ||
if ret: | ||
cv2.imshow("Display", frame) | ||
time.sleep(1/fps) | ||
else: | ||
break | ||
|
||
paused = False | ||
|
||
# Increment or decrement the frame based on status. | ||
if not paused: | ||
n += 1 | ||
|
||
if not paused and DEFINEMODE: | ||
print(f"=> n={n}") | ||
|
||
# Release. | ||
mp4.release() | ||
|
||
# Close. | ||
cv2.destroyAllWindows() | ||
|
||
if __name__ == "__main__": | ||
main() |
34 changes: 34 additions & 0 deletions
34
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/s00a_Title.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from manim import * | ||
|
||
class s00a_Title(Scene): | ||
|
||
def construct(self): | ||
|
||
# Actors. | ||
title = Text("Hello Tello!") | ||
subtitle = Text("Week 2/3").scale(0.75) | ||
footnote = VGroup(*[ | ||
Text(x).scale(0.50) for x in ( | ||
"Made possible by the Solar Energy Association", | ||
"and Engineering Service Learning at UC Merced.", | ||
) | ||
]) | ||
|
||
# Positioning. | ||
title.shift(0.50*UP) | ||
subtitle.next_to(title, DOWN) | ||
footnote[0].next_to(subtitle, DOWN).shift(0.5*DOWN) | ||
footnote[1].next_to(footnote[0], DOWN) | ||
|
||
# Animations. | ||
|
||
actors = [title, subtitle, footnote] | ||
|
||
for actor in actors: | ||
self.play(Write(actor)) | ||
self.wait(0.5) | ||
|
||
# Cleanup. | ||
self.wait(0.5) | ||
self.play(*[FadeOut(actor) for actor in actors]) | ||
|
42 changes: 42 additions & 0 deletions
42
2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/s01a_Agenda.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from manim import * | ||
|
||
class s01a_Agenda(Scene): | ||
|
||
def construct(self): | ||
|
||
# Actors. | ||
title = Text("Agenda") | ||
points = VGroup(*[ | ||
Text(x) for x in ( | ||
"- OpenCV2 Fix (!)", | ||
"- More About Functions", | ||
"- Intro to Tello Drones", | ||
"- Networks 101", | ||
"- Basic Tello Methods", | ||
"- Algorithms", | ||
) | ||
]).scale(0.75) | ||
|
||
# Positioning. | ||
title.to_edge(UP+LEFT) | ||
points.arrange(direction=DOWN, aligned_edge=LEFT) | ||
points.next_to(title, DOWN).to_edge(LEFT) | ||
|
||
# Modifiers. | ||
ul = Underline(title) | ||
|
||
# Animations. | ||
|
||
actors = [title, ul, *points] | ||
|
||
for i in range(len(actors)): | ||
|
||
self.play(Write(actors[i])) | ||
|
||
if i > 1: | ||
self.wait(0.5) | ||
|
||
# Cleanup. | ||
self.wait(0.5) | ||
self.play(*[FadeOut(actor) for actor in actors]) | ||
|
Oops, something went wrong.