2 * RobomonTuning.cpp 07/10/31
4 * Robot`s visualization and control GUI for robot of the
5 * Eurobot 2008 (Mission to Mars).
7 * Copyright: (c) 2008 DCE Eurobot Dragon Team
8 * CTU FEE - Department of Control Engineering
9 * Authors: Martin Zidek, Michal Sojka, Tran Duy Khanh
10 * License: GNU GPL v.2
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
26 #include <path_planner.h>
32 #include "PlaygroundScene.h"
34 #include "RobomonTuning.h"
36 #include <QCoreApplication>
40 #include <QMessageBox>
42 RobomonTuning::RobomonTuning(QWidget *parent)
51 // createRightLayout();
53 QHBoxLayout *mainLayout = new QHBoxLayout;
54 mainLayout->addLayout(leftLayout);
55 // mainLayout->addLayout(rightLayout);
56 setLayout(mainLayout);
61 setFocusPolicy(Qt::StrongFocus);
64 /**********************************************************************
66 **********************************************************************/
67 void RobomonTuning::createLeftLayout()
69 leftLayout = new QVBoxLayout();
74 leftLayout->addWidget(pwrGroupBox);
75 leftLayout->addWidget(canGroupBox);
78 void RobomonTuning::createPwrGroupBox()
80 pwrGroupBox = new QGroupBox(tr("Pwr"));
81 QGridLayout *layout = new QGridLayout();
83 pwrAlertCBox = new QCheckBox();
85 layout->addWidget(pwrAlertCBox,0,0);
88 pwrGroupBox->setLayout(layout);
91 void RobomonTuning::createCanGroupBox()
93 canGroupBox = new QGroupBox(tr("Can"));
94 QHBoxLayout *layout = new QHBoxLayout();
96 canData1 = new QLineEdit(tr("data1"));
97 canData2 = new QLineEdit(tr("data2"));
98 canData3 = new QLineEdit(tr("data3"));
99 canData4 = new QLineEdit(tr("data4"));
100 canData5 = new QLineEdit(tr("data5"));
101 canData6 = new QLineEdit(tr("data6"));
102 canData7 = new QLineEdit(tr("data7"));
103 canData8 = new QLineEdit(tr("data8"));
104 canMsgLen = new QLineEdit(tr("len"));
105 canId = new QLineEdit(tr("ID"));
107 canSendPButton = new QPushButton(tr("Send"));
109 layout->addWidget(canData1);
110 layout->addWidget(canData2);
111 layout->addWidget(canData3);
112 layout->addWidget(canData4);
113 layout->addWidget(canData5);
114 layout->addWidget(canData6);
115 layout->addWidget(canData7);
116 layout->addWidget(canData8);
117 layout->addWidget(canMsgLen);
118 layout->addWidget(canId);
119 layout->addWidget(canSendPButton);
121 canGroupBox->setLayout(layout);
124 /**********************************************************************
126 **********************************************************************/
127 void RobomonTuning::createActions()
129 connect(pwrAlertCBox, SIGNAL(stateChanged(int)),
130 this, SLOT(setPwrAlert(int)));
132 connect(canSendPButton, SIGNAL(clicked()),
133 this, SLOT(setCanMsg()));
136 void RobomonTuning::setPwrAlert(int value)
139 orte.pwr_alert.value = 2;
142 orte.pwr_alert.value = 0;
148 void RobomonTuning::setCanMsg()
150 orte.can_msg.data[0] = canData1->text().toInt();
151 orte.can_msg.data[1] = canData2->text().toInt();
152 orte.can_msg.data[2] = canData3->text().toInt();
153 orte.can_msg.data[3] = canData4->text().toInt();
154 orte.can_msg.data[4] = canData5->text().toInt();
155 orte.can_msg.data[5] = canData6->text().toInt();
156 orte.can_msg.data[6] = canData7->text().toInt();
157 orte.can_msg.data[7] = canData8->text().toInt();
159 orte.can_msg.len = canMsgLen->text().toInt();
160 orte.can_msg.id = canId->text().toInt();
162 ORTEPublicationSend(orte.publication_can_msg);
166 /**********************************************************************
168 **********************************************************************/
169 bool RobomonTuning::event(QEvent *event)
171 switch (event->type()) {
172 case QEVENT(QEV_MOTION_STATUS):
174 case QEVENT(QEV_REFERENCE_POSITION):
176 case QEVENT(QEV_ESTIMATED_POSITION_ODO):
178 case QEVENT(QEV_SHARP_LONGS):
180 case QEVENT(QEV_SHARP_SHORTS):
182 case QEVENT(QEV_POWER_VOLTAGE):
185 if (event->type() == QEvent::Close)
186 closeEvent((QCloseEvent *)event);
187 else if (event->type() == QEvent::KeyPress)
188 keyPressEvent((QKeyEvent *)event);
189 else if (event->type() == QEvent::KeyRelease)
190 keyReleaseEvent((QKeyEvent *)event);
191 else if (event->type() == QEvent::FocusIn)
193 else if (event->type() == QEvent::FocusOut)
205 void RobomonTuning::keyPressEvent(QKeyEvent *event)
207 if (event->isAutoRepeat()) {
208 switch (event->key()) {
224 switch (event->key()) {
240 void RobomonTuning::keyReleaseEvent(QKeyEvent *event)
242 if (event->isAutoRepeat()) {
247 switch (event->key()) {
260 void RobomonTuning::closeEvent(QCloseEvent *)
262 robottype_roboorte_destroy(&orte);
265 /**********************************************************************
267 **********************************************************************/
268 void RobomonTuning::createOrte()
270 memset(&orte, 0, sizeof(orte));
271 if (robottype_roboorte_init(&orte) != 0) {
272 perror("robottype_roboorte_init");
276 orte.pwr_alert.value = 0;
279 robottype_publisher_can_msg_create(&orte, NULL, NULL);
280 robottype_publisher_pwr_ctrl_create(&orte, NULL, NULL);
281 robottype_publisher_pwr_alert_create(&orte, dummy_publisher_callback, NULL);
283 /*Power supply hack*/
284 orte.pwr_ctrl.voltage33 = true;
285 orte.pwr_ctrl.voltage50 = true;
286 orte.pwr_ctrl.voltage80 = true;
289 /**********************************************************************
291 **********************************************************************/