12 #include <QVBoxLayout> 13 #include <QGridLayout> 15 #include <QDoubleValidator> 17 #include <QFileDialog> 18 #include <QDialogButtonBox> 19 #include <QMessageBox> 34 : QMainWindow(parent), menu_bar(this), app_menu(&menu_bar),
35 help_menu(&menu_bar), tool_bar(this), start_stop_action(this),
36 about_action(this), about_Qt_action(this), ROS_server(this),
37 motion_model(-.5, .5, M_PI/4, -.6, .5, -M_PI/8, M_PI/8),
38 controller( new
NoCtrl(motion_model) ), ctrl_node(argc, argv),
39 ctrl_wdgt( new
ViewCtrlWdgt(*this, *controller, motion_model) ),
40 display(*this), logs(this) {
41 setWindowTitle( tr(
"ROS - Qt Controlers Benchmark") );
42 setWindowIcon( QIcon(
":/files/icon.png") );
45 SIGNAL( errorOccurred(
const int,
const QString&) ),
46 this, SLOT(
threadError(
const int,
const QString&) ) );
57 qApp, SLOT( aboutQt() ) );
71 QWidget *central_widget =
new QWidget(
this);
72 setCentralWidget(central_widget);
74 QGridLayout *central_layout =
new QGridLayout(central_widget);
76 central_layout->addWidget(&
display, 0, 1);
77 QGroupBox *log_box =
new QGroupBox(tr(
"Logs"), central_widget);
78 QBoxLayout *log_layout =
79 new QBoxLayout(QBoxLayout::LeftToRight, log_box);
80 logs.setMinimumSize(400, 100);
81 log_layout->addWidget(&
logs);
82 central_layout->addWidget(log_box, 1, 0, 1, 2);
91 connect( &(
ctrl_node), SIGNAL( loggingUpdated() ),
94 qRegisterMetaType<State>();
100 QSettings settings(
"Qt-Ros Package",
"qt_ctrl");
101 restoreGeometry(settings.value(
"geometry").toByteArray());
102 restoreState(settings.value(
"windowState").toByteArray());
103 QString master_url = settings.value
104 (
"master_url",QString(
"http://192.168.1.2:11311/")).toString();
105 QString host_url = settings.value
106 (
"host_url", QString(
"192.168.1.3")).toString();
125 QSettings settings(
"Qt-Ros Package",
"qt_ctrl");
142 static const char* error_msg[]
143 = {
"Failed to start",
"Crashed",
"Timeout",
144 "Write error",
"Read error",
"Unknown error" };
145 QMessageBox::critical
146 (
this,
"Thread Error Occured",
147 QString(
"Starting %1 generated error #%2 (%3)")
148 .arg( program ).arg( error ).arg( error_msg[error] ),
149 QMessageBox::Ok, QMessageBox::Ok );
155 (
this, tr(
"About ROS-Qt Control GUI"),
156 tr(
"<h2>ROS-Qt Control GUI</h2>\ 157 <p>Copyright <a href=\"http://members.loria.fr/AScheuer\"\ 158 >Alexis Scheuer</a>, <a href= \ 159 \"http://www.univ-lorraine.fr\">UL</a>|<a href= \ 160 \"http://fst.univ-lorraine.fr\">FST</a> & <a href=\ 161 \"http://www.loria.fr\">Loria</a></p> \ 162 <p>This package proposes several controllers for ROS \ 163 with a Qt GUI, in order to compare them.</p>"));
168 bool not_connected, trying, tracking, reaching;
173 const QMessageBox::StandardButton ans = QMessageBox::question
174 (
this, tr(
"Stopping ROS master?"),
175 tr(
"Should this GUI stop the TurtleBot simulation " 176 "(you may not be able to start it again)?"),
178 QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
179 if (ans == QMessageBox::Yes)
186 trying = dialog.exec() == QDialog::Accepted;
196 QMessageBox::information(
this,
"Workspace Script",
197 QString(
"Using script '%1'")
198 .arg( wrksp.c_str() ),
199 QMessageBox::Ok, QMessageBox::Ok);
213 QGridLayout *central_layout =
214 (QGridLayout*)( centralWidget()->layout() );
215 old_wdgt->
widget().hide();
216 central_layout->removeWidget( &( old_wdgt->
widget() ) );
224 if ( (! saveFile.isNull() ) && (! saveFile.isEmpty() ) )
229 }
while (trying && not_connected);
246 int main(
int argc,
char** argv) {
247 QApplication app(argc, argv);
251 app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
ROSnode ctrl_node
The ROS node at the center of this GUI.
Qt based GUI for qt_ctrl package.
bool emptyROSworkspace() const
Indicates if starting ROS should use empty workspace.
Controller is the abstract class inherited by all the implemented controllers.
QMenuBar menu_bar
The menu bar of this GUI.
void updateLogging()
Method activated when this GUI's log view is updated.
void buttonStartStop()
Method activated by the "Start/Stop" button.
QMenu app_menu
The actions' menu of this GUI.
int main(int argc, char **argv)
This is qt_ctrl main function, starting a Qt control GUI in a Qt application.
ROSserver ROS_server
The instance used to start a ROS server, if needed.
Qt control widget showing current and aimed velocities.
QToolBar tool_bar
The tool bar of this GUI.
void init(Controller &ctrl)
Connects to ROS server with main arguments.
bool startROS() const
Indicates whether ROS should be started.
QMenu help_menu
The help menu of this GUI.
Default controller, which does not move.
void connectCtrl()
Connects the controller signals to this class' methods.
void actionAbout()
Method activated by the "About" menu item (not yet used).
This class is a Qt widget which allows to show the controller's behaviour (current and aimed velociti...
ControlWidget * ctrl_wdgt
The widget showing the controller's velocities can also change.
std::string worldCommandFile(const bool empty=true)
File name for the script starting the simulation.
void readSettings()
Load up Qt program settings at startup.
static const double time_step
The default time step.
QStringListModel & loggingModel()
The Qt object used to show the logs.
ControlWidget * newCtrlWidget()
Gives the selected controller's widget, or null pointer if the dialog was cancelled.
void stop()
Stops the ROS server (and the thread's execution).
This class defines a state, i.e. a configuration and its (translation and rotation) velocities...
Controller * controller
The controller of the ROS node can change.
bool connected() const
Indicates whether the node is connected to ROS.
void setWorkspace(const std::string &wrksp)
Set the workspace name.
QAction about_action
The Qt action starting a dialog box about Qt Ctrl.
void writeSettings()
Save Qt program settings when closing.
Qt dialog window to select the control used by the qt_ctrl GUI.
MotionModel motion_model
The motion model of the controlled robot.
DataWidget display
The data display widget of the ROS node.
QAction about_Qt_action
The Qt action starting a dialog box about Qt.
This class is the Qt main window of qt_ctrl package.
QtCtrlGUI(const int argc, char **argv, QWidget *parent=0)
The constructor requires main()'s arguments (they can be forwarded by the ROS node to ROS)...
QAction start_stop_action
The Qt action starting the ROS node.
const QString & saveFileName() const
Gives the save file name.
void end()
Stops ROS if it has been started.
void threadError(const int error, const QString &program)
Signals which error occured when starting ROS server.
This class defines an accept/cancel dialog to create a controller and its display widget which will b...
QListView logs
The Qt list view showing the logs of the ROS node.
Controller * newController()
Gives the selected controller, or null pointer if the dialog was cancelled.
void sleep(const long &seconds) const
Waits for a given duration, in seconds.