]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/robomon/RobomonAtlantis.h
Merge branch 'maint-demo' into demo
[eurobot/public.git] / src / robomon / RobomonAtlantis.h
index cb95ac47ef218affda9d640cfe0042b258c10aa3..947b9578d3943215b27b18eb44e9b8b202f0c48d 100644 (file)
@@ -14,6 +14,8 @@
 #define ROBOMON_ATLANTIS_H
 
 #include <QDialog>
+#include <QDateTime>
+#include <QTimer>
 
 #include <trgen.h>
 #include "PlaygroundScene.h"
@@ -41,6 +43,39 @@ class QProgressBar;
 class QFont;
 class QImage;
 
+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
@@ -81,6 +116,7 @@ private slots:
        void simulateObstaclesHokuyo();
        void changeObstacle(QPointF position);
        void sendStart(int plug);
+       void setMotorSimulation(int state);
 
        /************************************************************
         * ORTE
@@ -161,6 +197,7 @@ private:
 
        /* misc */
        QCheckBox *obstacleSimulationCheckBox;
+       QCheckBox *motorSimulationCheckBox;
        QLabel *fsm_main_state;
        QLabel *fsm_act_state;
        QLabel *fsm_motion_state;
@@ -200,6 +237,8 @@ private:
        QTimer *obstacleSimulationTimer;
        Point simulatedObstacle;
 
+       class MotorSimulation motorSimulation;
+
        /************************************************************
         * ORTE
         ************************************************************/