diff --git a/source/NN/__pycache__/model.cpython-311.pyc b/source/NN/__pycache__/model.cpython-311.pyc index 6623f05..76c3cf1 100644 Binary files a/source/NN/__pycache__/model.cpython-311.pyc and b/source/NN/__pycache__/model.cpython-311.pyc differ diff --git a/source/NN/__pycache__/neural_network.cpython-311.pyc b/source/NN/__pycache__/neural_network.cpython-311.pyc index 268eb3a..e26c58d 100644 Binary files a/source/NN/__pycache__/neural_network.cpython-311.pyc and b/source/NN/__pycache__/neural_network.cpython-311.pyc differ diff --git a/source/NN/neural_network.py b/source/NN/neural_network.py index 3202aa4..8152f40 100644 --- a/source/NN/neural_network.py +++ b/source/NN/neural_network.py @@ -7,6 +7,7 @@ import matplotlib.pyplot as plt from NN.model import * from PIL import Image import pygame +from area.constants import GREY device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu') @@ -84,16 +85,22 @@ def load_image(image_path): testImage = testImage.unsqueeze(0) return testImage +#display the image for prediction next to the field def display_image(screen, image_path, position): image = pygame.image.load(image_path) image = pygame.transform.scale(image, (250, 250)) screen.blit(image, position) +#display result of the guessed image (text under the image) def display_result(screen, position, predicted_class): font = pygame.font.Font(None, 30) displayed_text = font.render("The predicted image is: "+str(predicted_class), 1, (255,255,255)) screen.blit(displayed_text, position) +def clear_text_area(win, x, y, width, height, color=GREY): + pygame.draw.rect(win, color, (x, y, width, height)) + pygame.display.update() + def guess_image(model, image_tensor): with torch.no_grad(): testOutput = model(image_tensor) diff --git a/source/__pycache__/astar.cpython-311.pyc b/source/__pycache__/astar.cpython-311.pyc index c791e81..b705235 100644 Binary files a/source/__pycache__/astar.cpython-311.pyc and b/source/__pycache__/astar.cpython-311.pyc differ diff --git a/source/__pycache__/bfs.cpython-311.pyc b/source/__pycache__/bfs.cpython-311.pyc index 94f1cb7..b236869 100644 Binary files a/source/__pycache__/bfs.cpython-311.pyc and b/source/__pycache__/bfs.cpython-311.pyc differ diff --git a/source/__pycache__/crop_protection_product.cpython-311.pyc b/source/__pycache__/crop_protection_product.cpython-311.pyc index 855581b..997f2be 100644 Binary files a/source/__pycache__/crop_protection_product.cpython-311.pyc and b/source/__pycache__/crop_protection_product.cpython-311.pyc differ diff --git a/source/__pycache__/genetic.cpython-311.pyc b/source/__pycache__/genetic.cpython-311.pyc new file mode 100644 index 0000000..02cf8fc Binary files /dev/null and b/source/__pycache__/genetic.cpython-311.pyc differ diff --git a/source/__pycache__/ground.cpython-311.pyc b/source/__pycache__/ground.cpython-311.pyc index 071c593..63f109a 100644 Binary files a/source/__pycache__/ground.cpython-311.pyc and b/source/__pycache__/ground.cpython-311.pyc differ diff --git a/source/__pycache__/plant.cpython-311.pyc b/source/__pycache__/plant.cpython-311.pyc index 0fab647..a778e52 100644 Binary files a/source/__pycache__/plant.cpython-311.pyc and b/source/__pycache__/plant.cpython-311.pyc differ diff --git a/source/__pycache__/tile.cpython-311.pyc b/source/__pycache__/tile.cpython-311.pyc index 25b2aa6..2c03bbd 100644 Binary files a/source/__pycache__/tile.cpython-311.pyc and b/source/__pycache__/tile.cpython-311.pyc differ diff --git a/source/area/__pycache__/__init__.cpython-311.pyc b/source/area/__pycache__/__init__.cpython-311.pyc index b4b15ec..a3d75da 100644 Binary files a/source/area/__pycache__/__init__.cpython-311.pyc and b/source/area/__pycache__/__init__.cpython-311.pyc differ diff --git a/source/area/__pycache__/constants.cpython-311.pyc b/source/area/__pycache__/constants.cpython-311.pyc index 99fb7fd..ae86f18 100644 Binary files a/source/area/__pycache__/constants.cpython-311.pyc and b/source/area/__pycache__/constants.cpython-311.pyc differ diff --git a/source/area/__pycache__/field.cpython-311.pyc b/source/area/__pycache__/field.cpython-311.pyc index df05e7f..1d35bbe 100644 Binary files a/source/area/__pycache__/field.cpython-311.pyc and b/source/area/__pycache__/field.cpython-311.pyc differ diff --git a/source/area/__pycache__/tractor.cpython-311.pyc b/source/area/__pycache__/tractor.cpython-311.pyc index eea7c32..5986299 100644 Binary files a/source/area/__pycache__/tractor.cpython-311.pyc and b/source/area/__pycache__/tractor.cpython-311.pyc differ diff --git a/source/area/tractor.py b/source/area/tractor.py index 7416043..d3e0d07 100644 --- a/source/area/tractor.py +++ b/source/area/tractor.py @@ -156,6 +156,6 @@ def do_actions(tractor, WIN, move_list): tractor.rotate_to_left() tractor.draw_tractor(WIN) pygame.display.update() - time.sleep(1) + time.sleep(0.5) diff --git a/source/main.py b/source/main.py index 9a54d8b..17ac8f6 100644 --- a/source/main.py +++ b/source/main.py @@ -12,7 +12,7 @@ from ground import Dirt from plant import Plant from bfs import graphsearch, Istate, succ from astar import a_star -from NN.neural_network import load_model, load_image, guess_image, display_image, display_result +from NN.neural_network import load_model, load_image, guess_image, display_image, display_result, clear_text_area from PIL import Image from genetic import genetic_algorithm @@ -30,39 +30,15 @@ def main(): window = drawWindow(WIN) pygame.display.update() -#getting coordinates of our "goal tile": - tile_index = get_tile_index() - tile_x, tile_y = get_tile_coordinates(tile_index) - if tile_x is not None and tile_y is not None: - print(f"Coordinates of tile {tile_index} are: ({tile_x}, {tile_y})") - else: print("Such tile does not exist") - - #mark the goal tile: - tiles[tile_index].image = "resources/images/sampling_goal.png" - image = pygame.image.load(tiles[tile_index].image).convert() - image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE)) - WIN.blit(image, (tiles[tile_index].x, tiles[tile_index].y)) - pygame.display.flip() -#graphsearch activation: - istate = Istate(170, 100, 2) #initial state - - goaltest = [] - goaltest.append(tile_x) #final state (consists of x and y because direction doesnt matter) - goaltest.append(tile_y) +#Tractor initialization: tractor = Tractor(0*TILE_SIZE, 0*TILE_SIZE, 2, None, None) tractor.rect.x += fieldX - tractor.rect.y += fieldY - tractor.tractor_start = ((istate.get_x(), istate.get_y())) - #tractor.tractor_start = ((istate.get_x(), istate.get_y(), istate.get_direction)) - tractor.tractor_end = ((goaltest[0], goaltest[1])) - - #moves = (graphsearch(istate, succ, goaltest, tractor)) - moves = (a_star(istate, succ, goaltest, tractor)) - print(moves) - + tractor.rect.y += fieldY + tractor.tractor_start = ((170, 100)) + istate = Istate(170, 100, 2) #initial state #main loop: @@ -72,7 +48,35 @@ def main(): run = False time.sleep(1) - # movement based on route-planning (test): + #getting coordinates of our "goal tile": + tile_index = get_tile_index() + tile_x, tile_y = get_tile_coordinates(tile_index) + if tile_x is not None and tile_y is not None: + print(f"Coordinates of tile {tile_index} are: ({tile_x}, {tile_y})") + else: print("Such tile does not exist") + + #mark the goal tile: + tiles[tile_index].image = "resources/images/sampling_goal.png" + image = pygame.image.load(tiles[tile_index].image).convert() + image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE)) + WIN.blit(image, (tiles[tile_index].x, tiles[tile_index].y)) + pygame.display.flip() + + + tractor.tractor_end = ((tile_x, tile_y)) + goaltest = [] #final state (consists of x and y because direction doesnt matter) + goaltest.append(tile_x) + goaltest.append(tile_y) + goaltest[0] = tile_x + goaltest[1]=tile_y + + #moves = (graphsearch(istate, succ, goaltest, tractor)) #<-------BFS + moves = (a_star(istate, succ, goaltest, tractor)) + print(moves) + + + + # movement based on route-planning: tractor.draw_tractor(WIN) time.sleep(1) @@ -89,6 +93,7 @@ def main(): image_tensor = load_image(image_path) prediction = guess_image(load_model(), image_tensor) + clear_text_area(WIN, WIDTH - 50, 600, 400, 50) display_result(WIN, (WIDTH - 50 , 600), prediction) #display text under the photo pygame.display.update() print(f"The predicted image is: {prediction}") @@ -155,7 +160,10 @@ def main(): #work on field: if predykcje == 'work': tractor.work_on_field(goalTile, d1, p1) - time.sleep(50) + + #update the initial state for the next target: + istate = Istate(tile_x, tile_y, tractor.direction) + time.sleep(5) print("\n")