Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
CKAyano committed Sep 21, 2022
1 parent e28c909 commit fecd8b6
Show file tree
Hide file tree
Showing 3 changed files with 408 additions and 48 deletions.
139 changes: 91 additions & 48 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,35 +167,35 @@ def __init__(self):

self.setupUi(self)

self.tabWidget_main.setTabEnabled(1, False)
self.tabWidget_main.setTabEnabled(2, False)

self.setWindowIcon(QIcon(ICON_PATH))

self.doubleSpinBox_fk_j_list: list[QDoubleSpinBox] = []
self.doubleSpinBox_ik_init_list: list[QDoubleSpinBox] = []
self.pushButton_newDH.clicked.connect(self.open_addDH)
self.comboBox_dh.currentTextChanged.connect(self.dh_selected_event)

self.robot_instance: Optional[Robot] = None

self.is_rad = True
self.is_round = False
self.radioButton_fk_rad.clicked.connect(self.update_angle_type_rad)
self.radioButton_fk_deg.clicked.connect(self.update_angle_type_deg)

self.pushButton_fk_result.clicked.connect(self.update_fk_result)
self.checkBox_fk_round.clicked.connect(self.update_when_check_round)

self.comboBox_ik_method.currentTextChanged.connect(self.update_combobox_ik_method)

self.tabWidget_main.currentChanged.connect(self.dh_selected_event)

check_validated_config(DH_CONFIG_PATH)

self.update_dh_setting()
self.update_dh_combo_box()
self.dh_selected_event()

def open_addDH(self):
dlog = DHAddDlg(self)
dlog.exec()
self.update_dh_setting()
self.update_dh_combo_box()

def update_dh_setting(self):
def update_dh_combo_box(self):
self.comboBox_dh.clear()
self.comboBox_dh.addItem("< 請選擇 D-H >")
with open(DH_CONFIG_PATH, "r") as file:
Expand All @@ -214,6 +214,11 @@ def get_robot_instance(self):
robot = robot_dict_to_robot_instance(robot_dict)
return robot, robot_dict

def is_current_tab(self, idx: int):
if self.tabWidget_main.currentIndex() == idx:
return True
return False

def dh_selected_event(self):
robot_inst_dict = self.get_robot_instance()
if robot_inst_dict:
Expand All @@ -227,18 +232,35 @@ def dh_selected_event(self):
self.label_info.setText(
f"機械手臂: {robot_dict['robot_name']}, 軸數: {joints_count}, D-H型態: {dh_type_str}"
)
self.update_fk_input(joints_count)
self.update_fk_output(joints_count)
print(type(joints_count))
if self.is_current_tab(0):
self.update_fk_input(joints_count)
self.update_fk_output(joints_count)
if self.is_current_tab(1):
self.update_ik_input(joints_count)
self.update_ik_output()
self.update_combobox_ik_method()
else:
self.dh_default()

def dh_default(self):
self.robot_instance = None
self.label_info.setText(f"請選擇機械手臂D-H")
self.update_fk_input(2)
for i in self.doubleSpinBox_fk_j_list:
i.setDisabled(True)
self.pushButton_fk_result.setDisabled(True)

if self.is_current_tab(0):
self.update_fk_input(2)
for i in self.doubleSpinBox_fk_j_list:
i.setDisabled(True)
self.pushButton_fk_result.setDisabled(True)
if self.is_current_tab(1):
self.update_ik_input(2)
self.comboBox_ik_method.setDisabled(True)
self.doubleSpinBox_ik_x.setDisabled(True)
self.doubleSpinBox_ik_y.setDisabled(True)
self.doubleSpinBox_ik_z.setDisabled(True)
for i in self.doubleSpinBox_ik_init_list:
i.setDisabled(True)
self.pushButton_ik_result.setDisabled(True)

def update_fk_input(self, joints_count: int):
for i in reversed(range(self.horizontalLayout_fk_input.count())):
Expand Down Expand Up @@ -280,24 +302,11 @@ def update_fk_output(self, joints_count: int):
self.spinBox_fk_round.setDisabled(True)
self.pushButton_fk_result.setDisabled(False)

def update_angle_type_rad(self):
if self.is_rad:
return
self.is_rad = True

def update_angle_type_deg(self):
if not self.is_rad:
return
self.is_rad = False

def update_when_check_round(self):
if self.is_round:
self.spinBox_fk_round.setDisabled(True)
self.is_round = False
return
else:
if self.checkBox_fk_round.isChecked():
self.spinBox_fk_round.setDisabled(False)
self.is_round = True
return
self.spinBox_fk_round.setDisabled(True)

def get_fk_input_angle(self):
joints = []
Expand All @@ -306,11 +315,10 @@ def get_fk_input_angle(self):
return joints

def get_fk(self):
robots = self.get_robot_instance()
if robots:
robot, _ = robots
robot = self.robot_instance
if robot:
angles = self.get_fk_input_angle()
if not self.is_rad:
if self.radioButton_fk_deg.isChecked():
angles = deg2rad(angles)
links = robot.forword_kine(angles)

Expand Down Expand Up @@ -349,7 +357,6 @@ def update_fk_result(self):
if bool(output_index):
df.index = output_index

main_folder = f"{CONFIG_PATH}/df_style"
with open(f"{TMP_PATH}/fk_result_browser.html", "w") as f:
f.write(
HTML_STRING.format(
Expand All @@ -358,6 +365,54 @@ def update_fk_result(self):
)
self.textBrowser_fk_result.setSource(f"{TMP_PATH}/fk_result_browser.html")

def update_ik_input(self, joints_count):
self.comboBox_ik_method.setDisabled(False)
self.doubleSpinBox_ik_x.setDisabled(False)
self.doubleSpinBox_ik_y.setDisabled(False)
self.doubleSpinBox_ik_z.setDisabled(False)
for i in reversed(range(self.horizontalLayout_ik_initAngle.count())):
self.horizontalLayout_ik_initAngle.itemAt(i).widget().setParent(None)

self.label_ik_init_angle = QLabel(self.groupBox_ik_input)
self.label_ik_init_angle.setObjectName("label_ik_init_angle")
self.label_ik_init_angle.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)
self.label_ik_init_angle.setText("初始角度: ")

self.horizontalLayout_ik_initAngle.addWidget(self.label_ik_init_angle)

self.doubleSpinBox_ik_init_list = []
for i in range(joints_count):
doubleSpinBox_ik_j_n = QDoubleSpinBox(self.groupBox_ik_input)
doubleSpinBox_ik_j_n.setObjectName(f"doubleSpinBox_ik_init_j{i+1}")
doubleSpinBox_ik_j_n.setDecimals(6)
self.horizontalLayout_ik_initAngle.addWidget(doubleSpinBox_ik_j_n)
self.doubleSpinBox_ik_init_list.append(doubleSpinBox_ik_j_n)

self.radioButton_ik_init_rad = QRadioButton(self.groupBox_ik_input)
self.radioButton_ik_init_rad.setObjectName("radioButton_ik_init_rad")
self.radioButton_ik_init_rad.setChecked(True)
self.radioButton_ik_init_rad.setText("弳度 (rad)")

self.horizontalLayout_ik_initAngle.addWidget(self.radioButton_ik_init_rad)

self.radioButton_ik_init_deg = QRadioButton(self.groupBox_ik_input)
self.radioButton_ik_init_deg.setObjectName("radioButton_ik_init_deg")
self.radioButton_ik_init_deg.setChecked(False)
self.radioButton_ik_init_deg.setText("角度 (deg)")

self.horizontalLayout_ik_initAngle.addWidget(self.radioButton_ik_init_deg)

def update_ik_output(self):
self.pushButton_ik_result.setDisabled(False)

def update_combobox_ik_method(self):
if self.comboBox_ik_method.currentText() == "Simplex":
for i in self.doubleSpinBox_ik_init_list:
i.setDisabled(False)
if self.comboBox_ik_method.currentText() == "Pieper":
for i in self.doubleSpinBox_ik_init_list:
i.setDisabled(True)


class DHAddDlg(dialog_dhAdd, QDialog):

Expand Down Expand Up @@ -457,18 +512,6 @@ def update_dh_textBrowser(self, t: dict):

df["is_revol"] = self.revol_list

main_folder = f"{CONFIG_PATH}/df_style"

# html_string = """
# <html>
# <head><title>HTML Pandas Dataframe with CSS</title></head>
# <link rel="stylesheet" type="text/css" href="df_style.css"/>
# <body>
# {table}
# </body>
# </html>.
# """

with open(f"{TMP_PATH}/dh_browser.html", "w") as f:
f.write(
HTML_STRING.format(
Expand Down
Loading

0 comments on commit fecd8b6

Please sign in to comment.