24 #include <QMessageBox> 26 #include "../include/thormang3_offset_tuner_client/main_window.hpp" 42 : QMainWindow(parent),
43 offset_tuner_qnode_(argc, argv)
46 QObject::connect(
ui_.actionAbout_Qt, SIGNAL(triggered(
bool)), qApp, SLOT(aboutQt()));
48 setWindowIcon(QIcon(
":/images/icon.png"));
49 ui_.tab_manager->setCurrentIndex(0);
66 qRegisterMetaType<thormang3_offset_tuner_msgs::JointOffsetPositionData>(
67 "thormang3_offset_tuner_msgs::JointOffsetPositionData");
69 SIGNAL(update_present_joint_offset_data(thormang3_offset_tuner_msgs::JointOffsetPositionData)),
this,
101 std_msgs::String msg;
109 std_msgs::String msg;
110 msg.data =
"ini_pose";
124 QButtonGroup* torque_button_group = qobject_cast<QButtonGroup*>(button_group);
125 if (!torque_button_group)
128 QList<QAbstractButton *> torque_buttons = torque_button_group->buttons();
129 for (
int ix = 0; ix < torque_buttons.size(); ix++)
131 if (torque_buttons[ix]->isChecked() ==
false)
132 torque_buttons[ix]->click();
142 QButtonGroup* torque_button_group = qobject_cast<QButtonGroup*>(button_group);
143 if (!torque_button_group)
146 QList<QAbstractButton *> torque_buttons = torque_button_group->buttons();
147 for (
int ix = 0; ix < torque_buttons.size(); ix++)
149 if (torque_buttons[ix]->isChecked() ==
true)
150 torque_buttons[ix]->click();
157 QCheckBox* checkBox = qobject_cast<QCheckBox*>(widget);
161 std::string joint_name = checkBox->text().toStdString();
162 bool _is_on = checkBox->isChecked();
166 for (
int ix = 0; ix < spinbox_list.size(); ix++)
168 spinbox_list[ix]->setEnabled(_is_on);
177 thormang3_offset_tuner_msgs::JointTorqueOnOffArray msg_array;
178 thormang3_offset_tuner_msgs::JointTorqueOnOff msg;
180 msg.joint_name = joint_name;
181 msg.torque_enable = torque_on;
183 msg_array.torque_enable_data.push_back(msg);
196 thormang3_offset_tuner_msgs::JointOffsetData msg;
197 std::string current_joint_name = joint_name.toStdString();
200 QDoubleSpinBox *mod_spinBox;
202 msg.joint_name = current_joint_name;
204 for (
int ix = 0; ix < spinbox_list.size(); ix++)
206 if (spinbox_list[ix]->whatsThis().toStdString() ==
"goal")
208 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(spinbox_list[ix]);
212 msg.goal_value = spinbox->value() * M_PI / 180.0;
214 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"offset")
216 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(spinbox_list[ix]);
220 msg.offset_value = spinbox->value() * M_PI / 180.0;
222 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"mod")
224 mod_spinBox = qobject_cast<QDoubleSpinBox*>(spinbox_list[ix]);
226 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"p_gain")
228 QSpinBox* spinbox = qobject_cast<QSpinBox*>(spinbox_list[ix]);
232 msg.p_gain = spinbox->value();
234 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"i_gain")
236 QSpinBox* spinbox = qobject_cast<QSpinBox*>(spinbox_list[ix]);
240 msg.i_gain = spinbox->value();
242 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"d_gain")
244 QSpinBox* spinbox = qobject_cast<QSpinBox*>(spinbox_list[ix]);
248 msg.d_gain = spinbox->value();
253 mod_spinBox->setValue((msg.goal_value + msg.offset_value) * 180.0 / M_PI);
260 std::string joint_name = msg.joint_name;
264 for (
int ix = 0; ix < spinbox_list.size(); ix++)
266 if (spinbox_list[ix]->whatsThis().toStdString() ==
"goal")
268 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(spinbox_list[ix]);
272 spinbox->setValue(msg.goal_value * 180.0 / M_PI);
274 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"offset")
276 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(spinbox_list[ix]);
280 spinbox->setValue(msg.offset_value * 180.0 / M_PI);
282 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"present")
284 QDoubleSpinBox* spinbox = qobject_cast<QDoubleSpinBox*>(spinbox_list[ix]);
288 spinbox->setValue(msg.present_value * 180.0 / M_PI);
290 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"p_gain")
292 QSpinBox* spinbox = qobject_cast<QSpinBox*>(spinbox_list[ix]);
296 spinbox->setValue(msg.p_gain);
298 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"i_gain")
300 QSpinBox* spinbox = qobject_cast<QSpinBox*>(spinbox_list[ix]);
304 spinbox->setValue(msg.i_gain);
306 else if (spinbox_list[ix]->whatsThis().toStdString() ==
"d_gain")
308 QSpinBox* spinbox = qobject_cast<QSpinBox*>(spinbox_list[ix]);
312 spinbox->setValue(msg.d_gain);
328 ui_.view_logging->scrollToBottom();
341 std::map<int, std::string> &offset_group)
343 QSignalMapper *torque_checkbox_signalMapper =
new QSignalMapper(
this);
345 QGridLayout *grid_layout = (QGridLayout *) joint_widget->layout();
346 QGridLayout *torque_layout = (QGridLayout *) torque_widget->layout();
348 button_group =
new QButtonGroup();
349 button_group->setExclusive(
false);
352 int torque_checkbox_index = 0;
355 for (std::map<int, std::string>::iterator map_iter = offset_group.begin(); map_iter != offset_group.end(); ++map_iter)
357 QSignalMapper *spingox_signalMapper =
new QSignalMapper(
this);
358 QList<QAbstractSpinBox *> spinbox_list;
363 std::string joint_name = map_iter->second;
364 QString q_joint_name = QString::fromStdString(joint_name);
367 QLabel *joint_label =
new QLabel(q_joint_name);
368 grid_layout->addWidget(joint_label, row, col++, 1, size);
371 for (
int ix = 0; ix < 4; ix++)
373 QDoubleSpinBox *spin_box =
new QDoubleSpinBox();
375 spin_box->setMinimum(-360);
376 spin_box->setMaximum(360);
377 spin_box->setSingleStep(0.05);
383 spin_box->setReadOnly(
true);
387 spingox_signalMapper->setMapping(spin_box, q_joint_name);
388 QObject::connect(spin_box, SIGNAL(valueChanged(QString)), spingox_signalMapper, SLOT(map()));
392 grid_layout->addWidget(spin_box, row, col++, 1, size);
394 spinbox_list.append(spin_box);
398 for (
int ix = 0; ix < 3; ix++)
400 QSpinBox *spin_box =
new QSpinBox();
402 spin_box->setMinimum(0);
403 spin_box->setMaximum(1000);
404 spin_box->setSingleStep(1);
409 spin_box->setValue(32);
411 spingox_signalMapper->setMapping(spin_box, q_joint_name);
412 QObject::connect(spin_box, SIGNAL(valueChanged(QString)), spingox_signalMapper, SLOT(map()));
416 spin_box->setReadOnly(
true);
420 grid_layout->addWidget(spin_box, row, col++, 1, size);
422 spinbox_list.append(spin_box);
427 QObject::connect(spingox_signalMapper, SIGNAL(mapped(QString)),
this, SLOT(
spinBox_valueChanged(QString)));
432 torque_row = torque_checkbox_index / 6;
433 torque_col = torque_checkbox_index % 6;
435 QCheckBox *check_box =
new QCheckBox(q_joint_name);
436 check_box->setChecked(
true);
437 torque_layout->addWidget(check_box, torque_row, torque_col, 1, size);
438 button_group->addButton(check_box);
440 torque_checkbox_signalMapper->setMapping(check_box, check_box);
441 QObject::connect(check_box, SIGNAL(clicked()), torque_checkbox_signalMapper, SLOT(map()));
443 torque_checkbox_index += 1;
447 QSignalMapper *torque_on_signalMapper =
new QSignalMapper(
this);
448 QPushButton *on_button =
new QPushButton(tr(
"All torque ON"));
449 torque_layout->addWidget(on_button, torque_row + 1, 4, 1, 1);
450 torque_on_signalMapper->setMapping(on_button, button_group);
451 QObject::connect(on_button, SIGNAL(clicked()), torque_on_signalMapper, SLOT(map()));
452 QObject::connect(torque_on_signalMapper, SIGNAL(mapped(QObject*)),
this,
456 QSignalMapper *torque_off_signalMapper =
new QSignalMapper(
this);
457 QPushButton *off_button =
new QPushButton(tr(
"All torque OFF"));
458 torque_layout->addWidget(off_button, torque_row + 1, 5, 1, 1);
459 torque_off_signalMapper->setMapping(off_button, button_group);
460 QObject::connect(off_button, SIGNAL(clicked()), torque_off_signalMapper, SLOT(map()));
461 QObject::connect(torque_off_signalMapper, SIGNAL(mapped(QObject*)),
this,
464 QObject::connect(torque_checkbox_signalMapper, SIGNAL(mapped(QWidget*)),
this,
474 QMessageBox::about(
this, tr(
"About ..."), tr(
"<h2>THORMANG3 Offset tuner client</h2><p>Copyright ROBOTIS</p>"));
483 QMainWindow::closeEvent(event);
QNode offset_tuner_qnode_
void on_refresh_button_clicked(bool check)
void spinBox_valueChanged(QString joint_name)
void on_actionAbout_triggered()
void getPresentJointOffsetData()
void send_command_msg(std_msgs::String msg)
std::map< std::string, QList< QAbstractSpinBox * > > joint_spinbox_map_
std::map< int, std::string > right_arm_offset_group
void publish_torque_msgs(std::string &joint_name, bool torque_on)
QButtonGroup * left_arm_button_group_
void update_joint_offset_data_spinbox(thormang3_offset_tuner_msgs::JointOffsetPositionData msg)
QButtonGroup * right_arm_button_group_
std::vector< std::string > spinBox_list_
std::map< int, std::string > body_offset_group
QButtonGroup * legs_button_group_
void all_torque_off_button_clicked(QObject *button_group)
MainWindow(int argc, char **argv, QWidget *parent=0)
std::map< int, std::string > left_arm_offset_group
void on_save_button_clicked(bool check)
void send_torque_enable_msg(thormang3_offset_tuner_msgs::JointTorqueOnOffArray msg)
void on_inipose_button_clicked(bool checck)
QStringListModel * loggingModel()
void send_joint_offset_data_msg(thormang3_offset_tuner_msgs::JointOffsetData msg)
std::map< int, std::string > legs_offset_group
void MakeTabUI(QGroupBox *joint_widget, QGroupBox *torque_widget, QButtonGroup *button_group, std::map< int, std::string > &offset_group)
void all_torque_on_button_clicked(QObject *button_group)
void torque_checkbox_clicked(QWidget *widget)
QButtonGroup * body_button_group_
void closeEvent(QCloseEvent *event)