]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/robomon/RobomonAtlantis.h
robomon: Implement motor simulation
[eurobot/public.git] / src / robomon / RobomonAtlantis.h
index be41794707eab58c932c97d1954b73530c399dd4..f7983628b3200db586dd4012ae648f9291e85440 100644 (file)
@@ -14,6 +14,8 @@
 #define ROBOMON_ATLANTIS_H
 
 #include <QDialog>
+#include <QDateTime>
+#include <QTimer>
 
 #include <trgen.h>
 #include "PlaygroundScene.h"
@@ -38,6 +40,39 @@ class QSlider;
 class QProgressBar;
 class QFont;
 
+class MotorSimulation : QObject {
+    Q_OBJECT
+
+    QTimer timer;
+    qint64 last_time;
+    struct robottype_orte_data &orte;
+public:
+    MotorSimulation(struct robottype_orte_data &orte) : QObject(), timer(this), orte(orte) {}
+    void start()
+    {
+        robottype_publisher_motion_irc_create(&orte, 0, 0);
+        connect(&timer, SIGNAL(timeout()), this, SLOT(updateIRC()));
+        timer.start(50);
+    }
+
+    void stop()
+    {
+        robottype_publisher_motion_irc_destroy(&orte);
+        timer.stop();
+        disconnect(&timer, SIGNAL(timeout()), this, SLOT(updateIRC()));
+    }
+private slots:
+    void updateIRC()
+    {
+        qint64 now = QDateTime::currentMSecsSinceEpoch();
+        orte.motion_irc.left += orte.motion_speed.left * (now - last_time);   // TODO: Find constant for speed to irc conversion
+        orte.motion_irc.right+= orte.motion_speed.right * (now - last_time);
+        ORTEPublicationSend(orte.publication_motion_irc);
+        last_time = now;
+    }
+};
+
+
 class RobomonAtlantis : public QWidget
 {
        Q_OBJECT
@@ -60,6 +95,7 @@ public slots:
        void showMap(bool show);
        void useOpenGL(bool use);
        void showTrails(bool show);
+       void showShapeDetect(bool show);
        void resetTrails();
 private slots:
        /************************************************************
@@ -77,6 +113,8 @@ private slots:
        void simulateObstaclesHokuyo();
        void changeObstacle(QPointF position);
        void sendStart(int plug);
+       void setTeamColor(int plug);
+       void setMotorSimulation(int state);
 
        /************************************************************
         * ORTE 
@@ -118,7 +156,9 @@ private:
        QGroupBox *powerGroupBox;
        QGroupBox *fsmGroupBox;
 
+public:
        PlaygroundScene *playgroundScene;
+private:
        PlaygroundView *playgroundSceneView;
 
        /* position state */
@@ -139,6 +179,7 @@ private:
 /*     QSlider *rightMotorSlider; */
 /*     QCheckBox *bothMotorsCheckBox; */
 /*     QPushButton *stopMotorsPushButton; */
+       //QDial *vidle;
 
        /* power management */
        QCheckBox *voltage33CheckBox;
@@ -151,11 +192,12 @@ private:
 
        /* misc */
        QCheckBox *obstacleSimulationCheckBox;
+       QCheckBox *motorSimulationCheckBox;
        QLabel *fsm_main_state;
        QLabel *fsm_act_state;
        QLabel *fsm_motion_state;
        QCheckBox *startPlug;
-       QCheckBox *puckInside;
+       QCheckBox *colorChoser;
 public:
        /* robot */
        Robot *robotRefPos;
@@ -187,6 +229,8 @@ private:
        QTimer *obstacleSimulationTimer;
        Point simulatedObstacle;
 
+       class MotorSimulation motorSimulation;
+
        /************************************************************
         * ORTE 
         ************************************************************/