Skip to content

Commit

Permalink
Remove mode selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Flova committed Feb 11, 2024
1 parent bbdaae7 commit f78aefd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ def __init__(self, context):
self._motor_check_right_leg = QTreeWidgetItem(self._motor_check_legs)

# Save configuration of the trees checkboxes for each of the tree modes
self._check_boxes_save = {}
self._check_boxes_power = defaultdict(dict)
self._motors_active: dict[dict[str, int]] = {}
self._motors_torque: dict[dict[str, bool]] = defaultdict(dict)

# Create drag and dop list for keyframes
self._widget.frameList = DragDropList(self._widget, self)
Expand Down Expand Up @@ -139,7 +139,7 @@ def __init__(self, context):
self._current_goals[k] = self._initial_joints.position[i]
self._working_values[k] = self._initial_joints.position[i]
self._motor_switched[k] = True
self._check_boxes_power["#CURRENT_FRAME"][k] = 2
self._motors_torque["#CURRENT_FRAME"][k] = 2

# Create GUI components
self.create_motor_controller()
Expand Down Expand Up @@ -282,7 +282,7 @@ def save(self):
# QFileDialogue throws a gtk warning, that can not be suppressed or fixed. Should be ignored.
self._save_directory = QFileDialog.getExistingDirectory()
status = self._recorder.save_animation(
self._save_directory, self._widget.lineAnimationName.text(), self._check_boxes_save
self._save_directory, self._widget.lineAnimationName.text(), self._motors_active
)
self._widget.statusBar.showMessage(status)
else:
Expand All @@ -297,7 +297,7 @@ def save_as(self):
self.tree_mode_changed(self._previous_tree_mode)
self._save_directory = QFileDialog.getExistingDirectory()
self._recorder.save_animation(
self._save_directory, self._widget.lineAnimationName.text(), self._check_boxes_save
self._save_directory, self._widget.lineAnimationName.text(), self._motors_active
)
else:
self._widget.statusBar.showMessage("There is nothing to save!")
Expand Down Expand Up @@ -333,11 +333,11 @@ def open(self):
animstate = self._recorder.get_animation_state()
for i in animstate:
try:
self._check_boxes_power[i["name"]] = i["torque"]
self._motors_torque[i["name"]] = i["torque"]
except KeyError:
self._check_boxes_power[i["name"]] = {}
self._motors_torque[i["name"]] = {}
for key in self.ids:
self._check_boxes_power[i["name"]][key] = 2
self._motors_torque[i["name"]][key] = 2

self.update_frames()

Expand Down Expand Up @@ -389,7 +389,7 @@ def goto_frame(self):
torque_msg.joint_names = []
torque_msg.on = []

for k, v in self._check_boxes_power[self._widget.frameList.currentItem().text()].items():
for k, v in self._motors_torque[self._widget.frameList.currentItem().text()].items():
torque_msg.joint_names.append(k)
torque_msg.on.append(v)

Expand Down Expand Up @@ -495,12 +495,12 @@ def record(self, keep=False):

self.set_sliders_and_text_fields(manual=True)

self._check_boxes_power[self._working_name] = {}
self._motors_torque[self._working_name] = {}
init_torque = {}
for k, _v in self._working_values.items():
init_torque[k] = 2

self._check_boxes_power[self._working_name] = init_torque
self._motors_torque[self._working_name] = init_torque

self._recorder.record(
self._working_values,
Expand All @@ -515,7 +515,7 @@ def record(self, keep=False):

self._recorder.record(
self._working_values,
self._check_boxes_power[self._widget.frameList.currentItem().text()],
self._motors_torque[self._widget.frameList.currentItem().text()],
self._widget.lineFrameName.text(),
self._widget.spinBoxDuration.value(),
self._widget.spinBoxPause.value(),
Expand Down Expand Up @@ -557,9 +557,9 @@ def mirror_frame(self, direction):

boxmode = 0
if self._widget.treeModeSelector.currentIndex() == 0:
boxmode = self._check_boxes_power[self._widget.frameList.currentItem().text()]
boxmode = self._motors_torque[self._widget.frameList.currentItem().text()]
elif self._widget.treeModeSelector.currentIndex() == 1:
boxmode = self._check_boxes_save[self._widget.frameList.currentItem().text()]
boxmode = self._motors_active[self._widget.frameList.currentItem().text()]

for k in boxmode.keys():
if k[0] == opposite:
Expand Down Expand Up @@ -590,9 +590,9 @@ def invert_frame(self):

boxmode = 0
if self._widget.treeModeSelector.currentIndex() == 0:
boxmode = self._check_boxes_power
boxmode = self._motors_torque
elif self._widget.treeModeSelector.currentIndex() == 1:
boxmode = self._check_boxes_save
boxmode = self._motors_active

for k, v in boxmode[self._widget.frameList.currentItem().text()].items():
if k[0] == "L":
Expand Down Expand Up @@ -763,9 +763,9 @@ def copy_old_tree_config(self):
temp_dict[k] = self._treeItems[k].checkState(0)

if self._previous_tree_mode == 1:
self._check_boxes_save[self._selected_frame["name"]] = deepcopy(temp_dict)
self._motors_active[self._selected_frame["name"]] = deepcopy(temp_dict)
elif self._previous_tree_mode == 0:
self._check_boxes_power[self._selected_frame["name"]] = deepcopy(temp_dict)
self._motors_torque[self._selected_frame["name"]] = deepcopy(temp_dict)

def update_tree_config(self, index):
"""
Expand All @@ -775,14 +775,14 @@ def update_tree_config(self, index):
if self._widget.frameList.currentItem() is not None:
if not self._widget.frameList.currentItem().text() == "#CURRENT_FRAME":
if index == 1:
if self._selected_frame["name"] in self._check_boxes_save.keys():
temp_dict_2 = deepcopy(self._check_boxes_save[self._selected_frame["name"]])
if self._selected_frame["name"] in self._motors_active.keys():
temp_dict_2 = deepcopy(self._motors_active[self._selected_frame["name"]])
else:
for k in self._working_values:
temp_dict_2[k] = 2
elif index == 0:
if self._selected_frame["name"] in self._check_boxes_power.keys():
temp_dict_2 = deepcopy(self._check_boxes_power[self._selected_frame["name"]])
if self._selected_frame["name"] in self._motors_torque.keys():
temp_dict_2 = deepcopy(self._motors_torque[self._selected_frame["name"]])
else:
for k in self._working_values:
temp_dict_2[k] = 2
Expand Down
28 changes: 5 additions & 23 deletions bitbots_motion/bitbots_animation_rqt/resource/RecordUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -138,31 +138,13 @@
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="treeLayout">
<item>
<widget class="QComboBox" name="treeModeSelector">
<item>
<property name="text">
<string>Power mode</string>
</property>
</item>
<item>
<property name="text">
<string>Save mode</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QTreeWidget" name="motorTree">
<widget class="QTreeWidget" name="motorTree">
<column>
<property name="text">
<string notr="true">1</string>
</property>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
Expand Down

0 comments on commit f78aefd

Please sign in to comment.