-
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.
feat(training): Use video instead of single frames
Video postprocessing can be done on a more powerful computer
- Loading branch information
Showing
4 changed files
with
118 additions
and
82 deletions.
There are no files selected for viewing
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,47 @@ | ||
import pigpio | ||
|
||
# GPIO Pins for motor controller | ||
drivePower = 4 | ||
steerPower = 17 | ||
driveBack = 27 | ||
driveFwd = 22 | ||
steerLeft = 23 | ||
steerRight = 24 | ||
|
||
|
||
# GPIO | ||
pi = pigpio.pi() | ||
pi.set_PWM_frequency(drivePower, 8000) | ||
pi.write(steerPower, 1) | ||
|
||
# Throttle | ||
|
||
def stop(): | ||
pi.clear_bank_1(1 << driveBack | 1 << driveFwd) | ||
pi.set_PWM_dutycycle(drivePower, 0) | ||
|
||
def setThrottle(throttleVal): | ||
if throttleVal == 0: | ||
stop() | ||
else: | ||
pi.set_PWM_dutycycle(drivePower, abs(throttleVal) + 128) | ||
if throttleVal >= 0: | ||
pi.write(driveFwd, 1) | ||
pi.write(driveBack, 0) | ||
else: | ||
pi.write(driveFwd, 0) | ||
pi.write(driveBack, 1) | ||
|
||
|
||
|
||
# Steering | ||
def left(): | ||
pi.write(steerLeft, 1) | ||
pi.write(steerRight, 0) | ||
|
||
def center(): | ||
pi.clear_bank_1(1 << steerLeft | 1 << steerRight) | ||
|
||
def right(): | ||
pi.write(steerLeft, 0) | ||
pi.write(steerRight, 1) |
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,26 @@ | ||
import ffmpeg | ||
import shutil | ||
from time import time_ns | ||
import sys, os | ||
|
||
def process_video(start_time): | ||
if not os.path.exists(f"raw/temp_{start_time}"): | ||
os.makedirs(f"raw/temp_{start_time}") | ||
print(f"raw/out_{start_time}.h265") | ||
stream = (ffmpeg | ||
.input(f"raw/out_{start_time}.h265") | ||
.output(f"raw/temp_{start_time}/%05d.jpg")) | ||
stream.run() | ||
|
||
with open(f"raw/commands_{start_time}.txt", "r") as commandFile: | ||
lines = commandFile.readlines() | ||
for i in range(len(lines)): | ||
line = lines[i] | ||
line = line[0:-1] | ||
if line in ["stop", "", "kill"]: | ||
continue | ||
shutil.copyfile(f"raw/temp_{start_time}/{i:05}.jpg", | ||
f"data/{line}/{int(time_ns())}.jpg") | ||
|
||
if __name__ == "__main__": | ||
process_video(sys.argv[1]) |
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 @@ | ||
ffmpeg-python |
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