direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
obstacleCheckThread.h
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) Markus Knapp *
3  * www.direcs.de *
4  * *
5  * This file is part of direcs. *
6  * *
7  * direcs is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU General Public License as published *
9  * by the Free Software Foundation, version 3 of the License. *
10  * *
11  * direcs is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  *************************************************************************/
20 
21 #ifndef OBSTACLECHECKTHREAD_H
22 #define OBSTACLECHECKTHREAD_H
23 
24 //-------------------------------------------------------------------
25 #include "sensorThread.h"
26 #include "laserThread.h"
27 
28 #include <QTimer>
29 #include <QDateTime> // for the signal emit with a timestamp
30 #include <QThread>
31 //-------------------------------------------------------------------
32 
33 
34 // forward declarations because of circular includes!
35 class SensorThread;
36 
37 
49 class ObstacleCheckThread : public QThread
50 {
51  Q_OBJECT
52 
53  public:
56  void stop();
57  virtual void run();
58 
59 
60  public:
64  void init();
65 
66 
67  public slots:
71  void setSimulationMode(bool status);
72 
76  void setPassageWidth(int width);
77 
83  void setStraightForwardDeviation(int deviation);
84 
89  void setMinObstacleDistance(int distance);
90 
96  void setMinObstacleDistanceLaserFront(int distance);
97 
103  void setMinObstacleDistanceLaserRear(int distance);
104 
112  void setIgnoreArea(short int laser, int area, int start, int end);
113 
117  void systemerrorcatcher(int errorlevel);
118 
119 
120  signals:
126  void obstacleDetected(int sensors, QDateTime timestamp);
127 
135  void newDrivingAngleSet(int largestFreeAreaStart, int largestFreeAreaEnd, int centerOfFreeWay, float width);
136 
142  void message(QString text);
143 
144 
145  private:
155  double calculateDriveThroughWidth(short int laserscanner, int alpha, float b, float c);
156 
157 
158  QString className;
161  volatile bool stopped;
166  unsigned char sensorValue;
168 
171 
174 
179 
184 
189 
191 
193 
194  QList <int> freeStartAreas;
195  QList <int> freeEndAreas;
196 
198  static const int FREEWAY = 0;
199  static const int OBSTACLE = 1;
200  static const int LARGESTFREEWAY = 2;
201  static const int CENTEROFLARGESTFREEWAY = 3;
202  static const int IGNORETHIS = 4;
203 
207  static const int AREA1 = 1;
208  static const int AREA2 = 2;
209 
210  // Every thread sleeps some time, for having a bit more time fo the other threads!
211  // Time in milliseconds
212  static const unsigned long THREADSLEEPTIME = 50; // 250 ! original !
213 
214  // Give the sensors some names
215  //
216  // DONT CHANGE THIS NUMBERS!
217  // THEY ARE ALSO USED TO ADRESS THE ARRAY "iRSensorValue[]" !!
218  //
220  static const short int SENSOR1 = 1;
221  static const short int SENSOR2 = 2;
222  static const short int SENSOR3 = 4;
223  static const short int SENSOR4 = 8;
224  static const short int SENSOR5 = 16;
225  static const short int SENSOR6 = 32;
226  static const short int SENSOR7 = 64;
227  static const short int SENSOR8 = 128;
228 
229  // ultrasonic sensor
230  static const short int SENSOR16 = 256;
231 
233  static const short int OBSTACLEFRONTLEFT = 512;
234  static const short int OBSTACLEFRONTRIGHT = 1024;
235  static const short int OBSTACLESEVERYWHEREINFRONT = 2048;
236 
237  // Value if no sensor has a value to react
238  static const short int NONE = 0;
239 
240  // the laser scanners
241  static const short int LASER1 = 1;
242  static const short int LASER2 = 2;
243  static const short int LASER3 = 4;
244  static const short int LASER4 = 8;
245  static const short int LASER5 = 16;
246 };
247 
248 #endif