direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gui.h
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) Markus Knapp *
3  * www.direcs.de *
4  * *
5  * This file is part of direcs. *
6  * *
7  * direcs is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU General Public License as published *
9  * by the Free Software Foundation, version 3 of the License. *
10  * *
11  * direcs is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  *************************************************************************/
20 
21 #ifndef GUI_H
22 #define GUI_H
23 
24 //-------------------------------------------------------------------
25 #include <QtGlobal> // for Q_OS_* Makro!
26 #include <QtGui>
27 #include <QtOpenGL>
28 
29 #ifdef ACTIVELASERVIEW
30  #include <QGraphicsScene> // for OpenGL (Laser lines)
31 #endif
32 
33 //-------------------------------------------------------------------
34 #include "joystickDialog.h"
35 #include "settingsDialog.h"
36 #include "aboutDialog.h"
37 
38 #ifdef ACTIVELASERVIEW
39  #include "laserScene.h"
40 #endif
41 
42 //#include "compassWidget.h"
43 
44 //#ifdef USEROBOTGUI
45  #include "ui_direcsSmall.h"
46 //#else
47  #include "ui_direcs.h"
48 //#endif
49 
50 #ifndef BUILDFORROBOT
51  #include <qwt_plot_layout.h>
52  #include <qwt_plot_curve.h>
53  #include <qwt_plot_grid.h>
54  #include <qwt_scale_draw.h>
55  #include <qwt_scale_widget.h>
56  #include <qwt_legend.h>
57  #include <qwt_legend_item.h>
58  // #include <qwt_compass.h>
59  #include <qwt_dial_needle.h>
60 #endif
61 
62 
67 class Gui : public QMainWindow
68 {
69  Q_OBJECT
70 
71  public:
72  Gui(bool useSmallGUI, SettingsDialog *s, JoystickDialog *j, AboutDialog *a, QMainWindow *parent = 0);
73  ~Gui();
74 
75  /*
76  Shows a sensor distance in centimeters (cm) in a text label.
77  @param sensor is the sensor number.
78  @param distance is the distance in cm.
79  void showDistance(int sensor, int distance);
80  */
81 
88  void showDistanceGraphical(int sensor, int distance);
89 
95  void showDrivenDistance(int sensor, int distance);
96 
102  void showVoltage(int sensor, float voltage);
103 
109  void showAlarm(short int sensor, bool state);
110 
117  void showMotorStatus(int motor, bool power, int direction);
118 
119 #ifdef ACTIVELASERVIEW
120 
123  void initLaserView();
124 
129  void initLaserStuff();
130 #endif
131 
132 
133  public slots:
141  void appendLog(QString text, bool CR=true, bool sayIt=false, bool addTimestamp=true);
142 
150  void appendNetworkLog(QString text, bool CR=true, bool sayIt=false);
151 
157  void appendSerialLog(QString text, bool CR=true);
158 
164  void setCamImage(QImage* image);
165 
171  void setCamImageDepth(QImage* image);
172 
178  void setCamImageOpenCV(QImage* image);
179 
187  void showFaceTrackData(int faces, int faceX, int faceY, int faceRadius, int lastFaceX, int lastFaceY);
188 
193  void hideCameraControls();
194 
199  void disableFaceDetection();
200 
204  void disableCompass();
205 
211  void setRobotControls(bool state);
212 
213 /*
214 #ifndef BUILDFORROBOT
215  / **
216  Shows the actual plot data (e.g. measured current from motor 1). This slot is called from the plot thread.
217  @param xval points to an array with the values for the x axis (usually the time line).
218  @param yval points to an array with the values for the y axis (usually the measured values).
219  @param size is the size of the array.
220  @sa PlotThread()
221  * /
222  void setPlotData1(double *xval, double *yval, int size);
223 #endif
224 
225 #ifndef BUILDFORROBOT
226  / **
227  Shows the actual plot data (e.g. measured current from motor 2). This slot is called from the plot thread.
228  @param xval points to an array with the values for the x axis (usually the time line).
229  @param yval points to an array with the values for the y axis (usually the measured values).
230  @param size is the size of the array.
231  @sa PlotThread()
232  * /
233  void setPlotData2(double *xval, double *yval, int size);
234 #endif
235 
236 #ifndef BUILDFORROBOT
237  / **
238  Shows the actual plot data (e.g. measured current from motor 3). This slot is called from the plot thread.
239  @param xval points to an array with the values for the x axis (usually the time line).
240  @param yval points to an array with the values for the y axis (usually the measured values).
241  @param size is the size of the array.
242  @sa PlotThread()
243  * /
244  void setPlotData3(double *xval, double *yval, int size);
245 #endif
246 
247 #ifndef BUILDFORROBOT
248  / **
249  Shows the actual plot data (e.g. measured current from motor 4). This slot is called from the plot thread.
250  @param xval points to an array with the values for the x axis (usually the time line).
251  @param yval points to an array with the values for the y axis (usually the measured values).
252  @param size is the size of the array.
253  @sa PlotThread()
254  * /
255  void setPlotData4(double *xval, double *yval, int size);
256 #endif
257 */
258 
259 #ifndef BUILDFORROBOT
260 
267  void setPlotData5(double *xval, double *yval, int size);
268 #endif
269 
270 #ifndef BUILDFORROBOT
271 
278  void setPlotData6(double *xval, double *yval, int size);
279 #endif
280 
281 #ifndef BUILDFORROBOT
282 
289  void setPlotDataHeartbeat(double *xval, double *yval, int size);
290 #endif
291 
292 #ifdef ACTIVELASERVIEW
293 
296  void refreshLaserViewFront(QList <float> laserScannerValues, QList <int> laserScannerFlags);
297 
301  void refreshLaserViewRear(QList <float> laserScannerValues, QList <int> laserScannerFlags);
302 
306  void setRobotPosition(QGraphicsSceneMouseEvent* mouseEvent);
307 #endif
308 
314  void setLaserscannerAngle(short int laserscanner, int angle);
315 
321  void setLaserscannerResolution(short int laserscanner, float resolution);
322 
323 #ifdef ACTIVELASERVIEW
324 
327  void zoomLaserView(QGraphicsSceneWheelEvent* wheelEvent);
328 #endif
329 
337  void showLaserFrontAngles(int largestFreeAreaStart, int largestFreeAreaEnd, int centerOfFreeWay, float width);
338 
344  void showPreferredDirection(QString direction);
345 
350  void showFaceTrackDirection(QString direction);
351 
359  void showCompassData(float x, float y, float z, float heading);
360 
365  void setLEDHeartbeat(unsigned char state);
366 
371  void setLEDCompass(unsigned char state);
372 
377  void setLEDJoystick(unsigned char state);
378 
383  void setLEDCamera(unsigned char state);
384 
389  void setLEDNetwork(unsigned char state);
390 
395  void setLEDMasterSlave(unsigned char state);
396 
401  void setLEDLaser(unsigned char state);
402 
407  void setLabelMasterSlave(QString text);
408 
414  void setConsoleMode(bool state);
415 
419  void systemerrorcatcher(int errorlevel);
420 
425  void showKinectAngle(double angle);
426 
431  void showThreshold(int threshold);
432 
433 
434  protected:
435  void closeEvent(QCloseEvent *event);
436 
437 
438  signals:
442  void shutdown();
443 
447  void initCircuit();
448 
452  void initServos();
453 
458  void drive(const int command);
459 
464  void resetDrivenDistance(int sensor);
465 
471  void enableRemoteControlListening(bool state);
472 
483  void simulate(bool state);
484 
488  void writeLaserData();
489 
494  void enableFaceDetection(int state);
495 
500  void enableFaceTracking(int state);
501 
505  void speak(QString text);
506 
510  void test();
511 
514  void setKinectVideoMode(int mode);
515 
518  void setKinectAngle(double i);
519 
522  void resetKinectAngle();
523 
527  void setThreshold(int value);
528 
533  void demo(bool state);
534 
538  void mediaSkip();
539 
540 
541  protected slots:
548 #ifndef USEROBOTGUI
549  void on_actionAll_activated();
552  // void on_actionCurrent_activated();
554  void on_actionLog_activated();
555 #endif
565 
566 
567  private slots:
569 /*
570  void on_btnResetMovement1_clicked();
571  void on_btnResetMovement2_clicked();
572  void on_btnResetMovement3_clicked();
573  void on_btnResetMovement4_clicked();
574 */
575  //void on_ckeckBoxSaveSettings_stateChanged(int state);
577 
578 #ifdef ACTIVELASERVIEW
579  void on_sliderZoom_valueChanged(int);
580 #endif
581 
585 /*
586  void on_btnPower1_toggled(bool);
587  void on_btnPower2_toggled(bool);
588  void on_btnPower3_toggled(bool);
589  void on_btnPower4_toggled(bool);
590  void on_btnDirection1_toggled(bool);
591  void on_btnDirection2_toggled(bool);
592  void on_btnDirection3_toggled(bool);
593  void on_btnDirection4_toggled(bool);
594 */
595 // void on_btnKinectVideoRGB_clicked(bool checked);
596 // void on_btnKinectVideoYUVRGB_clicked(bool checked);
597 // void on_btnKinectVideoIR8Bit_clicked(bool checked);
601 
605  void saveCamImage(void);
606 
607  void processCam();
608 
609 
610  private:
611  void init();
612 #ifndef BUILDFORROBOT
613  void initPlots();
614 #endif
615  void initCompassView();
616 
617 #ifdef ACTIVELASERVIEW
618 
621  void createLaserScannerObjects();
622  void createLaserDistanceObjects();
623  void createLaserWidthObjects();
624 #endif
625 
631  QString removeHtml(QString text);
632 
633  bool robotIsOn;
634  bool useLargeGUI;
635  Ui::mainWindow ui;
636  Ui::mainWindowSmall uiSmall;
637  SettingsDialog *settingsDialog; // just a pointer to the object created in the direcs class!
638  JoystickDialog *joystickDialog; // just a pointer to the object created in the direcs class!
639  AboutDialog *aboutDialog; // just a pointer to the object created in the direcs class!
640 #ifndef BUILDFORROBOT
641  QwtPlot qwtPlotVoltage1; // this plot object will be added to the GUI layout if we don't build on the robot directly!
642  QwtPlot qwtPlotVoltage2; // this plot object will be added to the GUI layout if we don't build on the robot directly!
643  QwtPlot qwtPlotCurrent1; // this plot object will be added to the GUI layout if we don't build on the robot directly!
644  QwtPlot qwtPlotCurrent2; // this plot object will be added to the GUI layout if we don't build on the robot directly!
645  QwtPlot qwtPlotHeartbeat; // this plot object will be added to the GUI layout if we don't build on the robot directly!
646  QwtPlotCurve curveVoltage1;
647  QwtPlotCurve curveVoltage2;
648  QwtPlotCurve curveCurrent1;
649  QwtPlotCurve curveCurrent2;
650  QwtPlotCurve curveCurrent3;
651  QwtPlotCurve curveCurrent4;
652  QwtPlotCurve curveHeartbeat;
653  QwtPlotGrid gridVoltage1;
654  QwtPlotGrid gridVoltage2;
655  QwtPlotGrid gridCurrent1;
656  QwtPlotGrid gridCurrent2;
657  QwtPlotGrid gridHeartbeat;
658 // QwtCompassMagnetNeedle needle;
659 #endif
661 
665  QColor gridColor;
682 
683 #ifdef ACTIVELASERVIEW
684  QPen laserLinePen;
685  int lastZoom;
686  qreal startScale;
687  qreal laserXPos;
688  qreal laserYPos;
689  QGraphicsScene *scene;
690  QList <QGraphicsLineItem*> *laserLineListFront;
691  QList <QGraphicsLineItem*> *laserLineListRear;
692  QList <QGraphicsEllipseItem*> *laserDistanceLineListFront;
693  QList <QGraphicsSimpleTextItem*> *laserDistanceTextFront;
694  QList <QGraphicsEllipseItem*> *laserDistanceLineListRear;
695  QList <QGraphicsSimpleTextItem*> *laserDistanceTextRear;
696  QGraphicsPixmapItem *pixmapBot1;
697  QGraphicsPixmapItem *pixmapBot2;
698  QGraphicsEllipseItem *widthLeftCircleFront;
699  QGraphicsEllipseItem *widthRightCircleFront;
700  QGraphicsLineItem *widthLineFront;
701  QGraphicsSimpleTextItem *widthTextFront;
702  QGraphicsEllipseItem *widthLeftCircleRear;
703  QGraphicsEllipseItem *widthRightCircleRear;
704  QGraphicsLineItem *widthLineRear;
705  QGraphicsSimpleTextItem *widthTextRear;
706  qreal widthCirclesWidth;
707 #endif
708 
709  QPixmap pixmap; // for IplImageToQImage()
710 
711 // CompassWidget *compassWidget; /// The 3D OpenGL compass widget
712  bool consoleMode;
713  QDateTime now;
714  QString string; // this is a free to use string
715 /*
716  cv::Mat frame;
717 */
718 
719  static const int SENSORPROGRESSBARMAXIR = 50;
720  static const int SENSORPROGRESSBARMAXUS = 400;
722 // static const float AMPERESMAXPLOTCURVE1 = 3000.0; /// The maximum axis Y value in Amperes (A) for plot curve number 1
723 // static const float AMPERESMAXPLOTCURVE2 = 3000.0; /// The maximum axis Y value in Amperes (A) for plot curve number 2
724 // static const float AMPERESSTEPPLOTCURVE1 = 500.0; /// The step value for the y axis for plot curve number 1
725 // static const float AMPERESSTEPPLOTCURVE2 = 500.0; /// The step value for the y axis for plot curve number 1
726 
727  static const bool ON = true;
728  static const bool OFF = false;
730 
731  static const int FORWARD = 10;
732  static const int BACKWARD = 20;
733  static const int LEFT = 30;
734  static const int RIGHT = 40;
735  static const int TURNLEFT = 50;
736  static const int TURNRIGHT = 60;
737  static const int START = 70;
738  static const int STOP = 80;
739  static const int WAIT = 90;
740  // static const int DIAGONAL_FORWARD_LEFT
741  // static const int DIAGONAL_FORWARD_RIGHT
742  // static const int DIAGONAL_BACKWARD_LEFT
743  // static const int DIAGONAL_BACKWARD_RIGHT
744 
745  static const int SAME = 200;
746  static const int MOTOR1 = 210;
747  static const int MOTOR2 = 220;
748  static const int MOTOR3 = 230;
749  static const int MOTOR4 = 240;
750  static const int ALLMOTORS = 250;
751 
752  static const int MOTOR1FW = 300;
753  static const int MOTOR1BW = 310;
754  static const int MOTOR1OFF = 320;
755  static const int MOTOR2FW = 330;
756  static const int MOTOR2BW = 340;
757  static const int MOTOR2OFF = 350;
758  static const int MOTOR3FW = 360;
759  static const int MOTOR3BW = 370;
760  static const int MOTOR3OFF = 380;
761  static const int MOTOR4FW = 390;
762  static const int MOTOR4BW = 400;
763  static const int MOTOR4OFF = 410;
764 
765  static const int READ_AXIS_X = 500;
766  static const int READ_AXIS_Y = 510;
767  static const int READ_AXIS_Z = 520;
768 
775  static const short int SENSOR1 = 1;
776  static const short int SENSOR2 = 2;
777  static const short int SENSOR3 = 4;
778  static const short int SENSOR4 = 8;
779  static const short int SENSOR5 = 16;
780  static const short int SENSOR6 = 32;
781  static const short int SENSOR7 = 64;
782  static const short int SENSOR8 = 128;
783 
785  static const short int SENSOR16 = 256;
787  static const short int NONE = 0;
788 
789  static const short int MOTORSENSOR1 = 0;
790  static const short int MOTORSENSOR2 = 1;
791  static const short int MOTORSENSOR3 = 2;
792  static const short int MOTORSENSOR4 = 3;
793 
794  static const short int VOLTAGESENSOR1 = 0;
795  static const short int VOLTAGESENSOR2 = 1;
796 
797  static const float MINIMUMVOLTAGE1 = 13.20;
798  static const float MINIMUMVOLTAGE2 = 24.00;
799 
800  static const float MAXIMUMVOLTAGE1 = 18.00;
801  static const float MAXIMUMVOLTAGE2 = 26.00;
802 
803  static const float MAXIMUMPLOTVOLTAGE1 = 18.00;
804  static const float MAXIMUMPLOTVOLTAGE2 = 26.00;
805 
806  static const float MAXIMUMPLOTHEARTBEAT = 5.00;
807 
818  static const int FITTOFRAMEFACTOR = 45;
819  static const int STARTZOOMLEVEL = 3;
820 
823  static const int INITIALLASERYPOSFRONT = 60.0; // FIXME: when values are different, the distance line do not fit on the lsaer lines in on_sliderZoom_valueChanged
824  static const int INITIALLASERYPOSREAR = 60.0; // FIXME: when values are different, the distance line do not fit on the lsaer lines in on_sliderZoom_valueChanged
825 
827  static const int LASERDISTANCECIRCLES = 27;
829  static const int LASERDISTANCEFIRSTCIRCLE = 82;
831  static const int LASERDISTANCEDISTANCE = 60;
832 
834  static const int FREEWAY = 0;
835  static const int OBSTACLE = 1;
836  static const int LARGESTFREEWAY = 2;
837  static const int CENTEROFLARGESTFREEWAY = 3;
838  static const int IGNORETHIS = 4;
839 
840  // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
845  //static const unsigned char LASERSCANNERARRAYSIZE = 181;
846 
850  static const short int LASER1 = 1;
851  static const short int LASER2 = 2;
852  static const short int LASER3 = 4;
853  static const short int LASER4 = 8;
854  static const short int LASER5 = 16;
855 
859  static const unsigned char LEDOFF = 0;
860  static const unsigned char RED = 1;
861  static const unsigned char GREEN = 2;
862 };
863 #endif