Skip to content

Commit

Permalink
Connected the gcode alignment system with the main program.
Browse files Browse the repository at this point in the history
Temporarily inserted a fake set of points to verify the correct application of the alignment on the gcode [will be removed later].
Linked the status of the Align Tool Button in the alignment tab with the procedure.
  • Loading branch information
MakersKlabs committed Jan 21, 2024
1 parent dfd18dc commit f1ab1cc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 67 deletions.
17 changes: 16 additions & 1 deletion src/TheAntFarm/controller/controller_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,22 @@ def get_probe_value(self):
return self.prb_val[0]

def get_align_data(self):
return self.align_data
print("GET ALIGN DATA")
# WARNING INJECTING FAKE DATA FOR TESTING PURPOSE
if not self.align_data:
print("INJECT FAKE DATA")
# FAKE DATA
fake_align_data = [
[(0, 0), (0, 0)],
[(0, 1), (-0.342020143325669, 0.939692620785908)],
[(1, 1), (0.59767247746024, 1.281712764111577)],
[(1, 0), (0.939692620785908, 0.342020143325669)],
]
self.align_data = fake_align_data
return fake_align_data
else:
print("RETURN VALID DATA")
return self.align_data

def get_abl_value(self):
return self.abl_val
Expand Down
4 changes: 2 additions & 2 deletions src/TheAntFarm/controller/controller_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,15 @@ def select_active_gcode(self, gcode_path):
logger.debug("ABL_active " + str(self.abl_apply_active))

align_data = self.control_controller.get_align_data()
logger.debug("Align_val " + str(abl_val))
logger.debug("Align_val " + str(align_data))
logger.debug("Align_active " + str(self.align_apply_active))

if align_data != [] and self.align_apply_active:
logger.debug("Apply Alignment")
self.control_controller.apply_alignment(gcode_path)
redraw_align = True
else:
logger.debug("Remove ABL")
logger.debug("Remove Alignment")
redraw_align = self.control_controller.remove_alignment(gcode_path)

if abl_val != [] and self.abl_apply_active:
Expand Down
21 changes: 18 additions & 3 deletions src/TheAntFarm/shape_core/gcode_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,14 @@ def __init__(self, lines):
self.modified_vectors = []
self.bb = None

def get_gcode_original_vectors_copy(self):
print("GCODEX")
govc = []
for p in self.original_vectors:
nwp = p.copy()
govc.append(nwp)
return govc


class GCodeParser:

Expand Down Expand Up @@ -734,8 +742,12 @@ def recode_gcode(self):
# - Modified Loaded
gcv = self.gc.modified_vectors
else:
# - Original Loaded
gcv = self.gc.original_vectors
if self.gc.aligned_vectors:
# - Aligned Loaded
gcv = self.gc.aligned_vectors
else:
# - Original Loaded
gcv = self.gc.original_vectors
gcl = self.gc.gcll
if gcv or gcl:
gcv_len = len(gcv)
Expand Down Expand Up @@ -823,7 +835,10 @@ def get_gcode_original_vectors(self):
return self.gc.original_vectors

def get_gcode_original_vectors_copy(self):
govc = [p.copy() for p in self.gc.original_vectors]
govc = []
for p in self.gc.original_vectors:
nwp = p.copy()
govc.append(nwp)
return govc

def get_gcode_vectors(self):
Expand Down
66 changes: 5 additions & 61 deletions src/TheAntFarm/ui_manager/ui_align_tab.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
from PySide2.QtCore import Signal, Slot, QObject
from PySide2.QtGui import QPixmap
from PySide2.QtWidgets import QLabel
import logging
import math

logger = logging.getLogger(__name__)


class UiAlignTab(QObject):
"""Class dedicated to UI <--> Control interactions on Align Tab. """
align_active_s = Signal(bool)
align_apply_s = Signal(bool, list)
align_apply_s = Signal(bool)
update_threshold_s = Signal(int)

def __init__(self, ui, control_worker):
super(UiAlignTab, self).__init__()
self.ui = ui
self.controlWo = control_worker
self.align_applied = False

# Align TAB related controls.
self.ui.main_tab_widget.currentChanged.connect(self.check_align_is_active)
self.align_active_s.connect(self.controlWo.set_align_is_active)
self.align_apply_s.connect(self.controlWo.set_align_active)
self.align_apply_s.connect(lambda align_active_bool: self.controlWo.set_align_active(align_active_bool))
self.ui.apply_alignment_tb.clicked.connect(self.apply_align)
self.ui.add_point_tb.clicked.connect(self.add_new_point)
self.ui.remove_point_tb.clicked.connect(self.remove_point)
self.ui.contrast_slider.valueChanged.connect(self.update_threshold)
self.update_threshold_s.connect(self.controlWo.update_threshold_value)

Expand All @@ -49,62 +46,9 @@ def update_camera_list(self, camera_list):
for cam in camera_list:
self.ui.camera_list_cb.addItem(str(cam))

def update_ui_alignment_applied(self, alignment_applied_flag=False):
if alignment_applied_flag:
self.ui.led_la.set_led_color("blue")
self.ui.led_la.setToolTip("Alignment Applied!")
self.ui.alignment_led_la.set_led_color("blue")
self.ui.alignment_led_la.setToolTip("Alignment Applied!")
else:
self.ui.led_la.set_led_color("grey")
self.ui.led_la.setToolTip("Alignment not applied")
self.ui.alignment_led_la.set_led_color("grey")
self.ui.alignment_led_la.setToolTip("Alignment not applied")

def apply_align(self):
alignment_points = list()
num_rows = self.ui.align_points_tw.rowCount()
align_to_be_applied_flag = self.ui.apply_alignment_tb.isChecked() and (num_rows >= 2)
# Grab alignment points only if apply alignment button is checked
if align_to_be_applied_flag:
self.update_ui_alignment_applied(True)
for r in range(0, num_rows):
x_base = float(self.ui.align_points_tw.cellWidget(r, 0).text())
y_base = float(self.ui.align_points_tw.cellWidget(r, 1).text())
x_offs = float(self.ui.align_points_tw.cellWidget(r, 2).text())
y_offs = float(self.ui.align_points_tw.cellWidget(r, 3).text())
points_l = [(x_base, y_base), (x_offs, y_offs)]
alignment_points.append(points_l)
else:
self.update_ui_alignment_applied(False)

self.align_apply_s.emit(align_to_be_applied_flag, alignment_points)

def add_new_point(self):
x_val = self.ui.x_point_layer_dsb.value()
y_val = self.ui.y_point_layer_dsb.value()
offset_val = self.ui.distance_offset_dsb.value()
angle_val = self.ui.angle_dsb.value()

new_x_val = x_val + (offset_val * math.cos(math.radians(angle_val)))
new_y_val = y_val + (offset_val * math.sin(math.radians(angle_val)))

num_rows = self.ui.align_points_tw.rowCount()
self.ui.align_points_tw.insertRow(num_rows)
self.ui.align_points_tw.setCellWidget(num_rows, 0, QLabel("{:.3f}".format(x_val)))
self.ui.align_points_tw.setCellWidget(num_rows, 1, QLabel("{:.3f}".format(y_val)))
self.ui.align_points_tw.setCellWidget(num_rows, 2, QLabel("{:.3f}".format(new_x_val)))
self.ui.align_points_tw.setCellWidget(num_rows, 3, QLabel("{:.3f}".format(new_y_val)))
self.apply_align()

def remove_point(self):
selection_model = self.ui.align_points_tw.selectionModel()
selected_rows = selection_model.selectedRows()
selected_rows.sort()
for r in selected_rows[::-1]:
self.ui.align_points_tw.removeRow(r.row())
self.ui.align_points_tw.clearSelection()
self.apply_align()
align_activated = not self.ui.apply_alignment_tb.isChecked()
self.align_apply_s.emit(align_activated)


if __name__ == "__main__":
Expand Down

0 comments on commit f1ab1cc

Please sign in to comment.