EtherCAT Control Framework v0.9
Implementation of EtherCAT protocol using IgH EtherCAT library for robot controller.
main_window.hpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright (C) 2021 Veysi ADIN, UST KIST
6 *
7 * This file is part of the IgH EtherCAT master userspace program in the ROS2 environment.
8 *
9 * The IgH EtherCAT master userspace program in the ROS2 environment is free software; you can
10 * redistribute it and/or modify it under the terms of the GNU General
11 * Public License as published by the Free Software Foundation; version 2
12 * of the License.
13 *
14 * The IgH EtherCAT master userspace program in the ROS2 environment is distributed in the hope that
15 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the IgH EtherCAT master userspace program in the ROS environment. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * ---
24 *
25 * The license mentioned above concerns the source code only. Using the
26 * EtherCAT technology and brand is only permitted in compliance with the
27 * industrial property and similar rights of Beckhoff Automation GmbH.
28 *
29 * Contact information: veysi.adin@kist.re.kr
30 *****************************************************************************/
31/*****************************************************************************
32 * \file main_window.hpp
33 * \brief MainWindow implementation to show slave status and controller commands
34 * and endoscope camera view in GUI in ROS2.
35 * All GUI functionality and updating GUI handled by this MainWindow class.
36 *******************************************************************************/
37#pragma once
38
39//CPP
40#include <chrono>
41#include <memory>
42#include <iostream>
43
44//ROS2
45#include "rclcpp/rclcpp.hpp"
46
47//GUI_Node Headers
48#include "gui_node.hpp"
49#include "video_capture.hpp"
50#include "gui_globals.hpp"
51
52// QT
53#include "ui_mainwindow.h"
54#include <QMainWindow>
55#include <QApplication>
56#include <QStandardItemModel>
57#include <QTableView>
58#include <QHeaderView>
59#include <QString>
60#include <QTextStream>
61#include <QTimer>
62
63
64using namespace GUI;
65namespace Ui {
66class MainWindow;
67}
68 class MainWindow : public QMainWindow {
69 Q_OBJECT
70 public:
71 MainWindow(int argc, char** argv, QWidget *parent = nullptr);
73
74 private slots:
75
76 void UpdateGUI();
77
78 void ResetControlButtonValues(unsigned char &button_val);
79
81
83
85
87
89
91
93
95
97
99
101
102 void on_b_send_clicked();
103
104 private:
109 void rosSpinThread();
113 void ShowAllMotorStatus();
117 void ShowComStatus();
121 void ShowEmergencyStatus();
127 QString GetReadableStatusWord(int index);
134
140 void CallInactiveStateUI();
145 void CallActiveStateUI();
146
150 void SetDisabledStyleSheet(QPushButton *button);
154 void SetEnabledStyleSheetSDO(QPushButton *button);
155
156 void SetEnabledStyleSheetPDO(QPushButton *button);
157
158 void ShowOperationMode();
159
160 QString GetDriveErrorMessage(const int& err_code);
161 Ui::MainWindow *ui;
162 int argc_;
163 char** argv_;
168 int GetDriveStates(const int & statusWord);
169 const QString blue_style_sheet_ ="QPushButton:pressed {background-color: rgb(5, 153, 44);}"
170 "QPushButton {color: rgb(255, 255, 255);"
171 "selection-background-color: rgb(238, 238, 236);"
172 "selection-color: rgb(238, 238, 236);"
173 "background-color: rgb(19, 61, 128);"
174 "alternate-background-color: rgb(0, 0, 0);"
175 "font: bold 75 16pt \"Noto Sans\";}";
176 const QString sdo_style_sheet_ = "QPushButton:pressed {background-color: rgb(5, 153, 44);}"
177 "QPushButton {color: rgb(255, 255, 255);"
178 "background-color: rgb(252, 119, 3);"
179 "font: bold 75 15pt \"Noto Sans\";}";
180 const QString red_style_sheet = "QPushButton:pressed {background-color: rgb(252, 186, 3);}"
181 "QPushButton {color: rgb(255, 255, 255);"
182 "background-color: rgb(252, 0, 0);"
183 "font: bold 75 15pt \"Noto Sans\";}";
184 QTimer my_timer;
185 // To get data from gui_node_ .
186 std::shared_ptr<GuiNode> gui_node_;
188 // Thread for ROS2 spinning.
189 std::thread ros_spin_thread_;
190 uint8_t em_state_=0;
191 };
Definition: main_window.hpp:68
uint8_t em_state_
Definition: main_window.hpp:190
void on_b_emergency_mode_clicked()
Definition: main_window.cpp:169
void on_b_enter_cyclic_pdo_clicked()
Definition: main_window.cpp:137
void UpdateGUI()
Definition: main_window.cpp:44
void on_b_init_ecat_clicked()
Definition: main_window.cpp:98
void CallUnconfiguredStateUI()
This function will update UI style (enable-disable buttons) based on unconfigured state style.
Definition: main_window.cpp:235
void ShowEmergencyStatus()
Shows emergency button and switch status in GUI.
Definition: main_window.cpp:321
const QString red_style_sheet
Definition: main_window.hpp:180
void on_b_enable_drives_clicked()
Definition: main_window.cpp:127
Ui::MainWindow * ui
Definition: main_window.hpp:161
std::thread ros_spin_thread_
Definition: main_window.hpp:189
void SetEnabledStyleSheetPDO(QPushButton *button)
Definition: main_window.cpp:70
void CallActiveStateUI()
This function will update UI style (enable-disable buttons) based on active state style.
Definition: main_window.cpp:305
std::shared_ptr< GuiNode > gui_node_
Definition: main_window.hpp:186
void on_b_send_clicked()
Definition: main_window.cpp:200
const QString sdo_style_sheet_
Definition: main_window.hpp:176
int GetDriveStates(const int &statusWord)
timer to update GUI in specific intervals.In this case 25ms.
Definition: main_window.cpp:556
int argc_
Definition: main_window.hpp:162
void on_b_enable_vel_clicked()
Definition: main_window.cpp:88
QString GetReadableStatusWord(int index)
Reads status word and turns it to readable string format.
Definition: main_window.cpp:636
VideoCapture * opencv_video_cap
Definition: main_window.hpp:187
void on_b_enable_pos_clicked()
Definition: main_window.cpp:93
void rosSpinThread()
To use ROS2 spinining functionality in our specific thread.
Definition: main_window.cpp:24
void SetEnabledStyleSheetSDO(QPushButton *button)
Sets GUI appearance for enabled buttons.
Definition: main_window.cpp:64
void ShowAllMotorStatus()
Shows motor status in GUI.
Definition: main_window.cpp:402
QString GetDriveErrorMessage(const int &err_code)
Definition: main_window.cpp:764
void on_b_disable_drives_clicked()
Definition: main_window.cpp:132
void on_b_reinit_ecat_clicked()
Definition: main_window.cpp:111
QTimer my_timer
Definition: main_window.hpp:184
void on_b_stop_cyclic_pdo_clicked()
Definition: main_window.cpp:153
void ResetControlButtonValues(unsigned char &button_val)
Definition: main_window.cpp:218
void on_b_enable_cyclic_pos_clicked()
Definition: main_window.cpp:76
void ShowComStatus()
Shows communication status in GUI.
Definition: main_window.cpp:350
void ShowOperationMode()
Definition: main_window.cpp:593
void SetDisabledStyleSheet(QPushButton *button)
Sets GUI appearance for disabled buttons.
Definition: main_window.cpp:56
const QString blue_style_sheet_
Definition: main_window.hpp:169
MainWindow(int argc, char **argv, QWidget *parent=nullptr)
Definition: main_window.cpp:3
~MainWindow()
Definition: main_window.cpp:17
char ** argv_
Definition: main_window.hpp:163
void on_b_enable_cylic_vel_clicked()
Definition: main_window.cpp:83
void CallInactiveStateUI()
This function will update UI style (enable-disable buttons) based on inactive state style.
Definition: main_window.cpp:288
Definition: video_capture.hpp:61
Definition: gui_node.hpp:67
Definition: endoscope_viewer.hpp:11