-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
194 lines (149 loc) · 7.4 KB
/
config.py
File metadata and controls
194 lines (149 loc) · 7.4 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# --- UI/Debug ---
VERBOSE = 1
USE_MINDSTORMS = True
# --- Camera Configuration ---
IP_ADDRESS = "192.168.xxx.xxx" # Your phone's IP address
PORT = "8080" # The port from the IP Webcam app
# Request Timeouts (in seconds)
REQUEST_TIMEOUT = 1 # General requests like getting a frame or status
PICTURE_TIMEOUT = 2 # Downloading the full 4K image
# --- File Paths and Folders ---
# Folders to store captured images
PUZZLE_PICTURES_FOLDER = "images/puzzle"
PIECE_PICTURES_FOLDER = "images/puzzle_pieces"
RECOVERY_FOLDER = "recovery"
WARP_MATRIX_PATH = "calibration/warp_matrix.npz"
SAVE_IMAGES_FOR_DEBUG = True
SAVE_CORNERS_DEBUG = True
SAVE_SIDES_DEBUG = True
SAVE_NORMALIZED_SIDES_PLOT_DEBUG = True
# --- EV3 Configuration ---
# EV3 Bluetooth Addresses
EV3_TOP_ADDRESS = "XX:XX:XX:XX:XX:XX"
EV3_BOTTOM_ADDRESS = "XX:XX:XX:XX:XX:XX"
# EV3 Movement Speeds in percent (5 - 100)
MOTOR_SPEED_X = 100
MOTOR_SPEED_Y = 100
MOTOR_SPEED_Z = 40
MOTOR_SPEED_ROTATE = 30
MOTOR_SPEED_SUCTION = 50
# Speed multiplier for calibration movements for X, Y and Z
MOTOR_SPEED_XYZ_CALIBRATION_MULTIPLIER = 0.1
# Y-axis breaking distance for custom deceleration profile (in degrees)
BRAKING_DISTANCE_DEGREES = 400
# Motor directions (1 for forward, -1 for reverse)
MOTOR_DIRECTION_X = -1
MOTOR_DIRECTION_Y = 1
MOTOR_DIRECTION_Z = 1
MOTOR_DIRECTION_ROTATE = -1
# Conversion factors for movement in mm to motor degrees
MM_PER_MOTOR_DEGREE_X = 4/75
MM_PER_MOTOR_DEGREE_Y = 32/675
# Conversion factor for rotation in degrees to motor degrees
MOTOR_DEGREES_PER_ROTATION_DEGREE = 7/5
# Slack compensation for X and Y axes (in mm)
X_SLACK_MM = 0.0
Y_SLACK_MM = 0.0
# Suction action parameters (degrees of rotation)
SUCTION_RELEASE_ANGLE = 0
SUCTION_ENGAGE_ANGLE = 180
# Percentage of the initial color sensor reflection reading to consider touching the bed
COLOR_SENSOR_THRESHOLD = 0.5
# Z positions in degrees
Z_UP_POSITION_DEGREES = 562
Z_SEMI_DOWN_POSITION_DEGREES = 500 # Slightly lower than up, to preven overrunning the motor when calibrating
Z_DOWN_POSITION_DEGREES = 200 # On the piece
Z_WIGGLE_POSITION_DEGREES = 400 # Low, but not quite pushing the sensor during a failed attempt to place
# Threshold for successful placement (in degrees)
# Below this target (smaller) is successful placement in case of 0 sag compensation
Z_PLACE_SUCCESS_THRESHOLD_DEGREES = 120
# X-Frame Sag Compensation
# The maximum measured sag of the X-axis, measured in Z-motor degrees (using determine_z_pos.py).
# This value is used to calculate a compensation spline.
Z_SAG_COMPENSATION_LEFT = 0
Z_SAG_COMPENSATION_CENTER = 25
Z_SAG_COMPENSATION_RIGHT = -10
# --- Scanning and Workspace Areas (Global origin is top left of the bed) ---
# Staging area location
STAGING_AREA_X_MIN_MM = 8.0
STAGING_AREA_Y_MIN_MM = 0.0
STAGING_AREA_X_MAX_MM = 280.0
STAGING_AREA_Y_MAX_MM = 352.0
# Solution area min and max positions for building the puzzle (Top left corner of the puzzle and bottom right corner of the puzzle)
SOLUTION_AREA_X_MIN_MM = 16.0
SOLUTION_AREA_Y_MIN_MM = 360.0
SOLUTION_AREA_X_MAX_MM = 272.0
SOLUTION_AREA_Y_MAX_MM = 552.0
# Reachable space of the motors in mm (min is the origin of the motors)
WORKSPACE_X_MIN_MM = 12.5
WORKSPACE_Y_MIN_MM = -54.5
WORKSPACE_X_MAX_MM = 275.5
WORKSPACE_Y_MAX_MM = 548.0
# Distance from the principal point of the camera to the bed in mm
CAMERA_DISTANCE_MM = 311.0 # (308mm from bed to phone, Principal point for my phone is an estimated 3mm deep.)
# Suction cup diameter for visualization in mm
SUCTION_CUP_DIAMETER_MM = 7.0
# --- Image Processing Parameters ---
PIECE_BRIGHTNESS_THRESHOLD = 80 # For simple black/white puzzles on contrasting background
MIN_PIECE_AREA = 30000 # Minimum pixel area to be considered a piece
EROSION_AMOUNT = 2 # Number of pixels to erode the image and dilate again to get rid of noise
# --- Side Removal Parameters ---
TANGENT_K = 10 # The distance along the contour to look for calculating the tangent.
MAX_CORRECTION_MAGNITUDE = 16 # How many pixels inward to "shave" the corrected points.
DILATION_AMOUNT = 1 # Number of pixels to dilate the image and erode again to sharpen corners
# --- Corner Detection & Scoring ---
# Step 2: Approximate Corner Finding
APPROX_DP_EPSILON_FACTOR = 0.009
# Step 3: Idealized Corner Calculation & Filtering
# The range of points away from the corner to use for line extrapolation.
# We fit a line to the contour points between `START` and `END` points away from the approximate corner to find the "true" direction of the edge.
# Used to sharpen corners that got rounded by previous processing.
CORNER_EXTRAPOLATE_START_PTS = 6
CORNER_EXTRAPOLATE_END_PTS = 14
# The hard filter for corner angles. Any corner candidate whose angle is outside this range (in degrees) will be instantly discarded.
MIN_CORNER_ANGLE_DEG = 40.0
MAX_CORNER_ANGLE_DEG = 160.0
# Step 4: Final Corner Set Selection
CORNER_SELECTION_CANDIDATES = 14 # How many corner candidates to consider for the final selection.
TARGET_ASPECT_RATIO = 4.0 / 3.0 # The target aspect ratio for the puzzle pieces.
# Scoring Weights for the Final Corner Selection
# Main scoring
# How important it is how well the four corners' bisectors point towards the piece's global centroid.
# This score is determined by the two worst-aligned corners (the "weakest links").
BISECTOR_ALIGNMENT_WEIGHT = 22.0
# Tie breakers
# How important it is that the shape is a convex rectangle.
FIT_SCORE_WEIGHT = 3.0
# How important it is how symmetrically the four corners are placed around their own center.
# Also uses the "weakest link" principle.
SYMMETRY_WEIGHT = 9.0
# How important it is how well the rectangle's aspect ratio matches the target.
ASPECT_RATIO_WEIGHT = 3.0
# How important using sharper corners is.
SHARPNESS_SCORE_WEIGHT = 3.5
# Defines the angle (in degrees) at which the alignment score becomes zero.
ALIGNMENT_MAX_ANGLE_DEG = 90.0
# Defines the angle that must be the minimum difference between any two bisects of the 4 corners.
MIN_BISECTOR_ANGLE_DEG = 45.0
# Step 6: Side Extraction
# The maximum deviation from an ideal straight edge to be considered a straight edge.
STRAIGHT_EDGE_THRESH = 15.0
# For simplifying the splines to avoid weird spline fitting outliers.
CONTOUR_SUBSAMPLING_STEP = 4
SPLINE_SMOOTHNESS = 0.0
# Debug output options
ANGLE_DEFINITION_RADIUS = 25.0 # Length of the lines used to visualize bisectors and angles in debug output
# --- Puzzle Solver Parameters ---
# Puzzle dimensions
PUZZLE_WIDTH = 10
PUZZLE_HEIGHT = 10
# The number of best-matching candidates to store for each side.
# This defines the search space for the final solver.
MAX_CANDIDATES_PER_SIDE = 30
# The following parameters, I just set to a very high value to practically ensure I would get a solution, just slightly slower.
# Phase 1: Placing the border where uncertainty is high
EARLY_PHASE_STEPS = 36 # How many pieces to place using the wider beam.
# Adjust this based on puzzle size (e.g., (W+H-2)*2 for the whole border)
EARLY_BEAM_WIDTH = 2000 # A much wider beam to explore diverse border options.
# Phase 2: Filling the center where constraints are stronger
NORMAL_BEAM_WIDTH = 1000 # The standard beam width for the rest of the puzzle.