direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
servo.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 SERVO_H
22 #define SERVO_H
23 
24 //-------------------------------------------------------------------
25 #include "interfaceAvr.h"
26 //-------------------------------------------------------------------
27 #include <QThread>
28 #include <QMutex>
29 //-------------------------------------------------------------------
30 
31 
38 class Servo : public QObject
39 {
40  Q_OBJECT
41 
42  public:
43  Servo(InterfaceAvr *i, QMutex *m);
44  ~Servo();
45 
52  void setServoPosition(int servo, unsigned char type, unsigned char position);
53 
60  unsigned char getServoPosition(int servo, unsigned char type=SVCURRENT);
61 
62 
63  public slots:
70  bool moveServo(unsigned char servo, unsigned char position);
71 
75  void init(void);
76 
82  void setRobotState(bool state);
83 
84 
85  signals:
89  void message(QString text);
90 
91 
92  private:
93  QString className;
94  mutable QMutex *mutex; // make this class thread-safe
96  bool robotState; // stores the robot state within this class
97 
98  // Every thread sleeps some time, for having a bit more time fo the other threads!
99  // Time in milliseconds
100  static const unsigned long THREADSLEEPTIME = 100; // Default: 25 ms
101 
103  static const unsigned char NUMBEROFSERVOS = 6;
110  //int servoPositionConvHelper[NUMBEROFSERVOS]; //! a conversion helper, if the servo is fixed the other way round!
111 
112  static const bool ON = true;
113  static const bool OFF = false;
115 
116  static const unsigned char SVSTART = 0;
117  static const unsigned char SVEND = 1;
118  static const unsigned char SVDEFAULT = 2;
119  static const unsigned char SVCURRENT = 3;
120  static const unsigned char SVMIN = 4;
121  static const unsigned char SVMAX = 5;
122 
124  static const unsigned char SERVO1 = 0;
125  static const unsigned char SERVO2 = 1;
126  static const unsigned char SERVO3 = 2;
127  static const unsigned char SERVO4 = 3;
128  static const unsigned char SERVO5 = 4;
129  static const unsigned char SERVO6 = 5;
130 
132  static const unsigned char SET_SERVO1 = 42;
133  static const unsigned char SET_SERVO2 = 43;
134  static const unsigned char SET_SERVO3 = 44;
135  static const unsigned char SET_SERVO4 = 45;
136  static const unsigned char SET_SERVO5 = 46;
137  static const unsigned char SET_SERVO6 = 47;
138 };
139 
140 #endif