]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/robomon/RobomonAtlantis.cpp
Merge branch 'maint-demo' into demo
[eurobot/public.git] / src / robomon / RobomonAtlantis.cpp
index 6679b8ed36b3b1427d174a7e01f446bf948752af..f6cb7e16d9aa80e48ccbdb0e7957fd7cea23c4a6 100644 (file)
 #include "playgroundview.h"
 #include "trail.h"
 
+
 #include <QCoreApplication>
 #include <QEvent>
 #include <QKeyEvent>
 #include <QDebug>
 #include <QMessageBox>
 
-RobomonAtlantis::RobomonAtlantis(QWidget *parent)
-    : QWidget(parent), motorSimulation(orte)
+RobomonAtlantis::RobomonAtlantis(QStatusBar *_statusBar)
+       : QWidget(0), statusBar(_statusBar), motorSimulation(orte)
 {
        QFont font;
        font.setPointSize(7);
@@ -65,6 +66,7 @@ RobomonAtlantis::RobomonAtlantis(QWidget *parent)
        createOrte();
        createRobots();
        createActions();
+       createMap();
 
 //     connect(vidle, SIGNAL(valueChanged(int)),
 //             robotEstPosBest, SLOT(setVidle(int)));
@@ -182,8 +184,8 @@ void RobomonAtlantis::createMiscGroupBox()
        motorSimulationCheckBox->setToolTip("Subscribes to motion_speed and\nbased on this publishes motion_irc.");
        layout->addWidget(motorSimulationCheckBox);
 
-       startPlug = new QCheckBox("&Start plug");
-       layout->addWidget(startPlug);
+//     startPlug = new QCheckBox("&Start plug");
+//     layout->addWidget(startPlug);
 
        colorChoser = new QCheckBox("&Team color");
        layout->addWidget(colorChoser);
@@ -229,21 +231,17 @@ void RobomonAtlantis::createDebugGroupBox()
 
 void RobomonAtlantis::createActuatorsGroupBox()
 {
-       actuatorsGroupBox = new QGroupBox(tr("Actuators"));
-       actuatorsGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
-       QHBoxLayout *layout = new QHBoxLayout();
-//     vidle = new QDial();
-
-//     vidle->setMinimum(VIDLE_VYSIP);
-//     vidle->setMaximum((VIDLE_UP-VIDLE_VYSIP)+VIDLE_VYSIP);
-//     vidle->setEnabled(true);
+       actuatorsGroupBox = new QGroupBox(tr("Status"));
+       actuatorsGroupBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Maximum);
+       QGridLayout *layout = new QGridLayout();
 
-       //createMotorsGroupBox();
+       layout->addWidget(MiscGui::createLabel("APP:"), 1, 0);
+        system_status = new QLabel();
+        system_status->setMinimumWidth(100);
+        system_status->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+        layout->addWidget(system_status, 1, 1);
 
-       layout->setAlignment(Qt::AlignLeft);
-//     layout->addWidget(vidle);
-       //layout->addWidget(enginesGroupBox);
-       actuatorsGroupBox->setLayout(layout);
+        actuatorsGroupBox->setLayout(layout);
 }
 
 void RobomonAtlantis::createPowerGroupBox()
@@ -283,46 +281,6 @@ void RobomonAtlantis::createPowerGroupBox()
        powerGroupBox->setLayout(layout);
 }
 
-#if 0
-void RobomonAtlantis::createMotorsGroupBox()
-{
-       enginesGroupBox = new QGroupBox(tr("Motors"));
-       QVBoxLayout *layout = new QVBoxLayout();
-       QHBoxLayout *layout1 = new QHBoxLayout();
-       QHBoxLayout *layout2 = new QHBoxLayout();
-
-       leftMotorSlider = new QSlider(Qt::Vertical);
-       rightMotorSlider = new QSlider(Qt::Vertical);
-       bothMotorsCheckBox = new QCheckBox(tr("Lock both"));
-       stopMotorsPushButton = new QPushButton(tr("Stop Motors"));
-
-       leftMotorSlider->setMinimum(-100);
-       leftMotorSlider->setMaximum(100);
-       leftMotorSlider->setTracking(false);
-       leftMotorSlider->setTickPosition(QSlider::TicksLeft);
-
-       rightMotorSlider->setMinimum(-100);
-       rightMotorSlider->setMaximum(100);
-       rightMotorSlider->setTracking(false);
-       rightMotorSlider->setTickPosition(QSlider::TicksRight);
-
-       stopMotorsPushButton->setMaximumWidth(90);
-
-       layout1->addWidget(leftMotorSlider);
-       layout1->addWidget(MiscGui::createLabel("0"));
-       layout1->addWidget(rightMotorSlider);
-
-       layout2->addWidget(bothMotorsCheckBox);
-
-       layout->addWidget(MiscGui::createLabel("100"));
-       layout->addLayout(layout1);
-       layout->addWidget(MiscGui::createLabel("-100"));
-       layout->addLayout(layout2);
-       layout->addWidget(stopMotorsPushButton);
-       enginesGroupBox->setLayout(layout);
-}
-#endif
-
 void RobomonAtlantis::createRobots()
 {
        robotRefPos = new Robot("Ref", QPen(Qt::darkBlue), QBrush(Qt::NoBrush));
@@ -362,6 +320,16 @@ void RobomonAtlantis::createRobots()
 
 }
 
+void RobomonAtlantis::createMap()
+{
+       mapImage = new Map();
+       mapImage->setZValue(3);
+       mapImage->setTransform(QTransform().scale(MAP_CELL_SIZE_MM, MAP_CELL_SIZE_MM), true);
+
+
+       playgroundScene->addItem(mapImage);
+}
+
 /**********************************************************************
  * GUI actions
  **********************************************************************/
@@ -383,8 +351,7 @@ void RobomonAtlantis::createActions()
 //     connect(stopMotorsPushButton, SIGNAL(clicked()),
 //                     this, SLOT(stopMotors()));
 
-       connect(startPlug, SIGNAL(stateChanged(int)), this, SLOT(sendStart(int)));
-       connect(colorChoser, SIGNAL(stateChanged(int)), this, SLOT(setTeamColor(int)));
+//     connect(startPlug, SIGNAL(stateChanged(int)), this, SLOT(sendStart(int)));
 
        /* obstacle simulation */
        simulationEnabled = 0;
@@ -485,7 +452,7 @@ void RobomonAtlantis::showMap(bool show)
                        disconnect(mapTimer, SIGNAL(timeout()), this, SLOT(paintMap()));
                }
        }
-       playgroundScene->showMap(show);
+       mapImage->setVisible(show);
 }
 
 void RobomonAtlantis::paintMap()
@@ -495,15 +462,14 @@ void RobomonAtlantis::paintMap()
 
         if (!map) return;
 
-       for(int i=0; i < MAP_WIDTH; i++) {
-               for(int j=0; j<MAP_HEIGHT; j++) {
+       for(int i = 0; i < MAP_WIDTH; i++) {
+               for(int j = 0; j < MAP_HEIGHT; j++) {
                         QColor color;
 
                         struct map_cell *cell = &map->cells[j][i];
                         color = lightGray;
 
-                        if ((cell->flags & MAP_FLAG_WALL) &&
-                           (cell->flags & MAP_FLAG_INVALIDATE_WALL) == 0)
+                        if (cell->flags & MAP_FLAG_WALL)
                                 color = darkYellow;
                         if (cell->flags & MAP_FLAG_IGNORE_OBST)
                                 color = darkGreen;
@@ -530,7 +496,8 @@ void RobomonAtlantis::paintMap()
                         if (cell->flags & MAP_FLAG_DET_OBST)
                                 color = cyan;
 
-                        playgroundScene->setMapColor(i, j, color);
+                       color.setAlpha(200);
+                        mapImage->setPixelColor(i, MAP_HEIGHT - j - 1, color);
                 }
        }
 }
@@ -560,10 +527,15 @@ void RobomonAtlantis::setObstacleSimulation(int state)
                        this, SLOT(simulateObstaclesHokuyo()));
                obstacleSimulationTimer->start(100);
                setMouseTracking(true);
+               hokuyoScan->setVisible(true);
+
+
        } else {
                if (obstacleSimulationTimer)
                        delete obstacleSimulationTimer;
-               //double distance = 0.8;
+
+               hokuyoScan->setVisible(false);  /* hide hokuyo scan*/
+
        }
 }
 
@@ -609,8 +581,8 @@ bool RobomonAtlantis::event(QEvent *event)
                case QEVENT(QEV_HOKUYO_SCAN):
                        hokuyoScan->newScan(&orte.hokuyo_scan);
                        break;
-               case QEVENT(QEV_VIDLE_CMD):
-                       robotEstPosBest->setVidle(orte.vidle_cmd.req_pos);
+               case QEVENT(QEV_CRANE_CMD):
+                       robotEstPosBest->setCrane(orte.crane_cmd.req_pos);
                        break;
                case QEVENT(QEV_REFERENCE_POSITION):
                        emit actualPositionReceivedSignal();
@@ -653,6 +625,12 @@ bool RobomonAtlantis::event(QEvent *event)
                case QEVENT(QEV_FSM_MOTION):
                        fsm_motion_state->setText(orte.fsm_motion.state_name);
                        break;
+                case QEVENT(QEV_STSTEM_STATUS):
+                        if (orte.system_status.system_condition)
+                                system_status->setText("WARNING");
+                        else
+                                system_status->setText("OK");
+                        break;
                default:
                        if (event->type() == QEvent::Close)
                                closeEvent((QCloseEvent *)event);
@@ -815,17 +793,19 @@ void RobomonAtlantis::createOrte()
                        generic_rcv_cb, new OrteCallbackInfo(this, QEV_ESTIMATED_POSITION_INDEP_ODO));
        robottype_subscriber_est_pos_best_create(&orte,
                        generic_rcv_cb, new OrteCallbackInfo(this, QEV_ESTIMATED_POSITION_BEST));
+        robottype_subscriber_system_status_create(&orte,
+                        generic_rcv_cb, new OrteCallbackInfo(this, QEV_STSTEM_STATUS));
        robottype_subscriber_hokuyo_scan_create(&orte,
                        generic_rcv_cb, new OrteCallbackInfo(this, QEV_HOKUYO_SCAN));
-       robottype_subscriber_vidle_cmd_create(&orte,
-                       generic_rcv_cb, new OrteCallbackInfo(this, QEV_VIDLE_CMD));
+       robottype_subscriber_crane_cmd_create(&orte,
+                       generic_rcv_cb, new OrteCallbackInfo(this, QEV_CRANE_CMD));
        robottype_subscriber_fsm_main_create(&orte,
                                             rcv_fsm_main_cb, this);
        robottype_subscriber_fsm_motion_create(&orte,
                                             rcv_fsm_motion_cb, this);
        robottype_subscriber_fsm_act_create(&orte,
                                             rcv_fsm_act_cb, this);
-    robottype_subscriber_motion_speed_create(&orte, NULL, NULL);
+       robottype_subscriber_motion_speed_create(&orte, NULL, NULL);
 
        /* power management */
         orte.pwr_ctrl.voltage33 = true;
@@ -892,9 +872,7 @@ void RobomonAtlantis::openSharedMemory()
        /* Get segment identificator in a read only mode  */
        segmentId = shmget(SHM_MAP_KEY, sharedSegmentSize, S_IRUSR);
        if(segmentId == -1) {
-               QMessageBox::critical(this, "robomon",
-                               "Unable to open shared memory segment!");
-               return;
+               statusBar->showMessage("No external map found - creating a new map.");
        }
 
        /* Init Shmap */
@@ -947,15 +925,15 @@ double RobomonAtlantis::distanceToObstacleHokuyo(int beamnum, Point obstacle, do
 {
        struct robot_pos_type e = orte.est_pos_best;
        double sensor_a;
-       struct sharp_pos s;
+       struct robot_pos_type s;
 
        s.x = HOKUYO_CENTER_OFFSET_M;
        s.y = 0.0;
-       s.ang = HOKUYO_INDEX_TO_RAD(beamnum);
+       s.phi = HOKUYO_INDEX_TO_RAD(beamnum);
 
        Point sensor(e.x + s.x*cos(e.phi) - s.y*sin(e.phi),
                     e.y + s.x*sin(e.phi) + s.y*cos(e.phi));
-       sensor_a = e.phi + s.ang;
+       sensor_a = e.phi + s.phi;
 
        const double sensorRange = 4.0; /*[meters]*/
 
@@ -987,12 +965,6 @@ void RobomonAtlantis::sendStart(int plug)
        ORTEPublicationSend(orte.publication_robot_cmd);
 }
 
-void RobomonAtlantis::setTeamColor(int plug)
-{
-       orte.robot_switches.team_color = plug ? 1 : 0;
-       ORTEPublicationSend(orte.publication_robot_switches);
-}
-
 void RobomonAtlantis::setMotorSimulation(int state)
 {
     if (state) {