00001
00002 #include <stdio.h>
00003 #include <QTimer>
00004 #include <QDebug>
00005 #include <QFile>
00006 #include <QColorGroup>
00007 #include <QImage>
00008 #include "romeomainwindow.h"
00009 #include <QTimeLine>
00010
00011 #include <iostream>
00012
00013
00014 #include "../../common/trajectory/Trajectory.h"
00015 #include "../../common/trajectory/LinearTrajectoryInterpolator.h"
00016 #include "../../common/trajectory/TrajectoryUtil.h"
00017
00018
00019 #include <sparser/all.h>
00020 #include "signal.h"
00021
00022
00023 #include <yarp/os/all.h>
00024
00025
00026 #include <opencv/cv.h>
00027 #include <opencv/highgui.h>
00028 #include <opencv/cxcore.h>
00029
00030 #define X_INITIAL_PIXEL 38
00031 #define Y_INITIAL_PIXEL 642
00032
00033 static const double Pi = 3.14159265358979323846264338327950288419717;
00034 using namespace std;
00035
00036
00037 RomeoMainWindow::RomeoMainWindow(QWidget* parent, Qt::WFlags fl)
00038 : QMainWindow( parent, fl ), Ui::MainWindow()
00039 {
00040 setupUi(this);
00041 initialValues();
00042 createActions();
00043 createGraphicsView();
00044 check_YARP_network();
00045 startYarpCommunications();
00046 statusbar->showMessage(tr("(INFO) - Ready"));
00047 }
00048
00049 RomeoMainWindow::~RomeoMainWindow()
00050 {
00051 }
00052
00053
00054 void RomeoMainWindow::initialValues()
00055 {
00056
00057 QPixmap pixmap(":/images/GRVClogo2-1.jpg");
00058 splash = new QSplashScreen(pixmap);
00059 splash->show();
00060
00061
00062
00063 x_ref=0;
00064 y_ref=0;
00065
00066 orient_ref=0;
00067 previous_orient_ref=0;
00068
00069 speed_ref=0;
00070 curv_ref=0;
00071
00072 yaw_ref=0;
00073 pitch_ref=0;
00074 roll_ref=0;
00075
00076 x_ini_local=0;
00077 y_ini_local=0;
00078
00079 x_ini_global=0;
00080 y_ini_global=0;
00081
00082 purpurState=0;
00083 previousPurpurState=0;
00084
00085 zoomPreviousValue=0;
00086
00087 trajectory_points_number=0;
00088 trajectory_edit_mode=false;
00089 theta_edit_mode=false;
00090 trajectory_executing_mode=false;
00091 setting_initial_point=false;
00092
00093 trajectoriesBYinterface=false;
00094
00095 theta=0;
00096 previous_theta=0;
00097 theta_offset=0;
00098
00099 map_x_axis_length=100;
00100 map_y_axis_length=100;
00101
00102 yarpRunning=true;
00103
00104
00105
00106 readLaser2DImage=false;
00107
00108 readElevationMapImage=false;
00109 elevationMapMainView=false;
00110
00111 readTransMapImage=false;
00112 transMapMainView=false;
00113
00114
00115
00116 elevationMap_SWITCH_VIEW_toolButton->setEnabled(false);
00117 transMap_SWITCH_VIEW_toolButton->setEnabled(false);
00118
00119 laser2D_STOP_toolButton->setEnabled(false);
00120 elevationMap_STOP_toolButton->setEnabled(false);
00121 transMap_STOP_toolButton->setEnabled(false);
00122
00123 launcher_STOP_toolButton->setEnabled(false);
00124
00125
00126
00127
00128
00129
00130 }
00131
00132
00133 void RomeoMainWindow::createActions()
00134 {
00135
00136
00137 QTimer *timer = new QTimer();
00138 connect(timer, SIGNAL(timeout()), this, SLOT(read_odometry_values()));
00139 timer->start(1000);
00140
00141 QTimer *timer2 = new QTimer();
00142 connect(timer2, SIGNAL(timeout()), this, SLOT(read_system_status()));
00143 timer2->start(2000);
00144
00145
00146 QTimeLine *timeLine= new QTimeLine(100,this);
00147 connect(timeLine, SIGNAL(finished()),splash, SLOT(close()));
00148 connect(timeLine, SIGNAL(finished()),this, SLOT(show()));
00149 timeLine->start();
00150
00151
00152 connect(this, SIGNAL(message(QString)), this, SLOT(showMessage(QString)) );
00153 connect(&scene, SIGNAL(messagemap(QString)), this, SLOT(showMessage(QString)) );
00154 connect(&SelectTrajectory, SIGNAL(preloadTrajectory(QString)), this, SLOT(showTrajectory(QString)) );
00155
00156
00157 connect(&scene, SIGNAL(changeRobot(QPoint)), this, SLOT(changeRobotPosition(QPoint)) );
00158 connect(&scene,SIGNAL(ungrabRobot()),this,SLOT(ungrabRomeo()));
00159 connect(&scene,SIGNAL(mapScenePressEvent(QPointF)),this,SLOT(mapPressEvent(QPointF)));
00160
00161
00162
00163 connect(aboutQt_toolButton, SIGNAL(clicked()), this, SLOT(aboutQt()));
00164 connect(about_RomeoHMI_toolButton, SIGNAL(clicked()), this, SLOT(about()));
00165 connect(EXIT_toolButton, SIGNAL(clicked()), this, SLOT(exitApplication()));
00166 connect(Zoom_verticalSlider, SIGNAL(valueChanged(int)), this, SLOT(zooming(int)));
00167
00168
00169
00170
00171
00172
00173
00174 connect(laser2D_START_toolButton, SIGNAL(clicked()), this, SLOT(connect_LASER2D_sensor()));
00175 connect(laser2D_STOP_toolButton, SIGNAL(clicked()), this, SLOT(disconnect_LASER2D_sensor()));
00176
00177 connect(elevationMap_START_toolButton, SIGNAL(clicked()), this, SLOT(connect_ELEVATIONMAP_sensor()));
00178 connect(elevationMap_STOP_toolButton, SIGNAL(clicked()), this, SLOT(disconnect_ELEVATIONMAP_sensor()));
00179 connect(elevationMap_SWITCH_VIEW_toolButton, SIGNAL(clicked()), this, SLOT(switchElevationView()));
00180
00181 connect(transMap_START_toolButton, SIGNAL(clicked()), this, SLOT(connect_TRANSMAP_sensor()));
00182 connect(transMap_STOP_toolButton, SIGNAL(clicked()), this, SLOT(disconnect_TRANSMAP_sensor()));
00183 connect(transMap_SWITCH_VIEW_toolButton, SIGNAL(clicked()), this, SLOT(switchTransView()));
00184
00185
00186
00187 connect(INIT_toolButton, SIGNAL(clicked()), this, SLOT(initialtrajectorypoint()));
00188 connect(NEXT_toolButton, SIGNAL(clicked()), this, SLOT(nexttrajectorypoint()));
00189 connect(thetaInit_ToolButton, SIGNAL(clicked()), this, SLOT(changeThetaInit()));
00190 connect(loadMap_toolButton, SIGNAL(clicked()), this, SLOT(openMap()));
00191 connect(loadTrajectory_toolButton, SIGNAL(clicked()), this, SLOT(openTraject()));
00192 connect(trashTrajectory_toolButton, SIGNAL(clicked()), this, SLOT(trashtrajectory()));
00193 connect(launchTrajectorytoolButton, SIGNAL(clicked()), this, SLOT(launchEvent()));
00194 connect(PANIC_toolButton, SIGNAL(clicked()), this, SLOT(panicEvent()));
00195
00196 connect(LEFT_toolButton, SIGNAL(clicked()), this, SLOT(leftArrow()));
00197 connect(RIGHT_toolButton, SIGNAL(clicked()), this, SLOT(rightArrow()));
00198 connect(UP_toolButton, SIGNAL(clicked()), this, SLOT(upArrow()));
00199 connect(DOWN_toolButton, SIGNAL(clicked()), this, SLOT(downArrow()));
00200
00201
00202
00203
00204 file.setFileName("trajectory.dat");
00205 if (file.open(QFile::WriteOnly))
00206 {
00207 test_trajectory_line.setDevice(&file);
00208 }
00209 }
00210
00211 void RomeoMainWindow::check_YARP_network()
00212 {
00213 statusbar->showMessage(tr("(INFO) - Checking Yarp Network ..."));
00214
00215
00216 yarpRunning=true;
00217 if(yarpRunning==true)
00218 {
00219 statusbar->showMessage(tr("(INFO) - Yarp OK ..."));
00220 }
00221 else
00222 {
00223 statusbar->showMessage(tr("(INFO) - Yarp Network DOWN..."));
00224 }
00225 }
00226
00227
00228 void RomeoMainWindow::startYarpCommunications()
00229 {
00230 if(yarpRunning==true)
00231 {
00232
00233 yarp::os::Network::init();
00234
00235
00236
00237 locInput.open("/romeo/hmi/ekfloc/data");
00238 odomInput.open("/romeo/hmi/dcx/data");
00239
00240
00241 laser2DImageInput.open("/romeo/hmi/laser2D/sensorimage");
00242 elevationMapImageInput.open("/romeo/hmi/sensormap/sensorimage");
00243 transMapImageInput.open("/romeo/hmi/transmap/sensorimage");
00244
00245
00246 yarp::os::Network::connect("/romeo/dcx/data","/romeo/hmi/dcx/data");
00247
00248 yarp::os::Network::connect("/romeo/ekfloc/data","/romeo/hmi/ekfloc/data");
00249
00250
00251 purpurStatePort.open("/romeo/hmi/purpur/state");
00252 yarp::os::Network::connect("/romeo/purpur/state","/romeo/hmi/purpur/state");
00253 }
00254 }
00255
00256 void RomeoMainWindow::aboutQt()
00257 {
00258 QMessageBox::aboutQt( this, "Qt About" );
00259 }
00260
00261 void RomeoMainWindow::about()
00262 {
00263 QMessageBox::about(this, tr("About Romeo Human Machine Interface 2.0"),
00264 tr("The Romeo HMI v 1.0 was developed by Daniel Perez Rodriguez "
00265 "member of <b>The Robotics, Vision and Control Group</b>, "
00266 "at the Engeneering High School of Seville."
00267 "<p>"
00268 "September 2009"));
00269 }
00270
00271 void RomeoMainWindow::exitApplication()
00272 {
00273 this->close();
00274 }
00275
00276 void RomeoMainWindow::read_odometry_values()
00277 {
00278 if( yarpRunning == true )
00279 {
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 pyarpDcx=odomInput.read(false);
00313 pyarpEkf=locInput.read(false);
00314
00315 if(pyarpDcx!=NULL)
00316 {
00317 speed_ref=pyarpDcx->dcxSpeed;
00318 curv_ref=pyarpDcx->dcxCurv;
00319 }
00320 else
00321 {
00322 yarp::os::Network::connect("/romeo/dcx/data", "/romeo/hmi/dcx/data");
00323 }
00324
00325 if(pyarpEkf!=NULL)
00326 {
00327 x_ref=pyarpEkf->x;
00328 y_ref=pyarpEkf->y;
00329 orient_ref=pyarpEkf->theta;
00330
00331
00332
00333
00334 theta=orient_ref*(-180/Pi);
00335 }
00336 else
00337 {
00338
00339 yarp::os::Network::connect("/romeo/ekfloc/data", "/romeo/hmi/ekfloc/data");
00340 }
00341
00342 XcoordinatelcdNumber->display(x_ref);
00343 YcoordinatelcdNumber->display(y_ref);
00344 YAWlcdNumber-> display(yaw_ref);
00345 PITCHlcdNumber-> display(pitch_ref);
00346 ROLLlcdNumber-> display(roll_ref);
00347 speedlcdNumber->display(speed_ref);
00348 curvatureDial->setProperty("value", (-100)*curv_ref);
00349
00350
00351
00352 if (trajectory_edit_mode==false)
00353 {
00354 romeo->setPos(global_init_point.x()+(x_ref*map_X_scale),global_init_point.y()-(y_ref*map_Y_scale));
00355
00356
00357 romeo->rotate((orient_ref-previous_orient_ref)*(-180/Pi));
00358 }
00359
00360 previous_orient_ref=orient_ref;
00361
00362
00363
00364
00365 if( readLaser2DImage==true )
00366 {
00367 laser2DImage=laser2DImageInput.read(false);
00368
00369 if(laser2DImage!=NULL)
00370 {
00371 if( (laserRange->scene()!=&laser2Dscene) && (romeoImage->scene()!=&laser2Dscene))
00372 {
00373 laserRange=laser2Dscene.addEllipse(QRectF(0,0,170,170));
00374 laserRange->setSpanAngle(2880);
00375 laserRange->setBrush(QColor(225,225,255,127));
00376 laserRange->setPen(QPen(Qt::blue, 1, Qt::DotLine, Qt::FlatCap, Qt::RoundJoin));
00377 laserRange->setPos(0,65);
00378
00379 romeoImage=laser2Dscene.addPixmap(QPixmap(":/images/romeo3.png"));
00380 romeoImage->setPos(90,150);
00381 romeoImage->setZValue(10);
00382 }
00383
00384 cvLaser2DImage=(IplImage *)laser2DImage->getIplImage();
00385 IplImage2QImage(cvLaser2DImage,laser2DPixmap, &laser2Dscene);
00386
00387 laser2D_x_axis_length=laser2DPixmap->pixmap().width();
00388 laser2D_y_axis_length=laser2DPixmap->pixmap().height();
00389
00390
00391 }
00392 else
00393 {
00394
00395
00396 QList<QGraphicsItem *> list1 =laser2Dscene.items();
00397
00398 foreach (QGraphicsItem *list, list1)
00399 {
00400 laser2Dscene.removeItem(list);
00401 }
00402
00403 laser2DInfoText=laser2Dscene.addText("Port Open\nBUT No Image\nReceived", infoFont);
00404 laser2DGraphicsView->resetMatrix();
00405 laser2DGraphicsView->centerOn(elevationMapInfoText);
00406 laser2Dscene.update();
00407 }
00408 }
00409 else
00410 {
00411
00412
00413 QList<QGraphicsItem *> list1 =laser2Dscene.items();
00414
00415 foreach (QGraphicsItem *list, list1)
00416 {
00417 laser2Dscene.removeItem(list);
00418 }
00419
00420 laser2DInfoText=laser2Dscene.addText(" - DISABLED -", infoFont);
00421 laser2DGraphicsView->resetMatrix();
00422 laser2DGraphicsView->centerOn(laser2DInfoText);
00423 laser2Dscene.update();
00424 }
00425
00426
00427
00428 if( readElevationMapImage==true )
00429 {
00430 elevationMapImage=elevationMapImageInput.read(false);
00431
00432 if(elevationMapImage!=NULL)
00433 {
00434 cvelevationMapImage=(IplImage *)elevationMapImage->getIplImage();
00435 IplImage2QImage(cvelevationMapImage,elevationMapPixmap, &elevationMapscene);
00436 elevationMap_SWITCH_VIEW_toolButton->setEnabled(true);
00437
00438 elevationMap_x_axis_length=elevationMapPixmap->pixmap().width();
00439 elevationMap_y_axis_length=elevationMapPixmap->pixmap().height();
00440
00441 if( elevationMapMainView==false )
00442 { elevationMapGraphicsView->fitInView (elevationMapPixmap,Qt::IgnoreAspectRatio );
00443 }
00444 }
00445 else
00446 {
00447
00448
00449 QList<QGraphicsItem *> list2 =elevationMapscene.items();
00450
00451 foreach (QGraphicsItem *list, list2)
00452 {
00453 elevationMapscene.removeItem(list);
00454 }
00455
00456 elevationMapInfoText=elevationMapscene.addText("Port Open\nBUT No Image\nReceived", infoFont);
00457 elevationMapGraphicsView->resetMatrix();
00458 elevationMapGraphicsView->centerOn(elevationMapInfoText);
00459 elevationMapscene.update();
00460 elevationMapMainView=false;
00461 elevationMap_SWITCH_VIEW_toolButton->setEnabled(false);
00462 }
00463 }
00464 else
00465 {
00466
00467
00468 QList<QGraphicsItem *> list2 =elevationMapscene.items();
00469
00470 foreach (QGraphicsItem *list, list2)
00471 {
00472 elevationMapscene.removeItem(list);
00473 }
00474
00475 elevationMapInfoText=elevationMapscene.addText(" - DISABLED -", infoFont);
00476 elevationMapGraphicsView->resetMatrix();
00477 elevationMapGraphicsView->centerOn(elevationMapInfoText);
00478 elevationMapMainView=false;
00479 elevationMap_SWITCH_VIEW_toolButton->setEnabled(false);
00480 elevationMapscene.update();
00481 }
00482
00483
00484
00485 if( readTransMapImage==true )
00486 {
00487 transMapImage=transMapImageInput.read(false);
00488
00489 if(transMapImage!=NULL)
00490 {
00491 cvTransMapImage=(IplImage *)transMapImage->getIplImage();
00492 IplImage2QImage(cvTransMapImage,transMapPixmap, &transMapscene);
00493 transMap_SWITCH_VIEW_toolButton->setEnabled(true);
00494
00495 transMap_x_axis_length=elevationMapPixmap->pixmap().width();
00496 transMap_y_axis_length=elevationMapPixmap->pixmap().height();
00497
00498 if( transMapMainView==false )
00499 { transMapGraphicsView->fitInView (transMapPixmap,Qt::IgnoreAspectRatio );
00500 }
00501
00502 }
00503 else
00504 {
00505
00506
00507 QList<QGraphicsItem *> list3 =transMapscene.items();
00508
00509 foreach (QGraphicsItem *list, list3)
00510 {
00511 transMapscene.removeItem(list);
00512 }
00513
00514 transMapInfoText=transMapscene.addText("Port Open\nBUT No Image\nReceived", infoFont);
00515 transMapGraphicsView->resetMatrix();
00516 transMapGraphicsView->centerOn(transMapInfoText);
00517 transMapscene.update();
00518 transMapMainView=false;
00519 transMap_SWITCH_VIEW_toolButton->setEnabled(false);
00520 }
00521 }
00522 else
00523 {
00524
00525
00526 QList<QGraphicsItem *> list3 =transMapscene.items();
00527
00528 foreach (QGraphicsItem *list, list3)
00529 {
00530 transMapscene.removeItem(list);
00531 }
00532
00533 transMapInfoText=transMapscene.addText(" - DISABLED -", infoFont);
00534 transMapGraphicsView->resetMatrix();
00535 transMapGraphicsView->centerOn(transMapInfoText);
00536 transMapMainView=false;
00537 transMap_SWITCH_VIEW_toolButton->setEnabled(false);
00538 transMapscene.update();
00539 }
00540
00541
00542
00543 }
00544 }
00545
00546 void RomeoMainWindow::closeEvent(QCloseEvent *event)
00547 {
00548 int ret = QMessageBox::question(this, tr("ROMEO HMI v 2.0"),
00549 tr("Do you really want to exit ?\n"),
00550 QMessageBox::Yes | QMessageBox::No );
00551
00552 if (ret == QMessageBox::Yes)
00553 {
00554 emit message(QString("Closing application ..."));
00555 stop_ALL_CONTROL_Process();
00556 yarp::os::Network::fini();
00557 event->accept();
00558 }
00559 else if (ret == QMessageBox::No)
00560 {
00561 event->ignore();
00562 }
00563 }
00564
00565 void RomeoMainWindow::openMap()
00566 {
00567 QString mapName = QFileDialog::getOpenFileName(this, tr("Open Map"), "../src/images/maps", tr("Map Files (*.png *.jpg *.bmp)"));
00568
00569 if (!mapName.isEmpty())
00570 {
00571 loadMap(mapName);
00572 statusbar->showMessage(tr("(INFO) - New map loaded"));
00573
00574
00575 if(MapScale.exec() == QDialog::Accepted)
00576 {
00577 map_x_axis_length=MapScale.spinBox_X_Dimension->value();
00578 map_y_axis_length=MapScale.spinBox_Y_Dimension->value();
00579 }
00580 }
00581 }
00582 void RomeoMainWindow::loadMap(QString mapName)
00583 {
00584 foreach (QGraphicsPixmapItem *actualMap, maps)
00585 {
00586 scene.removeItem(actualMap);
00587 }
00588
00589 map=QPixmap(QString("%1").arg(mapName));
00590 map.setMask(map.createMaskFromColor(Qt::black, Qt::MaskOutColor));
00591
00592
00593 QGraphicsPixmapItem *mapPoint=scene.addPixmap(map);
00594 scene.update();
00595 maps.append(mapPoint);
00596 mapPoint->setTransformationMode(Qt::SmoothTransformation);
00597
00598 map_width=map.width();
00599 map_height=map.height();
00600
00601 map_X_scale=map.width()/map_x_axis_length;
00602 map_Y_scale=map.width()/map_y_axis_length;
00603
00604 MapGraphicsView->setSceneRect(0,0, map_width, map_height);
00605 zoomFit();
00606 trashtrajectory();
00607
00608 loadSemanticSpots(mapName);
00609 }
00610
00611
00612
00613 void RomeoMainWindow::openTraject()
00614 {
00615 if( trajectoriesBYinterface == true )
00616 {
00617 QDir dir;
00618 QString trajectoryName;
00619 QString path=dir.currentPath();
00620
00621 SelectTrajectory.move(0,0);
00622
00623 int Result = SelectTrajectory.exec();
00624
00625 if(Result == QDialog::Accepted)
00626 {
00627 if(!trajectoryName.isEmpty())
00628 {
00629 trajectoryName=SelectTrajectory.trajectory;
00630 trajectoryName.prepend("/src/images/trajectories/UPC/");
00631 trajectoryName.prepend(path);
00632 loadTrajectory(trajectoryName);
00633 statusbar->showMessage(tr("(INFO) - New trajectory loaded: %1").arg(trajectoryName) );
00634 }
00635 }
00636
00637 if(Result == QDialog::Rejected)
00638 {
00639 trashtrajectory();
00640 trajectoryName.clear();
00641 statusbar->showMessage(tr("(WARN) - NO trajectory loaded.") );
00642 }
00643
00644 }
00645 else
00646 {
00647 QString trajectoryName = QFileDialog::getOpenFileName(this, tr("Open Trajectory"), "../src/images/trajectories", tr("Map Files (*.dat)"));
00648
00649 if (!trajectoryName.isEmpty())
00650 {
00651 loadTrajectory(trajectoryName);
00652 statusbar->showMessage(tr("(INFO) - New trajectory loaded"));
00653 }
00654 }
00655 }
00656
00657 void RomeoMainWindow::zooming(int value)
00658 {
00659 double dif;
00660
00661 dif=value-zoomPreviousValue;
00662
00663 if(dif>0)
00664 {
00665 MapGraphicsView->scale(1.2,1.2);
00666 statusbar->showMessage(tr("(INFO) - Zoom IN 10%"));
00667 }
00668 else if(dif<0)
00669 {
00670 MapGraphicsView->scale(0.8,0.8);
00671 statusbar->showMessage(tr("(INFO) - Zoom OUT 10%"));
00672 }
00673
00674 zoomPreviousValue=value;
00675
00676 update();
00677 }
00678
00679 void RomeoMainWindow::zoomFit()
00680 {
00681 zoomPreviousValue=0;
00682 Zoom_verticalSlider->setValue(0);
00683 MapGraphicsView->resetMatrix();
00684 MapGraphicsView->scale(0.5,0.5);
00685 scene.update();
00686 }
00687
00688
00689 void RomeoMainWindow::read_system_status()
00690 {
00691
00692
00693 QFile file_stats("/proc/stat", this);
00694 if ( !file_stats.open(QIODevice::ReadOnly | QIODevice::Text) )
00695 {
00696 qDebug() << "File /proc/stat could not be opened";
00697 return;
00698 }
00699
00700 QString cpu_line = file_stats.readLine();
00701 QStringList list1 = cpu_line.split(" ");
00702
00703 for ( int i=0; i < 4; i++)
00704 {
00705 m_stats_new[i]=list1[i+1].toDouble();
00706 }
00707
00708 double user = m_stats_new[0]- m_stats[0];
00709 double nice = m_stats_new[1]- m_stats[1];
00710 double system = m_stats_new[2]- m_stats[2];
00711
00712 double cpu_usage = (user + system + nice);
00713
00714 for (int i=0; i < 4; i++)
00715 {
00716 m_stats[i] = m_stats_new[i];
00717 }
00718
00719 CPUprogressBar->setValue(cpu_usage);
00720 file_stats.close();
00721
00722
00723
00724 QFile mem_stats("/proc/meminfo", this);
00725 if ( !mem_stats.open(QIODevice::ReadOnly | QIODevice::Text) )
00726 {
00727 qDebug() << "File /proc/stat could not be opened";
00728 return;
00729 }
00730
00731 QString mem_line = mem_stats.readLine();
00732 QStringList list2 = mem_line.split(QRegExp("\\W+"), QString::SkipEmptyParts);
00733
00734 double MemTotal=list2[1].toDouble();
00735
00736 mem_stats.seek(26);
00737 mem_line = mem_stats.readLine();
00738
00739 list2 = mem_line.split(QRegExp("\\W+"), QString::SkipEmptyParts);
00740
00741 double MemFree=list2[1].toDouble();
00742
00743 double mem_usage=((MemTotal-MemFree)/MemTotal)*100;
00744
00745 memoryProgressBar->setValue(mem_usage);
00746 mem_stats.close();
00747
00748
00749
00750 double tx_stats;
00751 double rx_stats;
00752
00753 QFile net_stats("/proc/net/dev", this);
00754 if ( !net_stats.open(QIODevice::ReadOnly | QIODevice::Text) )
00755 {
00756 qDebug() << "File /proc/net/dev could not be opened";
00757 return;
00758 }
00759
00760 for (int i=0;i<4;i++)
00761 {
00762 QString net_line = net_stats.readLine();
00763
00764 QStringList list3 = net_line.split(QRegExp("\\W+"), QString::SkipEmptyParts);
00765
00766 if(list3[0]=="eth0" )
00767 {
00768 tx_net_stats_new=list3[9].toDouble();
00769 rx_net_stats_new=list3[1].toDouble();
00770
00771 tx_stats = (tx_net_stats_new - tx_net_stats)/2048;
00772 rx_stats = (rx_net_stats_new - rx_net_stats)/2048;
00773
00774 tx_net_stats=tx_net_stats_new;
00775 rx_net_stats=rx_net_stats_new;
00776 }
00777 }
00778
00779 networkTX_progressBar->setValue(tx_stats);
00780 networkRX_progressBar->setValue(rx_stats);
00781
00782 net_stats.close();
00783 }
00784
00785
00786
00787 void RomeoMainWindow::createGraphicsView()
00788 {
00789
00790
00791 infoFont.setStyle(QFont::StyleItalic);
00792 infoFont.setStyleHint(QFont::System);
00793 infoFont.setWeight(QFont::Bold);
00794 infoFont.setPointSize(10);
00795
00796
00797
00798 MapGraphicsView->setInteractive(true);
00799 MapGraphicsView->setRenderHint(QPainter::Antialiasing);
00800 MapGraphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
00801 MapGraphicsView->setCacheMode(QGraphicsView::CacheBackground);
00802
00803 MapGraphicsView->setEnabled(true);
00804 MapGraphicsView->setScene(&scene);
00805
00806 romeo=&romeo_local;
00807 romeo->setPixmap(QPixmap(":/images/romeo3.png"));
00808 romeo->setTransformationMode(Qt::SmoothTransformation);
00809 romeo->setAcceptedMouseButtons(Qt::LeftButton);
00810 romeo->setAcceptDrops(true);
00811 romeo->setEnabled(true);
00812
00813 romeo->setPos(X_INITIAL_PIXEL,Y_INITIAL_PIXEL);
00814
00815
00816
00817
00818 romeo->setZValue(10);
00819
00820 last_trajectory_point=romeo->scenePos();
00821 initial_trajectory_point=romeo->scenePos();
00822
00823 qDebug() << "Initial Trajectory Point: " << initial_trajectory_point;
00824
00825 global_init_point=romeo->scenePos();
00826
00827 loadMap(QString("src/images/maps/upc2.png"));
00828
00829 x_ini_global=romeo->pos().x();
00830 y_ini_global=romeo->pos().y();
00831
00832 qDebug() << "X ini Global: " << x_ini_global << " [pixels]";
00833 qDebug() << "Y ini Global: " << y_ini_global << " [pixels]";
00834
00835 graphicview2map(&x_ini_global,&y_ini_global);
00836
00837 qDebug() << "X ini Global: " << x_ini_global << " [meters]";
00838 qDebug() << "Y ini Global: " << y_ini_global << " [meters]";
00839
00840 scene.addItem(romeo);
00841 zoomFit();
00842 scene.update();
00843
00844
00845
00846 laser2DGraphicsView->setScene(&laser2Dscene);
00847 laser2DGraphicsView->setRenderHint(QPainter::Antialiasing);
00848 laser2DGraphicsView->setCacheMode(QGraphicsView::CacheBackground);
00849 laser2DGraphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00850 laser2DGraphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00851 laser2DGraphicsView->setDragMode(QGraphicsView::NoDrag);
00852
00853 laser2DPixmap=&laser2DPixmap_local;
00854
00855 laser2DInfoText=laser2Dscene.addText(" - DISABLED -",infoFont);
00856
00857 laser2Dscene.update();
00858
00859
00860
00861 elevationMapGraphicsView->setScene(&elevationMapscene);
00862 elevationMapGraphicsView->setRenderHint(QPainter::Antialiasing);
00863 elevationMapGraphicsView->setCacheMode(QGraphicsView::CacheBackground);
00864 elevationMapGraphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00865 elevationMapGraphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00866 elevationMapGraphicsView->setDragMode(QGraphicsView::NoDrag);
00867
00868 elevationMapPixmap=&elevationMapPixmap_local;
00869 elevationMapInfoText=elevationMapscene.addText(" - DISABLED -",infoFont);
00870 elevationMapscene.update();
00871
00872
00873
00874 transMapGraphicsView->setScene(&transMapscene);
00875 transMapGraphicsView->setRenderHint(QPainter::Antialiasing);
00876 transMapGraphicsView->setCacheMode(QGraphicsView::CacheBackground);
00877 transMapGraphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00878 transMapGraphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00879 transMapGraphicsView->setDragMode(QGraphicsView::NoDrag);
00880
00881 transMapPixmap=&transMapPixmap_local;
00882 transMapInfoText=transMapscene.addText(" - DISABLED -",infoFont);
00883 transMapscene.update();
00884 }
00885
00886 void RomeoMainWindow::loadTrajectory(QString trajectoryName)
00887 {
00888 QFile file;
00889
00890 double x;
00891 double y;
00892 double speed;
00893 char endline;
00894
00895 QPointF nextPoint;
00896
00897 file.setFileName(trajectoryName);
00898
00899 if ( file.open(QFile::ReadOnly) )
00900 {
00901 trashtrajectory();
00902 QTextStream in(&file);
00903
00904 while ( !in.atEnd() )
00905 {
00906 in >> x;
00907 in >> y;
00908 in >> speed;
00909 in >> endline;
00910
00911 romeo2graphicview(&x,&y);
00912
00913 qDebug() << "X: " << x;
00914 qDebug() << "Y: " << y;
00915
00916 nextPoint.setX(x);
00917 nextPoint.setY(y);
00918
00919 trajectory_edit_mode=true;
00920 emit mapPressEvent( nextPoint );
00921 }
00922 file.close();
00923 trajectory_edit_mode=false;
00924 }
00925 }
00926
00927
00928 void RomeoMainWindow::loadSemanticSpots(QString mapName)
00929 {
00930 foreach (QGraphicsItem *list, semanticSpotsList)
00931 {
00932 scene.removeItem(list);
00933 }
00934
00935 foreach (QGraphicsItem *list, semanticSpotsText)
00936 {
00937 scene.removeItem(list);
00938 }
00939
00940 foreach (QGraphicsItem *list, semanticInfo)
00941 {
00942 scene.removeItem(list);
00943 }
00944
00945 char type[50];
00946 char name[50];
00947 double x;
00948 double y;
00949 char endline;
00950 int nspots=0;
00951
00952 QGraphicsTextItem *info[15];
00953 QGraphicsTextItem *spotNames[15];
00954 QGraphicsEllipseItem *semanticSpots[15];
00955
00956 QFont coordinates_font("Arial", 8, QFont::Bold);
00957 QFont info_font1("Arial", 20, QFont::Bold);
00958
00959 QFile fileSemanticPoints;
00960 fileSemanticPoints.setFileName(QString("%1.semanticMapList.txt").arg(mapName));
00961
00962 QFile fileSemanticInfo;
00963 fileSemanticInfo.setFileName(QString("%1.semanticInfoList.txt").arg(mapName));
00964
00965
00966 if ( fileSemanticInfo.open(QFile::ReadOnly) )
00967 {
00968 QTextStream in(&fileSemanticInfo);
00969
00970 while ( !in.atEnd() )
00971 {
00972 in >> type;
00973 in >> name;
00974 in >> x;
00975 in >> y;
00976 in >> endline;
00977
00978 info[nspots]=scene.addText(QString("%1").arg(name),info_font1);
00979 info[nspots]->setDefaultTextColor(Qt::lightGray);
00980 info[nspots]->setPos(x,y);
00981 semanticInfo.append(info[nspots]);
00982 nspots++;
00983
00984 }
00985 fileSemanticInfo.close();
00986 }
00987
00988
00989 if ( fileSemanticPoints.open(QFile::ReadOnly) )
00990 {
00991 nspots=0;
00992
00993 QTextStream in(&fileSemanticPoints);
00994
00995 while ( !in.atEnd() )
00996 {
00997 in >> name;
00998 in >> x;
00999 in >> y;
01000 in >> endline;
01001
01002 map2graphicview(&x,&y);
01003
01004 semanticSpots[nspots]=scene.addEllipse(QRectF(0,0,10,10));
01005 semanticSpots[nspots]->setPos(x,y-10);
01006 semanticSpots[nspots]->setBrush(Qt::darkGreen);
01007 semanticSpotsList.append(semanticSpots[nspots]);
01008
01009 spotNames[nspots]=scene.addText(QString("%1").arg(name),coordinates_font);
01010 spotNames[nspots]->setDefaultTextColor(Qt::darkGray);
01011 spotNames[nspots]->setPos(x-15,y);
01012 semanticSpotsText.append(spotNames[nspots]);
01013
01014 nspots++;
01015 }
01016 fileSemanticPoints.close();
01017 }
01018 }
01019
01020
01021
01022
01023 void RomeoMainWindow::trashtrajectory()
01024 {
01025 trajectory_edit_mode=false;
01026 trajectory_executing_mode=false;
01027 romeo->setAcceptedMouseButtons(0);
01028
01029 setCursor(Qt::ArrowCursor);
01030 MapGraphicsView->setCursor(Qt::ArrowCursor);
01031 romeo->setCursor(Qt::ArrowCursor);
01032 romeo->setAcceptedMouseButtons(Qt::LeftButton);
01033 emit message("Trajectory Trashed");
01034
01035 trajectory_points_number=0;
01036
01037
01038 file.remove();
01039
01040
01041 file.setFileName("trajectory.dat");
01042
01043 if (file.open(QFile::WriteOnly))
01044 {
01045 test_trajectory_line.setDevice(&file);
01046 }
01047
01048
01049
01050
01051
01052
01053 last_trajectory_point=QPointF(romeo->scenePos().x(),romeo->scenePos().y() );
01054 initial_trajectory_point=QPointF(romeo->scenePos().x(),romeo->scenePos().y() );
01055
01056 trajectory_edit_mode=false;
01057
01058 foreach (QGraphicsEllipseItem *spot, spots)
01059 {
01060 scene.removeItem(spot);
01061 }
01062
01063 foreach (QGraphicsLineItem *line, lines)
01064 {
01065 scene.removeItem(line);
01066 }
01067
01068 foreach (QGraphicsLineItem *line, absolutLines)
01069 {
01070 scene.removeItem(line);
01071 }
01072
01073 foreach (QGraphicsTextItem *text, waypoints)
01074 {
01075 scene.removeItem(text);
01076 }
01077
01078 foreach (QGraphicsTextItem *text, absolutWaypoints)
01079 {
01080 scene.removeItem(text);
01081 }
01082
01083 trajectory_lines.clear();
01084
01085 statusbar->showMessage(tr("(INFO) - Trajectory Crashed."));
01086 }
01087
01088
01089
01090
01091 void RomeoMainWindow::graphicview2romeo( double *x_graph,double *y_graph )
01092 {
01093
01094 graphicview2map(x_graph, y_graph);
01095
01096 (*x_graph)-=x_ini_global;
01097 (*y_graph)-=y_ini_global;
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127 }
01128
01129 void RomeoMainWindow::map2graphicview(double *x,double *y)
01130 {
01131 (*x)= (*x);
01132 (*y)= map_y_axis_length-(*y);
01133
01134
01135 (*x)=(*x)*map_X_scale;
01136 (*y)=(*y)*map_Y_scale;
01137
01138 }
01139
01140
01141 void RomeoMainWindow::graphicview2map(double *x, double *y)
01142 {
01143 (*x)=(*x)/map_X_scale;
01144 (*y)=(map_height-(*y))/map_Y_scale;
01145 }
01146
01147
01148 void RomeoMainWindow::romeo2graphicview( double *x_graph,double *y_graph )
01149 {
01150 double x_graph_ini = *x_graph;
01151 double y_graph_ini = *y_graph;
01152
01153
01154
01155 (*x_graph)= (x_graph_ini)*cos(theta*(Pi/180))+(y_graph_ini)*sin(theta*(Pi/180));
01156 (*y_graph)= (y_graph_ini)*cos(theta*(Pi/180))-(x_graph_ini)*sin(theta*(Pi/180));
01157
01158
01159 (*y_graph)=(*y_graph)*(-1);
01160
01161
01162 (*x_graph)=(*x_graph)*map_X_scale;
01163 (*y_graph)=(*y_graph)*map_Y_scale;
01164
01165
01166
01167 (*x_graph)= (*x_graph) + romeo->pos().x();
01168 (*y_graph)= (*y_graph) + romeo->pos().y();
01169
01170 }
01171
01172
01173
01174 void RomeoMainWindow:: mapPressEvent(QPointF clickedPoint)
01175 {
01176 qreal x = clickedPoint.x();
01177 qreal y = clickedPoint.y();
01178
01179 QPen pen1;
01180 pen1.setStyle(Qt::DashDotLine);
01181 pen1.setWidth(2);
01182 pen1.setBrush(Qt::blue);
01183 pen1.setCapStyle(Qt::RoundCap);
01184 pen1.setJoinStyle(Qt::RoundJoin);
01185
01186
01187 QPen pen2;
01188 pen2.setStyle(Qt::DotLine);
01189 pen2.setWidth(1);
01190 pen2.setBrush(Qt::darkGreen);
01191 pen2.setCapStyle(Qt::RoundCap);
01192 pen2.setJoinStyle(Qt::RoundJoin);
01193
01194
01195 emit message( QString("Mouse MAP PRESS Position at [ %1 - %2 ]").arg(x).arg(y) );
01196
01197 if(trajectory_edit_mode==true)
01198 {
01199 if(setting_initial_point==true)
01200 {
01201
01202 romeo->setPos(clickedPoint.x(),clickedPoint.y());
01203
01204 global_init_point=romeo->scenePos();
01205
01206 x_ini_global=romeo->pos().x();
01207 y_ini_global=romeo->pos().y();
01208
01209 graphicview2map(&x_ini_global,&y_ini_global);
01210 qDebug() << "Romeo Globlal Init Pos X: " << x_ini_global << " [meters]";
01211 qDebug() << "Romeo Globlal Init Pos Y: " << y_ini_global << " [meters]";
01212
01213 trashtrajectory();
01214 }
01215 else
01216 {
01217 QGraphicsEllipseItem *spot;
01218 QGraphicsTextItem *pointCoordinates;
01219 QGraphicsTextItem *absolutPointCoordinates;
01220 QFont coordinates_font1("Arial", 8, QFont::Bold);
01221 QFont coordinates_font2("Arial", 8, QFont::Bold);
01222
01223
01224
01225 spot=scene.addEllipse(QRectF(0,0,8,8));
01226 spot->setBrush(Qt::red);
01227
01228 spot->setPos(clickedPoint.x()-4,clickedPoint.y()-4);
01229
01230 trajectory_points_number++;
01231 spots.append(spot);
01232
01233
01234
01235 lines.append(scene.addLine(last_trajectory_point.x(),last_trajectory_point.y(),clickedPoint.x(),clickedPoint.y(),pen1));
01236 absolutLines.append(scene.addLine(initial_trajectory_point.x(),initial_trajectory_point.y(),clickedPoint.x(),clickedPoint.y(),pen2));
01237
01238
01239
01240 double x_meters=x;
01241 double y_meters=y;
01242
01243 qDebug() << "x meters (real): " << x_meters << "x meters (double): " << x;
01244 qDebug() << "y meters (real): " << x_meters << "y meters (double): " << y;
01245
01246
01247
01248 graphicview2romeo(&x_meters,&y_meters);
01249
01250 pointCoordinates=scene.addText(QString("[%1 , %2 ]").arg(x_meters-x_ini_local).arg(y_meters-y_ini_local),coordinates_font1);
01251 pointCoordinates->setDefaultTextColor(Qt::darkRed);
01252 pointCoordinates->setPos(clickedPoint.x(),clickedPoint.y());
01253 waypoints.append(pointCoordinates);
01254
01255 absolutPointCoordinates=scene.addText(QString("[%1 , %2 ]").arg(x_meters).arg(y_meters),coordinates_font2);
01256 absolutPointCoordinates->setDefaultTextColor(Qt::darkGreen);
01257 absolutPointCoordinates->setPos(clickedPoint.x(),clickedPoint.y()+10);
01258 absolutWaypoints.append(absolutPointCoordinates);
01259
01260
01261 last_trajectory_point=clickedPoint;
01262
01263
01264 trajectory_lines.append(QString("%1\t%2\t1\n").arg(x_meters).arg(y_meters ));
01265 qDebug() << "Final Point Coordinate: "<< x_meters << " , " << y_meters;
01266 }
01267 }
01268
01269 MapGraphicsView->setDragMode(QGraphicsView::ScrollHandDrag);
01270 trajectory_edit_mode=false;
01271 setting_initial_point=false;
01272 }
01273
01274
01275
01276 void RomeoMainWindow::showMessage(QString msg)
01277 {
01278 statusBar()->showMessage(msg);
01279 }
01280
01281
01282 void RomeoMainWindow::showTrajectory(QString file)
01283 {
01284 QDir dir;
01285 QString trajectoryName;
01286 QString path=dir.currentPath();
01287
01288 trajectoryName=file;
01289 trajectoryName.prepend("/src/images/trajectories/UPC/");
01290 trajectoryName.prepend(path);
01291
01292 loadTrajectory(trajectoryName);
01293 }
01294
01295
01296
01297
01298
01299 void RomeoMainWindow::changeRobotPosition(QPoint position)
01300 {
01301 romeo->setPos(position.x(),position.y());
01302 }
01303
01304 void RomeoMainWindow::ungrabRomeo()
01305 {
01306
01307 last_trajectory_point=romeo->scenePos();
01308 initial_trajectory_point=romeo->scenePos();
01309 trajectory_edit_mode=false;
01310 trashtrajectory();
01311 }
01312
01313
01314 void RomeoMainWindow::launchEvent()
01315 {
01316 if (trajectory_points_number==0)
01317 {
01318 QMessageBox::warning(this, tr("ROMEO HMI v 2.0"),
01319 tr("The trajectory is empty."));
01320 return;
01321 }
01322 else
01323 {
01324
01325 INIT_toolButton->setEnabled(FALSE);
01326 NEXT_toolButton->setEnabled(FALSE);
01327 trashTrajectory_toolButton->setEnabled(FALSE);
01328 LEFT_toolButton->setEnabled(FALSE);
01329 RIGHT_toolButton->setEnabled(FALSE);
01330 UP_toolButton->setEnabled(FALSE);
01331 DOWN_toolButton->setEnabled(FALSE);
01332 launchTrajectorytoolButton->setEnabled(FALSE);
01333 loadTrajectory_toolButton->setEnabled(FALSE);
01334 loadMap_toolButton->setEnabled(FALSE);
01335 thetaInit_ToolButton->setEnabled(FALSE);
01336
01337
01338 trajectory_lines.last().replace(QRegExp("\t1\n"), "\t0.0\n");
01339
01340 foreach (QString line, trajectory_lines)
01341 {
01342 test_trajectory_line << line;
01343 }
01344 test_trajectory_line.flush();
01345
01346
01347
01348 file.close();
01349
01350 ParseBlock config;
01351
01352 config.load("loader.conf");
01353
01354 TrajectoryLoader *loader = TrajectoryUtil::createLoader(config["loader"]);
01355 TrajectoryInterpolator *interpolator = TrajectoryUtil::createInterpolator(config["interpolator"]);
01356
01357 std::fstream filestr;
01358 filestr.open ("trajectory.dat");
01359
01360 Trajectory* trajectory;
01361 trajectory = loader->load(filestr);
01362 interpolator->interpolate( *trajectory );
01363
01364 yarp::os::Port trajectoryOutput;
01365
01366 trajectoryOutput.open("/romeo/hmi/trajectory");
01367
01368 if( yarp::os::Network::connect("/romeo/hmi/trajectory", "/romeo/purpur/trajectory") )
01369 {
01370 trajectoryOutput.write(*trajectory);
01371 statusbar->showMessage(tr("(INFO) - Sending Trajectory ..."));
01372 theta_offset=0;
01373 return;
01374 }
01375 else
01376 {
01377 QMessageBox::warning(this, tr("ROMEO HMI v 2.0"),
01378 tr("Destiny Port INACTIVE."));
01379
01380 INIT_toolButton->setEnabled(TRUE);
01381 NEXT_toolButton->setEnabled(TRUE);
01382 trashTrajectory_toolButton->setEnabled(TRUE);
01383 LEFT_toolButton->setEnabled(TRUE);
01384 RIGHT_toolButton->setEnabled(TRUE);
01385 UP_toolButton->setEnabled(TRUE);
01386 DOWN_toolButton->setEnabled(TRUE);
01387 launchTrajectorytoolButton->setEnabled(TRUE);
01388 loadTrajectory_toolButton->setEnabled(TRUE);
01389 loadMap_toolButton->setEnabled(TRUE);
01390 thetaInit_ToolButton->setEnabled(TRUE);
01391
01392 return;
01393 }
01394 }
01395 }
01396
01397 void RomeoMainWindow::upArrow()
01398 {
01399 if (trajectory_points_number==0)
01400 {
01401 locale_romeo_x_ref=romeo->scenePos().x();
01402 locale_romeo_y_ref=romeo->scenePos().y();
01403 romeo->setPos(locale_romeo_x_ref,locale_romeo_y_ref-1);
01404 last_trajectory_point=romeo->scenePos();
01405 initial_trajectory_point=romeo->scenePos();
01406 return;
01407 }
01408 else
01409 {
01410
01411 spots.last()->setPos(spots.last()->pos().x(),spots.last()->pos().y()-9);
01412
01413
01414 last_trajectory_point.setY(last_trajectory_point.y()-9);
01415
01416 lines.last()->setLine(lines.last()->line().x1(),lines.last()->line().y1(),
01417 spots.last()->pos().x()+4,spots.last()->pos().y()+4);
01418
01419 absolutLines.last()->setLine(absolutLines.last()->line().x1(),absolutLines.last()->line().y1(),
01420 spots.last()->pos().x()+4,spots.last()->pos().y()+4);
01421
01422
01423
01424
01425 qreal x_meters=( spots.last()->x()- initial_trajectory_point.x() )/map_X_scale;
01426 qreal y_meters=(initial_trajectory_point.y()-spots.last()->y())/map_Y_scale;
01427
01428 waypoints.last()->setPlainText(QString("[%1 , %2]").arg(x_meters).arg(y_meters));
01429 waypoints.last()->setPos(last_trajectory_point);
01430
01431 absolutWaypoints.last()->setPlainText(QString("[%1 , %2]").arg(x_meters+x_ini_local).arg(y_meters+y_ini_local));
01432 absolutWaypoints.last()->setPos(last_trajectory_point.x(),last_trajectory_point.y()+10);
01433
01434
01435
01436
01437 trajectory_lines.removeLast();
01438 trajectory_lines.append(QString("%1\t%2\t1\n").arg(x_meters).arg(y_meters));
01439 }
01440 }
01441
01442 void RomeoMainWindow::downArrow()
01443 {
01444 if (trajectory_points_number==0)
01445 {
01446 locale_romeo_x_ref=romeo->scenePos().x();
01447 locale_romeo_y_ref=romeo->scenePos().y();
01448 romeo->setPos(locale_romeo_x_ref,locale_romeo_y_ref+1);
01449 last_trajectory_point=romeo->scenePos();
01450 initial_trajectory_point=romeo->scenePos();
01451 return;
01452 }
01453 else
01454 {
01455
01456 spots.last()->setPos(spots.last()->pos().x(),spots.last()->pos().y()+9);
01457
01458
01459 last_trajectory_point.setY(last_trajectory_point.y()+9);
01460
01461
01462
01463 lines.last()->setLine(lines.last()->line().x1(),lines.last()->line().y1(),
01464 spots.last()->pos().x()+4,spots.last()->pos().y()+4);
01465
01466
01467
01468 qreal x_meters=( spots.last()->x()- initial_trajectory_point.x() )/map_X_scale;
01469 qreal y_meters=(initial_trajectory_point.y()-spots.last()->y())/map_Y_scale;
01470
01471 waypoints.last()->setPlainText(QString("[%1 , %2]").arg(x_meters).arg(y_meters));
01472 waypoints.last()->setPos(last_trajectory_point);
01473
01474
01475
01476 trajectory_lines.removeLast();
01477 trajectory_lines.append(QString("%1\t%2\t1\n").arg(x_meters).arg(y_meters));
01478 }
01479 }
01480
01481 void RomeoMainWindow::leftArrow()
01482 {
01483 if( theta_edit_mode==true )
01484 {
01485 previous_theta=theta;
01486 theta_offset-=10;
01487
01488 theta=(orient_ref*(-180/Pi))+theta_offset;
01489
01490 romeo->rotate(theta - previous_theta);
01491
01492 qDebug() << "Theta: " << theta;
01493 return;
01494 }
01495
01496
01497 if (trajectory_points_number==0)
01498 {
01499 locale_romeo_x_ref=romeo->scenePos().x();
01500 locale_romeo_y_ref=romeo->scenePos().y();
01501 romeo->setPos(locale_romeo_x_ref-1,locale_romeo_y_ref);
01502 last_trajectory_point=romeo->scenePos();
01503 initial_trajectory_point=romeo->scenePos();
01504 return;
01505 }
01506 else
01507 {
01508
01509 spots.last()->setPos( spots.last()->pos().x()-9, spots.last()->pos().y());
01510
01511
01512 last_trajectory_point.setX(last_trajectory_point.x()-9);
01513 lines.last()->setLine(lines.last()->line().x1(),lines.last()->line().y1(),spots.last()->pos().x()+8,spots.last()->pos().y()+8);
01514
01515
01516 qreal x_meters=( spots.last()->x()- initial_trajectory_point.x() )/map_X_scale;
01517 qreal y_meters=(initial_trajectory_point.y()-spots.last()->y())/map_Y_scale;
01518
01519 waypoints.last()->setPlainText(QString("[%1 , %2]").arg(x_meters).arg(y_meters));
01520 waypoints.last()->setPos(last_trajectory_point);
01521
01522
01523 trajectory_lines.removeLast();
01524 trajectory_lines.append(QString("%1\t%2\t1\n").arg(x_meters).arg(y_meters));
01525 }
01526 }
01527
01528 void RomeoMainWindow::rightArrow()
01529 {
01530 if( theta_edit_mode==true )
01531 {
01532 previous_theta=theta;
01533 theta_offset+=10;
01534 theta=(orient_ref*(-180/Pi))+theta_offset;
01535
01536 romeo->rotate( theta-previous_theta );
01537 qDebug() << "Theta: " << theta;
01538 return;
01539 }
01540
01541 if (trajectory_points_number==0)
01542 {
01543 locale_romeo_x_ref=romeo->scenePos().x();
01544 locale_romeo_y_ref=romeo->scenePos().y();
01545 romeo->setPos(locale_romeo_x_ref+1,locale_romeo_y_ref);
01546 last_trajectory_point=romeo->scenePos();
01547 initial_trajectory_point=romeo->scenePos();
01548 return;
01549 }
01550 else
01551 {
01552
01553 spots.last()->setPos(spots.last()->pos().x()+9,spots.last()->pos().y());
01554
01555
01556 last_trajectory_point.setX(last_trajectory_point.x()+9);
01557
01558 lines.last()->setLine(lines.last()->line().x1(),lines.last()->line().y1(),spots.last()->pos().x()+8,spots.last()->pos().y()+8);
01559
01560
01561
01562 qreal x_meters = ( spots.last()->x() - initial_trajectory_point.x() ) / map_X_scale;
01563 qreal y_meters = ( initial_trajectory_point.y() - spots.last()->y() ) / map_Y_scale;
01564
01565 waypoints.last()->setPlainText(QString("[%1 , %2]").arg(x_meters).arg(y_meters));
01566 waypoints.last()->setPos(last_trajectory_point);
01567
01568
01569
01570 trajectory_lines.removeLast();
01571 trajectory_lines.append(QString("%1\t%2\t1\n").arg(x_meters).arg(y_meters));
01572 }
01573 }
01574
01575 void RomeoMainWindow::panicEvent()
01576 {
01577 stop_ALL_CONTROL_Process();
01578
01579 QMessageBox::critical(this, tr("ROMEO HMI v 3.0"),
01580 tr("PANIC BUTTON PRESSED.\nStopping Romeo"));
01581
01582
01583 INIT_toolButton->setEnabled(TRUE);
01584 NEXT_toolButton->setEnabled(TRUE);
01585 trashTrajectory_toolButton->setEnabled(TRUE);
01586 LEFT_toolButton->setEnabled(TRUE);
01587 RIGHT_toolButton->setEnabled(TRUE);
01588 UP_toolButton->setEnabled(TRUE);
01589 DOWN_toolButton->setEnabled(TRUE);
01590 launchTrajectorytoolButton->setEnabled(TRUE);
01591 loadTrajectory_toolButton->setEnabled(TRUE);
01592 loadMap_toolButton->setEnabled(TRUE);
01593 thetaInit_ToolButton->setEnabled(TRUE);
01594
01595 x_ini_global=x_ref;
01596 y_ini_global=y_ref;
01597
01598
01599
01600
01601 trashtrajectory();
01602
01603
01604 }
01605
01606
01607 void RomeoMainWindow::trajetoryFinalized()
01608 {
01609 stop_ALL_CONTROL_Process();
01610
01611 QMessageBox::information(this, tr("ROMEO HMI v 3.0"),
01612 tr("The Trajectory has been concluded.\nStopping Romeo"));
01613
01614
01615 INIT_toolButton->setEnabled(TRUE);
01616 NEXT_toolButton->setEnabled(TRUE);
01617 trashTrajectory_toolButton->setEnabled(TRUE);
01618 LEFT_toolButton->setEnabled(TRUE);
01619 RIGHT_toolButton->setEnabled(TRUE);
01620 UP_toolButton->setEnabled(TRUE);
01621 DOWN_toolButton->setEnabled(TRUE);
01622 launchTrajectorytoolButton->setEnabled(TRUE);
01623 loadTrajectory_toolButton->setEnabled(TRUE);
01624 loadMap_toolButton->setEnabled(TRUE);
01625 thetaInit_ToolButton->setEnabled(TRUE);
01626
01627
01628
01629
01630 trashtrajectory();
01631
01632
01633 }
01634
01635
01636
01637 void RomeoMainWindow::initialtrajectorypoint()
01638 {
01639 trajectory_edit_mode=true;
01640 trajectory_executing_mode=false;
01641 setting_initial_point=true;
01642
01643
01644 MapGraphicsView->setDragMode(QGraphicsView::NoDrag);
01645 MapGraphicsView->setCursor(Qt::CrossCursor);
01646
01647 romeo->setAcceptedMouseButtons(Qt::LeftButton);
01648 emit message("Trajectory Edit Mode ON");
01649 }
01650
01651 void RomeoMainWindow::nexttrajectorypoint()
01652 {
01653 trajectory_edit_mode=true;
01654 trajectory_executing_mode=false;
01655
01656 MapGraphicsView->setDragMode(QGraphicsView::NoDrag);
01657 MapGraphicsView->setCursor(Qt::CrossCursor);
01658 scene.clearFocus();
01659 romeo->setAcceptedMouseButtons(0);
01660
01661 emit message("Insert NEXT trajectory Point");
01662 }
01663
01664
01665 void RomeoMainWindow::changeThetaInit()
01666 {
01667 theta_edit_mode=not(theta_edit_mode);
01668
01669
01670 if( theta_edit_mode==true )
01671 {
01672 emit message("(INFO) - Change Theta Init.");
01673 UP_toolButton->setEnabled(false);
01674 DOWN_toolButton->setEnabled(false);
01675 INIT_toolButton->setEnabled(false);
01676 NEXT_toolButton->setEnabled(false);
01677 }
01678 else
01679 {
01680
01681 UP_toolButton->setEnabled(true);
01682 DOWN_toolButton->setEnabled(true);
01683 INIT_toolButton->setEnabled(true);
01684 NEXT_toolButton->setEnabled(true);
01685 }
01686
01687
01688
01689
01690
01691 }
01692
01693
01694 void RomeoMainWindow::launch_LAUNCHER_Process()
01695 {
01696
01697
01698
01699
01700
01701 }
01702
01703 void RomeoMainWindow::stop_LAUNCHER_Process()
01704 {
01705
01706
01707
01708
01709
01710
01711
01712
01713 }
01714
01715
01716 void RomeoMainWindow::stop_ALL_CONTROL_Process()
01717 {
01718 stop_LAUNCHER_Process();
01719 sleep(0.5);
01720 }
01721
01722 void RomeoMainWindow::connect_LASER2D_sensor()
01723 {
01724 if(yarpRunning==true)
01725 {
01726
01727 if( yarp::os::Network::connect("/romeo/laser2D/imageOut/data", "/romeo/hmi/laser2D/sensorimage") )
01728 {
01729 readLaser2DImage=true;
01730
01731 laser2D_START_toolButton->setEnabled(false);
01732 laser2D_STOP_toolButton->setEnabled(true);
01733 statusbar->showMessage(tr("(INFO) - Laser 2D Sensor Active."));
01734
01735 laserRange=laser2Dscene.addEllipse(QRectF(0,0,170,170));
01736 laserRange->setSpanAngle(2880);
01737 laserRange->setBrush(QColor(225,225,255,127));
01738 laserRange->setPen(QPen(Qt::blue, 1, Qt::DotLine, Qt::FlatCap, Qt::RoundJoin));
01739 laserRange->setPos(0,65);
01740
01741 romeoImage=laser2Dscene.addPixmap(QPixmap(":/images/romeo3.png"));
01742 romeoImage->setPos(90,150);
01743 romeoImage->setZValue(10);
01744
01745 laser2Dscene.removeItem(laser2DInfoText);
01746 laser2Dscene.addItem(laser2DPixmap);
01747 laser2Dscene.update();
01748 }
01749 else
01750 {
01751 statusbar->showMessage(tr("(ERROR) - Laser 2D Sensor INACTIVE."));
01752 }
01753 }
01754 else
01755 {
01756 statusbar->showMessage(tr("(ERROR) - Yarp Network Inactive."));
01757 }
01758
01759 }
01760
01761 void RomeoMainWindow::disconnect_LASER2D_sensor()
01762 {
01763 if(yarpRunning==true)
01764 {
01765 if(yarp::os::Network::disconnect("/romeo/laser2D/imageOut/data", "/romeo/hmi/laser2D/sensorimage"))
01766 {
01767 readLaser2DImage=false;
01768
01769 laser2D_START_toolButton->setEnabled(true);
01770 laser2D_STOP_toolButton->setEnabled(false);
01771
01772 laser2Dscene.removeItem(laser2DPixmap);
01773 laser2Dscene.removeItem(laser2DInfoText);
01774 laser2Dscene.update();
01775 }
01776 statusbar->showMessage(tr("(INFO) - Laser 2D Sensor Inactive."));
01777 }
01778 else
01779 {
01780 statusbar->showMessage(tr("(ERROR) - Yarp Network Inactive."));
01781 }
01782 }
01783
01784 void RomeoMainWindow::connect_ELEVATIONMAP_sensor()
01785 {
01786 if(yarpRunning==true)
01787 {
01788
01789 if(yarp::os::Network::connect("/romeo/elevationmap/imageOut/data", "/romeo/hmi/sensormap/sensorimage"))
01790 {
01791 readElevationMapImage=true;
01792 elevationMap_SWITCH_VIEW_toolButton->setEnabled(true);
01793 elevationMap_START_toolButton->setEnabled(false);
01794 elevationMap_STOP_toolButton->setEnabled(true);
01795 statusbar->showMessage(tr("(INFO) - Elevation MAP Sensor Active."));
01796
01797 scene.removeItem(elevationMapPixmap);
01798 elevationMapscene.removeItem(elevationMapInfoText);
01799 elevationMapscene.addItem(elevationMapPixmap);
01800 elevationMapscene.update();
01801 }
01802 else
01803 {
01804 statusbar->showMessage(tr("(ERROR) - Elevation MAP Sensor INACTIVE."));
01805 }
01806 }
01807 else
01808 {
01809 statusbar->showMessage(tr("(ERROR) - Yarp Network Inactive."));
01810 }
01811 }
01812
01813 void RomeoMainWindow::disconnect_ELEVATIONMAP_sensor()
01814 {
01815 if(yarpRunning==true)
01816 {
01817 if(yarp::os::Network::disconnect("/romeo/elevationmap/imageOut/data", "/romeo/hmi/sensormap/sensorimage"))
01818 {
01819 if(elevationMapMainView==true)
01820 {
01821 double xScale;
01822 double yScale;
01823
01824 xScale = elevationMap_x_axis_length / map_width;
01825 yScale = elevationMap_y_axis_length / map_height;
01826
01827 elevationMapPixmap->scale( xScale, yScale );
01828
01829 scene.removeItem(elevationMapPixmap);
01830 elevationMapscene.removeItem(elevationMapInfoText);
01831 elevationMapscene.update();
01832 }
01833
01834 readElevationMapImage=false;
01835 elevationMap_SWITCH_VIEW_toolButton->setEnabled(false);
01836 elevationMap_START_toolButton->setEnabled(true);
01837 elevationMap_STOP_toolButton->setEnabled(false);
01838 }
01839 statusbar->showMessage(tr("(INFO) - Elevation Map Sensor Inactive."));
01840 }
01841 else
01842 {
01843 statusbar->showMessage(tr("(ERROR) - Yarp Network Inactive."));
01844 }
01845 }
01846
01847
01848 void RomeoMainWindow::connect_TRANSMAP_sensor()
01849 {
01850 if(yarpRunning==true)
01851 {
01852
01853 if(yarp::os::Network::connect("/romeo/elevationmap/transvOut/data", "/romeo/hmi/transmap/sensorimage"))
01854 {
01855 readTransMapImage=true;
01856 transMap_SWITCH_VIEW_toolButton->setEnabled(true);
01857 statusbar->showMessage(tr("(INFO) - Transversability MAP Sensor Active."));
01858 transMap_START_toolButton->setEnabled(false);
01859 transMap_STOP_toolButton->setEnabled(true);
01860
01861 scene.removeItem(transMapPixmap);
01862 transMapscene.removeItem(transMapInfoText);
01863 transMapscene.addItem(transMapPixmap);
01864 transMapscene.update();
01865 }
01866 else
01867 {
01868 statusbar->showMessage(tr("(ERROR) - Transversability MAP Sensor INACTIVE."));
01869 }
01870 }
01871 else
01872 {
01873 statusbar->showMessage(tr("(ERROR) - Yarp Network Inactive."));
01874 }
01875 }
01876
01877 void RomeoMainWindow::disconnect_TRANSMAP_sensor()
01878 {
01879 if(yarpRunning==true)
01880 {
01881 if(yarp::os::Network::disconnect("/romeo/elevationmap/transvOut/data", "/romeo/transmap/sensorimage"))
01882 {
01883 if(transMapMainView==true)
01884 {
01885 double xScale;
01886 double yScale;
01887
01888 xScale = transMap_x_axis_length / map_width;
01889 yScale = transMap_y_axis_length / map_height;
01890
01891 transMapPixmap->scale( xScale, yScale );
01892
01893 scene.removeItem(transMapPixmap);
01894 transMapscene.removeItem(transMapInfoText);
01895 }
01896
01897 readTransMapImage=false;
01898 transMap_START_toolButton->setEnabled(true);
01899 transMap_STOP_toolButton->setEnabled(false);
01900 transMap_SWITCH_VIEW_toolButton->setEnabled(false);
01901 }
01902 statusbar->showMessage(tr("(INFO) - Transversability Map Sensor Inactive."));
01903 }
01904 else
01905 {
01906 statusbar->showMessage(tr("(ERROR) - Yarp Network Inactive."));
01907 }
01908 }
01909
01910
01911 void RomeoMainWindow::IplImage2QImage(IplImage *src, QGraphicsPixmapItem * pixmapElement, QGraphicsScene *sensorScene)
01912 {
01913 int width = src->width;
01914 int widthStep = src->widthStep;
01915 int height = src->height;
01916
01917
01918
01919
01920 uchar *qImageBuffer = (uchar *)malloc(width * height * 4 * sizeof(uchar));
01921 uchar *QImagePtr = qImageBuffer;
01922 const uchar *iplImagePtr = (const uchar *)src->imageData;
01923
01924 for (int y = 0; y < height; ++y)
01925 {
01926 for (int x = 0; x < width; ++x)
01927 {
01928
01929 QImagePtr[0] = iplImagePtr[0];
01930 QImagePtr[1] = iplImagePtr[1];
01931 QImagePtr[2] = iplImagePtr[2];
01932 QImagePtr[3] = 255;
01933
01934
01935 if( (QImagePtr[0]==255) && (QImagePtr[1]==255) && (QImagePtr[2]==255) )
01936 {
01937 QImagePtr[0] = 0;
01938 QImagePtr[1] = 0;
01939 QImagePtr[2] = 255;
01940 }
01941
01942 if( (QImagePtr[0]==0) && (QImagePtr[1]==0) && (QImagePtr[2]==0) )
01943 {
01944 QImagePtr[0] = 255;
01945 QImagePtr[1] = 255;
01946 QImagePtr[2] = 255;
01947 }
01948
01949 QImagePtr += 4;
01950 iplImagePtr += 3;
01951 }
01952 iplImagePtr += widthStep - 3 * width;
01953 }
01954
01955 QImage tmp_img(qImageBuffer,width,height,QImage::Format_RGB32);
01956 pixmapElement->setPixmap(QPixmap::fromImage(tmp_img));
01957
01958 sensorScene->update();
01959 free(qImageBuffer);
01960 }
01961
01962
01963 void RomeoMainWindow::switchElevationView()
01964 {
01965 elevationMapMainView=not(elevationMapMainView);
01966
01967 double xScale;
01968 double yScale;
01969
01970 if(elevationMapMainView==true)
01971 {
01972 xScale = map_width / elevationMap_x_axis_length ;
01973 yScale = map_height / elevationMap_y_axis_length ;
01974
01975 elevationMapPixmap->scale( xScale, yScale);
01976
01977 scene.addItem(elevationMapPixmap);
01978 elevationMapscene.removeItem(elevationMapInfoText);
01979 elevationMapInfoText=elevationMapscene.addText("Representing Data\non Map View", infoFont);
01980 elevationMapGraphicsView->centerOn(elevationMapInfoText);
01981 elevationMapscene.update();
01982 }
01983 else
01984 {
01985 xScale = elevationMap_x_axis_length / map_width;
01986 yScale = elevationMap_y_axis_length / map_height;
01987
01988 elevationMapPixmap->scale( xScale, yScale );
01989
01990 scene.removeItem(elevationMapPixmap);
01991 elevationMapscene.removeItem(elevationMapInfoText);
01992 elevationMapscene.addItem(elevationMapPixmap);
01993 elevationMapscene.update();
01994 }
01995 elevationMapGraphicsView->resetMatrix();
01996 }
01997
01998 void RomeoMainWindow::switchTransView()
01999 {
02000 transMapMainView=not(transMapMainView);
02001
02002 double xScale;
02003 double yScale;
02004
02005 if(transMapMainView==true)
02006 {
02007 xScale = map_width / transMap_x_axis_length ;
02008 yScale = map_height / transMap_y_axis_length ;
02009
02010 transMapPixmap->scale( xScale, yScale);
02011
02012 scene.addItem(transMapPixmap);
02013 transMapscene.removeItem(transMapInfoText);
02014 transMapInfoText=transMapscene.addText("Representing Data\non Map View", infoFont);
02015 transMapGraphicsView->centerOn(transMapInfoText);
02016 transMapscene.update();
02017 }
02018 else
02019 {
02020 xScale = transMap_x_axis_length / map_width;
02021 yScale = transMap_y_axis_length / map_height;
02022
02023 transMapPixmap->scale( xScale, yScale );
02024
02025 scene.removeItem(transMapPixmap);
02026 transMapscene.removeItem(transMapInfoText);
02027 transMapscene.addItem(transMapPixmap);
02028 transMapscene.update();
02029 }
02030 transMapGraphicsView->resetMatrix();
02031 }
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042
02043