main_window.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright 2019 ROBOTIS CO., LTD.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
16 
17 /* Authors: Darby Lim, Hye-Jong KIM, Ryan Shim, Yong-Ho Na */
18 
19 /*****************************************************************************
20 ** Includes
21 *****************************************************************************/
22 
23 #include <QtGui>
24 #include <QMessageBox>
25 #include <iostream>
26 #include "../include/open_manipulator_p_control_gui/main_window.hpp"
27 
28 /*****************************************************************************
29 ** Namespaces
30 *****************************************************************************/
31 
33 
34 using namespace Qt;
35 
36 /*****************************************************************************
37 ** Implementation [MainWindow]
38 *****************************************************************************/
39 
40 MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
41  : QMainWindow(parent)
42  , qnode(argc,argv)
43 {
44  ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.
45  QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt())); // qApp is a global variable for the application
46  connect(ui.tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tabSelected()));
47  QObject::connect(&qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
48 
49  qnode.init();
50 }
51 
53 
55 {
56  std::vector<double> joint_angle = qnode.getPresentJointAngle();
57 
58  int joint_size = 6;
59  if (qnode.getWithGripperState()) joint_size = 7;
60 
61  if(joint_angle.size() != joint_size)
62  return;
63 
64  ui.txt_j1->setText(QString::number(joint_angle.at(0),'f', 3));
65  ui.txt_j2->setText(QString::number(joint_angle.at(1),'f', 3));
66  ui.txt_j3->setText(QString::number(joint_angle.at(2),'f', 3));
67  ui.txt_j4->setText(QString::number(joint_angle.at(3),'f', 3));
68  ui.txt_j5->setText(QString::number(joint_angle.at(4),'f', 3));
69  ui.txt_j6->setText(QString::number(joint_angle.at(5),'f', 3));
70  if (qnode.getWithGripperState()) ui.txt_grip->setText(QString::number(joint_angle.at(6),'f', 3));
71 
72  std::vector<double> position = qnode.getPresentKinematicsPosition();
73  Eigen::Vector3d orientation_rpy = qnode.getPresentKinematicsOrientationRPY();
74 
75  if(position.size() != 3 || orientation_rpy.size() != 3)
76  return;
77 
78  ui.txt_x->setText(QString::number(position.at(0),'f', 3));
79  ui.txt_y->setText(QString::number(position.at(1),'f', 3));
80  ui.txt_z->setText(QString::number(position.at(2),'f', 3));
81 
82  ui.txt_roll->setText(QString::number(orientation_rpy.coeffRef(0,0),'f', 3));
83  ui.txt_pitch->setText(QString::number(orientation_rpy.coeffRef(1,0),'f', 3));
84  ui.txt_yaw->setText(QString::number(orientation_rpy.coeffRef(2,0),'f', 3));
85 
87  ui.txt_actuactor_state->setText("Actuator enabled");
88  else
89  ui.txt_actuactor_state->setText("Actuator disabled");
91  ui.txt_moving_state->setText("Robot is moving");
92  else
93  ui.txt_moving_state->setText("Robot is stopped");
94 
95 }
97 {
98  if(ui.tabWidget->currentIndex()==0)
100  if(ui.tabWidget->currentIndex()==1)
102 }
103 
104 void MainWindow::writeLog(QString str)
105 {
106  ui.plainTextEdit_log->moveCursor (QTextCursor::End);
107  ui.plainTextEdit_log->appendPlainText(str);
108 }
109 
111 {
112  timer = new QTimer(this);
113  connect(timer, SIGNAL(timeout()), this, SLOT(timerCallback()));
114  timer->start(100);
115 
116  writeLog("QTimer start : 100ms");
117  ui.btn_timer_start->setEnabled(false);
118  ui.btn_actuator_disable->setEnabled(true);
119  ui.btn_actuator_enable->setEnabled(true);
120  ui.btn_home_pose->setEnabled(true);
121  ui.btn_init_pose->setEnabled(true);
122  ui.btn_read_joint_angle->setEnabled(true);
123  ui.btn_read_kinematic_pose->setEnabled(true);
124  ui.btn_send_joint_angle->setEnabled(true);
125  ui.btn_send_kinematic_pose->setEnabled(true);
126  ui.btn_send_drawing_trajectory->setEnabled(true);
127 
129  {
130  ui.btn_gripper_close->setEnabled(true);
131  ui.btn_gripper_open->setEnabled(true);
132  ui.btn_set_gripper->setEnabled(true);
133  }
134 }
135 
137 {
138  if(!qnode.setActuatorState(true))
139  {
140  writeLog("[ERR!!] Failed to send service");
141  return;
142  }
143 
144  writeLog("Send actuator state to enable");
145 }
146 
148 {
149  if(!qnode.setActuatorState(false))
150  {
151  writeLog("[ERR!!] Failed to send service");
152  return;
153  }
154 
155  writeLog("Send actuator state to disable");
156 }
157 
159 {
160  std::vector<std::string> joint_name;
161  std::vector<double> joint_angle;
162  double path_time = 2.0;
163  joint_name.push_back("joint1"); joint_angle.push_back(0.0);
164  joint_name.push_back("joint2"); joint_angle.push_back(0.0);
165  joint_name.push_back("joint3"); joint_angle.push_back(0.0);
166  joint_name.push_back("joint4"); joint_angle.push_back(0.0);
167  joint_name.push_back("joint5"); joint_angle.push_back(0.0);
168  joint_name.push_back("joint6"); joint_angle.push_back(0.0);
169 
170  if(!qnode.setJointSpacePath(joint_name, joint_angle, path_time))
171  {
172  writeLog("[ERR!!] Failed to send service");
173  return;
174  }
175 
176  writeLog("Send joint angle to initial pose");
177 }
178 
180 {
181  std::vector<std::string> joint_name;
182  std::vector<double> joint_angle;
183  double path_time = 2.0;
184 
185  joint_name.push_back("joint1"); joint_angle.push_back(0.0);
186  joint_name.push_back("joint2"); joint_angle.push_back(-PI/4);
187  joint_name.push_back("joint3"); joint_angle.push_back(PI/8);
188  joint_name.push_back("joint4"); joint_angle.push_back(0.0);
189  joint_name.push_back("joint5"); joint_angle.push_back(PI/8);
190  joint_name.push_back("joint6"); joint_angle.push_back(0.0);
191 
192  if(!qnode.setJointSpacePath(joint_name, joint_angle, path_time))
193  {
194  writeLog("[ERR!!] Failed to send service");
195  return;
196  }
197  writeLog("Send joint angle to home pose");
198 }
199 
201 {
202  std::vector<double> joint_angle;
203  joint_angle.push_back(0.0);
204  if(!qnode.setToolControl(joint_angle))
205  {
206  writeLog("[ERR!!] Failed to send service");
207  return;
208  }
209 
210  writeLog("Send gripper open");
211 }
212 
214 {
215  std::vector<double> joint_angle;
216  joint_angle.push_back(1.1);
217  if(!qnode.setToolControl(joint_angle))
218  {
219  writeLog("[ERR!!] Failed to send service");
220  return;
221  }
222 
223  writeLog("Send gripper close");
224 }
225 
226 
228 {
229  std::vector<double> joint_angle = qnode.getPresentJointAngle();
230  ui.doubleSpinBox_j1->setValue(joint_angle.at(0));
231  ui.doubleSpinBox_j2->setValue(joint_angle.at(1));
232  ui.doubleSpinBox_j3->setValue(joint_angle.at(2));
233  ui.doubleSpinBox_j4->setValue(joint_angle.at(3));
234  ui.doubleSpinBox_j5->setValue(joint_angle.at(4));
235  ui.doubleSpinBox_j6->setValue(joint_angle.at(5));
236  // ui.doubleSpinBox_gripper->setValue(joint_angle.at(4));
237 
238  writeLog("Read joint angle");
239 }
241 {
242  std::vector<std::string> joint_name;
243  std::vector<double> joint_angle;
244  double path_time = ui.doubleSpinBox_time_js->value();
245 
246  joint_name.push_back("joint1"); joint_angle.push_back(ui.doubleSpinBox_j1->value());
247  joint_name.push_back("joint2"); joint_angle.push_back(ui.doubleSpinBox_j2->value());
248  joint_name.push_back("joint3"); joint_angle.push_back(ui.doubleSpinBox_j3->value());
249  joint_name.push_back("joint4"); joint_angle.push_back(ui.doubleSpinBox_j4->value());
250  joint_name.push_back("joint5"); joint_angle.push_back(ui.doubleSpinBox_j5->value());
251  joint_name.push_back("joint6"); joint_angle.push_back(ui.doubleSpinBox_j6->value());
252 
253  if(!qnode.setJointSpacePath(joint_name, joint_angle, path_time))
254  {
255  writeLog("[ERR!!] Failed to send service");
256  return;
257  }
258 
259  writeLog("Send joint angle");
260 }
262 {
263  std::vector<double> position = qnode.getPresentKinematicsPosition();
264  Eigen::Vector3d orientation_rpy = qnode.getPresentKinematicsOrientationRPY();
265 
266  ui.doubleSpinBox_x->setValue(position.at(0));
267  ui.doubleSpinBox_y->setValue(position.at(1));
268  ui.doubleSpinBox_z->setValue(position.at(2));
269  ui.doubleSpinBox_roll->setValue(orientation_rpy.coeffRef(0,0));
270  ui.doubleSpinBox_pitch->setValue(orientation_rpy.coeffRef(1,0));
271  ui.doubleSpinBox_yaw->setValue(orientation_rpy.coeffRef(2,0));
272 
273  writeLog("Read task pose");
274 }
276 {
277  std::vector<double> kinematics_pose;
278  Eigen::Quaterniond temp_orientation;
279  temp_orientation = robotis_manipulator::math::convertRPYToQuaternion(ui.doubleSpinBox_roll->value(), ui.doubleSpinBox_pitch->value(), ui.doubleSpinBox_yaw->value());
280 
281  double path_time = ui.doubleSpinBox_time_cs->value();
282 
283  kinematics_pose.push_back(ui.doubleSpinBox_x->value());
284  kinematics_pose.push_back(ui.doubleSpinBox_y->value());
285  kinematics_pose.push_back(ui.doubleSpinBox_z->value());
286  kinematics_pose.push_back(temp_orientation.w());
287  kinematics_pose.push_back(temp_orientation.x());
288  kinematics_pose.push_back(temp_orientation.y());
289  kinematics_pose.push_back(temp_orientation.z());
290 
291  if(!qnode.setTaskSpacePath(kinematics_pose, path_time))
292  {
293  writeLog("[ERR!!] Failed to send service");
294  return;
295  }
296 
297  writeLog("Send task pose");
298 }
300 {
301  std::vector<double> joint_angle;
302  joint_angle.push_back(ui.doubleSpinBox_gripper->value());
303  if(!qnode.setToolControl(joint_angle))
304  {
305  writeLog("[ERR!!] Failed to send service");
306  return;
307  }
308  writeLog("Send gripper value");
309 }
310 
312 {
313  qnode.setOption("print_open_manipulator_setting");
314  writeLog("Check the terminal of open_manipulator_controller package");
315 }
316 
317 
319 {
320  ui.txt_drawing_arg_1->setText("Transpose X");
321  ui.txt_drawing_arg_2->setText("Transpose Y");
322  ui.txt_drawing_arg_3->setText("Transpose Z");
323  ui.txt_drawing_arg_unit_1->setText("m");
324  ui.txt_drawing_arg_unit_2->setText("m");
325  ui.txt_drawing_arg_unit_3->setText("m");
326  ui.doubleSpinBox_drawing_arg_1->setValue(0.0);
327  ui.doubleSpinBox_drawing_arg_2->setValue(0.0);
328  ui.doubleSpinBox_drawing_arg_3->setValue(0.0);
329 }
331 {
332  ui.txt_drawing_arg_1->setText("Radius");
333  ui.txt_drawing_arg_2->setText("Revolution");
334  ui.txt_drawing_arg_3->setText("Start angle");
335  ui.txt_drawing_arg_unit_1->setText("m");
336  ui.txt_drawing_arg_unit_2->setText("rev");
337  ui.txt_drawing_arg_unit_3->setText("rad");
338  ui.doubleSpinBox_drawing_arg_1->setValue(0.0);
339  ui.doubleSpinBox_drawing_arg_2->setValue(0.0);
340  ui.doubleSpinBox_drawing_arg_3->setValue(0.0);
341 }
343 {
344  ui.txt_drawing_arg_1->setText("Radius");
345  ui.txt_drawing_arg_2->setText("Revolution");
346  ui.txt_drawing_arg_3->setText("Start angle");
347  ui.txt_drawing_arg_unit_1->setText("m");
348  ui.txt_drawing_arg_unit_2->setText("rev");
349  ui.txt_drawing_arg_unit_3->setText("rad");
350  ui.doubleSpinBox_drawing_arg_1->setValue(0.0);
351  ui.doubleSpinBox_drawing_arg_2->setValue(0.0);
352  ui.doubleSpinBox_drawing_arg_3->setValue(0.0);
353 }
355 {
356  ui.txt_drawing_arg_1->setText("Radius");
357  ui.txt_drawing_arg_2->setText("Revolution");
358  ui.txt_drawing_arg_3->setText("Start angle");
359  ui.txt_drawing_arg_unit_1->setText("m");
360  ui.txt_drawing_arg_unit_2->setText("rev");
361  ui.txt_drawing_arg_unit_3->setText("rad");
362  ui.doubleSpinBox_drawing_arg_1->setValue(0.0);
363  ui.doubleSpinBox_drawing_arg_2->setValue(0.0);
364  ui.doubleSpinBox_drawing_arg_3->setValue(0.0);
365 }
367 {
368  std::string name;
369  if(ui.radio_drawing_line->isChecked()) name = "line";
370  else if(ui.radio_drawing_circle->isChecked()) name = "circle";
371  else if(ui.radio_drawing_rhombus->isChecked()) name = "rhombus";
372  else if(ui.radio_drawing_heart->isChecked()) name = "heart";
373 
374  std::vector<double> arg;
375  arg.push_back(ui.doubleSpinBox_drawing_arg_1->value());
376  arg.push_back(ui.doubleSpinBox_drawing_arg_2->value());
377  arg.push_back(ui.doubleSpinBox_drawing_arg_3->value());
378 
379  double path_time = ui.doubleSpinBox_time_drawing->value();
380 
381  if(!qnode.setDrawingTrajectory(name, arg, path_time))
382  {
383  writeLog("[ERR!!] Failed to send service");
384  return;
385  }
386  writeLog("Send drawing trajectory");
387 }
388 
389 } // namespace open_manipulator_p_control_gui
390 
std::vector< double > getPresentJointAngle()
Definition: qnode.cpp:146
bool setActuatorState(bool actuator_state)
Definition: qnode.cpp:251
void setOption(std::string opt)
Definition: qnode.cpp:177
MainWindow(int argc, char **argv, QWidget *parent=0)
Definition: main_window.cpp:40
std::vector< double > getPresentKinematicsPosition()
Definition: qnode.cpp:150
bool setJointSpacePath(std::vector< std::string > joint_name, std::vector< double > joint_angle, double path_time)
Definition: qnode.cpp:184
Eigen::Quaterniond convertRPYToQuaternion(double roll, double pitch, double yaw)
bool setDrawingTrajectory(std::string name, std::vector< double > arg, double path_time)
Definition: qnode.cpp:222
#define PI
bool setTaskSpacePath(std::vector< double > kinematics_pose, double path_time)
Definition: qnode.cpp:198
Eigen::Vector3d getPresentKinematicsOrientationRPY()
Definition: qnode.cpp:158
bool setToolControl(std::vector< double > joint_angle)
Definition: qnode.cpp:238


open_manipulator_p_control_gui
Author(s): Ryan Shim , Yong-Ho Na , Hye-Jong KIM
autogenerated on Thu Oct 22 2020 03:16:32