2323from zividsamples .gui .marker_widget import MarkerConfiguration
2424from zividsamples .gui .pose_pair_selection_widget import PosePair , PosePairSelectionWidget , directory_has_pose_pair_data
2525from zividsamples .gui .pose_widget import PoseWidget , PoseWidgetDisplayMode
26+ from zividsamples .gui .robot_configuration import RobotConfiguration
2627from zividsamples .gui .robot_control import RobotTarget
2728from zividsamples .gui .rotation_format_configuration import RotationInformation
2829from zividsamples .gui .set_fixed_objects import FixedCalibrationObjectsData , set_fixed_objects
3334
3435class HandEyeCalibrationGUI (QWidget ):
3536 data_directory : Path
36- use_robot : bool
37+ robot_configuration : RobotConfiguration
3738 hand_eye_configuration : HandEyeConfiguration
3839 marker_configuration : MarkerConfiguration = MarkerConfiguration ()
3940 pose_pair : PosePair
@@ -51,7 +52,7 @@ class HandEyeCalibrationGUI(QWidget):
5152 def __init__ (
5253 self ,
5354 data_directory : Path ,
54- use_robot : bool ,
55+ robot_configuration : RobotConfiguration ,
5556 hand_eye_configuration : HandEyeConfiguration ,
5657 marker_configuration : MarkerConfiguration ,
5758 cv2_handler : CV2Handler ,
@@ -69,7 +70,7 @@ def __init__(
6970 ]
7071
7172 self .data_directory = data_directory
72- self .use_robot = use_robot
73+ self .robot_configuration = robot_configuration
7374 self .hand_eye_configuration = hand_eye_configuration
7475 self .marker_configuration = marker_configuration
7576 self .fixed_objects = FixedCalibrationObjectsData (
@@ -84,7 +85,6 @@ def __init__(
8485 self .update_instructions (
8586 has_detection_result = self .has_detection_result ,
8687 robot_pose_confirmed = self .has_confirmed_robot_pose ,
87- used_data = False ,
8888 calibrated = False ,
8989 )
9090
@@ -98,15 +98,14 @@ def create_widgets(self, initial_rotation_information: RotationInformation):
9898 self .robot_pose_widget .setObjectName ("HE-Calibration-robot_pose_widget" )
9999 self .confirm_robot_pose_button = QPushButton ("Confirm Robot Pose" )
100100 self .confirm_robot_pose_button .setCheckable (True )
101- self .confirm_robot_pose_button .setVisible (not self .use_robot )
101+ self .confirm_robot_pose_button .setVisible (self .robot_configuration . has_no_robot () )
102102 self .confirm_robot_pose_button .setObjectName ("HE-Calibration-confirm_robot_pose_button" )
103103 self .detection_visualization_widget = DetectionVisualizationWidget (
104104 hand_eye_configuration = self .hand_eye_configuration
105105 )
106106 self .pose_pair_selection_widget = PosePairSelectionWidget (directory = self .data_directory )
107107 self .pose_pair_selection_widget .setVisible (False )
108108 self .hand_eye_calibration_buttons = HandEyeCalibrationButtonsWidget ()
109- self .hand_eye_calibration_buttons .use_data_button .setEnabled (False )
110109 self .hand_eye_calibration_buttons .calibrate_button .setEnabled (False )
111110 self .hand_eye_calibration_buttons .setObjectName ("HE-Calibration-hand_eye_calibration_buttons" )
112111
@@ -134,24 +133,21 @@ def setup_layout(self):
134133 self .setLayout (layout )
135134
136135 def connect_signals (self ):
137- self .hand_eye_calibration_buttons .use_data_button_clicked .connect (self .on_use_data_button_clicked )
138136 self .hand_eye_calibration_buttons .calibrate_button_clicked .connect (self .on_calibrate_button_clicked )
139137 self .hand_eye_calibration_buttons .use_fixed_objects_toggled .connect (self .on_use_fixed_objects_toggled )
140138 self .confirm_robot_pose_button .clicked .connect (self .on_confirm_robot_pose_button_clicked )
141139 self .robot_pose_widget .pose_updated .connect (self .on_robot_pose_manually_updated )
142140 self .pose_pair_selection_widget .pose_pair_clicked .connect (self .on_pose_pair_clicked )
143141 self .pose_pair_selection_widget .pose_pairs_updated .connect (self .on_pose_pairs_update )
144142
145- def update_instructions (
146- self , has_detection_result : bool , robot_pose_confirmed : bool , used_data : bool , calibrated : bool
147- ):
143+ def update_instructions (self , has_detection_result : bool , robot_pose_confirmed : bool , calibrated : bool ):
148144 self .has_confirmed_robot_pose = robot_pose_confirmed
149145 self .has_detection_result = has_detection_result and self .has_confirmed_robot_pose
150146 minimum_captures_to_go = (
151147 self .minimum_pose_pairs_for_calibration - self .pose_pair_selection_widget .number_of_active_pose_pairs ()
152148 )
153149 self .instruction_steps = {}
154- if self .use_robot :
150+ if self .robot_configuration . can_control :
155151 self .instruction_steps [
156152 "Move Robot (click 'Move to next target', 'Home' or Disconnect→manually move robot→Connect)"
157153 ] = self .has_confirmed_robot_pose
@@ -161,13 +157,9 @@ def update_instructions(
161157 self .instruction_steps [f"Capture (at least { minimum_captures_to_go } more)" ] = self .has_detection_result
162158 else :
163159 self .instruction_steps ["Capture" ] = self .has_detection_result
164- self .instruction_steps ["Use data" ] = used_data
165160 if minimum_captures_to_go <= 0 :
166161 self .instruction_steps ["Calibrate" ] = calibrated
167162 self .instructions_updated .emit ()
168- self .hand_eye_calibration_buttons .use_data_button .setEnabled (
169- self .has_detection_result and self .has_confirmed_robot_pose
170- )
171163 self .confirm_robot_pose_button .setStyleSheet (
172164 "background-color: green;" if self .has_confirmed_robot_pose else ""
173165 )
@@ -189,6 +181,15 @@ def marker_configuration_update(self, marker_configuration: MarkerConfiguration)
189181 def rotation_format_update (self , rotation_format : RotationInformation ):
190182 self .robot_pose_widget .set_rotation_format (rotation_format )
191183
184+ def robot_configuration_update (self , robot_configuration : RobotConfiguration ):
185+ self .robot_configuration = robot_configuration
186+ self .confirm_robot_pose_button .setVisible (self .robot_configuration .has_no_robot ())
187+ self .update_instructions (
188+ has_detection_result = self .has_detection_result ,
189+ robot_pose_confirmed = self .has_confirmed_robot_pose ,
190+ calibrated = False ,
191+ )
192+
192193 def on_select_fixed_objects_action_triggered (self ):
193194 updated_fixed_objects = set_fixed_objects (self .fixed_objects , self .robot_pose_widget .rotation_information )
194195 if updated_fixed_objects is not None :
@@ -197,16 +198,6 @@ def on_select_fixed_objects_action_triggered(self):
197198 def toggle_advanced_view (self , checked ):
198199 self .robot_pose_widget .toggle_advanced_section (checked )
199200
200- def toggle_use_robot (self , use_robot : bool ):
201- self .use_robot = use_robot
202- self .confirm_robot_pose_button .setVisible (not self .use_robot )
203- self .update_instructions (
204- has_detection_result = self .has_detection_result ,
205- robot_pose_confirmed = self .has_confirmed_robot_pose ,
206- used_data = False ,
207- calibrated = False ,
208- )
209-
210201 def on_start_auto_run (self ) -> bool :
211202 if self .pose_pair_selection_widget .number_of_active_pose_pairs () == 0 :
212203 return True
@@ -270,22 +261,23 @@ def process_capture(self, frame: zivid.Frame, rgba: NDArray[Shape["N, M, 4"], UI
270261 detection_result = detection_result ,
271262 camera_pose = copy .deepcopy (camera_pose ),
272263 )
273- self .update_instructions (
274- has_detection_result = True ,
275- robot_pose_confirmed = self .has_confirmed_robot_pose ,
276- used_data = False ,
277- calibrated = False ,
278- )
264+ if self .has_confirmed_robot_pose :
265+ self .use_data ()
266+ else :
267+ self .update_instructions (
268+ has_detection_result = True ,
269+ robot_pose_confirmed = self .has_confirmed_robot_pose ,
270+ calibrated = False ,
271+ )
279272 except RuntimeError as ex :
280273 self .detection_visualization_widget .set_error_message (str (ex ))
281274 raise ex
282275
283- def on_use_data_button_clicked (self ):
276+ def use_data (self ):
284277 self .pose_pair_selection_widget .add_pose_pair (self .pose_pair )
285278 self .update_instructions (
286279 has_detection_result = False ,
287280 robot_pose_confirmed = False ,
288- used_data = True ,
289281 calibrated = False ,
290282 )
291283
@@ -325,7 +317,6 @@ def on_calibrate_button_clicked(self):
325317 self .update_instructions (
326318 has_detection_result = False ,
327319 robot_pose_confirmed = False ,
328- used_data = False ,
329320 calibrated = True ,
330321 )
331322 self .calibration_finished .emit (TransformationMatrix .from_matrix (hand_eye_transform ))
@@ -340,7 +331,6 @@ def confirm_robot_pose(self, confirmed: bool = True):
340331 self .update_instructions (
341332 has_detection_result = False ,
342333 robot_pose_confirmed = confirmed ,
343- used_data = False ,
344334 calibrated = False ,
345335 )
346336
0 commit comments