Skip to content

Commit

Permalink
Added 2021 Fall SEA x ENGRSL Workshop 2.
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnduong committed Oct 21, 2021
1 parent 9002213 commit 7576e12
Show file tree
Hide file tree
Showing 26 changed files with 949 additions and 0 deletions.
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
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]

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]

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def function_name():
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def function_name(x, y, z):
...
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
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)
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."
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 2021-10-Python-SEA-ENGRSL-Workshops/Workshop_2-Hello-Tello/play.py
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()
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])

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])

Loading

0 comments on commit 7576e12

Please sign in to comment.