Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
b3f68d1
Changed variable names to fit with snakecase
PhilipMF Jun 6, 2024
fce8525
Merge branch 'development' into variableNameChange
PhilipMF Jun 6, 2024
8629a40
webcam works now
EsbenSE Jun 7, 2024
eeabe2f
added testFile
EsbenSE Jun 7, 2024
2a25ed4
Fixed transfer of path as .json
Holmst33n Jun 7, 2024
511735c
added front motor
Jakob-SA Jun 7, 2024
4d392f9
Merge branch 'development' into integrationTesting
PhilipMF Jun 7, 2024
7970a51
convert grid data to nodes
PhilipMF Jun 7, 2024
7dcee70
ComputerMain is good to go
Holmst33n Jun 7, 2024
85e306b
Added get_ball_position function
PhilipMF Jun 10, 2024
09bbc4a
Final changes to the code for the intergration tessting.
Holmst33n Jun 10, 2024
7463272
Merge branch 'integrationTesting' of https://github.com/CDIO-gr-17/Go…
Holmst33n Jun 10, 2024
8964eaa
get_robot_and position function implemented. not testet.
EsbenSE Jun 10, 2024
099247d
Merge branch 'integrationTesting' of https://github.com/CDIO-gr-17/Go…
EsbenSE Jun 10, 2024
647938f
Function for getting green and blue color
Jakob-SA Jun 10, 2024
86832be
Set the robot to move 10mm per grid
PhilipMF Jun 10, 2024
5702733
Merge branch 'integrationTesting' of https://github.com/CDIO-gr-17/Go…
PhilipMF Jun 10, 2024
2b3552f
Improved write_pixel_grid 1000x and refactored it to create_combined_…
PhilipMF Jun 10, 2024
e9e2525
Post-debugging. Not working as intended but as we have shown in video.
PhilipMF Jun 10, 2024
dd76dbe
robotPosition initial commit
EsbenSE Jun 11, 2024
ac78659
findangle from centre to robot
EsbenSE Jun 11, 2024
6873dfb
move_point function that displaces a position in the direction of the…
Jakob-SA Jun 11, 2024
4088d0e
done in hand, but will probaby use numpy
EsbenSE Jun 11, 2024
d31f9e0
Merge branch 'robotPosition' of https://github.com/CDIO-gr-17/GolfBot…
EsbenSE Jun 11, 2024
cb8c16d
Made function to get direction of robot by tail and head
Jakob-SA Jun 11, 2024
f07d7bc
Comment on function
Jakob-SA Jun 11, 2024
687284b
Removed unused methods
Jakob-SA Jun 11, 2024
96712f3
Change x and y values and made combined grid show correctly
PhilipMF Jun 11, 2024
3576b02
Movement from array is now working.
Holmst33n Jun 11, 2024
211f66e
Merge branch 'development' into integrationTesting
PhilipMF Jun 11, 2024
91f6c30
Merge remote-tracking branch 'origin/development' into movementAndCom…
Holmst33n Jun 11, 2024
0005856
Removed display_grid function and moved code for readability
PhilipMF Jun 11, 2024
aa5904e
Combines the new movement with the new computervision
Holmst33n Jun 11, 2024
06bde09
Changed return statement of get_grid to use dictonaries and refactore…
PhilipMF Jun 11, 2024
2b73035
Rewrote get_grid to correctly use numpy and not iterate through grid,…
PhilipMF Jun 11, 2024
6b7a950
Moved resolution into get_masks_from_camera
PhilipMF Jun 11, 2024
6a376ac
getting ready to work with robot position
Holmst33n Jun 11, 2024
eb5ee65
Merge remote-tracking branch 'origin/development' into movementAndCom…
Holmst33n Jun 11, 2024
eee6980
Now robots actual position is implemented
Holmst33n Jun 11, 2024
9f0b7d8
Robot can now move approx to one ball from any pos
Jakob-SA Jun 11, 2024
c077786
minor adjustment to builder
Jakob-SA Jun 11, 2024
41db370
Removed mainTest and added error print for displacement
Jakob-SA Jun 12, 2024
369087a
degrees added
Jun 12, 2024
63f5908
Made function for finding robot pos and one for robot heading. Refact…
Jakob-SA Jun 12, 2024
c943f79
Added function for diffing position
PhilipMF Jun 12, 2024
5175ba5
Refactor files
Jakob-SA Jun 12, 2024
9c7114d
Correct error messages
Jakob-SA Jun 12, 2024
a61ef2c
Removed single print
Jakob-SA Jun 12, 2024
521ad3b
Added function for detecting clusters and getting info about them
PhilipMF Jun 12, 2024
d5ebab9
Merge branch 'development' of https://github.com/CDIO-gr-17/GolfBot i…
PhilipMF Jun 12, 2024
976c3c3
Merge branch 'development' into maskProcessing
PhilipMF Jun 12, 2024
9a9525d
removed code and test
Jun 12, 2024
c938d9c
Fix til Jakob
PhilipMF Jun 12, 2024
ba67ab7
first commit. does not work
EsbenSE Jun 12, 2024
714067f
Merge branch 'development' into continuousMovement
EsbenSE Jun 12, 2024
8f6bb2f
Merge branch 'development' into headingToDegrees
Jun 12, 2024
9658c84
sry team. name change
PhilipMF Jun 12, 2024
c71613a
Merge branch 'development' into headingToDegrees
Jun 12, 2024
bb7271d
Adjustments
Jakob-SA Jun 12, 2024
b633a5b
Merge branch 'development' into headingToDegrees
Jun 12, 2024
a20fa15
To Esben fixed import
Jakob-SA Jun 12, 2024
a436cad
Made the feedback of robot position work correctly (hopefully)
PhilipMF Jun 12, 2024
4eeee01
?
PhilipMF Jun 12, 2024
9b597da
Connect to robot before determining start and end node
PhilipMF Jun 12, 2024
f787a50
works okay a this point.
EsbenSE Jun 12, 2024
ae63b6f
Making going straight work from stat node
Jossemand Jun 12, 2024
d948a41
Merge branch 'development' into continuousMovement
EsbenSE Jun 12, 2024
7461886
fix
Jun 12, 2024
4645130
ye
Jun 12, 2024
06410c7
Merge branch 'development' into headingToDegrees
Jun 12, 2024
5068632
Made positions take mask and grid as parameters
PhilipMF Jun 12, 2024
8642ee1
Changed the feedbackloop to not call itself
PhilipMF Jun 12, 2024
248fd9f
Made startrobot function in computermain
PhilipMF Jun 12, 2024
10499af
working on
Jossemand Jun 12, 2024
2e3f9d9
Continous movement should work with moveForward
Jossemand Jun 12, 2024
938329b
Merge remote-tracking branch 'origin/development' into continuousMove…
Jossemand Jun 12, 2024
02b0761
Fixed dublicate heading attribute
Jossemand Jun 12, 2024
1207202
Balls and robot only return their center positions
PhilipMF Jun 13, 2024
0cf43a4
Made get_robot_angle take multiple masks
PhilipMF Jun 13, 2024
5af24ff
feedbackLoop is implemented between robot and computer
Holmst33n Jun 13, 2024
ec58087
should work now. trying on robot.
EsbenSE Jun 13, 2024
8ac6f4e
Added the ability to calibrate the camera using opencv
PhilipMF Jun 13, 2024
6d66d94
Fix
Jakob-SA Jun 13, 2024
d83551b
Continous movement allmost works (on mock path)
Jossemand Jun 13, 2024
c792493
more work on the feedbackLoop
Holmst33n Jun 13, 2024
0899ee4
Merge branch 'feedbackLoop' of https://github.com/CDIO-gr-17/GolfBot …
Holmst33n Jun 13, 2024
9dc4454
Small printout fixes
Holmst33n Jun 13, 2024
686f831
Kill me please
Jossemand Jun 13, 2024
9ab2331
Merge remote-tracking branch 'origin/development' into feedbackLoop
Holmst33n Jun 13, 2024
4d3940f
feedback loop changes
Holmst33n Jun 13, 2024
dcec71c
Calculation of heading, now works
Holmst33n Jun 13, 2024
ad40f37
Fixed heading +-45
Jakob-SA Jun 13, 2024
104c317
small changes to inbuild waits
Holmst33n Jun 13, 2024
c7142ba
kill me a bit less now
Jossemand Jun 13, 2024
6ed2964
Works on testing with mock data when driving both up down and diagonal
Jossemand Jun 13, 2024
c286736
Small stability changes
Holmst33n Jun 14, 2024
3899512
Merge branch 'feedbackLoop' into continuousMovement
Jossemand Jun 14, 2024
5bc91c0
ability to load and optionally use calibration in getmasksfromcamera
PhilipMF Jun 14, 2024
65e4a93
added hsvcolorpicker
PhilipMF Jun 17, 2024
4bc0838
Work done on navigation and heading.
Holmst33n Jun 17, 2024
81ca115
adjusted color ranges for computer vision
PhilipMF Jun 17, 2024
2c70bf1
Merge branch 'feedbackLoop' of https://github.com/CDIO-gr-17/GolfBot …
Holmst33n Jun 17, 2024
5bea193
Merge branch 'feedbackLoop' of https://github.com/CDIO-gr-17/GolfBot …
PhilipMF Jun 17, 2024
48890f6
color pickup correction
Holmst33n Jun 17, 2024
213b923
Merge branch 'feedbackLoop' of https://github.com/CDIO-gr-17/GolfBot …
Holmst33n Jun 17, 2024
b22e3f1
Navigation now works with regards to logic
Holmst33n Jun 17, 2024
bc3cb99
Changed implementation of calibration to not take parameters
PhilipMF Jun 17, 2024
6120855
Merge branch 'feedbackLoop' into cameraCalibration
PhilipMF Jun 17, 2024
6022e35
Edited the masks and removed calibration due to import issue
PhilipMF Jun 17, 2024
9aebed3
changed resolution to 320x180
PhilipMF Jun 17, 2024
56c8e59
Changes small things in feedback feedbackLoop
Holmst33n Jun 17, 2024
309cabc
Merge branch 'feedbackLoop' of https://github.com/CDIO-gr-17/GolfBot …
Holmst33n Jun 17, 2024
6f8d6d3
deleted unused .jpg
Holmst33n Jun 17, 2024
239fc53
The feedback loop, now comunicates with the robot, controlling it's h…
Holmst33n Jun 18, 2024
8d6386f
Coffee break. Good way
Jakob-SA Jun 18, 2024
b3afde6
Get grid function changed
Jakob-SA Jun 18, 2024
87fefea
Threads should be working. Imports need fixing
Jakob-SA Jun 18, 2024
94cb0d7
Before checkout
Jakob-SA Jun 18, 2024
6213114
Started on refactor all uses of positions
Jakob-SA Jun 18, 2024
f69b541
Underway with new implementation of CV with THREADS
Jakob-SA Jun 18, 2024
1eedad1
To Philip
Jakob-SA Jun 18, 2024
1583180
Heading updates as it should
Jakob-SA Jun 18, 2024
3febba7
Minor adjustments and comments
Jakob-SA Jun 18, 2024
247996c
To PHILIP
Jakob-SA Jun 18, 2024
65c666d
resolutions of big and small frame should be fixed
PhilipMF Jun 18, 2024
33e17d3
Robot pos is printed
Jakob-SA Jun 18, 2024
22bd984
Deleted unused file
Jakob-SA Jun 18, 2024
7ef3363
Renaming in Computermain
Jakob-SA Jun 19, 2024
4942bf2
Linting and naming adjustments
Jakob-SA Jun 19, 2024
f1d47d2
Changes to the feedback loop
Holmst33n Jun 20, 2024
2552564
Now removing bright spots on the course due to sun
Jakob-SA Jun 20, 2024
132fabf
Added comment
Jakob-SA Jun 20, 2024
b8a2bba
The robot now pick ups a ball, if cirsumstances allow
Holmst33n Jun 21, 2024
800f9b6
Merge branch 'CV-remake' of https://github.com/CDIO-gr-17/GolfBot int…
Holmst33n Jun 21, 2024
ba1da6e
changes to make pickup take effect
Holmst33n Jun 21, 2024
ce3b14f
Here work will be done to integrate the solution
Holmst33n Jun 21, 2024
82b53ed
adjustsments to navigation and pickup
Holmst33n Jun 21, 2024
ec792f0
Added function to sort balls by closest distance to robot
PhilipMF Jun 21, 2024
dd3eee5
Adjusted parameters
Jakob-SA Jun 21, 2024
c45d23d
Another parameter
Jakob-SA Jun 21, 2024
93fe4b6
New change
Jakob-SA Jun 21, 2024
de67b11
Remove balls outside court
Jakob-SA Jun 21, 2024
db58db8
Beginning to implement goal scoring
Holmst33n Jun 21, 2024
79c671f
Merge branch 'navigation_pickup_scoring' of https://github.com/CDIO-g…
Holmst33n Jun 21, 2024
7cda23f
Finding goal coordinates and path to them should now be working and a…
Jakob-SA Jun 22, 2024
60adc05
Only detect ball clusters of a certain size
PhilipMF Jun 23, 2024
f76028d
Using flobal variables for grid size
Jakob-SA Jun 23, 2024
6ee81a5
Dilation adjusted
Jakob-SA Jun 23, 2024
b71804e
small changes to triangle detection
Holmst33n Jun 23, 2024
451649e
Merge remote-tracking branch 'origin/development' into navigation_pic…
Holmst33n Jun 23, 2024
6a1874d
Filter by area instead of width and height
PhilipMF Jun 23, 2024
443237b
Filter by area instead of width and height
PhilipMF Jun 23, 2024
67c7042
adjusted forward movement when picking up ball
Jakob-SA Jun 23, 2024
3ec8573
Should be a fix for closing the socket correctly on error
Jakob-SA Jun 23, 2024
28c7331
a lot of stuff to deposit balls
Holmst33n Jun 23, 2024
9dfe6db
Merge branch 'development' into ballsorting
PhilipMF Jun 23, 2024
8e6ae82
Merge branch 'development' of https://github.com/CDIO-gr-17/GolfBot i…
Holmst33n Jun 23, 2024
df7dc98
closing socket when encountering an error
Holmst33n Jun 23, 2024
22c883c
Merge branch 'development' into ballsorting
PhilipMF Jun 23, 2024
4c8ce87
Implemented sorting of balls
PhilipMF Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 999
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__pycache__/
*.pyc
.venv/
*.jpg
.DS_Store
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Download and Run",
"type": "ev3devBrowser",
"request": "launch",
"program": "/home/robot/${workspaceRootFolderName}/main.py",
"program": "/home/robot/${workspaceRootFolderName}/src/on_ev3/EV3Main.py",
"interactiveTerminal": false
}
]
Expand Down
Empty file added __init__.py
Empty file.
140 changes: 140 additions & 0 deletions border_array.txt

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions calibration_matrix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
camera_matrix:
- - 37164.97931469605
- 0.0
- 638.2287694582017
- - 0.0
- 25034.419645088034
- 364.4191971665351
- - 0.0
- 0.0
- 1.0
dist_coeff:
- - 5.219524221436717
- 3.8691893079446813
- -0.24236571736516715
- 0.08563888557233278
- 0.0030729958759180345
180 changes: 180 additions & 0 deletions combined_grid.txt

Large diffs are not rendered by default.

Empty file added src/__init__.py
Empty file.
134 changes: 134 additions & 0 deletions src/on_computer/CameraCalibration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
from cv2.gapi import video
import numpy as np
import cv2
import glob
import pathlib
import yaml

x = 1280
y = 720
resolution = (x, y)

def get_calibration_data(filename="calibration_matrix.yaml"):
with open(filename, "r") as f:
data = yaml.safe_load(f)
return np.array(data['camera_matrix']), np.array(data['dist_coeff'])

def capture_calibration_images():
no_of_calibration_images = 20

video_capture = cv2.VideoCapture(1, cv2.CAP_DSHOW) #Open camera WINDOWS OS
#video_capture = cv.VideoCapture(0) #Open camera MAC OS

path = 'images'
pathlib.Path(path).mkdir(parents=True, exist_ok=True)

i = 0
while i < no_of_calibration_images:
ret, frame = video_capture.read()
frame = cv2.resize(frame, resolution, interpolation=cv2.INTER_NEAREST)
cv2.imshow('capture calibration image - "q" to capture', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
cv2.imwrite(path + '/calib' + str(i) + '.jpg', frame)
print("Image " + str(i) + " saved")
i += 1

video_capture.release()
cv2.destroyAllWindows()

def calibrate_camera():
chessboardCorners = (6, 9)

# Define the size of the squares in the chessboard, in meters
squaresize = 0.05 # 2.3 cm = 0.023 m

# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((chessboardCorners[0]*chessboardCorners[1],3), np.float32)
objp[:,:2] = np.mgrid[0:chessboardCorners[0],0:chessboardCorners[1]].T.reshape(-1,2)
objp = objp * squaresize # Multiply by the size of the squares to get the actual dimensions
# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.

images = glob.glob(r'images/*.jpg')
print(f'Found {len(images)} images.')

# path = 'results'
# pathlib.Path(path).mkdir(parents=True, exist_ok=True)

found = 0
for fname in images:
img = cv2.imread(fname) # Capture frame-by-frame
#print(images[im_i])
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.resize(img, resolution, interpolation=cv2.INTER_NEAREST)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, chessboardCorners, None)
# If found, add object points, image points (after refining them)
if ret == True:
print('Found corners in image', fname)
objpoints.append(objp) # Certainly, every loop objp is the same, in 3D.
corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
imgpoints.append(corners2)
# Draw and display the corners
img = cv2.drawChessboardCorners(img, chessboardCorners, corners2, ret)
found += 1
cv2.imshow('img', img)
cv2.waitKey(500)
# if you want to save images with detected corners
# uncomment following 2 lines and lines 5, 18 and 19
# image_name = path + '/calibresult' + str(found) + '.png'
# cv2.imwrite(image_name, img)
else:
print('Corners not found in image', fname)

print("Number of images used for calibration: ", found)

# When everything done, release the capture
# cap.release()
cv2.destroyAllWindows()

# calibration
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)

cap = cv2.VideoCapture(1, cv2.CAP_DSHOW)

while True:
# Capture frame-by-frame
ret, frame = cap.read()

frame = cv2.resize(frame, resolution, interpolation=cv2.INTER_NEAREST)

# If frame is read correctly, ret is True
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break

# Undistort the frame
undistorted_frame = cv2.undistort(frame, mtx, dist, None, mtx)

# Display the resulting frame
cv2.imshow('Undistorted Video Capture - "q" to close', undistorted_frame)

# Break the loop on 'q' key press
if cv2.waitKey(1) == ord('q'):
break

# After the loop release the cap object
cap.release()
# Destroy all the windows
cv2.destroyAllWindows()


# transform the matrix and distortion coefficients to writable lists
data = {'camera_matrix': np.asarray(mtx).tolist(),
'dist_coeff': np.asarray(dist).tolist()}

# and save it to a file
with open("calibration_matrix.yaml", "w") as f:
yaml.dump(data, f)

#capture_calibration_images()
calibrate_camera()
142 changes: 126 additions & 16 deletions src/on_computer/ComputerMain.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,134 @@
import socket
import PathfindingAlgorithm
from PathfindingAlgorithm import grid, start, end, Node
import copy
import json
import socket
import threading
import time

import Globals as G

from pathfinding.feedback import is_robot_position_correct
from pathfinding.PathfindingAlgorithm import a_star
from positions.Positions import find_start_node, find_first_ball, sort_balls_by_distance
from computer_vision.Camera import capture_frames
from computer_vision.ComputerVision import update_positions
from helpers.end_of_path_pickup import distance_between
from helpers.get_path_to_goal import get_path_to_goal
from pathfinding.PathfindingAlgorithm import a_star
from pathfinding.feedback import is_robot_position_correct
from positions.Positions import find_first_ball, find_start_node
from positions.Robot_direction import calculate_heading



# Assign thread to capture continous frames
threading.Thread(target=capture_frames).start()


while G.BIG_FRAME is None or G.SMALL_FRAME is None:
time.sleep(0.2)

# Assign thread to update positions using CV
threading.Thread(target=update_positions).start()

# We are in danger of going on old data cause we dont check if a new position,
# is found in pictures. Dont really know if it is a problem,
# shouldnt be if recognition is good enough
while G.ROBOT_POSITION is None or G.ROBOT_HEADING is None or G.GRID is None or G.BALLS is None:
print('Heading: ', G.ROBOT_HEADING)
print('The robot position: ', G.ROBOT_POSITION)
print('The ball position: ', G.BALLS)
time.sleep(0.2)

# Creates a socket object, and established a connection to the robot
socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
HOST = "192.168.8.111"
PORT = 9999
client_socket.connect((HOST, PORT))

print(G.ROBOT_POSITION, G.ROBOT_HEADING, G.BALLS[0])
end_node = G.GRID[G.BALLS[0][1]][G.BALLS[0][0]] #Is it possible to do this?


balls_picked_up = 0

while True:
# If statement for depositing the balls in goal
if balls_picked_up == 3:
client_socket.send('GOAL'.encode('utf-8'))
goal_path = get_path_to_goal()
to_goal_start_node = goal_path[0]
if goal_path is None:
print('The algorithm could not find a path to the goal')
time.sleep(5)
else:
path_as_tuples = [(node.x, node.y) for node in goal_path]
print(path_as_tuples)
path_as_json = json.dumps(path_as_tuples)
json_length = len(path_as_json)
client_socket.send(json_length.to_bytes(4, 'big'))
client_socket.send(path_as_json.encode('utf-8'))
balls_picked_up = 0
while is_robot_position_correct(G.ROBOT_HEADING, goal_path, to_goal_start_node):
client_socket.send('KEEP'.encode('utf-8'))
time.sleep(1)
to_goal_start_node = find_start_node()
print('attempting to stop robot')
for i in range(10):
client_socket.send('STOP'.encode('utf-8'))
response = client_socket.recv(7).decode('utf-8').strip()

# If statement for picking up balls
elif distance_between(G.ROBOT_POSITION, (end_node.x, end_node.y)) < 50:
if G.BALLS is not None:
heading_to_ball = calculate_heading(G.ROBOT_POSITION, G.BALLS[0])
distance = distance_between(G.ROBOT_POSITION, G.BALLS[0])
client_socket.send('PICK'.encode('utf-8'))
client_socket.send(str(distance).encode('utf-8'))
client_socket.send(str(int(heading_to_ball)).encode('utf-8'))
client_socket.send(str(int(G.ROBOT_HEADING)).encode('utf-8'))
response = client_socket.recv(7).decode('utf-8').strip()
balls_picked_up += 1
end_node = G.GRID[G.BALLS[0][1]][G.BALLS[0][0]] # We make sure the robot is going to the next ball

# The robot will follow a path to the first ball in G.BALLS
if balls_picked_up != 3:
client_socket.send('PATH'.encode('utf-8'))

start_node = find_start_node() # Function for diffing the calculated robot position with the camera robot position

if G.ROBOT_HEADING is None:
print('ERROR: No heading calcultated')
else:
heading_as_string = str(int(G.ROBOT_HEADING))
client_socket.send(heading_as_string.encode('utf-8'))
print('Heading send')

host = "192.168.8.111"
port = 9999
grid_copy = copy.deepcopy(G.GRID)
end_node_copy = grid_copy[end_node.y][end_node.x]
start_node_copy = grid_copy[start_node.y][start_node.x]
path = a_star(grid_copy, start_node_copy, end_node_copy)

socket.connect((host, port))
if path is None:
print('The algorithm could not find a path')
else:
print('Path: OK')
path_as_touples = [(node.x, node.y) for node in path[:-5]]
path_as_json = json.dumps(path_as_touples)
json_length = len(path_as_json)
client_socket.send(json_length.to_bytes(4, 'big'))
client_socket.send(path_as_json.encode('utf-8'))

# Send the path to the robot
path = PathfindingAlgorithm.a_star(grid, start, end)
path_as_dictionaries = [{'x': node.x, 'y': node.y} for node in path]
path_as_json = json.dumps(path_as_dictionaries)
while is_robot_position_correct(G.ROBOT_HEADING, path, start_node):
client_socket.send('KEEP'.encode('utf-8'))
time.sleep(1)
start_node = find_start_node()
if (distance_between(G.ROBOT_POSITION, (end_node.x, end_node.y)) < 50):
break

command = 'PATH'
socket.send(command.encode('utf-8'))
socket.send(path_as_json.encode('utf-8'))
# Send the stop command to the robot
print('attempting to stop robot')
for i in range(10):
client_socket.send('STOP'.encode('utf-8'))

# Close the connection
socket.close()
response = client_socket.recv(7).decode('utf-8').strip()
print(response)
8 changes: 8 additions & 0 deletions src/on_computer/Globals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BIG_FRAME = None
SMALL_FRAME = None

ROBOT_POSITION = None
ROBOT_HEADING = None
GRID_DATA = None
GRID = None
BALLS = None
56 changes: 0 additions & 56 deletions src/on_computer/computer_vision/Algorithms.py

This file was deleted.

Loading