Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
831 additions
and
104 deletions.
There are no files selected for viewing
File renamed without changes.
457 changes: 457 additions & 0 deletions
457
Data_processing/Training/5_directions_models_Obstacle.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
384 changes: 282 additions & 102 deletions
384
Data_processing/Training/5_directions_models_Opti.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Binary file not shown.
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,77 @@ | ||
from pivideostream import PiVideoStream | ||
from keras.models import load_model | ||
import Adafruit_PCA9685 | ||
from const import * | ||
import numpy as np | ||
import sys | ||
import time | ||
|
||
#Load model | ||
model = load_model(sys.argv[1]) | ||
print("Model loaded") | ||
|
||
# Init engines | ||
speed = SPEED_FAST | ||
direction = DIR_C | ||
pwm = Adafruit_PCA9685.PCA9685() | ||
pwm.set_pwm_freq(50) | ||
|
||
# created a *threaded *video stream, allow the camera sensor to warmup | ||
vs = PiVideoStream().start() | ||
time.sleep(2.0) | ||
|
||
from PIL import Image | ||
frame = vs.read() | ||
img = Image.fromarray(frame) | ||
img.save("test.png") | ||
|
||
|
||
# Starting loop | ||
print("Ready ! press CTRL+C to START/STOP :") | ||
try: | ||
while True: | ||
pass | ||
except KeyboardInterrupt: | ||
pass | ||
|
||
# Handle START/STOP event | ||
try: | ||
head = H_UP | ||
# loop over some frames...this time using the threaded stream | ||
while True: | ||
# grab the frame from the threaded video stream | ||
frame = vs.read() | ||
image = np.array([frame]) / 255.0 | ||
## # Model prediction | ||
preds_raw = model.predict(image) | ||
preds = [np.argmax(pred, axis=1) for pred in preds_raw] | ||
## # Action | ||
if preds[1] == 0: | ||
speed = SPEED_NORMAL | ||
direction = DIR_L | ||
elif preds[1] == 1: | ||
if preds[0] == 1: | ||
if speed == SPEED_FAST: | ||
head = H_UP | ||
speed = SPEED_FAST | ||
else: | ||
speed = SPEED_NORMAL | ||
direction = DIR_C | ||
elif preds[1] == 2: | ||
speed = SPEED_NORMAL | ||
direction = DIR_R | ||
## # Apply values to engines | ||
pwm.set_pwm(0, 0, direction) | ||
pwm.set_pwm(1, 0, speed) | ||
## # Move Head | ||
pwm.set_pwm(2, 0, head) | ||
|
||
except: | ||
pass | ||
|
||
# Stop the machine | ||
pwm.set_pwm(0, 0, 0) | ||
pwm.set_pwm(1, 0, 0) | ||
pwm.set_pwm(2, 0, 0) | ||
vs.stop() | ||
print("Stop") |