direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
direcs.cpp
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 #include "direcs.h"
22 
23 
24 int main(int argc, char *argv[])
25 {
26  bool consoleMode = false;
27  bool forceSmallGUI = false;
28  bool forceLargeGUI = false;
29 
30 
31  // Check for command-line argument "console".
32  // A deeper argument check will be done later within the class Direcs!
33  if (argc > 1)
34  {
35  qDebug() << argc - 1 << "argument(s) passed...";
36 
37  for (int i=1; i<argc; i++)
38  {
39  // now search for the "console" parameter (case insensitive)
40  if (strcasecmp(argv[i], "console") == 0)
41  {
42  consoleMode = true;
43  qDebug() << "Console mode enabled.";
44  }
45 
46  // force small GUI ?
47  if (strcasecmp(argv[i], "small") == 0)
48  {
49  forceSmallGUI = true;
50  qDebug() << "Using small GUI.";
51  }
52 
53  // force large GUI ?
54  if (strcasecmp(argv[i], "large") == 0)
55  {
56  forceLargeGUI = true;
57  qDebug() << "Using large GUI.";
58  }
59 
60  // now search for the "console" parameter (case insensitive)
61  if ((strcasecmp(argv[i], "-h") == 0) || (strcasecmp(argv[i], "-help") == 0) || (strcasecmp(argv[i], "help") == 0) || (strcasecmp(argv[i], "?") == 0) || (strcasecmp(argv[i], "-?") == 0))
62  {
63  qDebug() << "Possible parameters:\n\n";
64  qDebug() << "console\tuse console mode";
65  qDebug() << "small\tforce small GUI";
66  qDebug() << "large\tforce large GUI\n\n";
67  }
68  }
69  }
70 
71 
72  if (consoleMode)
73  {
74  //----------------------
75  // CREATE A CONSOLE APP
76  //----------------------
77 
78  // The QCoreApplication class provides an event loop for console Qt applications.
79  QCoreApplication app(argc, argv);
80 
81  CleanExit cleanExit;
82 
83  // create Direcs class object
84  Direcs d(consoleMode, forceSmallGUI, forceLargeGUI);
85 
86  // init direcs
87  d.init();
88 
89  return app.exec();
90  }
91  else
92  {
93  //----------------------
94  // CREATE A GUI APP
95  //----------------------
96 
97  // Initialize the resource file
98  Q_INIT_RESOURCE(direcs);
99 
100  // The QApplication class manages the GUI application's control flow and main settings.
101  QApplication app(argc, argv);
102 
103  // create the Direcs class object
104  Direcs d(consoleMode, forceSmallGUI, forceLargeGUI);
105 
106  // init direcs
107  d.init();
108 
109  return app.exec();
110  }
111 }
112 
113 
114 Direcs::Direcs(bool bConsoleMode, bool bForceSmallGUI, bool bForceLargeGUI)
115 {
116  // store mode from main method
117  consoleMode = bConsoleMode;
118  forceSmallGUI = bForceSmallGUI;
119  forceLargeGUI = bForceLargeGUI;
120 
121  //-------------------------
122  // Creating logfile object
123  //-------------------------
124  logfile = new Logfile();
125  logfile->setFilename("direcs.log");
126  logfile->appendLog("- start -------------------------------------------------------------------------------------------");
127 
128 
129  //----------------------
130  // check local hostname
131  //----------------------
132  QString hostname = QHostInfo::localHostName();
133 
134  logfile->appendLog(QString("The hostname of this machine is %1").arg(hostname));
135 
136  if (hostname.contains("robot"))
137  {
138  logfile->appendLog("Hostname contains 'robot'. We will use the small robot GUI.");
139  useSmallGUI = true;
140  }
141  else
142  {
143  logfile->appendLog("Hostname does not contain 'robot'. We will use the large GUI.");
144  useSmallGUI = false;
145  }
146 
147  if (forceSmallGUI)
148  {
149  logfile->appendLog("Overriding GUI use due to command line argument. We will use the small robot GUI!");
150  useSmallGUI = true;
151  }
152 
153  if (forceLargeGUI)
154  {
155  logfile->appendLog("Overriding GUI use due to command line argument. We will use the large robot GUI!");
156  useSmallGUI = false;
157  }
158 
159 
160  //--------------------------
161  // create all other objects
162  //--------------------------
163 #ifdef Q_OS_LINUX // currently supported only under linux (no MAC OS at the moment)
164  speakThread = new SpeakThread();
165 #endif
166 
167  if (consoleMode)
168  {
169  consoleGui = new ConsoleGui();
170 // myEvent = new Events();
172 // consoleGui->installEventFilter(myEvent);
173 // this->installEventFilter(myEvent);
174  }
175  else
176  {
179  aboutDialog = new AboutDialog();
181  splash = new QSplashScreen(QPixmap(":/images/images/splash.png"));
182  }
183 
184 
185  mutex = new QMutex();
186  interface1 = new InterfaceAvr();
189  motors = new Motor(interface1, mutex);
191  servos = new Servo(interface1, mutex);
192  rgbLeds = new RgbLed(interface1, mutex);
193  laserThread = new LaserThread();
195 
196 #ifndef BUILDFORROBOT
197  if (!consoleMode)
198  {
200  }
201 #endif
202 
203  inifile1 = new Inifile();
204  netThread = new NetworkThread();
205  // creation of kinect instance moved to init method to see something on the splash screen
206  joystick = new Joystick();
207  // head = new Head(servos); disabled since the head is not in use use!
208 
209  if (!consoleMode)
210  {
211  camThread = new CamThread();
212  }
213 
214  timerThread = new TimerThread();
215 
216  drivingSpeedTimer = new QTimer();
217 
218  // create Phonon media player
219  mediaObject = new Phonon::MediaObject();
220 
221  demoThread = new DemoThread();
222 }
223 
224 
226 {
227  if (!consoleMode)
228  {
229  aboutDialog->setVersion("1.0");
230  splashTextColor = Qt::white;
231  }
232  forceShutdown = false;
233  inifile1->setFilename("direcs.ini");
234  useSmallGUI=false;
235  serialPortMicrocontroller = "error1";
236  serialPortLaserscannerFront = "error1";
237  laserscannerTypeFront= "error1";
238  laserscannerTypeRear= "error1";
239  writeLogFile = false;
240  // robotIsOn = false;
241  robotDrives = false;
242  mot1Speed = 0;
243  mot2Speed = 0;
244  mot3Speed = 0;
245  mot4Speed = 0;
246  robotSimulationMode = false;
247  robotRemoteMode = false;
248  iAmTheMaster = true;
249  firstDataReceived = false;
250  servoTestMode = false;
251  testDriveMode = false;
252  mecanumDriveMode = false; // if false, a joystick move to the right, lets the robot "turn right". If true, the robots "moves right" - without turning around itself.
253  eyeTestMode = false;
255  useCamera = false;
256  cameraTestMode = false;
257  faceTrackingIsEnabled = false;
258  laserScannerFrontFound = false;
259  laserScannerRearFound = false;
262  endSpeedMotor1Reached = false;
263  endSpeedMotor2Reached = false;
264  endSpeedMotor3Reached = false;
265  endSpeedMotor4Reached = false;
266  preferredDrivingDirection = FORWARD; // this is to allow the robot to drive forward, if the obstacleCheckThread is not running (because of offline laser). Mainly for testing reasons!
267  demoMode = false;
268 
269 
270  //-----------------------------------------------------------------------------------------------------------------------------------------
271  // check which OS we have. ACTUALLY we check for the WINDOW system, since the OS check doesn't worked (unix was recognized under mac os x)
272  //-----------------------------------------------------------------------------------------------------------------------------------------
273  #ifdef Q_OS_UNIX
274  qDebug("UNIX OS detected.");
275  logfile->appendLog("UNIX OS detected.");
276  #endif
277 
278  #ifdef Q_OS_LINUX
279  qDebug("Linux OS detected.");
280  logfile->appendLog("Linux OS detected.");
281  #endif
282 
283  #ifdef Q_WS_X11
284  qDebug("X11 detected.");
285  logfile->appendLog("X11 detected.");
286  #endif
287 
288  #ifdef Q_OS_MAC
289  qDebug("MAC OS detected.");
290  logfile->appendLog("MAC OS detected.");
291  #endif
292 
293  #ifdef Q_WS_MAC
294  qDebug("MAC OS WS detected.");
295  logfile->appendLog("MAC OS WS detected.");
296  #endif
297 
298  //--------------------------------------------------------------------------
299  // show the splash screen and set application name
300  //--------------------------------------------------------------------------
301  if (!consoleMode)
302  {
303  splash->show();
304 
305  // this is for the Phonon library to export audio output names through the DBUS interface
306  QCoreApplication::setApplicationName("direcs");
307  }
308 
309  //--------------------------------------------------------------------------
310  // show splash messages in the splash screen
311  //--------------------------------------------------------------------------
312  connect(this, SIGNAL( splashMessage(QString) ), this, SLOT( showSplashMessage(QString) ));
313 
314  //--------------------------------------------------------------------------
315  // let the splash screen also show laser init messages
316  //--------------------------------------------------------------------------
317  connect(laserThread, SIGNAL(message(QString)), this, SLOT(showSplashMessage(QString)));
318 
319  //--------------------------------------------------------------------------
320  // let the GUI (or console) also show laser init messages
321  //--------------------------------------------------------------------------
322  if (consoleMode)
323  {
324  connect(laserThread, SIGNAL(message(QString)), consoleGui, SLOT(appendLog(QString)));
325  }
326  else
327  {
328  connect(laserThread, SIGNAL(message(QString)), gui, SLOT(appendLog(QString)));
329  }
330 
331  //--------------------------------------------------------------------------
332  // let some other classes know if we are in the console mode
333  //--------------------------------------------------------------------------
335 
336  /*
337  not in use at the moment...
338 
339  //--------------------------------------------------------------------------------
340  // create the commmand line arguments list
341  //--------------------------------------------------------------------------------
342  arguments = QCoreApplication::arguments();
343  int count = arguments.count() - 1;
344 
345  // check if arguments were passed on the command-line
346  if (count > 0)
347  {
348  qDebug() << count << "argument(s) passed...";
349  // check the arguments
350  checkArguments();
351  }
352  */
353 
354  //------------------------------------------------------------------
355  // Set the number format to "," for comma and 1000 separator to "."
356  // For example: 1.234,00 EUR
357  //------------------------------------------------------------------
358  QLocale::setDefault(QLocale::German);
359  commaSeparator = ",";
360 
361  //--------------------------------------------------------------------------
362  // show messages in the GUI log or in the console
363  //--------------------------------------------------------------------------
364  if (consoleMode)
365  {
366  connect(this, SIGNAL( message(QString) ), consoleGui, SLOT( appendLog(QString) ));
367  }
368  else
369  {
370  connect(this, SIGNAL( message(QString, bool, bool, bool) ), gui, SLOT( appendLog(QString, bool, bool, bool) ));
371  }
372 
373  //--------------------------------------------------------------------------
374  // Check for the current programm path
375  //--------------------------------------------------------------------------
376  emit splashMessage("Loading config file...");
377  emit message(QString("Current path: %1").arg(inifile1->checkPath()));
378 
379  //--------------------------------------------------------------------------
380  // show a QMessage wth the possibility to exit the main programm, when errors occured!
381  //--------------------------------------------------------------------------
382  connect(interface1, SIGNAL(tooMuchErrors()), this, SLOT(showExitDialog()));
383 
384  //--------------------------------------------------------------------------
385  // let some classes know the robots state
386  //--------------------------------------------------------------------------
387  // this is needed, when the first openCOMPort method fails:
388  connect(interface1, SIGNAL( robotState(bool) ), circuit1, SLOT( setRobotState(bool) ));
389  connect(interface1, SIGNAL( robotState(bool) ), motors, SLOT( setRobotState(bool) ));
390  connect(interface1, SIGNAL( robotState(bool) ), sensorThread, SLOT( setRobotState(bool) ));
391 // connect(interface1, SIGNAL( robotState(bool) ), heartbeat, SLOT( setRobotState(bool) ));
392  connect(interface1, SIGNAL( robotState(bool) ), rgbLeds, SLOT( setRobotState(bool) ));
393 // connect(interface1, SIGNAL( robotState(bool) ), this, SLOT( setRobotState(bool) ));
394  if (!consoleMode)
395  {
396  connect(interface1, SIGNAL( robotState(bool) ), gui, SLOT( setRobotControls(bool) ));
397  }
398 
399  // also set the robot to OFF, when there are problems with the circuit
400  connect(circuit1, SIGNAL( robotState(bool) ), motors, SLOT( setRobotState(bool) ));
401  connect(circuit1, SIGNAL( robotState(bool) ), sensorThread, SLOT( setRobotState(bool) ));
402 // connect(circuit1, SIGNAL( robotState(bool) ), heartbeat, SLOT( setRobotState(bool) ));
403  connect(circuit1, SIGNAL( robotState(bool) ), rgbLeds, SLOT( setRobotState(bool) ));
404 // connect(circuit1, SIGNAL( robotState(bool) ), this, SLOT( setRobotState(bool) ));
405  if (!consoleMode)
406  {
407  connect(circuit1, SIGNAL( robotState(bool) ), gui, SLOT( setRobotControls(bool) ));
408  }
409 
410  // let the sensorthread know, if only the compass is not connected
411  connect(circuit1, SIGNAL( compassState(bool) ), sensorThread, SLOT( setCompassState(bool) ));
412 
413 
414  if (!consoleMode)
415  {
416  //--------------------------------------------------------------------------
417  // shutdown Direcs program on exit button
418  // shutdown is also called, when the gui is closed
419  //--------------------------------------------------------------------------
420  connect(gui, SIGNAL(shutdown()), this, SLOT(shutdown()));
421 
422  //--------------------------------------------------------------------------
423  // call (a) test method(s) when clicking the test button
424  //--------------------------------------------------------------------------
425  connect(gui, SIGNAL(test()), this, SLOT(test()));
426  }
427 
428  if (!consoleMode)
429  {
430  //--------------------------------------------------------------------------
431  // resets the driven distance, when signal comes from Gui
432  //--------------------------------------------------------------------------
433  connect(gui, SIGNAL(resetDrivenDistance(int)), sensorThread, SLOT(resetDrivenDistance(int)));
434  }
435 
436  if (!consoleMode)
437  {
438  //--------------------------------------------------------------------------
439  // set the motor speed, when signal comes from Gui
440  //--------------------------------------------------------------------------
441  connect(settingsDialog, SIGNAL(setMotorSpeed(int, int)), motors, SLOT(setMotorSpeed(int, int)));
442 
443  //--------------------------------------------------------------------------
444  // set the maximum robot speed, when signal comes from Gui
445  //--------------------------------------------------------------------------
446  connect(settingsDialog, SIGNAL(setMaximumSpeed(int)), motors, SLOT(setMaximumSpeed(int)));
447 
448  //--------------------------------------------------------------------------
449  // set the robot slot, when signal comes from Gui
450  //--------------------------------------------------------------------------
451  connect(settingsDialog, SIGNAL(setPassageWidth(int)), obstCheckThread, SLOT(setPassageWidth(int)));
452 
453  //--------------------------------------------------------------------------
454  // set the straight forward deviation, when signal comes from Gui
455  //--------------------------------------------------------------------------
456  connect(settingsDialog, SIGNAL(setStraightForwardDeviation(int)), obstCheckThread, SLOT(setStraightForwardDeviation(int)));
457 
458  //--------------------------------------------------------------------------
459  // set the minimum distance, when signal comes from Gui
460  //--------------------------------------------------------------------------
461  connect(settingsDialog, SIGNAL(setMinObstacleDistance(int)), obstCheckThread, SLOT(setMinObstacleDistance(int)));
462 
463  //--------------------------------------------------------------------------
464  // set the minimum laser distance, when signal comes from Gui
465  //--------------------------------------------------------------------------
466  connect(settingsDialog, SIGNAL(setMinObstacleDistanceLaserFront(int)), obstCheckThread, SLOT(setMinObstacleDistanceLaserFront(int)));
468 
469  //--------------------------------------------------------------------------
470  // let the GUI show servo messages in the log
471  //--------------------------------------------------------------------------
472  connect(rgbLeds, SIGNAL(message(QString)), gui, SLOT(appendLog(QString)));
473  }
474 
475 
476  //--------------------------------------------------------------------------
477  // Check for the programm ini file
478  // AND read the settings AND d o a l l t h e r e s t ! ! !
479  //--------------------------------------------------------------------------
480  if (inifile1->checkFiles() == true)
481  {
482  //----------------------------------------------------------------------------
483  // say a text
484  //----------------------------------------------------------------------------
485  #ifdef Q_OS_LINUX // currently supported only under linux (no MAC OS at the moment)
486  // a phase can also be emitted to the regarding slot (int parameter here)
487  connect(this, SIGNAL( speak(QString, int) ), speakThread, SLOT( speak(QString, int) ));
488 
489  if (!consoleMode)
490  {
491  connect(gui, SIGNAL( speak(QString) ), speakThread, SLOT( speak(QString) ));
492  }
493 
494 
495  if (speakThread->isRunning() == false)
496  {
497  emit message("Starting speak thread...", false);
498  speakThread->start();
499  emit message("Speak thread started.");
500  }
501  #endif
502 
503  // file found-Msg
504  emit message(QString("Using ini-File \"%1\".").arg(inifile1->getInifileName()));
505 
506  //=========================
507  // read all settings
508  //=========================
509  emit splashMessage("Reading settings...");
510  readSettings();
511 
512 #ifndef BUILDFORROBOT
513  if (!consoleMode)
514  {
515  //----------------------------------------------------------------------------
516  // connect plotThread signal to "setPlotData"
517  // (Whenever the plot thread has new data, the data are show in the GUI)
518  //----------------------------------------------------------------------------
519 /* plot of motor currents disabled
520  connect(plotThread, SIGNAL( plotDataComplete1(double *, double *, int) ), gui, SLOT( setPlotData1(double *, double *, int) ));
521  connect(plotThread, SIGNAL( plotDataComplete2(double *, double *, int) ), gui, SLOT( setPlotData2(double *, double *, int) ));
522  connect(plotThread, SIGNAL( plotDataComplete3(double *, double *, int) ), gui, SLOT( setPlotData3(double *, double *, int) ));
523  connect(plotThread, SIGNAL( plotDataComplete4(double *, double *, int) ), gui, SLOT( setPlotData4(double *, double *, int) ));
524 */
525  connect(plotThread, SIGNAL( plotDataComplete5(double *, double *, int) ), gui, SLOT( setPlotData5(double *, double *, int) ));
526  connect(plotThread, SIGNAL( plotDataComplete6(double *, double *, int) ), gui, SLOT( setPlotData6(double *, double *, int) ));
527  connect(plotThread, SIGNAL( plotDataCompleteHeartbeat(double *, double *, int) ), gui, SLOT( setPlotDataHeartbeat(double*, double*, int) ));
528  }
529 #endif
530 
531  //----------------------------------------------------------------------------
532  // let the GUI show messages in the logs
533  //----------------------------------------------------------------------------
534  if (!consoleMode)
535  {
536  connect(joystick, SIGNAL(message(QString)), gui, SLOT(appendLog(QString)));
537  connect(interface1, SIGNAL(message(QString)), gui, SLOT(appendSerialLog(QString)));
538  connect(circuit1, SIGNAL(message(QString)), gui, SLOT(appendSerialLog(QString)));
539  connect(obstCheckThread, SIGNAL(message(QString)), gui, SLOT(appendLog(QString)));
540  connect(timerThread, SIGNAL(message(QString)), gui, SLOT(appendLog(QString)));
541  connect(demoThread, SIGNAL(message(QString)), gui, SLOT(appendLog(QString)));
542  }
543  else
544  {
545  connect(joystick, SIGNAL(message(QString)), consoleGui, SLOT(appendLog(QString)));
546  connect(interface1, SIGNAL(message(QString)), consoleGui, SLOT(appendSerialLog(QString)));
547  connect(obstCheckThread, SIGNAL(message(QString)), consoleGui, SLOT(appendLog(QString)));
548  connect(timerThread, SIGNAL(message(QString)), consoleGui, SLOT(appendLog(QString)));
549  connect(demoThread, SIGNAL(message(QString)), consoleGui, SLOT(appendLog(QString)));
550  }
551 
552  // also emit interface class messages to the *logfile*
553  connect(interface1, SIGNAL(message(QString)), logfile, SLOT(appendLog(QString))); // FIXME: to fast in case of error for writing the logfile!
554  connect(circuit1, SIGNAL(message(QString)), logfile, SLOT(appendLog(QString)));
555  connect(obstCheckThread, SIGNAL(message(QString)), logfile, SLOT(appendLog(QString)));
556  connect(timerThread, SIGNAL(message(QString)), logfile, SLOT(appendLog(QString)));
557  connect(demoThread, SIGNAL(message(QString)), logfile, SLOT(appendLog(QString)));
558 
560  // connect(joystick, SIGNAL(message(QString)), logfile, SLOT(appendLog(QString)));
561 
562  //----------------------------------------------------------------------------
563  // connect demo button from gui to activate the demo mode
564  //----------------------------------------------------------------------------
565  connect(gui, SIGNAL( demo(bool) ), this, SLOT( setDemoMode(bool) ));
566 
567 #ifdef Q_OS_LINUX // currently supported only under linux (no MAC OS at the moment)
568  //----------------------------------------------------------------------------
569  // also let the speakThread inform the nextDemoPhase Slot about that the speech was completed to enter the next demo phase
570  //----------------------------------------------------------------------------
571  connect(speakThread, SIGNAL( speechCompleted(int) ), this, SLOT( nextDemoPhase(int) ));
572 #endif
573 
574  //-------------------------------------------------------
575  // start the network thread (waiting for commands)
576  //-------------------------------------------------------
577 
578  // we swap the ports for first listening for a network master
579  netThread->swapPorts();
581 
582  //-------------------------------------------------------
583  // Open serial port for microcontroller communication
584  //-------------------------------------------------------
585  emit splashMessage("Opening serial port for microcontroller communication...");
586  emit message(QString("Opening serial port %1 for microcontroller communication...").arg(serialPortMicrocontroller));
587 
589  {
590  //*****************************
591  //* ERROR opening serial port *
592  //*****************************
593  // Error message will be send via signals to the GUI or Console!
594  emit message("<font color=\"#FF0000\">The robot is OFF!</font>");
595  if (consoleMode)
596  {
597  consoleGui->appendSerialLog("<font color=\"#FF0000\">+++++++++++++++++++++</font>");
598  consoleGui->appendSerialLog("<font color=\"#FF0000\">+ The robot is OFF! +</font>");
599  consoleGui->appendSerialLog("<font color=\"#FF0000\">+++++++++++++++++++++</font>");
600  }
601  else
602  {
603  gui->appendSerialLog("<font color=\"#FF0000\">The robot is OFF!</font>");
604  }
605  logfile->appendLog("ERROR: The robot is OFF!");
606 
607  /* not in use. Don't show a message box
608  if (!consoleMode)
609  {
610  // show a warning dialog!
611  QMessageBox msgbox(QMessageBox::Warning, tr("Error with robots serial port"),
612  tr("Error opening serial port %1").arg(serialPortMicrocontroller),
613  QMessageBox::Ok | QMessageBox::Default);
614  msgbox.exec();
615  }
616  */
617 
618  if (!consoleMode)
619  {
620  // set GUI LED for compass module
621  // has to be OFF, since the Atmel circuit is OFF
623  gui->disableCompass();
624  }
625  }
626  else
627  {
628  //**********************
629  //* Serial port opened *
630  //**********************
631  emit message("Serial port opened.");
632  if (consoleMode)
633  {
634  consoleGui->appendSerialLog("Serial port opened.");
635  }
636  else
637  {
638  gui->appendSerialLog("Serial port opened.");
639  }
640  logfile->appendLog("Serial port opened.");
641 
642 
643  //-------------------------------------------------------
644  // Basic init for all the bits on the robot circuit
645  // AND check, if the robot is "on" (it answers correct)
646  //-------------------------------------------------------
647  if (!consoleMode)
648  {
649  // init the circuit & Co. when hitting the button in the GUI
650  connect(gui, SIGNAL( initCircuit() ), circuit1, SLOT( initCircuit() ) );
651  connect(gui, SIGNAL( initServos() ), servos, SLOT( init() ) );
652 // connect(gui, SIGNAL( initServos() ), rgbLeds, SLOT( init() ) ); // @todo: build this < < < < < < <
653  }
654 
655 
656  //==========================
657  // init the robots circuit
658  //==========================
659  emit splashMessage("Searching robot...");
660 
661  if (circuit1->initCircuit() == true)
662  {
663  emit message("Robot is <font color=\"#00FF00\">ON</font> and answers.");
664 
665 /*
666  // check compass module
667  if (circuit1->initCompass() == true)
668  {
669  emit message("3D compass module detected.");
670  if (!consoleMode)
671  {
672  gui->setLEDCompass(GREEN);
673  }
674  }
675  else
676  {
677  emit message("<font color=\"#FF0000\">3D compass module not connected!</font>");
678  if (!consoleMode)
679  {
680  gui->setLEDCompass(RED);
681  }
682  }
683 */
684  //-------------------------------------------------------
685  // set the read motor speed
686  //-------------------------------------------------------
687  emit message("Setting motor speed in microcontroller");
692  emit message("Motor speed set.");
693 
694 /*
695  //-------------------------------------------------------
696  // move all Servos in their default positions
697  //-------------------------------------------------------
698  servos->init();
699  emit message("Servos moved to default positions");
700 */
701 
702  //-------------------------------------------------------
703  // set all RGB LEDs in their default brightness
704  //-------------------------------------------------------
705  rgbLeds->init();
706  emit message("RGB LEDs set to default brightness");
707 
708 
710  //-----------------------------------------------------------
711  // start the heartbeat thread
712  //-----------------------------------------------------------
713  /*
714  if (heartbeat->isRunning() == false)
715  {
716  emit splashMessage("Starting heartbeat thread...");
717 
718  emit message("Starting heartbeat thread...", false);
719  heartbeat->start();
720  emit message("Heartbeat thread started.");
721  }
722  */
723 
724  //-----------------------------------------------------------
725  // start the sensor thread for reading the sensors)
726  //-----------------------------------------------------------
727  if (sensorThread->isRunning() == false)
728  {
729  emit splashMessage("Starting sensor thread...");
730  emit message("Starting sensor thread...", false);
731  sensorThread->start();
732  emit message("Sensor thread started.");
733 
734  // whenever there is a material error, react!
735  connect(sensorThread, SIGNAL( systemerror(int) ), this, SLOT( systemerrorcatcher(int) ) );
736  }
737 
738 #ifndef BUILDFORROBOT
739  if (!consoleMode)
740  {
741  //-----------------------------------------------------------
742  // start the plot thread ("clock" for plotting the curves)
743  //-----------------------------------------------------------
744  if (plotThread->isRunning() == false)
745  {
746  emit splashMessage("Starting plot thread...");
747  emit message("Starting plot thread...", false);
748  plotThread->start();
749  emit message("Plot thread started.");
750  }
751  }
752 #endif
753  } // init was successfull
754  else
755  {
756  logfile->appendLog("Robot is OFF! Please turn it ON!");
757  emit message("<font color=\"#FF0000\">The robot is OFF! Please turn it ON!</font>");
758  emit message("Heartbeat thread NOT started!");
759  emit message("Sensor thread NOT started!");
760  emit message("Plot thread NOT started!");
761  }
762  } // robot is ON
763 
764 
765  //-----------------------------------------------------------
766  // start the timer thread
767  //-----------------------------------------------------------
768  if (timerThread->isRunning() == false)
769  {
770  emit splashMessage("Starting timer thread...");
771  emit message("Starting timer thread...", false);
772  timerThread->start();
773  emit message("Timer thread started.");
774  }
775 
776 
777  //-----------------------------------------------------------
778  // check if a joystick is connected
779  //-----------------------------------------------------------
780  if (joystick->isConnected())
781  {
782  // set GUI LED
783  if (!consoleMode)
785 
786  // start the joystick thread
787  if (joystick->isRunning() == false)
788  {
789  emit splashMessage("Starting joystick thread...");
790  emit message("Starting joystick thread...", false);
791  joystick->start();
792  emit message("Joystick thread started.");
793  }
794  }
795  else
796  {
797  // set GUI LED
798  if (!consoleMode)
800 
801  emit message("Joystick thread NOT started.");
802  }
803 
804  if (!consoleMode)
805  {
806  //----------------------------------------------------------------------------
807  // drive in the direction which was emited from the gui
808  //----------------------------------------------------------------------------
809  connect(gui, SIGNAL( drive(int) ), this, SLOT( drive(int) ));
810  }
811 
812  //----------------------------------------------------------------------------
813  // increase the speed by an interval defined as a const in the header file
814  // this is used when starting to drive
815  //----------------------------------------------------------------------------
816  connect(drivingSpeedTimer, SIGNAL( timeout() ), this, SLOT( increaseDrivingSpeed() ));
817 
818  //----------------------------------------------------------------------------
819  // connect sensor signals to "show sensor data"
820  // (Whenever the sensor data are completely read, show the result in the GUI)
821  //----------------------------------------------------------------------------
822  connect(sensorThread, SIGNAL( sensorDataComplete() ), this, SLOT( showSensorData() ) );
823  connect(sensorThread, SIGNAL( sendNetworkString(QString) ), netThread, SLOT( sendNetworkCommand(QString) ) );
824  // show error messages in GUI, too
825  connect(sensorThread, SIGNAL( message(QString, bool, bool, bool) ), gui, SLOT( appendLog(QString, bool, bool, bool) ));
826  // write error messages to logfile
827  connect(sensorThread, SIGNAL( message(QString, bool) ), logfile, SLOT( appendLog(QString, bool) ));
828 
829  if (!consoleMode)
830  {
831  connect(sensorThread, SIGNAL( compassDataComplete(float, float, float, float) ), gui, SLOT( showCompassData(float, float, float, float) ) );
832  }
833 
834 
835  //----------------------------------------------------------------------------
836  // connect sensor signals to "show that the robot is still alive"
837  // (Whenever a specifiv sensor data is received, show the result in the GUI)
838  //----------------------------------------------------------------------------
839  if (!consoleMode)
840  {
841  connect(sensorThread, SIGNAL( heartbeat(unsigned char)), gui, SLOT( setLEDHeartbeat(unsigned char) ) );
842  }
843  //----------------------------------------------------------------------------
844  // connect sensor signals and write the heartbeat to the logfile
845  // (Whenever a specific sensor data is received, write this to the logfile)
846  //----------------------------------------------------------------------------
847  // connect(sensorThread, SIGNAL( heartbeat(unsigned char)), logfile, SLOT( writeHeartbeat(unsigned char) ) );
848  // FIXME: this is too often!! Because of 10ms sensor thread!!
849 
850  //----------------------------------------------------------------------------
851  // connect obstacle check (alarm!) sensor signal to "logical unit"
852  //----------------------------------------------------------------------------
853  connect(obstCheckThread, SIGNAL(obstacleDetected(int, QDateTime)), this, SLOT(logicalUnit(int, QDateTime)));
854 
855  if (!consoleMode)
856  {
857  //----------------------------------------------------------------------------
858  // show the angle where to drive in a GUI label
859  //----------------------------------------------------------------------------
860  connect(obstCheckThread, SIGNAL(newDrivingAngleSet(int, int, int, float)), gui, SLOT(showLaserFrontAngles(int, int, int, float)));
861 
862  //----------------------------------------------------------------------------
863  // show the preferred driving direction in a GUI label
864  //----------------------------------------------------------------------------
865  connect(this, SIGNAL(showPreferredDirection(QString)), gui, SLOT(showPreferredDirection(QString)));
866 
867  //----------------------------------------------------------------------------
868  // connect remote control button from gui to remote control method here
869  // (Whenever the button is pushed, enable the network remote control)
870  //----------------------------------------------------------------------------
871  connect(gui, SIGNAL( enableRemoteControlListening(bool) ), this, SLOT( enableRemoteControlListening(bool) ));
872  }
873 
874  //----------------------------------------------------------------------------
875  // execute the received remote commands
876  //----------------------------------------------------------------------------
877  connect(netThread, SIGNAL( dataReceived(QString) ), this, SLOT( executeRemoteCommand(QString) ));
878 
879  //---------------------------------------------------------------------------------------
880  // check the network state after some seconds after pgm start (are we master or slave?)
881  //---------------------------------------------------------------------------------------
882  connect(timerThread, SIGNAL(checkNetworkState()), this, SLOT(setNetworkState()));
883 
884  // connect signal from timerThread to networkThread (enable sending 'master' signal every second)
885  connect(timerThread, SIGNAL(checkNetworkState()), netThread, SLOT(setNetworkMaster()));
886 
887  // show network master/slave state in GUI LED
888  if (!consoleMode)
889  {
890  connect(netThread, SIGNAL(heartbeat(unsigned char)), gui, SLOT( setLEDMasterSlave(unsigned char) ) );
891  }
892 
893  //----------------------------------------------------------------------------
894  // connect networkThread signal to "dataReceived"
895  // (Whenever data were received, the data are shown in the GUI)
896  //----------------------------------------------------------------------------
897  if (!consoleMode)
898  {
899  connect(netThread, SIGNAL( dataReceived(QString) ), gui, SLOT( appendNetworkLog(QString) ));
900  }
901  else
902  {
903  connect(netThread, SIGNAL( dataReceived(QString) ), consoleGui, SLOT( appendNetworkLog(QString) ));
904  }
905 
906  //----------------------------------------------------------------------------
907  // connect sendNetworkString signal to netThreads slot "sendNetworkCommand"
908  // (Whenever the signal is emmited, send the given string over the net)
909  //----------------------------------------------------------------------------
910  connect(this, SIGNAL(sendNetworkString(QString) ), netThread, SLOT( sendNetworkCommand(QString) ));
911 
912  // connect signal from demoThread to rgbLed class (enable setting RGB LEDs from demoThread)
913  connect(demoThread, SIGNAL(setRGBLEDBrightness(unsigned char, unsigned char)), rgbLeds, SLOT(setBrightness(unsigned char,unsigned char)));
914 
915 #ifdef ACTIVELASERVIEW
916  if (!consoleMode)
917  {
918  //----------------------------------------------------------------------------
919  // connect laserThread signal to "dataReceived"
920  // (Whenever data were received, the data are shown in the GUI)
921  //----------------------------------------------------------------------------
922  qRegisterMetaType < QList <float> > ("QList <float>");
923  qRegisterMetaType < QList <int> > ("QList <int>");
924 
925  connect(laserThread, SIGNAL( laserDataCompleteFront(QList <float>, QList <int>) ), gui, SLOT( refreshLaserViewFront(QList <float>, QList <int>) ));
926  connect(laserThread, SIGNAL( laserDataCompleteRear(QList <float>, QList <int>) ), gui, SLOT( refreshLaserViewRear(QList <float>, QList <int>) ));
927  }
928 #endif
929 
930  //------------------------------------------------------------------------------
931  // connect laserThread signal to networkThread
932  // (Whenever laserscanner data are read, send the data over the network thread)
933  //------------------------------------------------------------------------------
934  connect(laserThread, SIGNAL( sendNetworkString(QString) ), netThread, SLOT( sendNetworkCommand(QString) ) );
935 
936  // whenever there is an error in the laser sensor, stop the obstacle check thread!
937  connect(laserThread, SIGNAL( systemerror(int) ), obstCheckThread, SLOT( systemerrorcatcher(int) ) );
938 
939  // whenever there is an error in the laser sensor, turn the laser GUI LED off
940  connect(laserThread, SIGNAL( systemerror(int) ), gui, SLOT( systemerrorcatcher(int) ) );
941 
942  // whenever there is an error in the laser sensor, stop driving, or so.
943  connect(laserThread, SIGNAL( systemerror(int) ), this, SLOT( systemerrorcatcher(int) ) );
944 
945  // write laser thread messages to logfile, too
946  connect(laserThread, SIGNAL(message(QString)), logfile, SLOT(appendLog(QString)));
947 
948  //----------------------------------------------------------------------------
949  // connect joystick signals to "show joystick data"
950  // (Whenever the joystick is moved or a button is pressed, show the result in the GUI)
951  //----------------------------------------------------------------------------
952  if (!consoleMode)
953  {
954  connect(joystick, SIGNAL(joystickMoved(int, int)), joystickDialog, SLOT(showJoystickAxes(int, int)));
955  connect(joystick, SIGNAL(joystickButtonPressed(int, bool)), joystickDialog, SLOT(showJoystickButtons(int, bool)));
956 #ifdef Q_OS_MAC // for Mac OS only:
957  connect(joystick, SIGNAL(joystickPOVButtonPressed(int)), joystickDialog, SLOT(showJoystickPOVButtons(int)));
958 #endif
959  }
960 
961  connect(joystick, SIGNAL(joystickMoved(int, int)), this, SLOT(executeJoystickCommand(int, int)));
962  connect(joystick, SIGNAL(joystickButtonPressed(int, bool)), this, SLOT(executeJoystickCommand(int, bool)));
963 
964  if (!consoleMode)
965  {
966  emit splashMessage("Detecting Kinect camera...");
967  emit message("Detecting Kinect camera...");
968 
969  // show Kinect messages in GUI
970  connect(camThread, SIGNAL(message(QString)), logfile, SLOT(appendLog(QString)));
971  connect(camThread, SIGNAL(message(QString)), gui, SLOT(appendLog(QString)));
972 
973 
974  //-----------------------------------------------------------
975  // check if Kinect camera is connected
976  //-----------------------------------------------------------
977  emit splashMessage("Initialising Kinect camera...");
978  emit message("Initialising Kinect camera...");
979 
980  if (camThread->init() == true)
981  {
982  emit splashMessage("Kinect found.");
983  emit message("Kinect found.");
984 
985  // connect sensor contact signals to "show contact alarm"
986  // (Whenever the an alarm contact was closed, show the result in the cam image)
987  // connect(sensorThread, SIGNAL(contactAlarm(char, bool)), camThread, SLOT(drawContactAlarm(char, bool)));
988 
989  // connect camDataComplete from the cam thread to signal "setCamImage"
990  // (Whenever the image is complete, the image is shown in the GUI)
991  connect(camThread, SIGNAL( camImageComplete(QImage*) ), gui, SLOT( setCamImage(QImage*) ));
992  connect(camThread, SIGNAL( camImageDepthComplete(QImage*) ), gui, SLOT( setCamImageDepth(QImage*) ));
993  connect(camThread, SIGNAL( camImageOpenCVComplete(QImage*) ), gui, SLOT( setCamImageOpenCV(QImage*) ));
994 
995  // connect faceDetected from the camThread to the faceTracking unit and to the GUI (to show some values)
996  connect(camThread, SIGNAL( faceDetected(int, int, int, int, int, int) ), this, SLOT( faceTracking(int, int, int, int) ));
997  connect(camThread, SIGNAL( faceDetected(int, int, int, int, int, int) ), gui, SLOT( showFaceTrackData(int, int, int, int, int, int) ));
998 
999  // enable face detection, when activated in the GUI
1000  connect(gui, SIGNAL( enableFaceDetection(int) ), camThread, SLOT( enableFaceDetection(int) ));
1001 
1002  // enable face tracking, when activated in the GUI
1003  connect(gui, SIGNAL( enableFaceTracking(int) ), this, SLOT( enableFaceTracking(int) ));
1004 
1005  // show the face track direction in the gui
1006  connect(this, SIGNAL( showFaceTrackDirection(QString) ), gui, SLOT( showFaceTrackDirection(QString)) );
1007 
1008  //-------------------------------------------------------------------------------------
1009  // disable face detection in the GUI, on error with loading haar cascade in CamThread
1010  // Must be before readSettings!
1011  //-------------------------------------------------------------------------------------
1013 
1014  //-------------------------------------------------------------------------------------
1015  // disable camera controls in the GUI, on error opeing the camera in the CamThread
1016  // Must be before readSettings!
1017  //-------------------------------------------------------------------------------------
1019 
1020  // send error messages to the gui
1021  connect(camThread, SIGNAL(message(QString)), gui, SLOT(appendLog(QString)));
1022 
1023  // set the Threshold in the camThread when changed in GUI
1024  connect(gui, SIGNAL(setThreshold(int)), camThread, SLOT(setThreshold(int)));
1025 
1026  //--------------------------------------------
1027  // start threading and grabbing live pictures
1028  //--------------------------------------------
1029  camThread->start();
1030 
1031  // look a bit up
1032  // kinect->setAngle(5); /// \todo: put angle value to ini file and settings dialog
1033  // gui->showKinectAngle(5);
1034 
1035  // show kinect camera state in gui
1037 
1038  // the signals for the LED actions
1039 
1040  // connect(gui, SIGNAL(setLedOff()), kinect, SLOT(setLedOff()));
1041  // connect(gui, SIGNAL(setRedLed()), kinect, SLOT(setRedLed()));
1042  // connect(gui, SIGNAL(setGreenLed()), kinect, SLOT(setGreenLed()));
1043  // connect(gui, SIGNAL(setYellowLed()), kinect, SLOT(setYellowLed()));
1044  // connect(gui, SIGNAL(setRedLedFlash()), kinect, SLOT(setRedLedFlash()));
1045  // connect(gui, SIGNAL(setGreenLedFlash()), kinect, SLOT(setGreenLedFlash()));
1046  // connect(gui, SIGNAL(setYellowLedFlash()), kinect, SLOT(setYellowLedFlash()));/
1047 
1049  //connect(gui, SIGNAL(setKinectAngle(double)), kinect, SLOT(setAngle(double)));
1050 
1052  //connect(gui, SIGNAL(resetKinectAngle()), kinect, SLOT(resetAngle()));
1053 
1054  // the signal for setting the video mode
1055  // connect(gui, SIGNAL(setKinectVideoMode(int)), kinect, SLOT(setVideoMode(int)));
1056  }
1057  else
1058  {
1059  emit splashMessage("Kinect not found.");
1060  emit message("Kinect camera not found.", false);
1061 
1062  // show kinect camera state in gui
1063  gui->setLEDCamera(RED);
1065 
1066  //gui->disableCamera();
1067  emit message("No Kinect detected.");
1068 
1069  }
1070 
1071  }
1072 
1073 
1074  if (!consoleMode)
1075  {
1076  //----------------------------------------------------------------------------
1077  // connect simulation button from gui to activate the simulation mode
1078  // (sets the direcs an the threads to simulation mode)
1079  //----------------------------------------------------------------------------
1080  connect(gui, SIGNAL( simulate(bool) ), this, SLOT( setSimulationMode(bool) ));
1081  connect(gui, SIGNAL( simulate(bool) ), sensorThread, SLOT( setSimulationMode(bool) ));
1082  connect(gui, SIGNAL( simulate(bool) ), laserThread, SLOT( setSimulationMode(bool) ));
1083  connect(gui, SIGNAL( simulate(bool) ), obstCheckThread, SLOT( setSimulationMode(bool) ));
1084 
1085  // let the laserThread write a data file from its laser values if requested by the GUI
1086  connect(gui, SIGNAL( writeLaserData() ), laserThread, SLOT( saveLaserData() ));
1087  }
1088 
1089 
1090  //---------------------------------------------------------------------
1091  // check if laser scanners are connected
1092  //---------------------------------------------------------------------
1093  // check FRONT laser
1094  emit splashMessage("Searching front laser...");
1096 
1097  // check REAR laser
1098  emit splashMessage("Searching rear laser...");
1100 
1102  {
1104  {
1105  if (!consoleMode)
1106  {
1107  gui->setLEDLaser(GREEN);
1108  }
1109  emit message("Front laser scanner found.");
1110  }
1111  else
1112  {
1113  emit message("Front laser scanner NOT found.");
1114  }
1115 
1117  {
1118  emit message("Rear laser scanner found.");
1119  }
1120  else
1121  {
1122  emit message("Rear laser scanner NOT found.");
1123  }
1124 
1125  if (!consoleMode)
1126  {
1128  if (!QGLFormat::hasOpenGL())
1129  {
1130  qDebug() << "This system has no OpenGL support" << endl;
1131  showExitDialog();
1132  }
1133  }
1134 
1135 
1136  // start the laserThread
1137  if (laserThread->isRunning() == false)
1138  {
1139  emit splashMessage("Starting Laser thread...");
1140  emit message("Starting Laser thread...", false);
1141  laserThread->start();
1142  emit message("Laser thread started.");
1143  }
1144 
1145 
1146  if (obstCheckThread->isRunning() == false)
1147  {
1148  emit splashMessage("Initializing obstacle check thread...");
1149  emit message("Initializing obstacle check thread...", false);
1150  obstCheckThread->init();
1151  emit message("Obstacle check thread initialized.");
1152 
1153  emit splashMessage("Starting obstacle check thread...");
1154  emit message("Starting obstacle check thread...", false);
1155  obstCheckThread->start();
1156  emit message("Obstacle check thread started.");
1157  }
1158  }
1159  else
1160  {
1161  emit message("<font color=\"#FF0000\">NO laser scanners found! Thread NOT started!</font>");
1162 
1163  if (!consoleMode)
1164  {
1165  // choose a red instead of a off LED since this looks more important
1166  gui->setLEDLaser(RED);
1167  }
1168  }
1169 
1170 
1171  if (!consoleMode)
1172  {
1173  // start random number generator
1174  srand(time(NULL));
1175 
1176  // generate one number
1177  int number = rand() % 6 +1; // (1 to 6)
1178  qDebug("file number %d", number);
1179 
1180  // create phonon player and set filename
1181 // music->Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource("../../../../dr.mp3"));
1182 
1184 // mediaObject->setCurrentSource(Phonon::MediaSource("../../../../dr.mp3"));
1185 // mediaObject->setCurrentSource(Phonon::MediaSource("../../../../media/1"));
1186 #ifdef Q_OS_LINUX
1187  mediaObject->setCurrentSource(Phonon::MediaSource(QString("../../../../media/%1").arg(number)));
1188 #else
1189  mediaObject->setCurrentSource(Phonon::MediaSource(QString("../../../../media/%1.mp3").arg(number)));
1190 #endif
1191 
1192  Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
1193  Phonon::createPath(mediaObject, audioOutput);
1194 
1195  // let the media player restart when files endend and demo mode is enabled
1196  connect(mediaObject, SIGNAL( finished() ), this, SLOT( mediaPlayerFinished() ));
1197 
1198  // let the media player skip a track if the button is pressed in the GUI
1199  connect(gui, SIGNAL( mediaSkip() ), this, SLOT( mediaPlayerFinished() ));
1200  }
1201 
1202  if (!consoleMode)
1203  {
1204  //------------------------------------------------------------------
1205  // hide some dialogues
1206  //------------------------------------------------------------------
1207  settingsDialog->hide();
1208  joystickDialog->hide();
1209  aboutDialog->hide();
1210 
1211  //------------------------------------------------------------------
1212  // for getting the screen resolution
1213  //------------------------------------------------------------------
1214  QDesktopWidget *desktop = QApplication::desktop();
1215 
1216  //------------------------------------------------------------------
1217  // place gui window at a nice position on the screen
1218  //------------------------------------------------------------------
1219  if (desktop->width() > 1024)
1220  {
1221  // move mainWindow to the center of the screen
1222  gui->move( (desktop->width() - gui->width())/2, (desktop->height() - gui->height())/2 );
1223 
1224  // show the gui
1225  gui->show();
1226 
1227  // delete the splash screen
1228  //QTimer::singleShot(SPLASHTIME, this, SLOT( finishSplash() ));
1229  }
1230  else
1231  {
1232  // resolution too smal for this window. Maximizing...
1233  // show the main window
1234  gui->showMaximized();
1235 
1236  // delete the splash screen
1237  // QTimer::singleShot(SPLASHTIME, this, SLOT( finishSplash() ));
1238  }
1239 
1240 #ifdef ACTIVELASERVIEW
1241  // one time init for the laser view
1242  gui->initLaserView();
1243 #endif
1244 
1245 
1246  //-----------------------------------------------------------
1247  // check voltages and write them to logfile
1248  //-----------------------------------------------------------
1249  emit splashMessage("Checking voltages...");
1250  logfile->appendLog(QString("INFO: Voltage of Sensor %1 is %2 Volt.").arg(VOLTAGESENSOR1).arg(sensorThread->getVoltage(VOLTAGESENSOR1)));
1251  logfile->appendLog(QString("INFO: Voltage of Sensor %1 is %2 Volt.").arg(VOLTAGESENSOR2).arg(sensorThread->getVoltage(VOLTAGESENSOR2)));
1252 
1253 
1254  // delete the splash screen
1255  finishSplash();
1256  }
1257  } // ini-file found
1258  else
1259  {
1260  if (!consoleMode)
1261  {
1262  // file not found-Msg
1263  QMessageBox msgbox(QMessageBox::Critical,
1264  tr("direcs"),
1265  tr("Required configuration file \"%1\" not found! File perhaps not in the same directory?\n%2\n\nSorry, exiting direcs NOW...").arg(inifile1->getInifileName()).arg( QDir::currentPath() ),
1266  QMessageBox::Ok | QMessageBox::Default);
1267  msgbox.exec();
1268  forceShutdown = true; // don't ask for AreYouSure, later when shutting down
1269  emit message(QString("<b><font color=\"#FF0000\">File '%1' not found!</font></b>").arg(inifile1->getInifileName()));
1270 
1271  // call my own exit routine
1272  shutdown();
1273 
1274  // here we're back from the shutdown method, so bye bye
1275  // QCoreApplication::exit(-1); does not work!
1276  exit(1); // FIXME: works, but doesn't call the destructor :-(
1277  }
1278  }
1279 }
1280 
1281 
1283 {
1284  emit message("----------------");
1285  emit message("Shutting down...");
1286  emit message("----------------");
1287 
1288  if (!consoleMode)
1289  {
1290  //-----------------------------------------
1291  // hide all dialogs, except the mainDialog
1292  //-----------------------------------------
1293  if (settingsDialog->isVisible())
1294  settingsDialog->hide();
1295 
1296  if (joystickDialog->isVisible())
1297  joystickDialog->hide();
1298 
1299  if (aboutDialog->isVisible())
1300  aboutDialog->hide();
1301 
1302  splash->show();
1303  emit splashMessage("Shutting down...");
1304 
1305  // stop phonon media player
1306  if (mediaObject->state() == Phonon::PlayingState)
1307  {
1308  emit splashMessage("Stopping media player...");
1309  mediaObject->stop();
1310  }
1311  }
1312 
1313  // just 4 fun
1314 // head->look("NORMAL"); no head mounted at the moment...
1315 // head->look("DOWN"); no head mounted at the moment...
1316 
1317  //---------------------------------------------------------------
1318  // save changes to ini-file (if check box is checked!)
1319  //---------------------------------------------------------------
1320  // THIS SETTING HAS TO BE SAVED ALWAYS!
1321  // "Save the setting, that no settings shoud be saved"
1322  //
1323  // save check box status
1324  if (!consoleMode)
1325  {
1326  if (forceShutdown==false) // don't write this setting when we have a forced shutdown (so the ini-file with only one line won't be created anymore)
1327  {
1328  inifile1->writeSetting("Config", "saveOnExit", settingsDialog->getCheckBoxSaveSettings());
1329  }
1330 
1331 
1332  if (settingsDialog->getCheckBoxSaveSettings() == Qt::Checked)
1333  {
1334  emit message("Writing settings...");
1335  emit splashMessage("Writing settings...");
1336 
1337  // save gui slider values
1338  inifile1->writeSetting("Config", "motor1Speed", settingsDialog->getSliderMotorSpeed(1));
1339  inifile1->writeSetting("Config", "motor2Speed", settingsDialog->getSliderMotorSpeed(2));
1340  inifile1->writeSetting("Config", "minimumSpeed", settingsDialog->getSliderMinimumSpeed());
1341  inifile1->writeSetting("Config", "maximumSpeed", settingsDialog->getSliderMaximumSpeed());
1342  inifile1->writeSetting("Config", "minObstacleDistance", settingsDialog->getSliderObstacleValue());
1343  inifile1->writeSetting("Config", "minObstacleDistanceLaserScanner", settingsDialog->getSliderObstacleLaserScannerValue());
1344  inifile1->writeSetting("Config", "robotSlotWidth", settingsDialog->getSliderPassageWidth());
1345  inifile1->writeSetting("Config", "straightForwardDeviation", settingsDialog->getSliderStraightForwardDeviationValue());
1346 
1347  // save check box status
1348  inifile1->writeSetting("Config", "saveOnExit", settingsDialog->getCheckBoxSaveSettings());
1349 
1350  // Later...
1351  //
1352  //noHardwareErrorMessages
1353  //exitDialog
1354 
1355  // force writing *immediately*
1356  inifile1->sync();
1357 
1358  emit message("Settings written.");
1359  }
1360  }
1361 
1362 
1363  // show dialog if set in ini-file
1364  if (exitDialog == true)
1365  {
1366  if (!consoleMode)
1367  {
1368  if (forceShutdown==false) // this is true, if no ini-file was found at startup
1369  {
1370  // ask user if he really wants to exit.
1371  if (QMessageBox::question(0, "Exiting...", "Are you sure?", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape) == QMessageBox::No)
1372  {
1373  //---------
1374  // if NO
1375  //---------
1376  // don't leave! :-)
1377  return;
1378  }
1379  }
1380  }
1382  }
1383 
1384 
1385 // emit message("STOPPING drive!");
1386 // drive(STOP); /// \todo what if the robot (serial communication hangs here?!?) tmeout?!?
1387 
1388  if (forceShutdown==false)
1389  {
1390  // turn off all RGB LEDs
1397  }
1398 
1400  if (!consoleMode)
1401  {
1402  //--------------------------------
1403  // quit the camThread
1404  //--------------------------------
1405  if (camThread->isRunning() == true)
1406  {
1407  emit message("Stopping camera thread...");
1408  emit splashMessage("Stopping camera thread...");
1409 
1410  // my own stop routine :-)
1411  camThread->stop();
1412 
1413  // slowing thread down
1414  camThread->setPriority(QThread::IdlePriority);
1415  camThread->quit();
1416 
1417  //-------------------------------------------
1418  // start measuring time for timeout ckecking
1419  //-------------------------------------------
1420  QTime t;
1421  t.start();
1422  do
1423  {
1424  } while ((camThread->isFinished() == false) && (t.elapsed() <= 2000));
1425 
1426  if (camThread->isFinished() == true)
1427  {
1428  emit message("Camera thread stopped.");
1429  }
1430  else
1431  {
1432  emit message("ERROR: Terminating camera thread because it doesn't answer...");
1433  emit splashMessage("Terminating camera thread because it doesn't answer...");
1434  camThread->terminate();
1435  camThread->wait(1000);
1436  emit message("Camera thread terminated.");
1437  }
1438  }
1439  }
1440 
1441 
1442  //--------------------------------
1443  // quit the obstacle check thread
1444  //--------------------------------
1445  //qDebug("Starting to stop the obstacle check thread NOW!");
1446  if (obstCheckThread->isRunning() == true)
1447  {
1448  emit message("Stopping obstacle check thread...");
1449  emit splashMessage("Stopping obstacle check thread...");
1450 
1451  // my own stop routine :-)
1452  obstCheckThread->stop();
1453 
1454  // slowing thread down
1455  obstCheckThread->setPriority(QThread::IdlePriority);
1456  obstCheckThread->quit();
1457 
1458  //-------------------------------------------
1459  // start measuring time for timeout ckecking
1460  //-------------------------------------------
1461  QTime t;
1462  t.start();
1463  do
1464  {
1465  } while ((obstCheckThread->isFinished() == false) && (t.elapsed() <= 2000));
1466 
1467  if (obstCheckThread->isFinished() == true)
1468  {
1469  emit message("Obstacle check thread stopped.");
1470  }
1471  else
1472  {
1473  emit message("ERROR: Terminating obstacle check thread because it doesn't answer...");
1474  emit splashMessage("Terminating obstacle check thread because it doesn't answer...");
1475  obstCheckThread->terminate();
1476  obstCheckThread->wait(1000);
1477  emit message("Obstacle check thread terminated.");
1478  }
1479  }
1480 
1481 
1482  //--------------------------------
1483  // quit the laserThread
1484  //--------------------------------
1485  if (laserThread->isRunning() == true)
1486  {
1487  emit message("Stopping laser thread...");
1488  emit splashMessage("Stopping laser thread...");
1489 
1490  // my own stop routine :-)
1491  laserThread->stop();
1492 
1493  // slowing thread down
1494  laserThread->setPriority(QThread::IdlePriority);
1495  laserThread->quit();
1496 
1497  //-------------------------------------------
1498  // start measuring time for timeout ckecking
1499  //-------------------------------------------
1500  QTime t;
1501  t.start();
1502  do
1503  {
1504  } while ((laserThread->isFinished() == false) && (t.elapsed() <= 2000));
1505 
1506  if (laserThread->isFinished() == true)
1507  {
1508  emit message("Laser thread stopped.");
1509  }
1510  else
1511  {
1512  emit message("ERROR: Terminating laser thread because it doesn't answer...");
1513  emit splashMessage("Terminating laser thread because it doesn't answer...");
1514  laserThread->terminate();
1515  laserThread->wait(1000);
1516  emit message("Laser thread terminated.");
1517  }
1518  }
1519 
1520 
1521 #ifdef Q_OS_LINUX // currently supported only under linux (no MAC OS at the moment)
1522  //--------------------------------
1523  // quit the speakThread
1524  //--------------------------------
1525  if (speakThread->isRunning() == true)
1526  {
1527  emit message("Stopping speak thread...");
1528  emit splashMessage("Stopping speak thread...");
1529 
1530  // my own stop routine :-)
1531  speakThread->stop();
1532 
1533  // slowing thread down
1534  speakThread->setPriority(QThread::IdlePriority);
1535  speakThread->quit();
1536 
1537  //-------------------------------------------
1538  // start measuring time for timeout ckecking
1539  //-------------------------------------------
1540  QTime t;
1541  t.start();
1542  do
1543  {
1544  } while ((speakThread->isFinished() == false) && (t.elapsed() <= 2000));
1545 
1546  if (speakThread->isFinished() == true)
1547  {
1548  emit message("Speak thread stopped.");
1549  }
1550  else
1551  {
1552  emit message("ERROR: Terminating speak thread because it doesn't answer...");
1553  emit splashMessage("Terminating speak thread because it doesn't answer...");
1554  speakThread->terminate();
1555  speakThread->wait(1000);
1556  emit message("Speak thread terminated.");
1557  }
1558  }
1559 #endif
1560 
1561 
1562  //--------------------------------
1563  // quit the joystick thread
1564  //--------------------------------
1565  if (joystick->isRunning() == true)
1566  {
1567  emit message("Stopping joystick thread...");
1568  emit splashMessage("Stopping joystick thread...");
1569 
1570  // my own stop routine :-)
1571  joystick->stop();
1572 
1573  // slowing thread down
1574  joystick->setPriority(QThread::IdlePriority);
1575  joystick->quit();
1576 
1577  //-------------------------------------------
1578  // start measuring time for timeout ckecking
1579  //-------------------------------------------
1580  QTime t;
1581  t.start();
1582  do
1583  {
1584  } while ((joystick->isFinished() == false) && (t.elapsed() <= 2000));
1585 
1586  if (joystick->isFinished() == true)
1587  {
1588  emit message("Joystick thread stopped.");
1589  }
1590  else
1591  {
1592  emit message("ERROR: Terminating joystick thread because it doesn't answer...");
1593  emit splashMessage("Terminating joystick thread because it doesn't answer...");
1594  joystick->terminate();
1595  joystick->wait(1000);
1596  emit message("Joystick thread terminated.");
1597  }
1598  }
1599 
1600 
1601  //--------------------------------
1602  // quit the timerThread
1603  //--------------------------------
1604  if (timerThread->isRunning() == true)
1605  {
1606  emit message("Stopping timer thread...");
1607  emit splashMessage("Stopping timer thread...");
1608 
1609  // my own stop routine :-)
1610  timerThread->stop();
1611 
1612  // slowing thread down
1613  timerThread->setPriority(QThread::IdlePriority);
1614  timerThread->quit();
1615 
1616  //-------------------------------------------
1617  // start measuring time for timeout ckecking
1618  //-------------------------------------------
1619  QTime t;
1620  t.start();
1621  do
1622  {
1623  } while ((timerThread->isFinished() == false) && (t.elapsed() <= 2000));
1624 
1625  if (timerThread->isFinished() == true)
1626  {
1627  emit message("Timer thread stopped.");
1628  }
1629  else
1630  {
1631  emit message("ERROR: Terminating timer thread because it doesn't answer...");
1632  emit splashMessage("Terminating timer thread because it doesn't answer...");
1633  timerThread->terminate();
1634  timerThread->wait(1000);
1635  emit message("Timer thread terminated.");
1636  }
1637  }
1638 
1639 
1640  //--------------------------------
1641  // quit the demoThread
1642  //--------------------------------
1643  if (demoThread->isRunning() == true)
1644  {
1645  emit message("Stopping demo thread...");
1646  emit splashMessage("Stopping demo thread...");
1647 
1648  // my own stop routine :-)
1649  demoThread->stop();
1650 
1651  // slowing thread down
1652  demoThread->setPriority(QThread::IdlePriority);
1653  demoThread->quit();
1654 
1655  //-------------------------------------------
1656  // start measuring time for timeout ckecking
1657  //-------------------------------------------
1658  QTime t;
1659  t.start();
1660  do
1661  {
1662  } while ((demoThread->isFinished() == false) && (t.elapsed() <= 2000));
1663 
1664  if (demoThread->isFinished() == true)
1665  {
1666  emit message("Timer thread stopped.");
1667  }
1668  else
1669  {
1670  emit message("ERROR: Terminating demo thread because it doesn't answer...");
1671  emit splashMessage("Terminating demo thread because it doesn't answer...");
1672  demoThread->terminate();
1673  demoThread->wait(1000);
1674  emit message("Demo thread terminated.");
1675  }
1676  }
1677 
1678 
1679 
1680 #ifndef BUILDFORROBOT
1681  if (!consoleMode)
1682  {
1683  //--------------------------------
1684  // quit the plotThread
1685  //--------------------------------
1686  if (plotThread->isRunning() == true)
1687  {
1688  emit message("Stopping Plot thread...");
1689  emit splashMessage("Stopping Plot thread...");
1690 
1691  // my own stop routine :-)
1692  plotThread->stop();
1693 
1694  // slowing thread down
1695  plotThread->setPriority(QThread::IdlePriority);
1696  plotThread->quit();
1697 
1698  //-------------------------------------------
1699  // start measuring time for timeout ckecking
1700  //-------------------------------------------
1701  QTime t;
1702  t.start();
1703  do
1704  {
1705  } while ((plotThread->isFinished() == false) && (t.elapsed() <= 2000));
1706 
1707  if (plotThread->isFinished() == true)
1708  {
1709  emit message("Plot thread stopped.");
1710  }
1711  else
1712  {
1713  emit message("ERROR: Terminating Plot thread because it doesn't answer...");
1714  emit splashMessage("Terminating Plot thread because it doesn't answer...");
1715  plotThread->terminate();
1716  plotThread->wait(1000);
1717  emit message("Plot thread terminated.");
1718  }
1719  }
1720  }
1721 #endif
1722 
1723 
1724  //--------------------------
1725  // quit the sensor thread
1726  //--------------------------
1727  //qDebug("Starting to stop the sensor thread NOW!");
1728  if (sensorThread->isRunning() == true)
1729  {
1730  emit message("Stopping sensor thread...");
1731  emit splashMessage("Stopping sensor thread...");
1732 
1733  // my own stop routine :-)
1734  sensorThread->stop();
1735 
1736  // slowing thread down
1737  sensorThread->setPriority(QThread::IdlePriority);
1738  sensorThread->quit();
1739 
1740  //-------------------------------------------
1741  // start measuring time for timeout ckecking
1742  //-------------------------------------------
1743  QTime t;
1744  t.start();
1745  do
1746  {
1747  } while ((sensorThread->isFinished() == false) && (t.elapsed() <= 2000));
1748 
1749  if (sensorThread->isFinished() == true)
1750  {
1751  emit message("Sensor thread stopped.");
1752  }
1753  else
1754  {
1755  emit message("ERROR: Terminating sensor thread because it doesn't answer...");
1756  emit splashMessage("Terminating sensor thread because it doesn't answer...");
1757  sensorThread->terminate();
1758  sensorThread->wait(1000);
1759  emit message("Sensor thread terminated.");
1760  }
1761  }
1762 
1763 
1764 /*
1765  //--------------------------
1767  //--------------------------
1768  if (heartbeat->isRunning() == true)
1769  {
1770  emit message("Stopping heartbeat thread...");
1771 
1772  // my own stop routine :-)
1773  heartbeat->stop();
1774 
1775  // slowing thread down
1776  heartbeat->setPriority(QThread::IdlePriority);
1777  heartbeat->quit();
1778 
1779  //-------------------------------------------
1780  // start measuring time for timeout ckecking
1781  //-------------------------------------------
1782  QTime t;
1783  t.start();
1784  do
1785  {
1786  } while ((heartbeat->isFinished() == false) && (t.elapsed() <= 2000));
1787 
1788  if (heartbeat->isFinished() == true)
1789  {
1790  emit message("Heartbeat thread stopped.");
1791  }
1792  else
1793  {
1794  emit message("ERROR: Terminating heartbeat thread because it doesn't answer...");
1795  emit splashMessage("Terminating heartbeat thread because it doesn't answer...");
1796  heartbeat->terminate();
1797  heartbeat->wait(1000);
1798  emit message("Heartbeat thread terminated.");
1799  }
1800  }
1801 */
1802 
1803 
1804  //--------------------------------
1805  // quit the network thread
1806  //--------------------------------
1807  if (netThread->isRunning() == true)
1808  {
1809  emit message("Stopping network thread...");
1810  if (!consoleMode)
1811  {
1812  gui->appendNetworkLog("Stopping network thread...");
1813  }
1814  emit splashMessage("Stopping network thread...");
1815 
1816  // my own stop routine :-)
1817  netThread->stop();
1818 
1819  // slowing thread down
1820  netThread->setPriority(QThread::IdlePriority);
1821  netThread->quit();
1822 
1823  //-------------------------------------------
1824  // start measuring time for timeout ckecking
1825  //-------------------------------------------
1826  QTime t;
1827  t.start();
1828  do
1829  {
1830  } while ((netThread->isFinished() == false) && (t.elapsed() <= 2000));
1831 
1832  if (netThread->isFinished() == true)
1833  {
1834  emit message("Network thread stopped.");
1835  }
1836  else
1837  {
1838  emit message("ERROR: Terminating network thread because it doesn't answer...");
1839  emit splashMessage("Terminating network thread because it doesn't answer...");
1840  netThread->terminate();
1841  netThread->wait(1000);
1842  emit message("Network thread terminated.");
1843  }
1844  }
1845 
1846 
1847  if (forceShutdown==false)
1848  {
1849  //-------------------------------------------------------
1850  // Last init for the robots circuits
1851  //-------------------------------------------------------
1852  emit splashMessage("Putting robot to sleep...");
1853  emit message("Putting robot to sleep...");
1854  circuit1->sleep();
1855 
1856  //-----------------------------
1857  // close serial port to mc
1858  //-----------------------------
1859  emit message("Closing serial port to microcontroller...");
1861  }
1862  else
1863  {
1864  emit splashMessage("Shutdown forced, no circuit communication anymore...");
1865  emit message("Shutdown forced, no circuit communication anymore...");
1866  }
1867 
1868 
1869  //-----------------------------
1870  // last log file message
1871  //-----------------------------
1872  if (writeLogFile)
1873  logfile->appendLog("-------------------------------------------------------------------------------------------- stop -");
1874 
1875 
1876  //--------------------------------
1877  // close all except the mainDialog
1878  //--------------------------------
1879  if (!consoleMode)
1880  {
1881  if (settingsDialog->isVisible())
1882  settingsDialog->close();
1883 
1884  if (joystickDialog->isVisible())
1885  joystickDialog->close();
1886 
1887  if (aboutDialog->isVisible())
1888  aboutDialog->close();
1889  }
1890 
1891 
1892  if (consoleMode)
1893  {
1894  // In the gui mode the quit is done automatically by the close signal.
1895  // In the Console mode, the following line automaticall calls the Direcs destructor.
1896  QCoreApplication::quit();
1897  }
1898 }
1899 
1900 
1902 {
1903  //--------------------------------------------------
1904  // clean up in reverse order (except from the gui)
1905  //--------------------------------------------------
1906  delete demoThread;
1907  delete timerThread;
1908  delete logfile;
1909  #ifdef Q_OS_LINUX // currently supported only under linux (no MAC OS at the moment)
1910  delete speakThread;
1911  #endif
1912  delete laserThread;
1913  delete netThread;
1914  delete joystick;
1915 
1916 #ifndef BUILDFORROBOT
1917  if (!consoleMode)
1918  {
1919  delete plotThread;
1920  }
1921 #endif
1922 
1923  delete inifile1;
1924  delete obstCheckThread;
1925  delete servos;
1926  delete rgbLeds;
1927  delete motors;
1928  delete sensorThread;
1929  // \todo delete heartbeat;
1930  delete circuit1;
1931  delete interface1;
1932  if (!consoleMode)
1933  {
1934  delete camThread;
1935  delete aboutDialog;
1936  delete joystickDialog;
1937  delete settingsDialog;
1938  }
1939 
1940  qDebug("Bye.");
1941 
1942  if (consoleMode)
1943  {
1944  delete consoleGui;
1945  }
1946  else
1947  {
1948  delete splash;
1949  delete gui;
1950  }
1951 }
1952 
1953 
1955 {
1956  emit message("<font color=\"#FF0000\">THERE IS A BIG COMMUNICATION PROBLEM WITH THE SERIAL PORT TO THE ROBOT!</font>");
1957 
1958  /*
1959  // ask user if he really wants to exit.
1960  if (QMessageBox::question(0, "Too much errors!",
1961  "Exit?",
1962  QMessageBox::Yes | QMessageBox::Default,
1963  QMessageBox::No | QMessageBox::Escape) == QMessageBox::No)
1964  {
1965  //---------
1966  // if NO
1967  //---------
1968  // don't leave! :-)
1969  return;
1970  }
1971 
1972  //\todo Is is the correct method to call the destrucotr, to end the program?!?
1973  QApplication::exit();
1974  */
1975 }
1976 
1977 
1978 void Direcs::showSplashMessage(QString text)
1979 {
1980  if (!consoleMode)
1981  {
1982  splash->showMessage(text, Qt::AlignHCenter | Qt::AlignBottom, splashTextColor);
1983  // for refreshing the splash...
1984  QApplication::processEvents();
1985  }
1986  else
1987  {
1988  QByteArray textForConsole;
1989 
1990  //------------------------------
1991  // remove HTML tags from string
1992  //------------------------------
1993  int start= -1;
1994  do
1995  {
1996  // search for the first HTML "<"
1997  start = text.indexOf("<");
1998 
1999  if (start != 1)
2000  {
2001  text.remove(start, text.indexOf(">") + 1 - start );
2002  }
2003  } while (text.contains(">"));
2004  // till the last HTML ">" is found
2005 
2006  // print text to console
2007  // qDebug() << text; is NOT used, because it adds quotation marks to all strings
2008  textForConsole = text.toLatin1();
2009  qDebug("%s", textForConsole.data());
2010  }
2011 }
2012 
2013 
2015 {
2016  if (!consoleMode)
2017  {
2018  splash->finish(gui);
2019  }
2020 }
2021 
2022 
2023 void Direcs::logicalUnit(int sensorAlarm, QDateTime timestamp)
2024 {
2025  //Q_UNUSED(timestamp);
2026 
2027  //static int alarmCounter = 0;
2028  static short int lastSensorValue = -1; // < the initial value has to be different to ALL SENSOR-constants!!
2029 
2030 
2031  if (!consoleMode)
2032  {
2033  // first switch all (old) sensor alarms OFF
2034  gui->showAlarm(SENSOR1, OFF);
2035  gui->showAlarm(SENSOR2, OFF);
2036  gui->showAlarm(SENSOR3, OFF);
2037  gui->showAlarm(SENSOR4, OFF);
2038  gui->showAlarm(SENSOR5, OFF);
2039  gui->showAlarm(SENSOR6, OFF);
2040  gui->showAlarm(SENSOR7, OFF);
2041  gui->showAlarm(SENSOR8, OFF);
2043  }
2044 
2045 
2046  // If all sensor values/the last alarm are/is the same like the last *and* the robot drives (already),
2047  // do nothing!
2048  //
2049  // So if the robot does *not* drive, we skip this step to store the 'prefrerred driving direction'.
2050  // This will be then used in the drive method, when the roboter later received the START command.
2051  if ((sensorAlarm == lastSensorValue) && (robotDrives))
2052  {
2053  // store this sensor alarm value
2054  lastSensorValue = sensorAlarm;
2055  //alarmCounter++;
2056  return;
2057  }
2058 
2059 
2060  if (sensorAlarm == NONE)
2061  {
2062  // show new driving direction in the GUI
2063  emit showPreferredDirection("FORWARD");
2064 
2065  // clear alarm buffers
2068 
2069  // store this sensor alarm value
2070  lastSensorValue = sensorAlarm;
2071  // reset the alarm counter
2072  //alarmCounter = 0;
2073 
2074  // store the preferred driving direction for the drive() slot, when we use the START command
2076 
2077  if (robotDrives)
2078  {
2079  //emit message("No obstacle in front of any sensor. :-)");
2080  //emit message("Driving forward...");
2081 
2082  //----------------
2083  // drive forward
2084  //----------------
2085  drive(FORWARD);
2086  motors->flashlight(OFF);
2087  }
2088 
2089  return;
2090  }
2091 
2092 
2093  if (sensorAlarm == OBSTACLEFRONTLEFT)
2094  {
2095  // increase "alarm left" buffer
2096  obstacleAlarmFrontLeftList.append(timestamp);
2097 
2098  // delete the oldest "alarm right" from alarm list
2099  if (!obstacleAlarmFrontRightList.isEmpty())
2100  {
2101  obstacleAlarmFrontRightList.removeFirst();
2102  }
2103 
2104  // check if this is a real or false alarm
2106  {
2107  // show new driving direction in the GUI
2108  emit showPreferredDirection("RIGHT");
2109 
2110  // clear alarm buffer
2112 
2113  // store this sensor alarm value
2114  lastSensorValue = sensorAlarm;
2115  // reset the alarm counter
2116  //alarmCounter = 0;
2117 
2118  // store the preferred driving direction for the drive() slot, when we use the START command
2120  if (robotDrives)
2121  {
2122  emit message("<b>Obstacle front left. Turning right.</b>");
2123 
2124  //----------------
2125  // drive right
2126  //----------------
2127  drive(TURNRIGHT);
2128  motors->flashlight(OFF);
2129  }
2130  }
2131 
2132  return;
2133  }
2134 
2135 
2136  if (sensorAlarm == OBSTACLEFRONTRIGHT)
2137  {
2138  // increase "alarm right" buffer
2139  obstacleAlarmFrontRightList.append(timestamp);
2140 
2141  // delete the oldest "alarm left" from alarm list
2142  if (!obstacleAlarmFrontLeftList.isEmpty())
2143  {
2144  obstacleAlarmFrontLeftList.removeFirst();
2145  }
2146 
2147  // check if this is a real or false alarm
2149  {
2150  // show new driving direction in the GUI
2151  emit showPreferredDirection("LEFT");
2152 
2153  // clear alarm buffer
2155 
2156  // store this sensor alarm value
2157  lastSensorValue = sensorAlarm;
2158  // reset the alarm counter
2159  //alarmCounter = 0;
2160 
2161  // store the preferred driving direction for the drive() slot, when we use the START command
2163  if (robotDrives)
2164  {
2165  emit message("<b>Obstacle front right. Turning left.</b>");
2166 
2167  //----------------
2168  // drive left
2169  //----------------
2170  drive(TURNLEFT);
2171  motors->flashlight(OFF);
2172  }
2173  }
2174 
2175  return;
2176  }
2177 
2178 
2179 
2180  if (sensorAlarm == OBSTACLESEVERYWHEREINFRONT)
2181  {
2182  // show driving direction in the GUI
2183  emit showPreferredDirection("NONE");
2184 
2185  // clear alarm buffers
2188 
2189  // store this sensor alarm value
2190  lastSensorValue = sensorAlarm;
2191  // reset the alarm counter
2192  //alarmCounter = 0;
2193 
2194  // store the preferred driving direction for the drive() slot, when we use the START command
2196 
2197  if (robotDrives)
2198  {
2199  emit message("<b>Obstacles everywhere in front of the robot. Waiting.</b>");
2200 
2201  //----------------
2202  // drive WAIT
2203  //----------------
2204  drive(WAIT);
2205  motors->flashlight(ON);
2206  emit speak("I think, I need some help!");
2207  }
2208 
2209  return;
2210  }
2211 }
2212 
2213 
2215 {
2216  if (state == Qt::Checked)
2217  {
2218  faceTrackingIsEnabled = true;
2219  }
2220  else
2221  {
2222  faceTrackingIsEnabled = false;
2223  }
2224 }
2225 
2226 
2227 void Direcs::faceTracking(int faces, int faceX, int faceY, int faceRadius)
2228 {
2229  Q_UNUSED(faces);
2230  Q_UNUSED(faceX);
2231  Q_UNUSED(faceY);
2232  Q_UNUSED(faceRadius);
2233 
2234 /*
2235 
2236 \todo kinect stuff
2237 
2238  if (!consoleMode)
2239  {
2240  Q_UNUSED (faces) // not in use, at the moment
2241 
2242  // \todo put values to consts or ini
2243  int xLevelRight = (camThread->imageWidth() / 2) + faceRadius;
2244  int xLevelLeft = (camThread->imageWidth() / 2) - faceRadius;
2245  int yLevelUp = (camThread->imageHeight() / 2) - faceRadius;
2246  int yLevelDown = (camThread->imageHeight() / 2) + faceRadius;
2247 
2248 
2249  // track nowhere (face is in the middle) or faceRadius is 0 -> no faces detected
2250  if (
2251  (faceRadius==0) || ((faceX > xLevelLeft) && ((faceX < xLevelRight)) && (faceY > yLevelUp) && (faceY < yLevelDown) ) ||
2252  (faceRadius == 0)
2253  )
2254  {
2255  //head->look("FORWARD");
2256  //head->look("NORMAL");
2257  emit showFaceTrackDirection("NONE");
2258 
2259  if (faceTrackingIsEnabled)
2260  {
2261  //motors->motorControl(MOTOR3, OFF, SAME);
2262  //motors->motorControl(MOTOR4, OFF, SAME);
2263  }
2264  return;
2265  }
2266 
2267 
2268  // face detected :-)
2269  //head->look("CURIOUS");
2270 
2271 
2272  // track left
2273  if ( (faceX < xLevelLeft) && (faceY > yLevelUp) && (faceY < yLevelDown) )
2274  {
2275  if (faceTrackingIsEnabled)
2276  {
2277  head->look("LEFT");
2278  //motors->motorControl(MOTOR3, ON, COUNTERCLOCKWISE);
2279  //motors->motorControl(MOTOR4, OFF, SAME);
2280  }
2281  emit showFaceTrackDirection("LEFT");
2282  return;
2283  }
2284 
2285  // track right
2286  if ( (faceX > xLevelRight) && (faceY > yLevelUp) && (faceY < yLevelDown) )
2287  {
2288  if (faceTrackingIsEnabled)
2289  {
2290  head->look("RIGHT");
2291  //motors->motorControl(MOTOR3, ON, CLOCKWISE);
2292  //motors->motorControl(MOTOR4, OFF, SAME);
2293  }
2294  emit showFaceTrackDirection("RIGHT");
2295  return;
2296  }
2297 
2298  // track up
2299  if ( (faceX > xLevelLeft) && (faceX < xLevelRight) && (faceY < yLevelUp) )
2300  {
2301  if (faceTrackingIsEnabled)
2302  {
2303  head->look("UP");
2304  //motors->motorControl(MOTOR3, OFF, SAME);
2305  //motors->motorControl(MOTOR4, ON, CLOCKWISE);
2306  }
2307  emit showFaceTrackDirection("UP");
2308  return;
2309  }
2310 
2311  // track up left
2312  if ( (faceX < xLevelLeft) && (faceY < yLevelUp) )
2313  {
2314  if (faceTrackingIsEnabled)
2315  {
2316  head->look("UPLEFT");
2317  //motors->motorControl(MOTOR3, ON, COUNTERCLOCKWISE);
2318  //motors->motorControl(MOTOR4, ON, CLOCKWISE);
2319  }
2320  emit showFaceTrackDirection("UPLEFT");
2321  return;
2322  }
2323 
2324  // track up right
2325  if ( (faceX > xLevelLeft) && (faceY < yLevelUp) )
2326  {
2327  if (faceTrackingIsEnabled)
2328  {
2329  head->look("UPRIGHT");
2330  //motors->motorControl(MOTOR3, ON, CLOCKWISE);
2331  //motors->motorControl(MOTOR4, ON, CLOCKWISE);
2332  }
2333  emit showFaceTrackDirection("UPRIGHT");
2334  return;
2335  }
2336 
2337  // track down
2338  if ( (faceX > xLevelLeft) && (faceX < xLevelRight) && (faceY > yLevelDown) )
2339  {
2340  if (faceTrackingIsEnabled)
2341  {
2342  head->look("DOWN");
2343  //motors->motorControl(MOTOR3, OFF, SAME);
2344  //motors->motorControl(MOTOR4, ON, COUNTERCLOCKWISE);
2345  }
2346  emit showFaceTrackDirection("DOWN");
2347  return;
2348  }
2349 
2350  // track down left
2351  if ( (faceX < xLevelLeft) && (faceY > yLevelDown) )
2352  {
2353  if (faceTrackingIsEnabled)
2354  {
2355  head->look("DOWNLEFT");
2356  //motors->motorControl(MOTOR3, ON, COUNTERCLOCKWISE);
2357  //motors->motorControl(MOTOR4, ON, COUNTERCLOCKWISE);
2358  }
2359  emit showFaceTrackDirection("DOWNLEFT");
2360  return;
2361  }
2362 
2363  // track down right
2364  if ( (faceX > xLevelRight) && (faceY > yLevelDown) )
2365  {
2366  if (faceTrackingIsEnabled)
2367  {
2368  head->look("DOWNRIGHT");
2369  //motors->motorControl(MOTOR3, ON, CLOCKWISE);
2370  //motors->motorControl(MOTOR4, ON, COUNTERCLOCKWISE);
2371  }
2372  emit showFaceTrackDirection("DOWNRIGHT");
2373  return;
2374  }
2375  }
2376 */
2377 }
2378 
2379 
2381 {
2382  if (!consoleMode)
2383  {
2384  /*
2385  //----------------------------------------
2386  // show sensor values with progress bars
2387  //----------------------------------------
2388  gui->showDistanceGraphical(SENSOR1, sensorThread->getDistance(SENSOR1));
2389  gui->showDistanceGraphical(SENSOR2, sensorThread->getDistance(SENSOR2));
2390  gui->showDistanceGraphical(SENSOR3, sensorThread->getDistance(SENSOR3));
2391  gui->showDistanceGraphical(SENSOR4, sensorThread->getDistance(SENSOR4));
2392  gui->showDistanceGraphical(SENSOR5, sensorThread->getDistance(SENSOR5));
2393  gui->showDistanceGraphical(SENSOR6, sensorThread->getDistance(SENSOR6));
2394  gui->showDistanceGraphical(SENSOR7, sensorThread->getDistance(SENSOR7));
2395  gui->showDistanceGraphical(SENSOR8, sensorThread->getDistance(SENSOR8));
2396  gui->showDistanceGraphical(SENSOR16, sensorThread->getUsSensorValue(SENSOR16));
2397 
2398  //-------------------------------------------------------
2399  // show distance value in a text label (in centimeters!)
2400  //-------------------------------------------------------
2401  gui->showDistance(SENSOR1, sensorThread->getDistance(SENSOR1));
2402  gui->showDistance(SENSOR2, sensorThread->getDistance(SENSOR2));
2403  gui->showDistance(SENSOR3, sensorThread->getDistance(SENSOR3));
2404  gui->showDistance(SENSOR4, sensorThread->getDistance(SENSOR4));
2405  gui->showDistance(SENSOR5, sensorThread->getDistance(SENSOR5));
2406  gui->showDistance(SENSOR6, sensorThread->getDistance(SENSOR6));
2407  gui->showDistance(SENSOR7, sensorThread->getDistance(SENSOR7));
2408  gui->showDistance(SENSOR8, sensorThread->getDistance(SENSOR8));
2409  gui->showDistance(SENSOR16, sensorThread->getUsSensorValue(SENSOR16));
2410  */
2411 
2412  //--------------------------------------------------------------
2413  // show driven distance value in a text label (in centimeters!)
2414  //--------------------------------------------------------------
2417 
2418  //-------------------------------------------------------
2419  // show voltage value in a text label
2420  //-------------------------------------------------------
2423  }
2424 
2425 /*
2426  //-------------------------------------------------------
2427  // Voltage alarm!
2428  // \todo do a check and emit this to the gui to show the lables in red!
2429  //-------------------------------------------------------
2430  // \todo is this the best place for the following lines?
2431  static bool marker=false; // \todo do this with a timer or something, for repeating it
2432 
2433  if (sensorThread->getVoltage(VOLTAGESENSOR1) < MINIMUMVOLTAGE1)
2434  {
2435 
2436  if (!marker)
2437  {
2438  marker = true;
2439  emit speak("The 12 volt batteries are empty.");
2440  // \todo maybe also do a shutdown or a 'stop" while driving...?!?
2441  }
2442  }
2443  else
2444  {
2445  marker = false;
2446  }
2447 
2448  if (sensorThread->getVoltage(VOLTAGESENSOR2) < MINIMUMVOLTAGE2)
2449  {
2450 
2451  if (!marker)
2452  {
2453  marker = true;
2454  emit speak("The 24 volt batteries are empty.");
2455  // \todo maybe also do a shutdown or a 'stop" while driving...?!?
2456  }
2457  }
2458  else
2459  {
2460  marker = false;
2461  }
2462 */
2463 }
2464 
2465 
2466 void Direcs::drive(const int command)
2467 {
2468  static unsigned char lastCommand = 255;
2469 
2470 
2471  // if its the same command, do nothing
2472  if (command == lastCommand)
2473  {
2474  return;
2475  }
2476 
2477  // store the current command
2478  lastCommand = command;
2479 
2480  switch (command)
2481  {
2482  case FORWARD:
2483  emit message("FORWARD... ", false);
2484  if (!consoleMode)
2485  {
2490  }
2491 
2493 
2494  if (motors->motorControl(ALLMOTORS, SAME, command))
2495  {
2496  emit message("ok", true, false, false);
2497  }
2498  else
2499  {
2500  emit message("Atmel-Error!");
2501  }
2502  return;
2503  break;
2504 
2505  case BACKWARD:
2506  emit message("BACKWARD... ", false);
2507  if (!consoleMode)
2508  {
2513  }
2514 
2516 
2517  if (motors->motorControl(ALLMOTORS, SAME, command))
2518  {
2519  emit message("ok", true, false, false);
2520  }
2521  else
2522  {
2523  emit message("Atmel-Error!");
2524  }
2525  return;
2526  break;
2527 
2528  case LEFT:
2529  emit message("LEFT... ", false);
2530  if (!consoleMode)
2531  {
2536  }
2537 
2539 
2540  if (motors->motorControl(ALLMOTORS, SAME, command))
2541  {
2542  emit message("ok", true, false, false);
2543  }
2544  else
2545  {
2546  emit message("Atmel-Error!");
2547  }
2548  return;
2549  break;
2550 
2551  case RIGHT:
2552  emit message("RIGHT... ", false);
2553  if (!consoleMode)
2554  {
2559  }
2560 
2562 
2563  if (motors->motorControl(ALLMOTORS, SAME, command))
2564  {
2565  emit message("ok", true, false, false);
2566  }
2567  else
2568  {
2569  emit message("Atmel-Error!");
2570  }
2571  return;
2572  break;
2573 
2574  case TURNLEFT:
2575  emit message("TURNLEFT... ", false);
2576  if (!consoleMode)
2577  {
2582  }
2583 
2585 
2586  if (motors->motorControl(ALLMOTORS, SAME, command))
2587  {
2588  emit message("ok", true, false, false);
2589  }
2590  else
2591  {
2592  emit message("Atmel-Error!");
2593  }
2594  return;
2595  break;
2596 
2597  case TURNRIGHT:
2598  emit message("TURNRIGHT... ", false);
2599  if (!consoleMode)
2600  {
2605  }
2606 
2608 
2609  if (motors->motorControl(ALLMOTORS, SAME, command))
2610  {
2611  emit message("ok", true, false, false);
2612  }
2613  else
2614  {
2615  emit message("Atmel-Error!");
2616  }
2617  return;
2618  break;
2619 
2620  case START:
2621  robotDrives = true;
2622  emit message("Starting to drive...");
2623  emit message("START... ", false);
2624 
2625  /*
2626  // set the motors to "drive FORWARD"
2627  if (!consoleMode)
2628  {
2629  gui->showMotorStatus(MOTOR1, ON, FORWARD);
2630  gui->showMotorStatus(MOTOR2, ON, FORWARD);
2631  gui->showMotorStatus(MOTOR3, ON, FORWARD);
2632  gui->showMotorStatus(MOTOR4, ON, FORWARD);
2633  }
2634  / * FIXME: to much data over serial port?!?
2635  motors->setMotorSpeed(MOTOR1, 0); /// \todo check if this works
2636  motors->setMotorSpeed(MOTOR2, 0); /// \todo check if this works
2637  motors->setMotorSpeed(MOTOR3, 0); /// \todo check if this works
2638  motors->setMotorSpeed(MOTOR4, 0); /// \todo check if this works
2639 
2640  resetDrivingSpeedTimer();
2641  drivingSpeedTimer->start(DRIVINGSPEEDINCREASER);
2644  * /
2645 */
2647 /*
2648  if (motors->motorControl(ALLMOTORS, SAME, command))
2649  {
2650  emit message("ok", true, false, false);
2651  }
2652  else
2653  {
2654  emit message("Atmel-Error!");
2655  }
2656 */
2657 
2658  // use the preferred driving start direction, already set in the logicalUnit
2660 
2661  return;
2662  break;
2663 
2664  case WAIT:
2665  emit message("WAIT... ", false);
2666  /* FIXME: to much data over serial port?!?
2667  resetDrivingSpeedTimer();
2668  */
2669  if (!consoleMode)
2670  {
2675  }
2676 
2678 
2679  // turning motors off
2680  if (motors->motorControl(ALLMOTORS, SAME, command))
2681  {
2682  emit message("ok", true, false, false);
2683  }
2684  else
2685  {
2686  emit message("Atmel-Error!");
2687  }
2688 
2689  // Don't stop the motThread (PWM)!
2690  // Only switching motors off!
2691  return;
2692  break;
2693 
2694  case STOP:
2695  emit message("STOP... ", false);
2696  /* FIXME: to much data over serial port?!?
2697  resetDrivingSpeedTimer();
2698  */
2699  if (!consoleMode)
2700  {
2705  }
2706 
2708 
2709  // turning motors off
2710  if (motors->motorControl(ALLMOTORS, SAME, command))
2711  {
2712  emit message("ok", true, false, false);
2713  }
2714  else
2715  {
2716  emit message("Atmel-Error!");
2717  }
2718 
2719  // Don't stop the motThread (clock)!
2720  // Only switching motors off!
2721  robotDrives = false;
2722  return;
2723  break;
2724 
2725  case MOTOR1FW: // for the test widget in the GUI!!
2726  emit message("Motor 1 forward");
2727  if (!consoleMode)
2728  {
2730  }
2732  emit message("ERROR motor 1 CCW");
2733  return;
2734  break;
2735 
2736  case MOTOR1BW: // for the test widget in the GUI!!
2737  emit message("Motor 1 backward");
2738  if (!consoleMode)
2739  {
2741  }
2742  if (!motors->motorControl(MOTOR1, ON, FORWARD))
2743  emit message("ERROR motor 1 CW");
2744  return;
2745  break;
2746 
2747  case MOTOR1OFF: // for the test widget in the GUI!!
2748  emit message("Motor 1 OFF");
2749  if (!consoleMode)
2750  {
2752  }
2753  if (!motors->motorControl(MOTOR1, OFF, SAME))
2754  emit message("ERROR motor 1 OFF");
2755  return;
2756  break;
2757 
2758  case MOTOR2FW: // for the test widget in the GUI!!
2759  emit message("Motor 2 forward");
2760  if (!consoleMode)
2761  {
2763  }
2765  return;
2766  break;
2767 
2768  case MOTOR2BW: // for the test widget in the GUI!!
2769  emit message("Motor 2 backward");
2770  if (!consoleMode)
2771  {
2773  }
2775  return;
2776  break;
2777 
2778  case MOTOR2OFF: // for the test widget in the GUI!!
2779  emit message("Motor 2 OFF");
2780  if (!consoleMode)
2781  {
2783  }
2785  return;
2786  break;
2787 
2788  case MOTOR3FW: // for the test widget in the GUI!!
2789  emit message("Motor 3 forward");
2790  if (!consoleMode)
2791  {
2793  }
2795  return;
2796  break;
2797 
2798  case MOTOR3BW: // for the test widget in the GUI!!
2799  emit message("Motor 3 backward");
2800  if (!consoleMode)
2801  {
2803  }
2805  return;
2806  break;
2807 
2808  case MOTOR3OFF: // for the test widget in the GUI!!
2809  emit message("Motor 3 OFF");
2810  if (!consoleMode)
2811  {
2813  }
2815  return;
2816  break;
2817 
2818  case MOTOR4FW: // for the test widget in the GUI!!
2819  emit message("Motor 4 forward");
2820  if (!consoleMode)
2821  {
2823  }
2825  return;
2826  break;
2827 
2828  case MOTOR4BW: // for the test widget in the GUI!!
2829  emit message("Motor 4 backward");
2830  if (!consoleMode)
2831  {
2833  }
2835  return;
2836  break;
2837 
2838  case MOTOR4OFF: // for the test widget in the GUI!!
2839  emit message("Motor 4 OFF");
2840  if (!consoleMode)
2841  {
2843  }
2845  return;
2846  break;
2847  default:
2848  // this case should never occur
2849  emit message(QString("<font color=\"#FF0000\">ERROR: Driving direction '%1' not implemented or set in Drive()!</font>").arg(command));
2850  return;
2851  break;
2852  }
2853 }
2854 
2855 
2857 {
2858  endSpeedMotor1Reached = false;
2859  endSpeedMotor2Reached = false;
2860  endSpeedMotor3Reached = false;
2861  endSpeedMotor4Reached = false;
2862 }
2863 
2864 
2866 {
2867  int currentSpeed1 = 0;
2868  int currentSpeed2 = 0;
2869  int currentSpeed3 = 0;
2870  int currentSpeed4 = 0;
2871  int increaseInterval = qRound(maximumSpeed * 0.1);
2872 
2873 
2874  currentSpeed1 = motors->getMotorSpeed(MOTOR1);
2875  if (currentSpeed1 < maximumSpeed)
2876  {
2877  endSpeedMotor1Reached = false;
2878  currentSpeed1 += increaseInterval;
2879  motors->setMotorSpeed(MOTOR1, currentSpeed1);
2880 // qDebug("increasing from speed %d to %d @ motor %d.", currentSpeed1, maximumSpeed, MOTOR1);
2881  }
2882  else
2883  {
2884  endSpeedMotor1Reached = true;
2885  }
2886 
2887  currentSpeed2 = motors->getMotorSpeed(MOTOR2);
2888  if (currentSpeed2 < maximumSpeed)
2889  {
2890  endSpeedMotor2Reached = false;
2891  currentSpeed2 += increaseInterval;
2892  motors->setMotorSpeed(MOTOR2, currentSpeed2);
2893  }
2894  else
2895  {
2896  endSpeedMotor2Reached = true;
2897  }
2898 
2899  currentSpeed3 = motors->getMotorSpeed(MOTOR3);
2900  if (currentSpeed3 < maximumSpeed)
2901  {
2902  endSpeedMotor3Reached = false;
2903  currentSpeed3 += increaseInterval;
2904  motors->setMotorSpeed(MOTOR3, currentSpeed3);
2905  }
2906  else
2907  {
2908  endSpeedMotor3Reached = true;
2909  }
2910 
2911  currentSpeed4 = motors->getMotorSpeed(MOTOR4);
2912  if (currentSpeed4 < maximumSpeed)
2913  {
2914  endSpeedMotor4Reached = false;
2915  currentSpeed4 += increaseInterval;
2916  motors->setMotorSpeed(MOTOR4, currentSpeed4);
2917  }
2918  else
2919  {
2920  endSpeedMotor4Reached = true;
2921  }
2922 
2923  // all motors at their end speed? /// \todo check if end speed is refreshed in this class, when changed via gui!!
2925  {
2926  drivingSpeedTimer->stop();
2927  // qDebug("**driving speed timer stopped**");
2928  }
2929 }
2930 
2931 
2933 {
2934  //---------------------------------------------------------------------
2935  // get the programm settings and set the items on the gui (sliders...)
2936  //---------------------------------------------------------------------
2937  emit message("Reading settings...");
2938 
2939 
2940  //---------------------------------------------------------------------
2941  // read setting
2942  switch (inifile1->readSetting("Config", "writeLogFile"))
2943  {
2944  case -1:
2945  emit message("<font color=\"#FF0000\">Value \"writeLogFile\"not found in ini-file!</font>");
2946  break;
2947  case 0:
2948  writeLogFile = false;
2949  emit message("Not writing a logfile.");
2950  break;
2951  case 1:
2952  writeLogFile = true;
2953  emit message("Writing a logfile!");
2954  //--------------------------------------------------------------------------
2955  // write messages for the GUI or fotthe console ALSO to a logfile
2956  //--------------------------------------------------------------------------
2957  connect(this, SIGNAL( message(QString) ), logfile, SLOT( appendLog(QString) ));
2958  break;
2959  }
2960 
2961 
2962  //---------------------------------------------------------------------
2963  // read setting
2964  #ifdef Q_OS_LINUX
2965  QString portString = "serialPortMicrocontrollerLinux";
2966  #endif
2967 
2968  #ifdef Q_OS_MAC
2969  QString portString = "serialPortMicrocontrollerMac";
2970  #endif
2971 
2972  serialPortMicrocontroller = inifile1->readString("Config", portString);
2973 
2974  if (serialPortMicrocontroller == "error1")
2975  {
2976  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(portString));
2977  }
2978  else
2979  {
2980  //
2981  // everything okay
2982  //
2983  emit message(QString("Serial port for microcontroller set to <b>%1</b>.").arg(serialPortMicrocontroller));
2984  }
2985 
2986 
2987  //---------------------------------------------------------------------
2988  // read first FRONT laser setting
2989  laserscannerTypeFront = inifile1->readString("Config", "laserscannerTypeFront");
2990 
2991  if (laserscannerTypeFront == "error1")
2992  {
2993  laserThread->setType(LASER1, "none");
2994  emit message("<font color=\"#FF0000\">Value \"laserscannerTypeFront\" not found in ini-file!</font>");
2995  }
2996  else
2997  {
2998  // everything okay
3000  emit message(QString("Front laser scanner type set to <b>%1</b>.").arg(laserscannerTypeFront));
3001 
3002 
3003  //---------------------------------------------------------------------
3004  // read next laser setting
3005  #ifdef Q_OS_LINUX
3006  portString = "serialPortLaserscannerFrontLinux";
3007  #endif
3008 
3009  #ifdef Q_OS_MAC
3010  portString = "serialPortLaserscannerFrontMac";
3011  #endif
3012 
3013  serialPortLaserscannerFront = inifile1->readString("Config", portString);
3014 
3015  if (serialPortLaserscannerFront == "error1")
3016  {
3017  laserThread->setSerialPort(LASER1, "none");
3018  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(portString));
3019  }
3020  else
3021  {
3022  // everything okay
3024  emit message(QString("Front laser scanner port set to <b>%1</b>.").arg(serialPortLaserscannerFront));
3025 
3026  //---------------------------------------------------------------------
3027  // read next laser setting
3028  laserscannerMounting = inifile1->readString("Config", "laserscannerMountingFront");
3029 
3030  if (laserscannerMounting == "error1")
3031  {
3032  laserThread->setMounting(LASER1, "normal");
3033  emit message("<font color=\"#FF0000\">Value \"laserscannerMountingFront\" not found in ini-file!</font>");
3034  }
3035  else
3036  {
3037  // everything okay
3039  emit message(QString("Front laser scanner mounting set to <b>%1</b>.").arg(laserscannerMounting));
3040 
3041  //---------------------------------------------------------------------
3042  // read next setting
3043  laserscannerAngleFront = inifile1->readSetting("Config", "laserscannerAngleFront");
3044 
3045  switch (laserscannerAngleFront)
3046  {
3047  case -1:
3048  emit message("<font color=\"#FF0000\">Value \"laserscannerAngleFront\"not found in ini-file!</font>");
3049  break;
3050  default:
3052  if (consoleMode)
3053  {
3055  }
3056  else
3057  {
3059  }
3060  emit message(QString("Front laser scanner angle set to <b>%1</b>.").arg(laserscannerAngleFront));
3061 
3062  //---------------------------------------------------------------------
3063  // read next setting
3064  floatValue = inifile1->readFloat("Config", "laserscannerResolutionFront");
3065 
3066  if (floatValue == -1)
3067  {
3068  emit message("<font color=\"#FF0000\">Value \"laserscannerResolutionFront\" not found in ini-file!</font>");
3069  }
3070  else
3071  {
3072  // everything okay
3074  if (consoleMode)
3075  {
3077  }
3078  else
3079  {
3081  }
3082  emit message(QString("Front laser scanner resolution set to <b>%1</b>.").arg(floatValue));
3083 
3084 
3085  //---------------------------------------------------------------------
3086  // read next setting
3087  laserscannerIgnoreAreaStart = inifile1->readSetting("Config", "laserscannerFrontIgnoreArea1Start");
3088 
3089  if (laserscannerIgnoreAreaStart == -1)
3090  {
3091  emit message("<font color=\"#FF0000\">Value \"laserscannerFrontIgnoreArea1Start\"not found in ini-file!</font>");
3092  }
3093  else
3094  {
3095 
3096  //---------------------------------------------------------------------
3097  // read next setting
3098  laserscannerIgnoreAreaEnd = inifile1->readSetting("Config", "laserscannerFrontIgnoreArea1End");
3099 
3100  if (laserscannerIgnoreAreaEnd == -1)
3101  {
3102  emit message("<font color=\"#FF0000\">Value \"laserscannerFrontIgnoreArea1End\"not found in ini-file!</font>");
3103  }
3104  else
3105  {
3106 
3107  if (consoleMode)
3108  {
3110  }
3111  else
3112  {
3114  }
3115  emit message(QString("Front laser scanner ignore area %1 set to <b>%2-%3%1</b>.").arg(AREA1).arg(laserscannerIgnoreAreaStart).arg(laserscannerIgnoreAreaEnd));
3116 
3117  // store settings in obstacle check thread
3119  }
3120  }
3121 
3122 
3123  //---------------------------------------------------------------------
3124  // read next setting
3125  laserscannerIgnoreAreaStart = inifile1->readSetting("Config", "laserscannerFrontIgnoreArea2Start");
3126 
3127  if (laserscannerIgnoreAreaStart == -1)
3128  {
3129  emit message("<font color=\"#FF0000\">Value \"laserscannerFrontIgnoreArea2Start\"not found in ini-file!</font>");
3130  }
3131  else
3132  {
3133 
3134  //---------------------------------------------------------------------
3135  // read next setting
3136  laserscannerIgnoreAreaEnd = inifile1->readSetting("Config", "laserscannerFrontIgnoreArea2End");
3137 
3138  if (laserscannerIgnoreAreaEnd == -1)
3139  {
3140  emit message("<font color=\"#FF0000\">Value \"laserscannerFrontIgnoreArea2End\"not found in ini-file!</font>");
3141  }
3142  else
3143  {
3144 
3145  if (consoleMode)
3146  {
3148  }
3149  else
3150  {
3152  }
3153  emit message(QString("Front laser scanner ignore area %1 set to <b>%2-%3%1</b>.").arg(AREA2).arg(laserscannerIgnoreAreaStart).arg(laserscannerIgnoreAreaEnd));
3154 
3155  // store settings in obstacle check thread
3157  }
3158  }
3159  }
3160  break;
3161  }
3162  }
3163  }
3164  }
3165 
3166  //---------------------------------------------------------------------
3167  // read first REAR laser setting
3168  laserscannerTypeRear = inifile1->readString("Config", "laserscannerTypeRear");
3169 
3170  if (laserscannerTypeRear == "error2")
3171  {
3172  laserThread->setType(LASER2, "none");
3173  emit message("<font color=\"#FF0000\">ini-file is not writeable!</font>");
3174  }
3175  else
3176  {
3177  if (laserscannerTypeRear == "error1")
3178  {
3179  laserThread->setType(LASER2, "none");
3180  emit message("<font color=\"#FF0000\">Value \"laserscannerTypeRear\" not found in ini-file!</font>");
3181  }
3182  else
3183  {
3184  // everything okay
3186  emit message(QString("Rear laser scanner type set to <b>%1</b>.").arg(laserscannerTypeRear));
3187 
3188  //---------------------------------------------------------------------
3189  // read next laser setting
3190  serialPortLaserscannerRear = inifile1->readString("Config", "serialPortLaserscannerRear");
3191 
3192  if (serialPortLaserscannerRear == "error2")
3193  {
3194  laserThread->setSerialPort(LASER2, "none");
3195  emit message("<font color=\"#FF0000\">ini-file is not writeable!</font>");
3196  }
3197  else
3198  {
3199  if (serialPortLaserscannerRear == "error1")
3200  {
3201  laserThread->setSerialPort(LASER2, "none");
3202  emit message("<font color=\"#FF0000\">Value \"serialPortLaserscannerRear\" not found in ini-file!</font>");
3203  }
3204  else
3205  {
3206  // everything okay
3208  emit message(QString("Rear laser scanner port set to <b>%1</b>.").arg(serialPortLaserscannerRear));
3209 
3210  //---------------------------------------------------------------------
3211  // read next laser setting
3212  laserscannerMounting = inifile1->readString("Config", "laserscannerMountingRear");
3213 
3214  if (laserscannerMounting == "error2")
3215  {
3216  laserThread->setMounting(LASER2, "normal");
3217  emit message("<font color=\"#FF0000\">ini-file is not writeable!</font>");
3218  }
3219  else
3220  {
3221  if (laserscannerMounting == "error1")
3222  {
3223  laserThread->setMounting(LASER2, "normal");
3224  emit message("<font color=\"#FF0000\">Value \"laserscannerMountingRear\" not found in ini-file!</font>");
3225  }
3226  else
3227  {
3228  // everything okay
3230  emit message(QString("Rear laser scanner mounting set to <b>%1</b>.").arg(laserscannerMounting));
3231 
3232  //---------------------------------------------------------------------
3233  // read next setting
3234  laserscannerAngleRear = inifile1->readSetting("Config", "laserscannerAngleRear");
3235 
3236  switch (laserscannerAngleRear)
3237  {
3238  case -1:
3239  emit message("<font color=\"#FF0000\">Value \"laserscannerAngleRear\"not found in ini-file!</font>");
3240  break;
3241  default:
3243  if (consoleMode)
3244  {
3246  }
3247  else
3248  {
3250  }
3251  emit message(QString("Rear laser scanner angle set to <b>%1</b>.").arg(laserscannerAngleRear));
3252 
3253  //---------------------------------------------------------------------
3254  // read next setting
3255  floatValue = inifile1->readFloat("Config", "laserscannerResolutionRear");
3256 
3257  if (floatValue == -1)
3258  {
3259  emit message("<font color=\"#FF0000\">Value \"laserscannerResolutionRear\" not found in ini-file!</font>");
3260  }
3261  else
3262  {
3263  // everything okay
3265  if (consoleMode)
3266  {
3268  }
3269  else
3270  {
3272  }
3273  emit message(QString("Rear laser scanner resolution set to <b>%1</b>.").arg(floatValue));
3274 
3275  //---------------------------------------------------------------------
3276  // read next setting
3277  laserscannerIgnoreAreaStart = inifile1->readSetting("Config", "laserscannerRearIgnoreArea1Start");
3278 
3279  if (laserscannerIgnoreAreaStart == -1)
3280  {
3281  emit message("<font color=\"#FF0000\">Value \"laserscannerRearIgnoreArea1Start\"not found in ini-file!</font>");
3282  }
3283  else
3284  {
3285 
3286  //---------------------------------------------------------------------
3287  // read next setting
3288  laserscannerIgnoreAreaEnd = inifile1->readSetting("Config", "laserscannerRearIgnoreArea1End");
3289 
3290  if (laserscannerIgnoreAreaEnd == -1)
3291  {
3292  emit message("<font color=\"#FF0000\">Value \"laserscannerRearIgnoreArea1End\"not found in ini-file!</font>");
3293  }
3294  else
3295  {
3296 
3297  if (consoleMode)
3298  {
3300  }
3301  else
3302  {
3304  }
3305  emit message(QString("Rear laser scanner ignore area %1 set to <b>%2-%3%1</b>.").arg(AREA1).arg(laserscannerIgnoreAreaStart).arg(laserscannerIgnoreAreaEnd));
3306 
3307  // store settings in obstacle check thread
3309  }
3310  }
3311 
3312  //---------------------------------------------------------------------
3313  // read next setting
3314  laserscannerIgnoreAreaStart = inifile1->readSetting("Config", "laserscannerRearIgnoreArea2Start");
3315 
3316  if (laserscannerIgnoreAreaStart == -1)
3317  {
3318  emit message("<font color=\"#FF0000\">Value \"laserscannerRearIgnoreArea2Start\"not found in ini-file!</font>");
3319  }
3320  else
3321  {
3322 
3323  //---------------------------------------------------------------------
3324  // read next setting
3325  laserscannerIgnoreAreaEnd = inifile1->readSetting("Config", "laserscannerRearIgnoreArea2End");
3326 
3327  if (laserscannerIgnoreAreaEnd == -1)
3328  {
3329  emit message("<font color=\"#FF0000\">Value \"laserscannerRearIgnoreArea2End\"not found in ini-file!</font>");
3330  }
3331  else
3332  {
3333 
3334  if (consoleMode)
3335  {
3337  }
3338  else
3339  {
3341  }
3342  emit message(QString("Rear laser scanner ignore area %1 set to <b>%2-%3%1</b>.").arg(AREA2).arg(laserscannerIgnoreAreaStart).arg(laserscannerIgnoreAreaEnd));
3343 
3344  // store settings in obstacle check thread
3346  }
3347  }
3348 
3349  }
3350  break;
3351  }
3352  }
3353  }
3354  }
3355  }
3356  }
3357  }
3358 
3359 #ifdef ACTIVELASERVIEW
3360  //---------------------------------------------------------------------
3361  // Create the laser lines and pixmaps in the GUI and place them nicely
3362  //---------------------------------------------------------------------
3363  if (!consoleMode)
3364  {
3365  gui->initLaserStuff();
3366  }
3367 #endif
3368 
3369  //---------------------------------------------------------------------
3370  // read setting
3371  switch (inifile1->readSetting("Config", "useCamera"))
3372  {
3373  case -1:
3374  emit message("<font color=\"#FF0000\">Value \"useCamera\"not found in ini-file!</font>");
3375  break;
3376  case 0:
3377  useCamera = false;
3378  if (!consoleMode)
3379  {
3380  // turning "off" camera
3381  //camThread->setCameraDevice(-2);
3382 // gui->disableCamera();
3383  }
3384  emit message("<font color=\"#FF0000\">No camera usage! (see ini-file)</font>");
3385  break;
3386  case 1:
3387  useCamera = true;
3388  break;
3389  }
3390 
3391  if (!consoleMode)
3392  {
3393  if (useCamera)
3394  {
3395  //---------------------------------------------------------------------
3396  // read setting
3397  int cameraDevice = inifile1->readSetting("Config", "cameraDevice");
3398 
3399  if (cameraDevice == -2)
3400  {
3402  emit message("<font color=\"#FF0000\">ini-file is not writeable!</font>");
3403  }
3404  else
3405  {
3406  if (cameraDevice == -1)
3407  {
3409  emit message("<font color=\"#FF0000\">Value \"cameraDevice\" not found in ini-file!</font>");
3410  }
3411  else
3412  {
3413  //
3414  // everything okay
3415  //
3416  // set it in the cam thread
3418 
3419 // emit message(QString("Camera file set to <b>%1</b>.").arg(cameraDevice));
3420 
3421 
3422  //---------------------------------------------------------------------
3423  // read setting
3424  QString haarClassifierCascade = inifile1->readString("Config", "haarClassifierCascade");
3425 
3426  if (haarClassifierCascade == "error2")
3427  {
3429  emit message("<font color=\"#FF0000\">ini-file is not writeable!</font>");
3430  }
3431  else
3432  {
3433  if (haarClassifierCascade == "error1")
3434  {
3436  emit message("<font color=\"#FF0000\">Value \"haarClassifierCascade\" not found in ini-file!</font>");
3437  }
3438  else
3439  {
3440  //
3441  // everything okay
3442  //
3443  // set it in the cam thread
3445  emit message(QString("Haar classifier cascade file set to<br><b>%1</b>.").arg(haarClassifierCascade));
3446  emit splashMessage("Initialising camera...");
3447 
3449 /*
3450  // initialise the cam
3451  if (camThread->init())
3452  {
3453  emit message("Camera initialised.");
3454  }
3455  else
3456  {
3457  emit message("Error initialising camera.");
3458  }
3459 */
3460  }
3461  }
3462  //---------------------------------------------------------------------
3463  }
3464  }
3465  } // use camera
3466  } // no console mode
3467 
3468  //---------------------------------------------------------------------
3469  // read setting / and error handling
3470  switch (inifile1->readSetting("Config", "noHardwareErrorMessages"))
3471  {
3472  case -1:
3473  emit message("<font color=\"#FF0000\">Value \"noHardwareErrorMessages\"not found in ini-file!</font>");
3474  break;
3475  case 0:
3476  noHardwareErrorMessages = false;
3477  break;
3478  case 1:
3479  noHardwareErrorMessages = true;
3480  emit message("<font color=\"#808080\">Suppressing hardware error messages (see ini-file)</font>");
3481  break;
3482  }
3483 
3484  //---------------------------------------------------------------------
3485  // read setting
3486  switch (inifile1->readSetting("Config", "saveOnExit"))
3487  {
3488  case -1:
3489  emit message("<font color=\"#FF0000\">Value \"saveOnExit\"not found in ini-file!</font>");
3490  break;
3491  case Qt::Unchecked:
3492  if (!consoleMode)
3493  {
3494  // uncheck checkbox
3495  settingsDialog->setCheckBoxSaveSettings(Qt::Unchecked);
3496  }
3497  break;
3498  case Qt::Checked:
3499  if (!consoleMode)
3500  {
3501  // set checkbox
3503  }
3504  break;
3505  }
3506 
3507  //---------------------------------------------------------------------
3508  // read setting
3509  switch (inifile1->readSetting("Config", "exitDialog"))
3510  {
3511  case -1:
3512  emit message("<font color=\"#FF0000\">Value \"exitDialog\"not found in ini-file!</font>");
3513  break;
3514  case 0:
3515  exitDialog = false;
3516  break;
3517  case 1:
3518  exitDialog = true;
3519  break;
3520  }
3521 
3522  //---------------------------------------------------------------------
3523  // read setting
3524  int minObstacleDistance = inifile1->readSetting("Config", "minObstacleDistance");
3525 
3526  switch (minObstacleDistance)
3527  {
3528  case -1:
3529  emit message("<font color=\"#FF0000\">Value \"minObstacleDistance\"not found in ini-file!</font>");
3530  break;
3531  default:
3532  if (!consoleMode)
3533  {
3534  // set slider to the read value
3535  settingsDialog->setSliderObstacleValue(minObstacleDistance);
3536  }
3537 
3538  // tell the obstacle check thread the distance
3539  obstCheckThread->setMinObstacleDistance(minObstacleDistance);
3540  // show text
3541  emit message(QString("Min. obstacle distance set to <b>%1 cm</b>.").arg(minObstacleDistance));
3542  break;
3543  }
3544 
3545  //---------------------------------------------------------------------
3546  // read setting
3547  int minObstacleDistanceLaserScannerFront = inifile1->readSetting("Config", "minObstacleDistanceLaserScannerFront");
3548 
3549  switch (minObstacleDistanceLaserScannerFront)
3550  {
3551  case -1:
3552  emit message("<font color=\"#FF0000\">Value \"minObstacleDistanceLaserScannerFront\"not found in ini-file!</font>");
3553  break;
3554  default:
3555  if (!consoleMode)
3556  {
3557  // set slider to the read value
3558  settingsDialog->setSliderObstacleLaserScannerValue(minObstacleDistanceLaserScannerFront);
3559  }
3560 
3561  // tell it the obstacle check thread
3562  obstCheckThread->setMinObstacleDistanceLaserFront(minObstacleDistanceLaserScannerFront);
3563  // show text
3564  emit message(QString("Min. obstacle distance front laser scanner set to <b>%1 cm</b>.").arg(minObstacleDistanceLaserScannerFront));
3565  break;
3566  }
3567 
3568  //---------------------------------------------------------------------
3569  // read setting
3570  int minObstacleDistanceLaserScannerRear = inifile1->readSetting("Config", "minObstacleDistanceLaserScannerRear");
3571 
3572  switch (minObstacleDistanceLaserScannerRear)
3573  {
3574  case -1:
3575  emit message("<font color=\"#FF0000\">Value \"minObstacleDistanceLaserScannerRear\"not found in ini-file!</font>");
3576  break;
3577  default:
3578  if (!consoleMode)
3579  {
3580  // set slider to the read value
3581 // @todo settingsDialog->setSliderObstacleLaserScannerValue(minObstacleDistanceLaserScannerRear);
3582  }
3583 
3584  // tell it the obstacle check thread
3585  obstCheckThread->setMinObstacleDistanceLaserRear(minObstacleDistanceLaserScannerRear);
3586  // show text
3587  emit message(QString("Min. obstacle distance rear laser scanner set to <b>%1 cm</b>.").arg(minObstacleDistanceLaserScannerRear));
3588  break;
3589  }
3590 
3591  //---------------------------------------------------------------------
3592  // read setting
3593  int passageWidth = inifile1->readSetting("Config", "robotPassageWidth");
3594 
3595  switch (passageWidth)
3596  {
3597  case -1:
3598  emit message("<font color=\"#FF0000\">Value \"robotPassageWidth\"not found in ini-file!</font>");
3599  break;
3600  default:
3601  if (!consoleMode)
3602  {
3603  // set slider to the read value
3604  settingsDialog->setSliderPassageWidth(passageWidth);
3605  }
3606 
3607  // tell it the obstacle check thread
3608  obstCheckThread->setPassageWidth(passageWidth);
3609  // show text
3610  emit message(QString("Robot passage width width set to <b>%1 cm.</b>").arg(passageWidth));
3611  break;
3612  }
3613 
3614  //---------------------------------------------------------------------
3615  // read setting
3616  int straightForwardDeviation = inifile1->readSetting("Config", "straightForwardDeviation");
3617 
3618  switch (straightForwardDeviation)
3619  {
3620  case -1:
3621  emit message("<font color=\"#FF0000\">Value \"straightForwardDeviation\"not found in ini-file!</font>");
3622  break;
3623  default:
3624  if (!consoleMode)
3625  {
3626  // set slider to the read value
3627  settingsDialog->setSliderStraightForwardDeviation(straightForwardDeviation);
3628  }
3629 
3630  // tell it the obstacle check thread
3631  obstCheckThread->setStraightForwardDeviation(straightForwardDeviation);
3632  // show text
3633  emit message(QString("Straight forward deviation set to <b>%1 deg.</b>").arg(straightForwardDeviation));
3634  break;
3635  }
3636 
3637  //---------------------------------------------------------------------
3638  // read setting
3639  QString joystickPort = inifile1->readString("Config", "joystickPort");
3640 
3641  if (joystickPort == "error2")
3642  {
3643  emit message("<font color=\"#FF0000\">ini-file is not writeable!</font>");
3644  }
3645  else
3646  {
3647  if (joystickPort == "error1")
3648  {
3649  emit message("<font color=\"#FF0000\">Value \"joystickPort\" not found in ini-file!</font>");
3650  }
3651  else
3652  {
3653  //
3654  // everything okay
3655  //
3656  // tell the obstacle check thread the distance
3657  joystick->setPort(joystickPort);
3658  emit message(QString("Joystick port set to <b>%1</b>.").arg(joystickPort));
3659  }
3660  }
3661 
3662  //---------------------------------------------------------------------
3663  // read setting
3664  mot1Speed = inifile1->readSetting("Config", "motor1Speed");
3665 
3666  switch (mot1Speed)
3667  {
3668  case -1:
3669  emit message("<font color=\"#FF0000\">Value \"motor1Speed\" not found in ini-file!</font>");
3670  mot1Speed = 0;
3671  break;
3672  default:
3673  if (mot1Speed > MAXPWM)
3674  {
3675  emit message(QString("<font color=\"#FF0000\">Value \"motor1Speed\" is greater than %1!! Value set to %1!</font>").arg(MAXPWM));
3676  mot1Speed = MAXPWM;
3677  }
3678 
3679  if (!consoleMode)
3680  {
3681  // set slider to the read value
3683  }
3684 
3685  // show text
3686  emit message(QString("Motor1 speed set to <b>%1</b>.").arg(mot1Speed));
3687  break;
3688  }
3689 
3690  //---------------------------------------------------------------------
3691  // read setting
3692  mot2Speed = inifile1->readSetting("Config", "motor2Speed");
3693 
3694  switch (mot2Speed)
3695  {
3696  case -1:
3697  emit message("<font color=\"#FF0000\">Value \"motor2Speed\" not found in ini-file!</font>");
3698  mot2Speed = 0;
3699  break;
3700  default:
3701  if (mot2Speed > MAXPWM)
3702  {
3703  emit message(QString("<font color=\"#FF0000\">Value \"motor2Speed\" is greater than %1!! Value set to %1!</font>").arg(MAXPWM));
3704  mot2Speed = MAXPWM;
3705  }
3706 
3707  if (!consoleMode)
3708  {
3709  // set slider to the read value
3711  }
3712 
3713  // show text
3714  emit message(QString("Motor2 speed set to <b>%1</b>.").arg(mot2Speed));
3715  break;
3716  }
3717 
3718  //---------------------------------------------------------------------
3719  // read setting
3720  mot3Speed = inifile1->readSetting("Config", "motor3Speed");
3721 
3722  switch (mot3Speed)
3723  {
3724  case -1:
3725  emit message("<font color=\"#FF0000\">Value \"motor3Speed\" not found in ini-file!</font>");
3726  mot3Speed = 0;
3727  break;
3728  default:
3729  if (mot3Speed > MAXPWM)
3730  {
3731  emit message(QString("<font color=\"#FF0000\">Value \"motor3Speed\" is greater than %1!! Value set to %1!</font>").arg(MAXPWM));
3732  mot3Speed = MAXPWM;
3733  }
3734 
3735  if (!consoleMode)
3736  {
3737  // set slider to the read value
3739  }
3740 
3741  // show text
3742  emit message(QString("Motor3 speed set to <b>%1</b>.").arg(mot3Speed));
3743  break;
3744  }
3745 
3746  //---------------------------------------------------------------------
3747  // read setting
3748  mot4Speed = inifile1->readSetting("Config", "motor4Speed");
3749 
3750  switch (mot4Speed)
3751  {
3752  case -1:
3753  emit message("<font color=\"#FF0000\">Value \"motor4Speed\" not found in ini-file!</font>");
3754  mot4Speed = 0;
3755  break;
3756  default:
3757  if (mot4Speed > MAXPWM)
3758  {
3759  emit message(QString("<font color=\"#FF0000\">Value \"motor1Speed\" is greater than %1!! Value set to %1!</font>").arg(MAXPWM));
3760  mot4Speed = MAXPWM;
3761  }
3762 
3763  if (!consoleMode)
3764  {
3765  // set slider to the read value
3767  }
3768 
3769  // show text
3770  emit message(QString("Motor4 speed set to <b>%1</b>.").arg(mot4Speed));
3771  break;
3772  }
3773 
3774  //---------------------------------------------------------------------
3775  // read setting
3776  minimumSpeed = inifile1->readSetting("Config", "minimumSpeed");
3777 
3778  switch (minimumSpeed)
3779  {
3780  case -1:
3781  emit message("<font color=\"#FF0000\">Value \"minimumSpeed\" not found in ini-file!</font>");
3782  minimumSpeed = 0;
3783  break;
3784  default:
3785  if (minimumSpeed > MAXPWM)
3786  {
3787  emit message(QString("<font color=\"#FF0000\">Value \"minimumSpeed\" is greater than %1!! Value set to %1!</font>").arg(MAXPWM));
3788  minimumSpeed = MAXPWM;
3789  }
3790 
3791  if (!consoleMode)
3792  {
3793  // set slider to the read value
3795  }
3796 
3797  // show text
3798  emit message(QString("Minimum speed speed set to <b>%1</b>.").arg(minimumSpeed));
3799  break;
3800  }
3801 
3802  //---------------------------------------------------------------------
3803  // read setting
3804  maximumSpeed = inifile1->readSetting("Config", "maximumSpeed");
3805 
3806  switch (maximumSpeed)
3807  {
3808  case -1:
3809  emit message("<font color=\"#FF0000\">Value \"maximumSpeed\" not found in ini-file!</font>");
3810  maximumSpeed = 0;
3811  break;
3812  default:
3813  if (maximumSpeed > MAXPWM)
3814  {
3815  emit message(QString("<font color=\"#FF0000\">Value \"maximumSpeed\" is greater than %1!! Value set to %1!</font>").arg(MAXPWM));
3816  maximumSpeed = MAXPWM;
3817  }
3818 
3819  if (!consoleMode)
3820  {
3821  // set slider to the read value
3823  }
3824 
3825  // show text
3826  emit message(QString("Maximum speed speed set to <b>%1</b>.").arg(maximumSpeed));
3827  break;
3828  }
3829 
3830  //---------------------------------------------------------------------
3831  // read servo START settings
3832  for (int servo=0; servo<NUMBEROFSERVOS; servo++)
3833  {
3834  QString settingName = QString("servo%1").arg(servo+1).append("StartPos");
3835  int settingValue = inifile1->readSetting("Config", settingName);
3836 
3837  switch (settingValue)
3838  {
3839  case -1:
3840  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(settingName));
3841  settingValue = 0;
3842  break;
3843  default:
3844  if (settingValue > 254)
3845  {
3846  emit message(QString("<font color=\"#FF0000\">Value \"%1\" is greater than 255!! Value set to 255!</font>").arg(settingName));
3847  settingValue = 255;
3848  }
3849 
3850  // store the servo values
3851  servos->setServoPosition(servo, SVSTART, settingValue);
3852 
3853  // show text
3854  //emit message(QString("%1 set to <b>%2</b>.").arg(settingName).arg(settingValue));
3855  break;
3856  }
3857  }
3858  emit message("Servo start settings read and set.");
3859 
3860  //---------------------------------------------------------------------
3861  // read servo END settings
3862  for (int servo=0; servo<NUMBEROFSERVOS; servo++)
3863  {
3864  QString settingName = QString("servo%1").arg(servo+1).append("EndPos");
3865  int settingValue = inifile1->readSetting("Config", settingName);
3866 
3867  switch (settingValue)
3868  {
3869  case -1:
3870  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(settingName));
3871  settingValue = 0;
3872  break;
3873  default:
3874  if (settingValue > 254)
3875  {
3876  emit message(QString("<font color=\"#FF0000\">Value \"%1\" is greater than 255!! Value set to 255!</font>").arg(settingName));
3877  settingValue = 255;
3878  }
3879 
3880  // store the servo values
3881  servos->setServoPosition(servo, SVEND, settingValue);
3882 
3883  // show text
3884  //emit message(QString("%1 set to <b>%2</b>.").arg(settingName).arg(settingValue));
3885  break;
3886  }
3887  }
3888  emit message("Servo end settings read and set.");
3889 
3890  //---------------------------------------------------------------------
3891  // read servo MIN settings
3892  for (int servo=0; servo<NUMBEROFSERVOS; servo++)
3893  {
3894  QString settingName = QString("servo%1").arg(servo+1).append("MinPos");
3895  int settingValue = inifile1->readSetting("Config", settingName);
3896 
3897  switch (settingValue)
3898  {
3899  case -1:
3900  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(settingName));
3901  settingValue = 0;
3902  break;
3903  default:
3904  if (settingValue > 254)
3905  {
3906  emit message(QString("<font color=\"#FF0000\">Value \"%1\" is greater than 255!! Value set to 255!</font>").arg(settingName));
3907  settingValue = 255;
3908  }
3909 
3910  // store the servo values
3911  servos->setServoPosition(servo, SVMIN, settingValue);
3912 
3913  // show text
3914  //emit message(QString("%1 set to <b>%2</b>.").arg(settingName).arg(settingValue));
3915  break;
3916  }
3917  }
3918  emit message("Servo min. settings read and set.");
3919 
3920  //---------------------------------------------------------------------
3921  // read servo MAX settings
3922  for (int servo=0; servo<NUMBEROFSERVOS; servo++)
3923  {
3924  QString settingName = QString("servo%1").arg(servo+1).append("MaxPos");
3925  int settingValue = inifile1->readSetting("Config", settingName);
3926 
3927  switch (settingValue)
3928  {
3929  case -1:
3930  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(settingName));
3931  settingValue = 0;
3932  break;
3933  default:
3934  if (settingValue > 254)
3935  {
3936  emit message(QString("<font color=\"#FF0000\">Value \"%1\" is greater than 255!! Value set to 255!</font>").arg(settingName));
3937  settingValue = 255;
3938  }
3939 
3940  // store the servo values
3941  servos->setServoPosition(servo, SVMAX, settingValue);
3942 
3943  // show text
3944  //emit message(QString("%1 set to <b>%2</b>.").arg(settingName).arg(settingValue));
3945  break;
3946  }
3947  }
3948  emit message("Servo max. settings read and set.");
3949 
3950  //---------------------------------------------------------------------
3951  // read servo DEFAULT settings
3952  for (int servo=0; servo<NUMBEROFSERVOS; servo++)
3953  {
3954  QString settingName = QString("servo%1").arg(servo+1).append("DefaultPos");
3955  int settingValue = inifile1->readSetting("Config", settingName);
3956 
3957  switch (settingValue)
3958  {
3959  case -1:
3960  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(settingName));
3961  settingValue = 0;
3962  break;
3963  default:
3964  if (settingValue > 254)
3965  {
3966  emit message(QString("<font color=\"#FF0000\">Value \"%1\" is greater than 255!! Value set to 255!</font>").arg(settingName));
3967  settingValue = 255;
3968  }
3969 
3970  // store the servo values
3971  servos->setServoPosition(servo, SVDEFAULT, settingValue);
3972 
3973  // show text
3974  //emit message(QString("%1 set to <b>%2</b>.").arg(settingName).arg(settingValue));
3975  break;
3976  }
3977  }
3978  emit message("Servo default settings read and set.");
3979 
3980 
3981 
3982  //---------------------------------------------------------------------
3983  // read RGB LED MIN brightness
3984  for (int led=0; led<NUMBEROFRGBLEDS; led++)
3985  {
3986  QString settingName = QString("RGBLED%1").arg(led+1).append("MinBrightness");
3987  int settingValue = inifile1->readSetting("Config", settingName);
3988 
3989  switch (settingValue)
3990  {
3991  case -1:
3992  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(settingName));
3993  settingValue = 0;
3994  break;
3995  default:
3996  if (settingValue > MAXPWM)
3997  {
3998  emit message(QString("<font color=\"#FF0000\">Value \"%1\" is greater than %2!! Value set to %2!</font>").arg(settingName).arg(MAXPWM));
3999  settingValue = MAXPWM;
4000  }
4001 
4002  // store the LED values
4003  rgbLeds->storeBrightness(led, RGBLEDMIN, settingValue);
4004 
4005  // show text
4006  emit message(QString("%1 set to <b>%2</b>.").arg(settingName).arg(settingValue));
4007  break;
4008  }
4009  }
4010  emit message("RGB LED min. settings read and set.");
4011 
4012  //---------------------------------------------------------------------
4013  // read RGB LED MAX brightness
4014  for (int led=0; led<NUMBEROFRGBLEDS; led++)
4015  {
4016  QString settingName = QString("RGBLED%1").arg(led+1).append("MaxBrightness");
4017  int settingValue = inifile1->readSetting("Config", settingName);
4018 
4019  switch (settingValue)
4020  {
4021  case -1:
4022  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(settingName));
4023  settingValue = 0;
4024  break;
4025  default:
4026  if (settingValue > MAXPWM)
4027  {
4028  emit message(QString("<font color=\"#FF0000\">Value \"%1\" is greater than %2!! Value set to %2!</font>").arg(settingName).arg(MAXPWM));
4029  settingValue = MAXPWM;
4030  }
4031 
4032  // store the LED values
4033  rgbLeds->storeBrightness(led, RGBLEDMAX, settingValue);
4034 
4035  // show text
4036  emit message(QString("%1 set to <b>%2</b>.").arg(settingName).arg(settingValue));
4037  break;
4038  }
4039  }
4040  emit message("RGB LED max. settings read and set.");
4041 
4042  //---------------------------------------------------------------------
4043  // read RGB LED DEFAULT brightness
4044  for (int led=0; led<NUMBEROFRGBLEDS; led++)
4045  {
4046  QString settingName = QString("RGBLED%1").arg(led+1).append("DefaultBrightness");
4047  int settingValue = inifile1->readSetting("Config", settingName);
4048 
4049  switch (settingValue)
4050  {
4051  case -1:
4052  emit message(QString("<font color=\"#FF0000\">Value \"%1\" not found in ini-file!</font>").arg(settingName));
4053  settingValue = 0;
4054  break;
4055  default:
4056  if (settingValue > MAXPWM)
4057  {
4058  emit message(QString("<font color=\"#FF0000\">Value \"%1\" is greater than %2!! Value set to %2!</font>").arg(settingName).arg(MAXPWM));
4059  settingValue = MAXPWM;
4060  }
4061 
4062  // store the LED values
4063  rgbLeds->storeBrightness(led, RGBLEDDEFAULT, settingValue);
4064 
4065  // show text
4066  emit message(QString("%1 set to <b>%2</b>.").arg(settingName).arg(settingValue));
4067  break;
4068  }
4069  }
4070  emit message("RGB LED default settings read and set.");
4071 
4072 
4073  //---------------------------------------------------------------------
4074  // read setting
4075  networkPortListen = inifile1->readSetting("Config", "networkPortListen");
4076 
4077  switch (networkPortListen)
4078  {
4079  case -1:
4080  emit message("<font color=\"#FF0000\">Value \"networkPortListen\" not found in ini-file!</font>");
4081  value = 0;
4082  break;
4083 
4084  default:
4085  //---------------------------------------------------------------------
4086  // read next network port
4087  networkPortSend = inifile1->readSetting("Config", "networkPortSend");
4088 
4089  switch (networkPortSend)
4090  {
4091  case -1:
4092  emit message("<font color=\"#FF0000\">Value \"networkPortSend\" not found in ini-file!</font>");
4093  networkPortListen = 0;
4094  break;
4095 
4096  default:
4097  // set value in networkThread, bind port
4099  {
4100  emit message(QString("Network ports set to <b>%1 and %2</b>.").arg(networkPortListen).arg(networkPortSend));
4101  if (!consoleMode)
4102  {
4104  }
4105  }
4106  else
4107  {
4108  // Error
4109  emit message(QString("<font color=\"#FF0000\">Error setting network ports to <b>%1 and %2</b>.</font>").arg(value).arg(networkPortSend));
4110  if (!consoleMode)
4111  {
4112  gui->setLEDNetwork(RED);
4113  }
4114  }
4115 
4116  break;
4117  }
4118  break;
4119  }
4120 
4121  //---------------------------------------------------------------------
4122  // read setting
4123  value = inifile1->readSetting("Config", "threshold");
4124 
4125  switch (value)
4126  {
4127  case -1:
4128  emit message("<font color=\"#FF0000\">Value \"threshold\" not found in ini-file!</font>");
4129  value = 0;
4130  break;
4131  default:
4132  if (!consoleMode)
4133  {
4134  // set value in camThread and GUI
4137  emit message(QString("Setting threshold to <b>%1</b>.").arg(value));
4138  }
4139  break;
4140  }
4141 }
4142 
4143 
4145 {
4146  // store the state gobal to Direcs
4147  robotRemoteMode = state;
4148 
4149  if (state == true)
4150  {
4151  //-----------------------------------------------------------
4152  // start the network thread (getting commands via network)
4153  //-----------------------------------------------------------
4154  if (netThread->isRunning() == false)
4155  {
4156  emit message("Starting network thread... ", false);
4157  if (!consoleMode)
4158  {
4159  gui->appendNetworkLog("Starting network thread... ", false);
4160  }
4161  netThread->start();
4162  emit message("started.", true, false, false);
4163  if (!consoleMode)
4164  {
4165  gui->appendNetworkLog("started");
4166  }
4167  }
4168  }
4169  else
4170  {
4171  if (netThread->isRunning() == true)
4172  {
4173  emit message("Stopping network thread...", false);
4174  if (!consoleMode)
4175  {
4176  gui->appendNetworkLog("Stopping network thread...");
4177  }
4178  netThread->stop();
4179  emit message("Network thread stopped.");
4180  }
4181  }
4182 }
4183 
4184 
4186 {
4187  // if still no data received (in executeRemoteCommand()
4188  if (firstDataReceived == false)
4189  {
4190  // from now on, we're no longer waiting for data (looking for a 'master
4191  firstDataReceived = true;
4192 
4193  // 'master' *not* received, so we are master now!
4194  iAmTheMaster = true;
4195 
4196  // show state in GUI
4197  gui->setLabelMasterSlave("Master");
4198 
4199  gui->appendNetworkLog("No network data received.");
4200  gui->appendNetworkLog("I am the master.");
4201 
4202  // we swap the ports back (to initial values) after listening for a network master
4203  netThread->swapPorts();
4204  }
4205 }
4206 
4207 
4208 void Direcs::executeRemoteCommand(QString command)
4209 {
4210  // if still no first and one time check if this is the master or the slave program
4211  if (firstDataReceived == false)
4212  {
4213  // is there already a master, sending its data over network?
4214  if (command.contains("*master#"))
4215  {
4216  firstDataReceived = true;
4217 
4218  // 'master' received, so we are slave now!
4219  iAmTheMaster = false;
4220 
4221  // show state in GUI
4222  gui->setLabelMasterSlave("Slave");
4223 
4224  gui->appendNetworkLog(QString("%1 received.").arg(command));
4225  gui->appendNetworkLog("I am the slave now.");
4226 
4227  // let the networkThread know this
4229  }
4230  else
4231  {
4232  firstDataReceived = true;
4233 
4234  // 'master' *not* received, so we are master now!
4235  iAmTheMaster = true;
4236 
4237  // show state in GUI
4238  gui->setLabelMasterSlave("Master");
4239 
4240  gui->appendNetworkLog(QString("%1 received.").arg(command));
4241  gui->appendNetworkLog("I am the master.");
4242 
4243  // we swap the ports back (to initial values) after listening for a network master
4244  netThread->swapPorts();
4245  }
4246  }
4247 
4248 
4249  // only react, when remote mode is activated in the GUI!
4250  if (robotRemoteMode==true)
4251  {
4252  if (command == "start")
4253  {
4254  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4255  drive(START);
4256  return;
4257  }
4258 
4259 
4260  if (command == "forward")
4261  {
4262  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4263  drive(FORWARD);
4264  return;
4265  }
4266 
4267 
4268  if (command == "backward")
4269  {
4270  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4271  drive(BACKWARD);
4272  return;
4273  }
4274 
4275 
4276  if (command == "stop")
4277  {
4278  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4279  drive(STOP);
4280  return;
4281  }
4282 
4283 
4284  if (command == "left")
4285  {
4286  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4287  drive(LEFT);
4288  return;
4289  }
4290 
4291 
4292  if (command == "right")
4293  {
4294  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4295  drive(RIGHT);
4296  return;
4297  }
4298 
4299 
4300  if (command == "increasespeedmotor1")
4301  {
4302  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4303 
4304  int newSpeed = motors->getMotorSpeed(1) + 1;
4305  motors->setMotorSpeed(1, newSpeed);
4306 
4307  if (!consoleMode)
4308  {
4309  settingsDialog->setSliderMotorSpeed(1, newSpeed);
4310  }
4311 
4312  return;
4313  }
4314 
4315 
4316  if (command == "increasespeedmotor2")
4317  {
4318  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4319 
4320  int newSpeed = motors->getMotorSpeed(2) + 1;
4321  motors->setMotorSpeed(2, newSpeed);
4322 
4323  if (!consoleMode)
4324  {
4325  settingsDialog->setSliderMotorSpeed(2, newSpeed);
4326  }
4327 
4328  return;
4329  }
4330 
4331 
4332  if (command == "reducespeedmotor1")
4333  {
4334  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4335 
4336  int newSpeed = motors->getMotorSpeed(1) - 1;
4337  motors->setMotorSpeed(1, newSpeed);
4338 
4339  if (!consoleMode)
4340  {
4341  settingsDialog->setSliderMotorSpeed(1, newSpeed);
4342  }
4343 
4344  return;
4345  }
4346 
4347 
4348  if (command == "reducespeedmotor2")
4349  {
4350  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4351 
4352  int newSpeed = motors->getMotorSpeed(2) - 1;
4353  motors->setMotorSpeed(2, newSpeed);
4354 
4355  if (!consoleMode)
4356  {
4357  settingsDialog->setSliderMotorSpeed(2, newSpeed);
4358  }
4359 
4360  return;
4361  }
4362 
4363  if (command == "shutdown")
4364  {
4365  emit message(tr("<font color=\"#0000FF\">Executing remote command \"%1\".</font>").arg(command));
4366  emit shutdown();
4367  return;
4368  }
4369  }
4370 }
4371 
4372 
4373 void Direcs::executeJoystickCommand(int axisNumber, int axisValue)
4374 {
4375  static unsigned char servo1Pos = servos->getServoPosition(SERVO1);
4376 
4377  //
4378  // Y axis
4379  //
4380  if (axisNumber == JOYSTICKAXISY2)
4381  {
4382  //------
4383  // down
4384  //------
4385  if (axisValue > 0)
4386  {
4387  //=========================================================
4388  // robot test drive mode
4389  // only drive, when activated and controlled via joystick!
4390  //=========================================================
4391  if (testDriveMode)
4392  {
4393  //
4394  // DRIVE backward
4395  //
4396 
4397  if (!consoleMode)
4398  {
4399  //speed = (axisValue / JOYSTICKDIVISOR);
4400  settingsDialog->setSliderMotorSpeed( 1, (axisValue / JOYSTICKDIVISOR) );
4401  settingsDialog->setSliderMotorSpeed( 2, (axisValue / JOYSTICKDIVISOR) );
4402  }
4403 
4404 // if (robotIsOn)
4405 // {
4406  motors->setMotorSpeed( 1, (axisValue / JOYSTICKDIVISOR) );
4407  motors->setMotorSpeed( 2, (axisValue / JOYSTICKDIVISOR) );
4408 
4409  if (robotDrives == false)
4410  {
4412  // drive(START);
4413  }
4414 
4415  drive(BACKWARD);
4416 // }
4417  }
4418 
4419 
4420  // ###############################################################################
4421  // disabled since the head is not in use use!
4422  // ###############################################################################
4423  //==================
4424  // eye test mode
4425  //==================
4426  if (eyeTestMode==true)
4427  {
4428  // eyes down
4431 
4434  }
4435 
4436  return;
4437  }
4438 
4439  //----
4440  // up
4441  //----
4442  if (axisValue < 0)
4443  {
4444  //=========================================================
4445  // robot test drive mode
4446  // only drive, when activated and controlled via joystick!
4447  //=========================================================
4448  if (testDriveMode)
4449  {
4450  //
4451  // DRIVE forward
4452  //
4453  if (!consoleMode)
4454  {
4455  //speed = (-axisValue / JOYSTICKDIVISOR);
4456  settingsDialog->setSliderMotorSpeed( 1, (-axisValue / JOYSTICKDIVISOR) );
4457  settingsDialog->setSliderMotorSpeed( 2, (-axisValue / JOYSTICKDIVISOR) );
4458  }
4459 
4460  motors->setMotorSpeed( 1, (-axisValue / JOYSTICKDIVISOR) );
4461  motors->setMotorSpeed( 2, (-axisValue / JOYSTICKDIVISOR) );
4462 
4463  if (robotDrives == false)
4464  {
4466  // drive(START);
4467  }
4468 
4469  drive(FORWARD);
4470  }
4471 
4472 
4473  // ###############################################################################
4474  // disabled since the head is not in use use!
4475  // ###############################################################################
4476  //==================
4477  // eye test mode
4478  //==================
4479  if (eyeTestMode==true)
4480  {
4481  // eyes down
4482  // left eye
4484  // right eye
4486 
4489  }
4490 
4491  return;
4492  }
4493 
4494  //------------------
4495  // STOP
4496  //------------------
4497  if (axisValue == 0)
4498  {
4499  //=========================================================
4500  // robot test drive mode
4501  // only drive, when activated and controlled via joystick!
4502  //=========================================================
4503  if (testDriveMode)
4504  {
4505  drive(WAIT);
4506  }
4507  return;
4508  }
4509  }
4510 
4511 
4512  //
4513  // X axis
4514  //
4515  if (axisNumber == JOYSTICKAXISX3)
4516  {
4517  //-------
4518  // right
4519  //-------
4520  if (axisValue > 0)
4521  {
4522  //=========================================================
4523  // robot test drive mode
4524  // only drive, when activated and controlled via joystick!
4525  //=========================================================
4526  if (testDriveMode)
4527  {
4528  //
4529  // DRIVE RIGHT
4530  //
4531  if (!consoleMode)
4532  {
4533  //speed = (axisValue / JOYSTICKDIVISOR);
4534  settingsDialog->setSliderMotorSpeed( 1, (axisValue / JOYSTICKDIVISOR) );
4535  settingsDialog->setSliderMotorSpeed( 2, (axisValue / JOYSTICKDIVISOR) );
4536  }
4537 
4538  motors->setMotorSpeed( 1, (axisValue / JOYSTICKDIVISOR) );
4539  motors->setMotorSpeed( 2, (axisValue / JOYSTICKDIVISOR) );
4540 
4541  if (robotDrives == false)
4542  {
4544  // drive(START);
4545  }
4546 
4547  drive(RIGHT);
4548  }
4549  return;
4550  }
4551 
4552  //------
4553  // left
4554  //------
4555  if (axisValue < 0)
4556  {
4557  //=========================================================
4558  // robot test drive mode
4559  // only drive, when activated and controlled via joystick!
4560  //=========================================================
4561  if (testDriveMode)
4562  {
4563  //
4564  // DRIVE left
4565  //
4566  if (!consoleMode)
4567  {
4568  //speed = (-axisValue / JOYSTICKDIVISOR);
4569  settingsDialog->setSliderMotorSpeed( 1, (-axisValue / JOYSTICKDIVISOR) );
4570  settingsDialog->setSliderMotorSpeed( 2, (-axisValue / JOYSTICKDIVISOR) );
4571  }
4572 
4573  motors->setMotorSpeed( 1, (-axisValue / JOYSTICKDIVISOR) );
4574  motors->setMotorSpeed( 2, (-axisValue / JOYSTICKDIVISOR) );
4575 
4576  if (robotDrives == false)
4577  {
4579  // drive(START);
4580  }
4581 
4582  drive(LEFT);
4583  }
4584  return;
4585  }
4586 
4587  //------------------
4588  // STOP
4589  //------------------
4590  if (axisValue == 0)
4591  {
4592  //=========================================================
4593  // robot test drive mode
4594  // only drive, when activated and controlled via joystick!
4595  //=========================================================
4596  if (testDriveMode)
4597  {
4598  drive(WAIT);
4599  }
4600  return;
4601  }
4602  }
4603 
4604 
4605  //
4606  // Y axis "buttons"
4607  //
4608  if (axisNumber == JOYSTICKAXISY5)
4609  {
4610  //==================
4611  // servo test mode
4612  //==================
4613  if (servoTestMode==true)
4614  {
4615  //------------------
4616  // servo down (servo2)
4617  //------------------
4618  if (axisValue > 0)
4619  {
4620  // --
4623  }
4624 
4625  //------------------
4626  // servo up (servo2)
4627  //------------------
4628  if (axisValue < 0)
4629  {
4630  // ++
4633  //servos->setServoPosition( currentTestServo, SVCURRENT, (servos->getServoPosition(currentTestServo))+1 );
4634  }
4635 
4636  // only move, when button is pressed - not, when released (=0)
4637  if (axisValue != 0)
4638  {
4640  emit message(QString("Servo %1 moved to %2.").arg(currentTestServo+1).arg(servos->getServoPosition(currentTestServo)));
4641  }
4642 
4643  return;
4644  }
4645 
4646 
4647 /*
4648  // ###############################################################################
4649  // disabled since this would use the motor 3 and 4 which are now in different use!
4650  // ###############################################################################
4651  //==================
4652  // camera test mode
4653  //==================
4654  if (cameraTestMode==true)
4655  {
4656  //------------------
4657  // camera up [tilt]
4658  //------------------
4659  if (axisValue > 0)
4660  {
4661  motors->motorControl(MOTOR4, ON, CLOCKWISE);
4662  //emit message("motor 4 on CW");
4663  }
4664 
4665  //------------------
4666  // camera down [tilt]
4667  //------------------
4668  if (axisValue < 0)
4669  {
4670  motors->motorControl(MOTOR4, ON, COUNTERCLOCKWISE);
4671  //emit message("motor 4 on CCW");
4672  }
4673 
4674  // move, when button is pressed
4675  if (axisValue != 0)
4676  {
4677  //emit message("Tilting Cam...");
4678  }
4679 
4680  // stop, when button is pressed!
4681  if (axisValue == 0)
4682  {
4683  //emit message("Tilt stop.");
4684  motors->motorControl(MOTOR4, OFF, SAME);
4685  }
4686  return;
4687  } // cam test mode [tilt]
4688 */
4689 
4690 /*
4691  // ###############################################################################
4692  // disabled since the head is not in use use!
4693  // ###############################################################################
4694  //==================
4695  // eye test mode
4696  //==================
4697  if (eyeTestMode==true)
4698  {
4699  //------------------
4700  // eyes down
4701  //------------------
4702  if (axisValue > 0)
4703  {
4704  head->look("DOWN");
4705  head->look("CURIOUS");
4706  }
4707 
4708  //------------------
4709  // eyes up
4710  //------------------
4711  if (axisValue < 0)
4712  {
4713  head->look("UP");
4714  head->look("ANGRY");
4715  }
4716 
4717  if (axisValue == 0)
4718  {
4719  }
4720  }
4721 */
4722 
4723  //==================
4724  // drive test mode
4725  //==================
4726  //------------------------------------------------------
4727  // drive backward (Y5 axis down/button down)
4728  //------------------------------------------------------
4729  if (axisValue > 0)
4730  {
4731  if (robotDrives == false)
4732  {
4734  // drive(START);
4735  }
4736 
4737  drive(BACKWARD);
4738  }
4739 
4740  //------------------------------------------------------
4741  // drive forward (Y5 axis/button up)
4742  //------------------------------------------------------
4743  if (axisValue < 0)
4744  {
4745  if (robotDrives == false)
4746  {
4748  // drive(START);
4749  }
4750 
4751  drive(FORWARD);
4752  }
4753 
4754  if (axisValue == 0)
4755  {
4756  drive(WAIT);
4757  }
4758 
4759  return;
4760  }
4761 
4762 
4763  //
4764  // X axis "buttons"
4765  //
4766  if (axisNumber == JOYSTICKAXISX4)
4767  {
4768  //==================
4769  // servo test mode
4770  //==================
4771  if (servoTestMode==true)
4772  {
4773  //------------------
4774  // servo right
4775  //------------------
4776  if (axisValue > 0)
4777  {
4778  servo1Pos++;
4779  }
4780 
4781  //------------------
4782  // servo left
4783  //------------------
4784  if (axisValue < 0)
4785  {
4786  servo1Pos--;
4787  }
4788 
4789  // only move, when button is pressed - not, when released (=0)
4790  if (axisValue != 0)
4791  {
4792  servos->moveServo(SERVO1, servo1Pos);
4793  emit message(QString("Servo 1 moved to %1.").arg(servo1Pos));
4794  }
4795  return;
4796  } // servo test mode
4797 
4798 /*
4799  // ###############################################################################
4800  // disabled since this would use the motor 3 and 4 which are now in different use!
4801  // ###############################################################################
4802  //==================
4803  // camera test mode
4804  //==================
4805  if (cameraTestMode==true)
4806  {
4807  //------------------
4808  // camera right [pan]
4809  //------------------
4810  if (axisValue > 0)
4811  {
4812  motors->motorControl(MOTOR3, ON, CLOCKWISE);
4813  //emit message("motor 3 on CW");
4814  }
4815 
4816  //------------------
4817  // camera left [pan]
4818  //------------------
4819  if (axisValue < 0)
4820  {
4821  motors->motorControl(MOTOR3, ON, COUNTERCLOCKWISE);
4822  //emit message("motor 3 on CCW");
4823  }
4824 
4825  // move, when button is pressed
4826  if (axisValue != 0)
4827  {
4828  //emit message("Panning Cam...");
4829  }
4830 
4831  // stop, when button is pressed!
4832  if (axisValue == 0)
4833  {
4834  motors->motorControl(MOTOR3, OFF, SAME);
4835  //emit message("Pan stop.");
4836  }
4837  return;
4838  } // cam test mode [pan]
4839 */
4840 
4841 /*
4842  // ###############################################################################
4843  // disabled since the head is not in use use!
4844  // ###############################################################################
4845  //==================
4846  // eye test mode
4847  //==================
4848  if (eyeTestMode==true)
4849  {
4850  //------------------
4851  // eyes right
4852  //------------------
4853  if (axisValue > 0)
4854  {
4855  head->look("RIGHT");
4856  }
4857 
4858  //------------------
4859  // eyes left
4860  //------------------
4861  if (axisValue < 0)
4862  {
4863  head->look("LEFT");
4864  }
4865 
4866  if (axisValue == 0)
4867  {
4868  }
4869  }
4870 */
4871 
4872  //==================
4873  // drive test mode
4874  //==================
4875  //------------------------------------------------------
4876  // drive right (X5 axis/button right)
4877  //------------------------------------------------------
4878  if (axisValue > 0)
4879  {
4880  if (mecanumDriveMode)
4881  {
4882  // moving to the right, without turning
4883  drive(RIGHT);
4884  }
4885  else
4886  {
4887  if (robotDrives == false)
4888  {
4890  // drive(START);
4891  }
4892 
4893  // do a right turn in a circle!
4894  drive(TURNRIGHT);
4895  }
4896  return;
4897  }
4898 
4899  //------------------------------------------------------
4900  // drive left (X5 axis/button left)
4901  //------------------------------------------------------
4902  if (axisValue < 0)
4903  {
4904  if (mecanumDriveMode)
4905  {
4906  // moving to the right, without turning
4907  drive(LEFT);
4908  }
4909  else
4910  {
4911  if (robotDrives == false)
4912  {
4914  // drive(START);
4915  }
4916 
4917  // do a left turn in a circle!
4918  drive(TURNLEFT);
4919  }
4920  return;
4921  }
4922 
4923  //------------------------------------------------------
4924  // wait (X5 axis/button)
4925  //------------------------------------------------------
4926  if (axisValue == 0)
4927  {
4928  drive(WAIT);
4929  }
4930 
4931  return;
4932  }
4933 }
4934 
4935 
4936 void Direcs::executeJoystickCommand(int buttonNumber, bool buttonState)
4937 {
4939  static bool toggle0 = false;
4940  static bool toggle1 = false;
4941  //static bool toggle2 = false;
4942  //static bool toggle3 = false;
4943  //static bool toggle4 = false;
4944  //static bool toggle5 = false;
4945  static bool toggle10 = false;
4946  static bool toggle11 = false;
4947 
4948 
4950  switch (buttonNumber)
4951  {
4952  case 0: // 1 on js
4953  if (buttonState==true)
4954  {
4955  if (toggle0 == false)
4956  {
4957  // ###############################################################################
4958  // disabled since the head is not in use use!
4959  // ###############################################################################
4960 // eyeTestMode=true;
4961 // emit message("<font color=\"#0000FF\">Eye test mode ON.</front>");
4962 // emit speak("Eye test mode.");
4963  }
4964  else
4965  {
4966  // ###############################################################################
4967  // disabled since the head is not in use use!
4968  // ###############################################################################
4969 // eyeTestMode=false;
4970 // head->look("FORWARD");
4971 // head->look("NORMAL");
4972 // emit message("<font color=\"#0000FF\">Eye test mode OFF.</front>");
4973 // emit speak("Eye test mode disabled.");
4974  }
4975  toggle0 = !toggle0;
4976  }
4977  break;
4978  case 1: // 2 on js
4979  if (buttonState==true)
4980  {
4981  if (toggle1 == false)
4982  {
4983  servoTestMode = true;
4984  emit message("<font color=\"#0000FF\">Servo test mode ON.</front>");
4985  emit message(QString("Servo %1 selected.").arg(currentTestServo+1));
4986  emit speak("Servo test mode");
4987  }
4988  else
4989  {
4990  servoTestMode = false;
4991  emit message("<font color=\"#0000FF\">Servo test mode OFF.</front>");
4992  emit speak("Servo test mode disabled");
4993  }
4994  toggle1 = !toggle1;
4995  }
4996  break;
4997  case 2: // 3 on js
4998  break;
4999  case 3: // 4 on js
5000  break;
5001  case 4: // 5 on js
5002  break;
5003  case 5: // 6 on js
5004  break;
5005  case 6: // 7 on js
5006  // left front button
5007  if (buttonState==true)
5008  {
5009  // servo test mode
5010  if (servoTestMode==true)
5011  {
5012  emit message(QString("Servo %1 selected.").arg((--currentTestServo)+1));
5013  }
5014  }
5015  break;
5016  case 7: // 8 on js
5017  // right front button
5018  if (buttonState==true)
5019  {
5020  // servo test mode
5021  if (servoTestMode==true)
5022  {
5023  emit message(QString("Servo %1 selected.").arg((++currentTestServo)+1));
5024  }
5025  }
5026  break;
5027  case 10:
5028  //
5029  // red button, right side
5030  //
5031  if (buttonState==true)
5032  {
5033  if (toggle10 == false)
5034  {
5035  mecanumDriveMode=true;
5036  emit message("<font color=\"#0000FF\">Mecanum test mode enabled.</front>");
5037  emit speak("Mecanum test mode.");
5038  }
5039  else
5040  {
5041  mecanumDriveMode=false;
5042  emit message("<font color=\"#0000FF\">Mecanum test mode disabled.</front>");
5043  emit speak("Mecanum test mode disabled.");
5044  }
5045  toggle10 = !toggle10;
5046  }
5047  break;
5048  case 11:
5049  //
5050  // button top, middle
5051  //
5052  if (buttonState==true)
5053  {
5054  if (toggle11 == false)
5055  {
5056  // ###############################################################################
5057  // disabled since this would use the motor 3 and 4 which are now in different use!
5058  // ###############################################################################
5059 // cameraTestMode = true;
5060 // emit message("<font color=\"#0000FF\">Camera test mode ON.</front>");
5061 // emit speak("Camerea test mode.");
5062  }
5063  else
5064  {
5065 // cameraTestMode = false;
5066 // emit message("<font color=\"#0000FF\">Camera test mode OFF.</front>");
5067 // emit speak("Camerea test mode disabled.");
5068  }
5069  toggle11 = !toggle11;
5070  }
5071  break;
5072  }
5073 }
5074 
5075 
5077 {
5078  return robotSimulationMode;
5079 }
5080 
5081 
5082 void Direcs::setSimulationMode(bool status)
5083 {
5084  robotSimulationMode = status;
5085 
5086  if (status == true)
5087  {
5088  emit message("<font color=\"#0000FF\">Simulation mode enabled!!</front>");
5089 
5090  if (laserThread->isRunning() == false)
5091  {
5092  emit message("Starting Laser thread...", false);
5093  laserThread->start();
5094  emit message("Started.");
5095  }
5096 
5097  if (sensorThread->isRunning() == false)
5098  {
5099  emit message("Starting Sensor thread...", false);
5100  sensorThread->start();
5101  emit message("Started.");
5102  }
5103 
5104 #ifndef BUILDFORROBOT
5105  if (!consoleMode)
5106  {
5107  if (plotThread->isRunning() == false)
5108  {
5109  emit message("Starting plot thread...", false);
5110  plotThread->start();
5111  emit message("Started.");
5112  }
5113  }
5114 #endif
5115 
5116  if (obstCheckThread->isRunning() == false)
5117  {
5118  emit message("Initializing obstacle check thread...", false);
5119  obstCheckThread->init();
5120  emit message("Initialized.");
5121  emit message("Starting obstacle check thread...", false);
5122  obstCheckThread->start();
5123  emit message("Started.");
5124  }
5125  }
5126  else
5127  {
5128  // FIXME: wozu das??? was ist mit dem plothread? merken welche geatartet waren? if robot is OFF stop all threads which read from the circuit!
5129 // if (robotIsOn == false)
5130 // {
5131 // sensorThread->stop();
5132 // emit message("Sensor thread stopped.");
5133 // }
5134  emit message("<font color=\"#0000FF\">Simulation mode disabled.</font>");
5135  }
5136 }
5137 
5138 
5139 /*
5140 void Direcs::setRobotState(bool state)
5141 {
5142  robotIsOn = state;
5143 }
5144 */
5145 
5146 
5148 {
5149  if (arguments.contains("console", Qt::CaseInsensitive))
5150  {
5151  consoleMode = true;
5153  qDebug("CONSOLE mode activated. Now passing all messages to the console.");
5154  }
5155 }
5156 
5157 
5158 void Direcs::nextDemoPhase(int phase)
5159 {
5160  static int iPhase = phase;
5161 
5162 
5163  if (demoMode)
5164  {
5165  emit message(QString("demo phase=%1").arg(iPhase));
5166 
5167  switch (phase)
5168  {
5169  // do some weird stuff here
5170  // mabye talk a bit
5171  // drive around for some seconds
5172  // blink
5173  case 1:
5174  // say something, next phase is no. 2
5175  emit speak("Hello Campuseros. I will introduce myself now for you guys. My name is direx 1. And I hope everything works fine now in the next minutes. Since Marcus updated my software yesterday night very late.", ++phase);
5176  break;
5177  case 2:
5178  // say something, next phase is no. 3
5179  emit speak("I am able of driving araound autonomically without hitting any obstacles. Well. Hopefully. I am using a laserscanner. and I can show my status with some R G B LEDs. I can also send my data over wireless network to show them on another laptop, or so.", ++phase);
5180  break;
5181  case 3:
5182  // say something, next phase is no. 3
5183  emit speak("But I do not want to bore you any longer. See me driving around and enjoy it. We should do some party now. The music is played by random. Because Sebastian complained that I played the same title all night long. So if the next song is still boring, Markus cann skip it on the touchscreen. Okay. lets go! Put your hands up in the air and wave them like you just dont care!", ++phase);
5184  break;
5185  case 4:
5186  // play some music
5187  mediaObject->play();
5188  break;
5189  case 5:
5190 /*
5191  if (mediaObject->state() == Phonon::PlayingState)
5192  {
5193  mediaObject->pause();
5194  }
5195 */
5196  break;
5197  default:
5198 // emit speak("Thanks you guys. Thats it.", -1);
5199  break;
5200  }
5201  }
5202 }
5203 
5204 
5205 void Direcs::setDemoMode(bool status)
5206 {
5207  // save state locally
5208  demoMode = status;
5209 
5210 
5211  if (status == true)
5212  {
5213  emit message("<font color=\"#0000FF\">Demo mode enabled!!</front>");
5214 
5215  if (demoThread->isRunning() == false)
5216  {
5217  emit message("Starting demo thread...", false);
5218  demoThread->start();
5219  emit message("Started.");
5220 
5221 emit speak("Okay, here we go.", 1);
5222 
5223  // play some music
5224 // mediaObject->play();
5225  }
5226  }
5227  else
5228  {
5229  emit message("<font color=\"#0000FF\">Demo mode disabled!!</front>");
5230 
5231  // stop the music
5232  if (mediaObject->state() == Phonon::PlayingState)
5233  {
5234  mediaObject->pause();
5235  }
5236 
5237  emit message("Stopping demo thread...", false);
5238  demoThread->stop();
5239  emit message("Stopped.");
5240  }
5241 }
5242 
5243 
5245 {
5246  int number = rand() % 6 +1; // (1 to 6)
5247 
5248 
5249  if (demoMode)
5250  {
5251  emit message(QString("Media player restart with file %1.").arg(number));
5252 
5254 // mediaObject->setCurrentSource(Phonon::MediaSource("../../../../dr.mp3"));
5255 // mediaObject->setCurrentSource(Phonon::MediaSource("../../../../media/MrRoboto.mp3"));
5256 #ifdef Q_OS_LINUX
5257  mediaObject->setCurrentSource(Phonon::MediaSource(QString("../../../../media/%1").arg(number)));
5258 #else
5259  mediaObject->setCurrentSource(Phonon::MediaSource(QString("../../../../media/%1.mp3").arg(number)));
5260 #endif
5261 
5262  // restart music, since the player finished
5263  mediaObject->play();
5264  }
5265 }
5266 
5267 
5268 void Direcs::systemerrorcatcher(int errorlevel)
5269 {
5270  switch (errorlevel)
5271  {
5272  case -1: // error with laserscanner thread
5273  if (robotDrives)
5274  {
5275  emit message("<font color=\"#0000FF\"Emergency stop due to laserscanner problems!/font>");
5276  logfile->appendLog("Emergency stop due to laserscanner problems!");
5277 
5278  // stop driving
5279  drive(STOP);
5280 
5281  // flashlight ON
5282  motors->flashlight(ON);
5283  }
5284  break;
5285 
5286  case -2: // error with sensor thread -> error in atmel read / write port!
5287  emit message("Error with sensor thread. Forcing shutdown when exitng direcs later (No last hardware init).");
5288  logfile->appendLog("Error with sensor thread. Forcing shutdown when exitng direcs later (No last hardware init).");
5289 #ifndef BUILDFORROBOT
5290  if (!consoleMode)
5291  {
5293  plotThread->stop();
5294  }
5295 #endif
5296  // force shutdown and do no circuit inits etc, when exiting direcs
5297  forceShutdown = true;
5298  break;
5299  }
5300 }
5301 
5302 
5303 void Direcs::drivingLight(unsigned char color)
5304 {
5305  switch (color)
5306  {
5307  case RED:
5314  break;
5315  case GREEN:
5322  break;
5323 
5324  case BLUE:
5331  break;
5332 
5333  case WHITE:
5340  break;
5341 
5342  case LEDOFF:
5349  break;
5350  }
5351 }
5352 
5353 
5355 {
5356 /*
5357  #ifdef Q_OS_LINUX
5358  Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource("../../../../dr.mp3"));
5359  #endif
5360 
5361  #ifdef Q_OS_MAC
5362  Phonon::MediaObject *music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource("../../../../dr.mp3"));
5363  #endif
5364 */
5365 
5366  /*
5367  if (mediaObject->state() != Phonon::PlayingState)
5368  {
5369  mediaObject->play();
5370  return;
5371  }
5372 
5373  if (mediaObject->state() == Phonon::PlayingState)
5374  {
5375  mediaObject->pause();
5376  return;
5377  }
5378 */
5379 
5380 // static bool toggle = false;
5381 
5382 
5383  speakThread->setLanguage("en");
5384  emit speak(tr("Hello world"));
5385  emit speak(tr("The voltage for battery %1 is %2 Volt. For battery %3 it is %4 Volt.").arg( 1 ).arg( sensorThread->getVoltage(VOLTAGESENSOR1) ).arg( 2 ).arg( sensorThread->getVoltage(VOLTAGESENSOR2) ));
5386 
5387 
5388 // toggle = !toggle;
5389 /*
5390  laserThread->setMeasureMode(toggle);
5391  emit message(QString("Measure mode = %1").arg(toggle));
5392 
5393 
5394  static int color = 0;
5395 
5396 
5397  if (color==0)
5398  {
5399  color++;
5400  drivingLight(RED);
5401  return;
5402  }
5403 
5404  if (color==1)
5405  {
5406  color++;
5407  drivingLight(GREEN);
5408  return;
5409  }
5410 
5411  if (color==2)
5412  {
5413  color++;
5414  drivingLight(BLUE);
5415  return;
5416  }
5417 
5418  if (color==3)
5419  {
5420  color++;
5421  drivingLight(WHITE);
5422  return;
5423  }
5424 
5425 
5426 
5427  if (color==4)
5428  {
5429  color++;
5430  rgbLeds->setBrightness(RGBLED1, MAXPWM);
5431  rgbLeds->setBrightness(RGBLED2, 1);
5432  rgbLeds->setBrightness(RGBLED3, 1);
5433 
5434  rgbLeds->setBrightness(RGBLED4, 1);
5435  rgbLeds->setBrightness(RGBLED5, MAXPWM);
5436  rgbLeds->setBrightness(RGBLED6, 1);
5437  return;
5438  }
5439 
5440  if (color==5)
5441  {
5442  color++;
5443  rgbLeds->setBrightness(RGBLED1, 1);
5444  rgbLeds->setBrightness(RGBLED2, MAXPWM);
5445  rgbLeds->setBrightness(RGBLED3, 1);
5446 
5447  rgbLeds->setBrightness(RGBLED4, 1);
5448  rgbLeds->setBrightness(RGBLED5, 1);
5449  rgbLeds->setBrightness(RGBLED6, MAXPWM);
5450  return;
5451  }
5452 
5453  if (color==6)
5454  {
5455  color++;
5456  rgbLeds->setBrightness(RGBLED1, 1);
5457  rgbLeds->setBrightness(RGBLED2, 1);
5458  rgbLeds->setBrightness(RGBLED3, MAXPWM);
5459 
5460  rgbLeds->setBrightness(RGBLED4, MAXPWM);
5461  rgbLeds->setBrightness(RGBLED5, 1);
5462  rgbLeds->setBrightness(RGBLED6, 1);
5463  return;
5464  }
5465 
5466  if (color==7)
5467  {
5468  color=0;
5469  drivingLight(LEDOFF);
5470  return;
5471  }
5472 */
5473 
5474 
5475 /*
5476  static bool toggle = OFF;
5477 
5478 
5479  if (toggle == OFF)
5480  {
5481  toggle = ON;
5482  //head->look("LEFT");
5483  emit sendNetworkString("ON");
5484 #ifdef Q_OS_LINUX // currently supported only under linux (no MAC OS at the moment)
5485  speakThread->setLanguage("en");
5486  //speakThread->setVoice(1, 200); // 1=male, 'age'=255
5487  // Say some text;
5488  QDateTime now = QDateTime::currentDateTime();
5489  emit speak(tr("Hello Markus. Today it's the %1 of %2, %3. The time is %4 %5.")
5490  .arg(now.toString("d"))
5491  .arg(now.toString("MMMM"))
5492  .arg(now.toString("yyyy"))
5493  .arg(now.toString("h"))
5494  .arg(now.toString("m")));
5495 #endif
5496  }
5497  else
5498  {
5499  toggle = OFF;
5500  emit sendNetworkString("OFF");
5501 
5502 #ifdef Q_OS_LINUX // currently supported only under linux (no MAC OS at the moment)
5503  speakThread->setLanguage("de");
5504  //speakThread->setVoice(2, 5); // 2=female, 'age'=5
5505  // Say some text;
5506  QDateTime now = QDateTime::currentDateTime();
5507  emit speak(tr("und das ganze geht auch auf Deutsch. Heute ist der %1te. %2, %3. Es ist jetzt %4 Uhr %5.")
5508  .arg(now.toString("d"))
5509  .arg(now.toString("MMMM"))
5510  .arg(now.toString("yyyy"))
5511  .arg(now.toString("h"))
5512  .arg(now.toString("m")));
5513 #endif
5514  }
5515  //head->look("RIGHT");
5516 
5517 
5518  motors->flashlight(toggle);
5519  */
5520 }