Skip to content

Commit

Permalink
Implementing critical solution part I
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjergus committed Nov 24, 2018
1 parent 98265d3 commit a9fc699
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 34 deletions.
Binary file modified AI/__pycache__/api_caller.cpython-36.pyc
Binary file not shown.
Binary file modified AI/__pycache__/image_func.cpython-36.pyc
Binary file not shown.
30 changes: 8 additions & 22 deletions AI/api_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,15 @@ def turn_right(self, angle):

def move_forward(self, cm):

params = {'cm': 1}
i = 0

while i < cm:

try:
self.logger.debug('Sending move_forward request ({0} cm)'.format(cm))
response = requests.get(self.url + '/move/forward', params=params, timeout=self.timeout)
is_in_range_response = requests.get(self.url + '/trash/isinrange', timeout=self.timeout)
except requests.exceptions.Timeout:
self.logger.warn('move_forward timeout exception')
#return False

if not response.ok or not is_in_range_response.ok:
self.logger.error('Response is not OK')
#return False

#self.logger.debug('Response: ' + str(response.json()))
if is_in_range_response.json() == True:
return True
params = {'cm': cm}

try:
self.logger.debug('Sending move_forward request ({0} cm)'.format(cm))
requests.get(self.url + '/move/forward', params=params, timeout=self.timeout)
except requests.exceptions.Timeout:
self.logger.warn('move_forward timeout exception')

return False
return True

def is_in_range(self):
"""
Expand Down Expand Up @@ -83,7 +69,7 @@ def pick_up(self):

def __send_turn_request(self, angle):

params = {'angle': angle / 3}
params = {'angle': angle}
try:
self.logger.debug('Sending turn request ({0} angle)'.format(angle))
response = requests.get(self.url + '/move/turn', params=params, timeout=self.timeout)
Expand Down
530 changes: 530 additions & 0 deletions AI/app.log

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion AI/image_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ def get_img():
else:
img.save(destination + '.jpg')
img = cv2.imread(destination + '.jpg')

return img
14 changes: 12 additions & 2 deletions AI/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ def navigate_to_bottle(result):
logging.debug('result of detection: ')
logging.debug(result)
process_result = process_bottle(result[0][1:-1])
if process_result != move_enum.FORWARD:
api.move_forward(500)
raise ValueError('Sorry, model hasn´t been trained pretty well, we cannot continue ...')

while True:
img = get_img()
Expand All @@ -129,17 +132,24 @@ def navigate_to_bottle(result):


def ultimate_finding_cycle():

num_of_turns = 0
while True:
img = get_img()
yolo.detect_from_cvmat(img)
result = filter_results(yolo.result)
if len(result) == 1:
print('Woooow, I got an image')
navigate_to_bottle(result)
break
else:
num_of_turns += 1
logging.debug('ultimate_finding_cycle can´t see anythink')
api.turn_right(10)
if num_of_turns < 4:
api.turn_right(10)
else:
api.turn_left(10)
if num_of_turns == 8:
num_of_turns = 0
#api.move_forward(1)


Expand Down
25 changes: 16 additions & 9 deletions AI/test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# -*- coding: utf-8 -*-
from YOLO_small_tf import YOLO_TF
import time
import cv2
import numpy as np

yolo = YOLO_TF()
def is_cell_red(cell):
return cell[3] > 180

yolo.imshow = False
s = time.time()
yolo.detect_from_file('resources/test.jpg')
print('Detection time: ' + str(time.time()-s))
def check_row(row):
distance = 0
large = 0

result = yolo.result
def detect(image):
# BGR
largest_distance = 0
for row in np.array(image)[0]:
print(row)



print('result')
detect(cv2.imread('resources/test_img.PNG'))

0 comments on commit a9fc699

Please sign in to comment.