-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaceMain.py
More file actions
97 lines (71 loc) · 3.8 KB
/
interfaceMain.py
File metadata and controls
97 lines (71 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import os
import sys
from dotenv import load_dotenv
# Check openCV version
import cv2
print(cv2.__version__)
# Local python script imports
import subModules.hardwareInterface.cameraConfig as cameraConfig
import subModules.hardwareInterface.roborockInterface as roborockInterface
import subModules.hardwareInterface.roborockHighResInterface as roborockHighResInterface
import subModules.hardwareInterface.controlRoborock as controlRoborock
import subModules.printParsers.roborockGcodeParser as roborockGcodeParser
import subModules.robotState.robotGlobalState as robotGlobalState
from subModules.printParsers.roborockGcodeParser import pathObjRepresentation
# Main script that handles the MobiPrint computer vision based printing pipeline
# For convience aruco markers are generated by this git project https://fodi.github.io/arucosheetgen/
# and printed out to be placed on the floor for reference
if __name__ == "__main__":
performingAPICalls = True
headlessRun = False
# Check flags
if len(sys.argv) > 1:
if '-d' in sys.argv:
performingAPICalls = False
print(performingAPICalls)
# For headless runs where open cv will not open the camera
if '-h' in sys.argv:
headlessRun = True
# FOR TESTING!
# Generate path, should be stored in another folder. This should be essentially the middleware
# representation between the slicing functionality of this project and the roborock control side
# WILL NORMALLY BE NOT MANUALLY SUPPLIED FORM ANOTHER FILE AND INSTEAD PASSED THROUGH METHOD
pathObjVectorRef = None
if not isinstance(pathObjVectorRef, pathObjRepresentation):
raise ValueError("pathObject is invalid object type!")
# Loads the dotenv
load_dotenv()
# Side length of the ArUco marker in meters
# Generally aruco markers that are widht/length 50 < work the best as smaller aruco markers
# as smaller aruco markers are harder to detect
aruco_marker_side_length = 0.054
# Below are variables that must be assigned upon moving the roborock between networks
# or if a different one is used or if you are setting up this project for the first time
# they are typically set in the .env file that you will have to create via
# touch .env
# each element is assigned in the env file like this: API_KEY=your-secret-api-key-here
# Roborock API key so that git stops complaining
api_key = str(os.getenv("API_KEY"))
IP_ADDRESS = str(os.getenv("IP_ADDRESS"))
if api_key == None or IP_ADDRESS == None:
print(f"ERROR: .env file has not been properly created, or api key/ ip address has not been added to .env file")
exit
robotGlobalStateRef = robotGlobalState.robotGlobalState(IP_ADDRESS=IP_ADDRESS,
API_KEY=api_key,
headlessRunStatus=headlessRun,
performingAPICalls=performingAPICalls,
aruco_marker_side_length=aruco_marker_side_length)
# Create interfaces, these objects hold wrapper functions for handling API calls and other complicated functionality
localRoborockInterface = roborockHighResInterface.roborockHighResInterface(IP_ADDRESS, api_key)
# Intiate manual control
robotGlobalStateRef.initiateRobotSubsystems()
# THIS IS WHERE THE MAIN ROBOT CODE WILL BE RUN
rGcodeParserRef = roborockGcodeParser.roborockGcodeParser(robotGlobalStateRef=robotGlobalStateRef)
# Parse gcode instructions generatd by user or the MobiPrint slicer
# if performingAPICalls:
# localRoborockInterface.disableHighResManualControl()
robotGlobalStateRef.stopRobotSubsystems()
cv2.destroyAllWindows()
# For testing
def createTestingPath() -> pathObjRepresentation:
pass