From 2a16634903cb0fedf253a67c25690e3467e721b4 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Wed, 13 Nov 2024 18:02:16 +0100 Subject: [PATCH] Fixed mirror error which came up because of the Qdoublespinbox --- .../bitbots_animation_rqt/record_ui.py | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/bitbots_motion/bitbots_animation_rqt/bitbots_animation_rqt/record_ui.py b/bitbots_motion/bitbots_animation_rqt/bitbots_animation_rqt/record_ui.py index 76a7db558..3dddba344 100755 --- a/bitbots_motion/bitbots_animation_rqt/bitbots_animation_rqt/record_ui.py +++ b/bitbots_motion/bitbots_animation_rqt/bitbots_animation_rqt/record_ui.py @@ -199,8 +199,8 @@ def q_joint_state_update(self, joint_states: JointState) -> None: # Check if the we are currently positioning the motor and want to store the value if motor_active and motor_torqueless: # Update textfield - self._motor_controller_text_fields[motor_name].setText( - str(round(math.degrees(joint_states.position[joint_states.name.index(motor_name)]), 2)) + self._motor_controller_text_fields[motor_name].setValue( + round(math.degrees(joint_states.position[joint_states.name.index(motor_name)]), 2) ) # Update working values self._working_angles[motor_name] = joint_states.position[joint_states.name.index(motor_name)] @@ -586,21 +586,26 @@ def mirror_frame(self, source: Literal["L", "R"]) -> None: """ Copies all motor values from one side of the robot to the other. Inverts values, if necessary """ + # Get direction to mirror to mirrored_source = {"R": "L", "L": "R"}[source] # Go through all active motors for motor_name, angle in self._working_angles.items(): - # Check if the motor is on the right or left side and get the mirrored motor name + # Set mirrored angles if motor_name.startswith(source): mirrored_motor_name = mirrored_source + motor_name[1:] - if self._working_angles[motor_name] == 0.0: - self._working_angles[mirrored_motor_name] = angle - else: - self._working_angles[mirrored_motor_name] = -angle + # Make -0.0 to 0.0 + mirrored_angle = -angle if angle != 0 else 0.0 + self._working_angles[mirrored_motor_name] = mirrored_angle # Update the UI for motor_name, angle in self._working_angles.items(): + # Block signals + self._motor_controller_text_fields[motor_name].blockSignals(True) + # Set values self._motor_controller_text_fields[motor_name].setValue(round(math.degrees(angle), 2)) + # Enable signals again + self._motor_controller_text_fields[motor_name].blockSignals(False) self._widget.statusBar.showMessage("Mirrored frame") @@ -631,7 +636,12 @@ def invert_frame(self): # Update the UI for motor_name, angle in self._working_angles.items(): + # Block signals + self._motor_controller_text_fields[motor_name].blockSignals(True) + # Set values self._motor_controller_text_fields[motor_name].setValue(round(math.degrees(angle), 2)) + # Enable signals again + self._motor_controller_text_fields[motor_name].blockSignals(False) self._widget.statusBar.showMessage("Inverted frame")